|
From: Richard F. <fa...@gm...> - 2024-10-29 04:05:25
|
I find that displaying lisp structure in pretty-printed form has much to
recommend it over trying to show trees as graphs with links.
To display a maxima expression in pretty-print form, though with
some abbreviations, consider this program..
...............ppshort.lisp
(defun shorten(r) ;; make maxima general form expression more lisp-like
(cond ((atom r) r)
(t (cons (caar r)(mapcar #'shorten (cdr r))))))
(defun shortmore(r)
(cond ((atom r)(shortatom r))
(t (mapcar #'shortmore r))))
(defun shortatom(r)
(cond
((eq r 'mtimes) '*)
((eq r 'mplus) '+)
((eq r 'mexpt) '^) ;;; etc
(t r)))
(defun $pp(r)(pprint(shortmore (shorten r))))
;; end of program...............
As an example. consider q:ratsimp((a+b+c+1)^10)$
which is kind of large. pp(q) shows its structure ... here are the first
few lines
displayed.. Note carefully the indentation, which shows the tree structure..
(+ 1 (* 10 $A) (* 45 (^ $A 2)) (* 120 (^ $A 3)) (* 210 (^ $A 4))
(* 252 (^ $A 5)) (* 210 (^ $A 6)) (* 120 (^ $A 7)) (* 45 (^ $A 8))
(* 10 (^ $A 9)) (^ $A 10)
(*
(+ 10 (* 90 $A) (* 360 (^ $A 2)) (* 840 (^ $A 3)) (* 1260 (^ $A 4))
(* 1260 (^ $A 5)) (* 840 (^ $A 6)) (* 360 (^ $A 7)) (* 90 (^ $A 8))
(* 10 (^ $A 9)))
$B)
(*
(+ 45 (* 360 $A) (* 1260 (^ $A 2)) (* 2520 (^ $A 3)) (* 3150 (^ $A 4))
(* 2520 (^ $A 5)) (* 1260 (^ $A 6)) (* 360 (^ $A 7)) (* 45 (^ $A 8)))
(^ $B 2))
....
>
>
>
|