Joh's blog

Featuring the Dragonfly web framework
Locked

johu
Posts: 143
Joined: Mon Feb 08, 2010 8:47 am

Re: Joh's blog

Post by johu »

Thank you for the introduction, Kazimir Majorinc.
It's my blog.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: Joh's blog

Post by Lutz »

Version 10.2 will add an optional Boolean flag to the 'det' and 'invert' functions. Without the flag, both functions will return 'nil' on singular matrices as already described in the manual, but with flag either the old behavior is displayed:

Code: Select all

; in version 10.2.0
(det '((2 -1) (4 -2)))       ;=> nil

(det '((2 -1) (4 -2)) true)  ;=> -4e-20

(invert  '((2 -1) (4 -2))) ; nil

(invert  '((2 -1) (4 -2)) true)  ;=> ((5e+19 -2.5e+19) (1e+20 -5e+19))
Or maybe TINY in the C source should be redefined or even set to 0.0 as suggested by "Numerical recipes" as an alternative to 1.0e-20.

This would give us:

Code: Select all

; in version 10.2.0
> (det '((2 -1) (4 -2)) true)
-0
> (invert '((2 -1) (4 -2)) true)
((inf -inf) (inf -inf))
> 
What do you think?

ps: welcome to the newLISP community

johu
Posts: 143
Joined: Mon Feb 08, 2010 8:47 am

Re: Joh's blog

Post by johu »

Thanks for the proposal, Lutz.
I think that the first draft is good.
Being aware of the error of numerical calculation is required.
Then, although I thought the second idea, I had no confidence.
In the first draft, the correct result and correct recognition will be obtained.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: Joh's blog

Post by Lutz »

Thanks for your input Joh.

We will have a solution where you can optionally substitute the pivot element with a specific value. This way both solutions are possible.

Since 10.1.12 many situations throwing a "symbol reference not found" error have been eliminated, especially for 'setf'. See the following examples from your blog http://johu02.spaces.live.com/default.aspx (February 25th):

Your definition of 'nflat':

Code: Select all

(define-macro (nflat)
  (letex (_L (args 0))
    (setf _L (flat $it))))

(set 'l '(a ( b c) d))

(nflat l) ;=> (a b c d)

l ;=> (a b c d)

; throws "symbol ref error" on 10.1.7 but fine on 10.1.12
(nflat (map list '(1 2 (3 4 (5 6)))))  ;=> (1 2 3 4 5 6)
On 10.1.7 some destructive operations (i.e. 'setf') did not work on content not referenced from a symbol. This limitation has been eliminated in 10.1.12 for 10.2.0.

So the more complex definition of 'nflat' using 'quote?' is not necessary anymore.

The same is true for the 'nconc' (works like append) function on the same blog entry, which now works in the simpler definition:

Code: Select all

(define-macro (nconc)
  (letex (_L (args 0)
          _A (cons 'list (args)))
      (setf _L (apply append _A))))

; throws "symbol ref error" on 10.1.7 but fine on 10.1.12
(nconc '(1 2 3) '(3 4 5) '(a b c)) ;=> (1 2 3 3 4 5 a b c)

johu
Posts: 143
Joined: Mon Feb 08, 2010 8:47 am

Re: Joh's blog

Post by johu »

Thanks!

Probably, I understand. I will wait for 10.2.0.

And I will try the next code.

Code: Select all

(module "macro.lsp")
(macro (nflat L)
  (setf L (flat $it)))
Is it possible?

johu
Posts: 143
Joined: Mon Feb 08, 2010 8:47 am

Re: Joh's blog

Post by johu »

I download V10.1.12.
And I tried.

Code: Select all

newLISP v.10.1.12 on Win32 IPv4 UTF-8, execute 'newlisp -h' for more info.

> (module "macro.lsp")
MAIN
> (macro (nflat L) (setf L (flat $it)))
(lambda-macro (L) (expand '(setf L (flat $it))))
> (nflat (map list '(1 2 (3 4 (5 6)))))
(1 2 3 4 5 6)
> (let (lst (map list '(1 2 (3 4 (5 6))))) (nflat lst) lst)
(1 2 3 4 5 6)
> (let (lst (map list '(1 2 (3 4 (5 6))))) (nflat (lst 2)) lst)
((1) (2) (3 4 5 6))
It is very useful!

Locked