Discussion:
[Maxima-discuss] declare(antisymmetric) bug?
Stanislav Maslovski
2017-07-08 06:58:10 UTC
Permalink
Hi,

On maxima 5.39.0 on Android:

(%i1) display2d: false;

(%o1) false
(%i2) declare(mult,antisymmetric);

(%o2) done
(%i3) mult(a,b)+mult(b,a);

(%o3) 2*mult(a,b)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Robert Dodier
2017-07-08 20:15:15 UTC
Permalink
Post by Stanislav Maslovski
(%i2) declare(mult,antisymmetric);
(%o2) done
(%i3) mult(a,b)+mult(b,a);
(%o3) 2*mult(a,b)
Hmm. I don't see that with 5.39.0 + Clisp + Ubuntu nor with current
post-5.40 + Clisp + Ubuntu. I get 0 for mult(a,b)+mult(b,a).

What output do you get for [mult(a,b), mult(b,a)] ?
I get: [mult(a, b), - mult(a, b)]

best

Robert Dodier
Stanislav Maslovski
2017-07-09 06:33:18 UTC
Permalink
Hi,
Post by Robert Dodier
Post by Stanislav Maslovski
(%i2) declare(mult,antisymmetric);
(%o2) done
(%i3) mult(a,b)+mult(b,a);
(%o3) 2*mult(a,b)
Hmm. I don't see that with 5.39.0 + Clisp + Ubuntu nor with current
post-5.40 + Clisp + Ubuntu. I get 0 for mult(a,b)+mult(b,a).
What output do you get for [mult(a,b), mult(b,a)] ?
I get: [mult(a, b), - mult(a, b)]
Here is what I get:

Maxima 5.39.0 http://maxima.sourceforge.net
using Lisp ECL 16.1.3
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) display2d:false;

(%o1) false
(%i2) declare(mult,antisymmetric);

(%o2) done
(%i3) [mult(a,b),mult(b,a)];

(%o3) [mult(a,b),mult(a,b)]
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Robert Dodier
2017-07-09 19:55:47 UTC
Permalink
Post by Stanislav Maslovski
Maxima 5.39.0 http://maxima.sourceforge.net
using Lisp ECL 16.1.3
(%i2) declare(mult,antisymmetric);
(%o2) done
(%i3) [mult(a,b),mult(b,a)];
(%o3) [mult(a,b),mult(a,b)]
Hmm. With 5.39.0 + ECL 16.1.3 + Ubuntu 14.04 (32bit),
I get [mult(a, b), - mult(a, b)].

I see that mult(b, a) was reordered to mult(a, b) but the minus sign
somehow got lost.

What do you get if you do this:

declare(mult,antisymmetric);
:lisp (trace antisym antisym1 bbsort1 neg)
mult(b, a);

I get:

1> (ANTISYM (($MULT (0 "stdin" SRC)) $B $A) NIL)
| 2> (ANTISYM1 (($MULT (0 "stdin" SRC)) $B $A) NIL)
| 3> (BBSORT1 ($B $A))
| <3 (BBSORT1 ($A $B) T)
| 3> (NEG (($MULT SIMP (0 "stdin" SRC)) $A $B))
| <3 (NEG ((MTIMES SIMP) -1 (($MULT SIMP (0 "stdin" SRC)) $A $B)))
| <2 (ANTISYM1 ((MTIMES SIMP) -1 (($MULT SIMP (0 "stdin" SRC)) $A $B)))
<1 (ANTISYM ((MTIMES SIMP) -1 (($MULT SIMP (0 "stdin" SRC)) $A $B)))
(%o2) - mult(a, b)

In the past we've encountered differences between interpreted and
compiled code with ECL (this is a bug). I see ANTISYM is defined in
src/asum.lisp. If you load("asum.lisp"); and then try mult(b, a) do you
get the correct result?

best

Robert Dodier
Stanislav Maslovski
2017-07-10 12:48:21 UTC
Permalink
Hi,
Post by Stanislav Maslovski
declare(mult,antisymmetric);
:lisp (trace antisym antisym1 bbsort1 neg)
mult(b, a);
I get this:

Maxima 5.39.0 http://maxima.sourceforge.net
using Lisp ECL 16.1.3
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) display2d:false;

(%o1) false
(%i2) declare(mult,antisymmetric);

(%o2) done
(%i3) :lisp (trace antisym antisym1 bbsort1 neg);

(ANTISYM ANTISYM1 BBSORT1 NEG)
(%i3) mult(b, a);
1> (ANTISYM (($MULT (0 "stdin" SRC)) $B $A) NIL)
<1 (ANTISYM (($MULT SIMP (0 "stdin" SRC)) $A $B))
(%o3) mult(a,b)

Looks quite different from your trace below, indeed.
Post by Stanislav Maslovski
1> (ANTISYM (($MULT (0 "stdin" SRC)) $B $A) NIL)
| 2> (ANTISYM1 (($MULT (0 "stdin" SRC)) $B $A) NIL)
| 3> (BBSORT1 ($B $A))
| <3 (BBSORT1 ($A $B) T)
| 3> (NEG (($MULT SIMP (0 "stdin" SRC)) $A $B))
| <3 (NEG ((MTIMES SIMP) -1 (($MULT SIMP (0 "stdin" SRC)) $A $B)))
| <2 (ANTISYM1 ((MTIMES SIMP) -1 (($MULT SIMP (0 "stdin" SRC)) $A $B)))
<1 (ANTISYM ((MTIMES SIMP) -1 (($MULT SIMP (0 "stdin" SRC)) $A $B)))
(%o2) - mult(a, b)
In the past we've encountered differences between interpreted and
compiled code with ECL (this is a bug). I see ANTISYM is defined in
src/asum.lisp. If you load("asum.lisp"); and then try mult(b, a) do you
get the correct result?
This just says "file not found":

(%i4) load("asum.lisp");

file_search1: asum.lisp not found in file_search_maxima,file_search_lisp.
-- an error. To debug this try: debugmode(true);
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Robert Dodier
2017-07-11 05:13:58 UTC
Permalink
Post by Stanislav Maslovski
(%i3) mult(b, a);
1> (ANTISYM (($MULT (0 "stdin" SRC)) $B $A) NIL)
<1 (ANTISYM (($MULT SIMP (0 "stdin" SRC)) $A $B))
(%o3) mult(a,b)
Looks quite different from your trace below, indeed.
Yeah ... it appears that ANTISYM1 wasn't called. How did that happen?!

Here's something else to try.

:lisp (trace antisym antisym1 bbsort1 neg mnctimesp simpnct $atom)

and then declare(mult, antisymmetric); and mult(b, a); as before. What
do you get?
Post by Stanislav Maslovski
(%i4) load("asum.lisp");
file_search1: asum.lisp not found in file_search_maxima,file_search_lisp.
Are the source code files packaged with Maxima on Android? Does Android
have a file system in a Unix-ish or Windows-ish sense? If yes to both
questions, can you determine the actual location of asum.lisp and then
try load("/some/path/to/asum.lisp"); instead? Otherwise, I don't know
what to do. Maybe someone who knows about the Maxima package for Android
can suggest something.

best

Robert Dodier
Stanislav Maslovski
2017-07-11 18:41:37 UTC
Permalink
Hi,
Post by Robert Dodier
Yeah ... it appears that ANTISYM1 wasn't called. How did that happen?!
Here's something else to try.
:lisp (trace antisym antisym1 bbsort1 neg mnctimesp simpnct $atom)
and then declare(mult, antisymmetric); and mult(b, a); as before. What
do you get?
I get this:

(%i1) display2d:false;

(%o1) false
(%i2) :lisp (trace antisym antisym1 bbsort1 neg mnctimesp simpnct $atom);

(ANTISYM ANTISYM1 BBSORT1 NEG MNCTIMESP SIMPNCT $ATOM)
(%i2) declare(mult,antisymmetric);

(%o2) done
(%i3) mult(b,a);
1> (ANTISYM (($MULT (0 "stdin" SRC)) $B $A) NIL)
| 2> ($ATOM (($MULT (0 "stdin" SRC)) $B $A))
| <2 ($ATOM NIL)
<1 (ANTISYM (($MULT SIMP (0 "stdin" SRC)) $A $B))
(%o3) mult(a,b)
Post by Robert Dodier
Post by Stanislav Maslovski
(%i4) load("asum.lisp");
file_search1: asum.lisp not found in
file_search_maxima,file_search_lisp.
Are the source code files packaged with Maxima on Android? Does Android
have a file system in a Unix-ish or Windows-ish sense? If yes to both
questions, can you determine the actual location of asum.lisp and then
try load("/some/path/to/asum.lisp"); instead?
Android has a unix-like filesystem. The Maxima-related files are placed under this directory (as I guess based on the content of file_search_lisp variable):

/data/data/jp.yhonda/

Here is what I did. I defined a function:

find(s,f) := block([n,d], for n in directory(sconcat(s,f)) do print(n), for d in directory(sconcat(s,"*/")) do find(d,f));

And then ran it like this:

find("/data/data/jp.yhonda/","a*.lisp");

This produced this list of lisp source files starting with "a":

(%i20) find("/data/data/jp.yhonda/","a*.lisp");

/data/data/jp.yhonda/files/maxima-5.39.1/share/sym/arite.lisp
/data/data/jp.yhonda/files/maxima-5.39.1/share/contrib/noninteractive/asksign1.lisp

/data/data/jp.yhonda/files/maxima-5.39.1/share/contrib/altsimp/altsimp.lisp
/data/data/jp.yhonda/files/maxima-5.39.1/share/contrib/alt-display/alt-display.lisp

/data/data/jp.yhonda/files/maxima-5.39.1/share/colnew/lisp/appsln.lisp
/data/data/jp.yhonda/files/maxima-5.39.1/share/colnew/lisp/approx.lisp
/data/data/jp.yhonda/files/maxima-5.39.1/share/amatrix/amatrix.lisp
/data/data/jp.yhonda/files/maxima-5.39.1/share/affine/aquotient.lisp
/data/data/jp.yhonda/files/maxima-5.39.1/share/affine/amacros.lisp
/data/data/jp.yhonda/files/maxima-5.39.1/share/affine/affine.lisp
(%o20) done

There is no "asum.lisp" (or any "asum.*") though:

(%i21) find("/data/data/jp.yhonda/","asum.*");

(%o21) done
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Gunter Königsmann
2017-07-11 19:36:41 UTC
Permalink
Post by Stanislav Maslovski
(%i21) find("/data/data/jp.yhonda/","asum.*");
(%o21) done
Honda san managed to squeeze maxima into an astonishingly small package.
Maybe not including the source is one thing needed in order to do that...
Robert Dodier
2017-07-12 03:19:00 UTC
Permalink
Post by Stanislav Maslovski
(%i3) mult(b,a);
1> (ANTISYM (($MULT (0 "stdin" SRC)) $B $A) NIL)
| 2> ($ATOM (($MULT (0 "stdin" SRC)) $B $A))
| <2 ($ATOM NIL)
<1 (ANTISYM (($MULT SIMP (0 "stdin" SRC)) $A $B))
(%o3) mult(a,b)
Hmm. I'm really puzzled. I can't tell what's going on here.
Post by Stanislav Maslovski
find(s,f) := block([n,d], for n in directory(sconcat(s,f)) do print(n), for d in directory(sconcat(s,"*/")) do find(d,f));
find("/data/data/jp.yhonda/","a*.lisp");
Hey, that's really awesome. That seems like a useful function.

I have one more idea. Below I've pasted the relevant part of asum.lisp.
Can you save that to a file, say foo.lisp, and then: load("foo.lisp");
and then try the whole thing over.

best,

Robert Dodier

PS. Here's foo.lisp:
(defmfun antisym (e z)
(when (and $dotscrules (mnctimesp e))
(let ($dotexptsimp)
(setq e (simpnct e 1 nil))))
(if ($atom e) e (antisym1 e z)))

(defun antisym1 (e z)
(let ((antisym-sign nil)
(l (mapcar #'(lambda (q) (simpcheck q z)) (cdr e))))
(when (or (not (eq (caar e) 'mnctimes)) (freel l 'mnctimes))
(multiple-value-setq (l antisym-sign) (bbsort1 l)))
(cond ((equal l 0) 0)
((prog1
(null antisym-sign)
(setq e (oper-apply (cons (car e) l) t)))
e)
(t (neg e)))))

(defun bbsort1 (l)
(prog (sl sl1 antisym-sign)
(if (or (null l) (null (cdr l))) (return (values l antisym-sign))
(setq sl (list nil (car l))))
loop (setq l (cdr l))
(if (null l) (return (values (nreverse (cdr sl)) antisym-sign)))
(setq sl1 sl)
loop1(cond ((null (cdr sl1)) (rplacd sl1 (cons (car l) nil)))
((alike1 (car l) (cadr sl1)) (return (values 0 nil)))
((great (car l) (cadr sl1)) (rplacd sl1 (cons (car l) (cdr sl1))))
(t (setq antisym-sign (not antisym-sign) sl1 (cdr sl1)) (go loop1)))
(go loop)))
Stanislav Maslovski
2017-07-12 07:13:26 UTC
Permalink
Hi,
Post by Robert Dodier
I have one more idea. Below I've pasted the relevant part of asum.lisp.
Can you save that to a file, say foo.lisp, and then: load("foo.lisp");
and then try the whole thing over.
Congrats! This worked:

Maxima 5.39.0 http://maxima.sourceforge.net
using Lisp ECL 16.1.3
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) display2d:false;

(%o1) false
(%i2) load("foo.lisp");

(%o2) "/sdcard/Download/foo.lisp"
(%i3) :lisp (trace antisym antisym1 bbsort1 neg mnctimesp simpnct $atom);

(ANTISYM ANTISYM1 BBSORT1 NEG MNCTIMESP SIMPNCT $ATOM)
(%i3) declare(mult,antisymmetric);

(%o3) done
(%i4) mult(b,a);
1> (ANTISYM (($MULT (0 "stdin" SRC)) $B $A) NIL)
| 2> ($ATOM (($MULT (0 "stdin" SRC)) $B $A))
| <2 ($ATOM NIL)
| 2> (ANTISYM1 (($MULT (0 "stdin" SRC)) $B $A) NIL)
| 3> (BBSORT1 ($B $A))
| <3 (BBSORT1 ($A $B) T)
| 3> (NEG (($MULT SIMP (0 "stdin" SRC)) $A $B))
| <3 (NEG ((MTIMES SIMP) -1 (($MULT SIMP (0 "stdin" SRC)) $A $B)))
| <2 (ANTISYM1 ((MTIMES SIMP) -1 (($MULT SIMP (0 "stdin" SRC)) $A $B)))
<1 (ANTISYM ((MTIMES SIMP) -1 (($MULT SIMP (0 "stdin" SRC)) $A $B)))
(%o4) -mult(a,b)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Robert Dodier
2017-07-13 04:45:49 UTC
Permalink
Post by Stanislav Maslovski
(%i2) load("foo.lisp");
(%o2) "/sdcard/Download/foo.lisp"
(%i3) :lisp (trace antisym antisym1 bbsort1 neg mnctimesp simpnct $atom);
(ANTISYM ANTISYM1 BBSORT1 NEG MNCTIMESP SIMPNCT $ATOM)
(%i3) declare(mult,antisymmetric);
(%o3) done
(%i4) mult(b,a);
1> (ANTISYM (($MULT (0 "stdin" SRC)) $B $A) NIL)
| 2> ($ATOM (($MULT (0 "stdin" SRC)) $B $A))
| <2 ($ATOM NIL)
| 2> (ANTISYM1 (($MULT (0 "stdin" SRC)) $B $A) NIL)
| 3> (BBSORT1 ($B $A))
| <3 (BBSORT1 ($A $B) T)
| 3> (NEG (($MULT SIMP (0 "stdin" SRC)) $A $B))
| <3 (NEG ((MTIMES SIMP) -1 (($MULT SIMP (0 "stdin" SRC)) $A $B)))
| <2 (ANTISYM1 ((MTIMES SIMP) -1 (($MULT SIMP (0 "stdin" SRC)) $A $B)))
<1 (ANTISYM ((MTIMES SIMP) -1 (($MULT SIMP (0 "stdin" SRC)) $A $B)))
(%o4) -mult(a,b)
OK, that's good, unfortunately this is fairly bad news. It appears that
the problem is that the compiled Lisp code (which is run when you
execute the binary) is different from the interpreted code (which is run
when you load the Lisp file and then call the function). That's a
serious bug in the compiler (ECL in this case).

Can you run_testsuite(); (without loading foo.lisp)? Do you get any
test failures?

Maxima is not the most reliable program to begin with, and incorrect
code just makes it worse ...

best,

Robert Dodier
Stanislav Maslovski
2017-07-13 17:58:54 UTC
Permalink
Hi,
Post by Robert Dodier
Can you run_testsuite(); (without loading foo.lisp)? Do you get any
test failures?
Unfortunately, in Maxima on Android the test suite seems to be stripped off:

(%i1) run_testsuite();

Maxima encountered a Lisp error:

Filesystem error with pathname #P"/data/user/0/jp.yhonda/files/maxima-5.39.1/tests/testsuite.lisp".
Either
1) the file does not exist, or
2) we are not allowed to access the file, or
3) the pathname points to a broken symbolic link.

Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.
Post by Robert Dodier
Maxima is not the most reliable program to begin with, and incorrect
code just makes it worse ...
Maybe Y. Honda will read this thread and find some workaround? Maybe another compiler can be used on Android. In any case, I've added a bug report to his repo on github referring to the discussion on this mailing list.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Loading...