Joh's blog

Started by Kazimir Majorinc, February 24, 2010, 05:44:52 PM

Previous topic - Next topic

Kazimir Majorinc

http://johu02.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&_c=BlogPart&partqs=cat%3DLISP">http://johu02.spaces.live.com/?_c11_Blo ... cat%3dLISP">http://johu02.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&_c=BlogPart&partqs=cat%3dLISP
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

johu

#1
Thank you for the introduction, Kazimir Majorinc.

It's my blog.

Lutz

#2
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:


; 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:


; 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

#3
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

#4
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">http://johu02.spaces.live.com/default.aspx (February 25th):



Your definition of 'nflat':


(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:


(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

#5
Thanks!



Probably, I understand. I will wait for 10.2.0.



And I will try the next code.


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

Is it possible?

johu

#6
I download V10.1.12.

And I tried.


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!