rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

Error on compiling a working maxima function #1140

Closed rtoy closed 3 months ago

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-04 00:47:54 Created by pankajsejwal on 2016-01-29 05:29:43 Original: https://sourceforge.net/p/maxima/bugs/3083


This method works fine on wxmaxima but it maxima gives error on compiling it,

ordersort(lis,vars,oper):=block([negsumdispflag:false,liss:lis,varlist:vars,temp], /*Does lexicographical sort */
for i:1 thru length(varlist) do (
    for j:1 thru i do (
        liss:sort(liss,lambda([x,y],apply("and",map(oper,makelist(part(x,2)[k],k,1,i)
                            ,makelist(part(y,2)[k],k,1,i)))))
    )),liss)$

ordersort([[-7,[0,2,1]],[3,[1,2,1]],[1,[0,4,1]],[6,[4,3,3]],[6,[4,4,3]],[-7,[3,5,4]],[2,[0,0,5]],[-10,[2,2,5]],[-10,[3,4,7]],[7,[3,8,9]]],[x,y,z],">=");

Giving output : [[6,[4,4,3]],[6,[4,3,3]],[7,[3,8,9]],[-7,[3,5,4]],[-10,[3,4,7]],[-10,[2,2,5]],[3,[1,2,1]],[1,[0,4,1]],[-7,[0,2,1]],[2,[0,0,5]]]

here each entry is a polynomial say of x,y,z represented as [coefficient,[power_of_x,power_of_y,power_of_z]]​ and I need to do lexicographical sort. Last entry is the comparison operator.

Comment from Robert Dodier: It appears the error comes from FREE-LISP-VARS in src/trans3.lisp. The problem occurs when its argument is a Lisp quasi-quote expression, i.e. something like

`((foo) ,@(bar baz))

The representation is implementation-dependent and FREE-LISP-VARS is happy in Clisp but not in SBCL. I didn't check other Lisps.

The quasi-quotes are generated from "for" expressions in src/trans1.lisp. I see there are four places where quasi-quotes are emitted. These are actually nested quasi-quotes, i.e. s.t. like

`(mumble `(blurf ...))

I have to wonder what's going on there. Probably the code could be clearer if some other construction were used for the interior quasi-quotes, and that would make the error in FREE-LISP-VARS go away too.

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-04 00:47:56 Created by robert_dodier on 2016-02-02 07:36:52 Original: https://sourceforge.net/p/maxima/bugs/3083/#ca2d


Diff:


--- old
+++ new
@@ -1,5 +1,6 @@
 This method works fine on wxmaxima but it maxima gives error on compiling it,

+~~~~
 ordersort(lis,vars,oper):=block([negsumdispflag:false,liss:lis,varlist:vars,temp], /*Does lexicographical sort */
 for i:1 thru length(varlist) do (
     for j:1 thru i do (
@@ -8,23 +9,30 @@
     )),liss)$

 ordersort([[-7,[0,2,1]],[3,[1,2,1]],[1,[0,4,1]],[6,[4,3,3]],[6,[4,4,3]],[-7,[3,5,4]],[2,[0,0,5]],[-10,[2,2,5]],[-10,[3,4,7]],[7,[3,8,9]]],[x,y,z],">=");
+~~~~

-Giving output : [[6,[4,4,3]],[6,[4,3,3]],[7,[3,8,9]],[-7,[3,5,4]],[-10,[3,4,7]],[-10,[2,2,5]],[3,[1,2,1]],[1,[0,4,1]],[-7,[0,2,1]],[2,[0,0,5]]]
+Giving output : `[[6,[4,4,3]],[6,[4,3,3]],[7,[3,8,9]],[-7,[3,5,4]],[-10,[3,4,7]],[-10,[2,2,5]],[3,[1,2,1]],[1,[0,4,1]],[-7,[0,2,1]],[2,[0,0,5]]]`

 here each entry is a polynomial say of x,y,z represented as [coefficient,[power_of_x,power_of_y,power_of_z]]​ and I need to do lexicographical sort. Last entry is the comparison operator.

 Comment from Robert Dodier:
 It appears the error comes from FREE-LISP-VARS in src/trans3.lisp. The
 problem occurs when its argument is a Lisp quasi-quote expression, i.e.
-something like `((foo) ,@(bar baz)).
-`The representation is
+something like 
+~~~~
+`((foo) ,@(bar baz))
+~~~~
+The representation is
 implementation-dependent and FREE-LISP-VARS is happy in Clisp but not in
 SBCL. I didn't check other Lisps.

 The quasi-quotes are generated from "for" expressions in
 src/trans1.lisp. I see there are four places where quasi-quotes are
 emitted. These are actually nested quasi-quotes, i.e. s.t. like
-`(mumble `(blurf ...)). I have to wonder what's going on there. Probably
+~~~~
+`(mumble `(blurf ...))
+~~~~
+I have to wonder what's going on there. Probably
 the code could be clearer if some other construction were used for the
 interior quasi-quotes, and that would make the error in FREE-LISP-VARS
 go away too.
rtoy commented 3 months ago

Imported from SourceForge on 2024-07-04 00:47:59 Created by robert_dodier on 2016-02-02 07:36:53 Original: https://sourceforge.net/p/maxima/bugs/3083/#6d7f


The problematic code is actually in the translation for makelist, not for.

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-04 00:48:03 Created by robert_dodier on 2016-02-02 07:43:27 Original: https://sourceforge.net/p/maxima/bugs/3083/#c100


rtoy commented 3 months ago

Imported from SourceForge on 2024-07-04 00:48:06 Created by robert_dodier on 2016-02-02 07:43:28 Original: https://sourceforge.net/p/maxima/bugs/3083/#1d82


Fixed by commit b8dae39. Closing this report accordingly.