From: Stavros M. <mac...@gm...> - 2024-10-30 18:30:28
|
When I was learning Lisp -- a very long time ago -- I found diagrams like this useful for two purposes: *1. Understanding structures with shared substructures.* Maxima does use substructure sharing, but it has very few destructive operations. So a beginner at Maxima (especially if they don't have a Lisp background) might have trouble understanding this: l1: [a,b,c]$ l2: [d,e,f]$ lll: append(l1,[l1],[l2],l2) => [a, b, c, [a, b, c], [d, e, f], d, e, f] l1[2]:bbb$ l2[2]:eee$ l1 => [a, bbb, c] l2 => [d, eee, f] lll => [a, b, c, [a, bbb, c], [d, eee, f], d, eee, f] But it isn't necessary to explain this with box <https://www.gnu.org/software/emacs/manual/html_node/elisp/Box-Diagrams.html> diagrams <https://www.gnu.org/software/emacs/manual/html_node/elisp/Box-Diagrams.html> or tree diagrams. It's enough to note that *append* shares its final argument's representation with the result of *append*. In any case, to diagram this, you need graph-structured (not tree-structured) displays, which you don't support. 2. *Working out clever in-place algorithms* ... such as *nreverse*, which uses *rplacd* (See Steele's paper <https://bitsavers.trailing-edge.com/pdf/mit/ai/aim/AIM-587.pdf> for an example which is even more complicated, because he is working with cdr-coded data <https://en.wikipedia.org/wiki/CDR_coding>.). Using box diagrams for this can be helpful. But Maxima has nothing like *rplacd*. On Mon, Oct 28, 2024 at 8:42 PM Eduardo Ochs <edu...@gm...> wrote: > Hi Barton, > > you are right - the conversion from "Maxima objects" to "Maxima trees" > is done in Maxima, by the functions in lisptree.mac whose names > start with "lisptree0". Try: > > load("/tmp/lisptree/lisptree.mac"); > block([inflag:true], lisptree(a/b)); > block([inflag:false], lisptree(a/b)); > block([inflag:true], lisptree0(a/b)); /* [*,a,[^,b,-1]] */ > block([inflag:false], lisptree0(a/b)); /* [/,a,b] */ > > The function `lisptree0_apatom' calls `args', and if I remember > correctly it is `args' that chooses between the representations a/b > and a*b^-1 depending on the value of `inflag'... anyway, I just saw > that it would be useful to have functions that generate trees like > this one > > MTIMES__. > | | > $A MEXPT__. > | | > $B -1 > > from Maxima objects like a/b, i.e., > > ((MTIMES SIMP) $A ((MEXPT SIMP) $B -1)) > > Here is a prototype. Run this in a REPL: > > load("/tmp/lisptree/lisptree.mac"); > block([inflag:true], lisptree(a/b)); > block([inflag:false], lisptree(a/b)); > block([inflag:true], format0(a/b)); > block([inflag:false], format0(a/b)); > o : a/b; > to_lisp(); > #$o$ > > (defun newsimplify (o) > (if (and (consp o) (consp (car o))) > `(,(caar o) ,@(map 'list #'newsimplify (cdr o))) > o)) > (defun $new2dtree_ (o) > (lisptree::toplain-lines (lisptree::lispytree (newsimplify o)))) > (defun $new2dtree (o) > (format nil "~%~a" ($new2dtree_ o))) > > ($new2dtree_ #$o$) > ($new2dtree #$o$) > (to-maxima) > > new2dtree(o); > > Here the output of its last line is this 2D tree: > > MTIMES__. > | | > $A MEXPT__. > | | > $B -1 > > Cheers, thanks for testing, more in other messages, etc, > Eduardo > > > On Mon, 28 Oct 2024 at 13:32, Eduardo Ochs <edu...@gm...> wrote: > >> Hi Barton! >> >> I forgot to test it with inflag! I will do that very soon... >> >> I don't know how to use WxMaxima for non-trivial things. Anyone has >> any idea of how to make it print multiline strings using a monospaced >> font? >> >> Cheers! >> Eduardo >> >> >> On Mon, 28 Oct 2024 at 12:13, Barton Willis <wi...@un...> wrote: >> >>> Thanks for your contribution. >>> >>> Question: Am I correct that lisptree displays the internal structure >>> when 'inflag' is true and otherwise shows the displayed structure? These >>> examples work okay: >>> >>> >>> (%i28) block([inflag : true], lisptree(a/b)); >>> (%o28) >>> *__. >>> | | >>> a ^__. >>> | | >>> b -1 >>> >>> (%i29) block([inflag : false], lisptree(a/b)); >>> (%o29) >>> /__. >>> | | >>> a b >>> (%i30) >>> >>> _______________________________________________ > Maxima-discuss mailing list > Max...@li... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss > |