## Re: [Maxima-discuss] Assigning positions to an expression's parts

 Re: [Maxima-discuss] Assigning positions to an expression's parts From: Barton Willis - 2014-08-11 17:23:35 Attachments: Message as HTML ```Bugs (doesn't handle base case of recursion correctly?) (%i2) call_expr_tree(1); last: empty argument. #0: finalize_list(tt=[])(tree.mac line 14) OK: (%i3) call_expr_tree(a+b); (%o3) ["+",b,a] (%i4) x[1] : 5; (%o4) 5 Not OK (fix this with a local, I think) (%i5) call_expr_tree(a+b); first: argument must be a non-atomic expression; found 5 both curr_exp and final are global variables--I think you could greatly simplify your code and eliminate these globals too. ________________________________ From: Pankaj Sejwal Sent: Monday, August 11, 2014 05:35 To: maxima-discuss@...; Stavros Macrakis; Barton Willis; Richard Fateman Subject: Assigning positions to an expression's parts Hi, Recently there was discussion regarding assigning position to list elements but that method wasn't for expressions. I have written some new methods that shall address this problem, _______________________________ load(basic); /*------------*/ call_expr_tree(lis):=block([final:[],temp:[],count:0,curr_exp],expr_tree(lis), final:map(lambda([x],[cons(first(x[1]),last(x[1])),last(x)]),final),finalize_list(final))\$ /*------------*/ expr_tree(lis):=block([oper],if(atom(lis)=false) then (oper:op(lis),push([[oper,args(lis)],curr_exp],final),(for i:1 thru length(args(lis)) do (curr_exp:args(lis)[i], expr_tree(args(lis)[i]))))else lis)\$ /*------------*/ finalize_list(tt):=block(for item:1 thru length(tt) do ( for i:1 thru length(tt) do (for j:1 thru length(first(tt[i])) do (if(last(tt[item])=first(tt[i])[j]) then first(tt[i])[j]:tt[item][1]))), first(last(tt)))\$ /*------------*/ %in: call_expr_tree(a^2+b^3+c^4); %out: ["+",["^",c,4],["^",b,3],["^",a,2]] /*------------*/ %in: tt:call_expr_tree((z+y+k+ll)^4+a^2+b^3+c^4+sin(s+f)); %out: ["+",["^",["+",z,y,ll,k],4],[sin,["+",s,f]],["^",c,4],["^",b,3],["^",a,2]] ________________________________ This shall give a expression tree sort of output. I tried searching a lot but there is no example I could find that could tell how trees are represented in functional languages, though there are plenty of examples for c/java etc. So, I tried this approach. In case someone knows how trees are implemented in functional languages, please share some link/details. __________________________________ /*These methods were discussed earlier but I am keeping it here to prevent the effort of re-search(in case one tries). It also has a subtle difference than earlier usage */ /*------------*/ assign_positions(lis):=block([ltemp2:[],count:-1],for item in lis do if(listp(item)) then (push([assign_positions(item), [count:count+1]],ltemp2)) else (push([item,[count:count+1]],ltemp2)) ,reverse(ltemp2))\$ /*------------*/ call_from_inside(lis):=block([olast:[],temp:0,final:[]],olast:from_inside(lis),reverse(final))\$ /*------------*/ from_inside(lis):=block([count:0],for item in lis do (if(atom(first(item))) then (if(olast=[]) then (push(item,final)) else (push([first(item), flatten(endcons(last(item),reverse(olast))) ],final))) else (push(last(item),olast), from_inside(first(item)),pop(olast))))\$ ​/*------------*/ ​%in: call_from_inside(assign_positions(tt)); %out: [["+",[0]],["^",[1,0]],["+",[1,1,0]],[z,[1,1,1]],[y,[1,1,2]],[ll,[1,1,3]],[k,[1,1,4]],[4,[1,2]],[sin,[2,0]],["+",[2,1,0] ],[s,[2,1,1]],[f,[2,1,2]],["^",[3,0]],[c,[3,1]],[4,[3,2]],["^",[4,0]],[b,[4,1]],[3,[4,2]],["^",[5,0]],[a,[5,1]],[2,[5,2]]]​ /* To see if it rhymes with "part" addressing, expr:(z+y+k+ll)^4+a^2+b^3+c^4+sin(s+f); part(expr,2,1,2); => f part(expr,2,1,0); => + ___________________________________ Which shows that results are consistent. Here addressing it upto leaf level, so a user can easily make out what's maximum address available to be used. The output is "depth-first" and it shouldn't be difficult to read it "breadth-first" too based on positions. It can also help find other stats on tree say depth,size etc. Here count for assignment is from "0" because of operators enlisted in lists while in case of simple lists discussed earlier it is from 1 as "[" need not be enlisted separately. _____________________________________ /* Collecting subtrees from main tree */ call_collect_subtrees(lis):=block([temp:[]],collect_subtrees(lis),push(lis,temp))\$ /*------------*/ collect_subtrees(lis):=block(for item in lis do if(listp(item)) then (push(item,temp),collect_subtrees(item)) else push(item,temp))\$ /*------------*/ %in:: call_collect_subtrees(tt); %out:: [["+",["^",["+",z,y,ll,k],4],[sin,["+",s,f]],["^",c,4],["^",b,3],["^",a,2]],2,a,"^",["^",a,2],3,b,"^",["^",b,3],4,c,"^",["^",c,4],f,s,"+",["+", s,f],sin,[sin,["+",s,f]],4,k,ll,y,z,"+",["+",z,y,ll,k],"^",["^",["+",z,y,ll,k],4],"+"] /* This will help in checking tree membership and specially if someone implements pattern sort of functionality no need to recurse through tree every time. ______________________________________ /*After someone has made some changes to the list, there is need to regenerate the expression */ call_create_exp(lis):=block([count:0,prev:[],tt1:lis,n_tt1],prev:tt1, create_expr_outwards(tt1), while(prev#tt1) do (prev:tt1,create_expr_outwards(tt1)),tt1)\$ /*---------*/ create_expr_outwards(lis):=block([], if(listp(lis) and sublist(lis,listp)=[]) then tt1:subst(apply(first(lis),rest(lis)),lis,tt1) else (for item in lis do if(listp(item))then (create_expr_outwards(item))))\$ /*---------*/ %in :: f1:call_expr_tree(sin(x+y)*'integrate(x,x)) %out:: ["*",[integrate,x,x],[sin,["+",y,x]]] %in:: subst(call_expr_tree(cos(w+d+diff(tan(x),x))),call_expr_tree(y+x),f1); %out:: ["*",[integrate,x,x],[sin,[cos,["+",["^",[sec,x],2],w,d]]]] %in:: call_create_exp(%); %out:: integrate(x,x)*sin(cos(sec(x)^2+w+d)) ___________________________________________ I have been suggested at times to write in lisp but I find it problematic to add appropriate headers at places in lisp code to make it compatible to Maxima though I am trying. Please try these once and suggest improvements. I find these useful, can we use them in share with more modifications/additions needed? There could be an experimental code in share that users can contribute to and others can use at their own risk :P and suggest modifications !. -- ​-----​ Regards, Pankaj Sejwal ________________________________________ "The more I read, the more I acquire, the more certain I am that I know nothing.” - Voltaire ```

 [Maxima-discuss] Assigning positions to an expression's parts From: Pankaj Sejwal - 2014-08-11 10:35:55 Attachments: Message as HTML ```Hi, Recently there was discussion regarding assigning position to list elements but that method wasn't for expressions. I have written some new methods that shall address this problem, _______________________________ load(basic); /*------------*/ call_expr_tree(lis):=block([final:[],temp:[],count:0,curr_exp],expr_tree(lis), final:map(lambda([x],[cons(first(x[1]),last(x[1])),last(x)]),final),finalize_list(final))\$ /*------------*/ expr_tree(lis):=block([oper],if(atom(lis)=false) then (oper:op(lis),push([[oper,args(lis)],curr_exp],final),(for i:1 thru length(args(lis)) do (curr_exp:args(lis)[i], expr_tree(args(lis)[i]))))else lis)\$ /*------------*/ finalize_list(tt):=block(for item:1 thru length(tt) do ( for i:1 thru length(tt) do (for j:1 thru length(first(tt[i])) do (if(last(tt[item])=first(tt[i])[j]) then first(tt[i])[j]:tt[item][1]))), first(last(tt)))\$ /*------------*/ %in: call_expr_tree(a^2+b^3+c^4); %out: ["+",["^",c,4],["^",b,3],["^",a,2]] /*------------*/ %in: tt:call_expr_tree((z+y+k+ll)^4+a^2+b^3+c^4+sin(s+f)); %out: ["+",["^",["+",z,y,ll,k],4],[sin,["+",s,f]],["^",c,4],["^",b,3],["^",a,2]] ________________________________ This shall give a expression tree sort of output. I tried searching a lot but there is no example I could find that could tell how trees are represented in functional languages, though there are plenty of examples for c/java etc. So, I tried this approach. In case someone knows how trees are implemented in functional languages, please share some link/details. __________________________________ /*These methods were discussed earlier but I am keeping it here to prevent the effort of re-search(in case one tries). It also has a subtle difference than earlier usage */ /*------------*/ assign_positions(lis):=block([ltemp2:[],count:-1],for item in lis do if(listp(item)) then (push([assign_positions(item), [count:count+1]],ltemp2)) else (push([item,[count:count+1]],ltemp2)) ,reverse(ltemp2))\$ /*------------*/ call_from_inside(lis):=block([olast:[],temp:0,final:[]],olast:from_inside(lis),reverse(final))\$ /*------------*/ from_inside(lis):=block([count:0],for item in lis do (if(atom(first(item))) then (if(olast=[]) then (push(item,final)) else (push([first(item), flatten(endcons(last(item),reverse(olast))) ],final))) else (push(last(item),olast), from_inside(first(item)),pop(olast))))\$ ​/*------------*/ ​%in: call_from_inside(assign_positions(tt)); %out: [["+",[0]],["^",[1,0]],["+",[1,1,0]],[z,[1,1,1]],[y,[1,1,2]],[ll,[1,1,3]],[k,[1,1,4]],[4,[1,2]],[sin,[2,0]],["+",[2,1,0] ],[s,[2,1,1]],[f,[2,1,2]],["^",[3,0]],[c,[3,1]],[4,[3,2]],["^",[4,0]],[b,[4,1]],[3,[4,2]],["^",[5,0]],[a,[5,1]],[2,[5,2]]]​ /* To see if it rhymes with "part" addressing, expr:(z+y+k+ll)^4+a^2+b^3+c^4+sin(s+f); part(expr,2,1,2); => f part(expr,2,1,0); => + ___________________________________ Which shows that results are consistent. Here addressing it upto leaf level, so a user can easily make out what's maximum address available to be used. The output is "depth-first" and it shouldn't be difficult to read it "breadth-first" too based on positions. It can also help find other stats on tree say depth,size etc. Here count for assignment is from "0" because of operators enlisted in lists while in case of simple lists discussed earlier it is from 1 as "[" need not be enlisted separately. _____________________________________ /* Collecting subtrees from main tree */ call_collect_subtrees(lis):=block([temp:[]],collect_subtrees(lis),push(lis,temp))\$ /*------------*/ collect_subtrees(lis):=block(for item in lis do if(listp(item)) then (push(item,temp),collect_subtrees(item)) else push(item,temp))\$ /*------------*/ %in:: call_collect_subtrees(tt); %out:: [["+",["^",["+",z,y,ll,k],4],[sin,["+",s,f]],["^",c,4],["^",b,3],["^",a,2]],2,a,"^",["^",a,2],3,b,"^",["^",b,3],4,c,"^",["^",c,4],f,s,"+",["+", s,f],sin,[sin,["+",s,f]],4,k,ll,y,z,"+",["+",z,y,ll,k],"^",["^",["+",z,y,ll,k],4],"+"] /* This will help in checking tree membership and specially if someone implements pattern sort of functionality no need to recurse through tree every time. ______________________________________ /*After someone has made some changes to the list, there is need to regenerate the expression */ call_create_exp(lis):=block([count:0,prev:[],tt1:lis,n_tt1],prev:tt1, create_expr_outwards(tt1), while(prev#tt1) do (prev:tt1,create_expr_outwards(tt1)),tt1)\$ /*---------*/ create_expr_outwards(lis):=block([], if(listp(lis) and sublist(lis,listp)=[]) then tt1:subst(apply(first(lis),rest(lis)),lis,tt1) else (for item in lis do if(listp(item))then (create_expr_outwards(item))))\$ /*---------*/ %in :: f1:call_expr_tree(sin(x+y)*'integrate(x,x)) %out:: ["*",[integrate,x,x],[sin,["+",y,x]]] %in:: subst(call_expr_tree(cos(w+d+diff(tan(x),x))),call_expr_tree(y+x),f1); %out:: ["*",[integrate,x,x],[sin,[cos,["+",["^",[sec,x],2],w,d]]]] %in:: call_create_exp(%); %out:: integrate(x,x)*sin(cos(sec(x)^2+w+d)) ___________________________________________ I have been suggested at times to write in lisp but I find it problematic to add appropriate headers at places in lisp code to make it compatible to Maxima though I am trying. Please try these once and suggest improvements. I find these useful, can we use them in share with more modifications/additions needed? There could be an experimental code in share that users can contribute to and others can use at their own risk :P and suggest modifications !. -- ​-----​ Regards, Pankaj Sejwal ________________________________________ "The more I read, the more I acquire, the more certain I am that I know nothing.” - Voltaire ```
 Re: [Maxima-discuss] Assigning positions to an expression's parts From: Bill Wood - 2014-08-11 16:12:53 ```On Mon, 2014-08-11 at 16:05 +0530, Pankaj Sejwal wrote: > This shall give a expression tree sort of output. I tried searching a > lot but there is no example I could find that could tell how trees are > represented in functional languages, though there are plenty of "Purely Functional Data Structures" by Chris Okasaki is a good starting point. There is also a lot of information in "Handbook of Data Structures and Applications" by Mehta and Sahni. These are both academic sources, with a good bit of information about, and analysis of, space and time complexity. I think some of Okasaki's work has showed up in Haskell and ML libraries. Hope this helps. -- Bill Wood ```
 Re: [Maxima-discuss] Assigning positions to an expression's parts From: Barton Willis - 2014-08-11 17:23:35 Attachments: Message as HTML ```Bugs (doesn't handle base case of recursion correctly?) (%i2) call_expr_tree(1); last: empty argument. #0: finalize_list(tt=[])(tree.mac line 14) OK: (%i3) call_expr_tree(a+b); (%o3) ["+",b,a] (%i4) x[1] : 5; (%o4) 5 Not OK (fix this with a local, I think) (%i5) call_expr_tree(a+b); first: argument must be a non-atomic expression; found 5 both curr_exp and final are global variables--I think you could greatly simplify your code and eliminate these globals too. ________________________________ From: Pankaj Sejwal Sent: Monday, August 11, 2014 05:35 To: maxima-discuss@...; Stavros Macrakis; Barton Willis; Richard Fateman Subject: Assigning positions to an expression's parts Hi, Recently there was discussion regarding assigning position to list elements but that method wasn't for expressions. I have written some new methods that shall address this problem, _______________________________ load(basic); /*------------*/ call_expr_tree(lis):=block([final:[],temp:[],count:0,curr_exp],expr_tree(lis), final:map(lambda([x],[cons(first(x[1]),last(x[1])),last(x)]),final),finalize_list(final))\$ /*------------*/ expr_tree(lis):=block([oper],if(atom(lis)=false) then (oper:op(lis),push([[oper,args(lis)],curr_exp],final),(for i:1 thru length(args(lis)) do (curr_exp:args(lis)[i], expr_tree(args(lis)[i]))))else lis)\$ /*------------*/ finalize_list(tt):=block(for item:1 thru length(tt) do ( for i:1 thru length(tt) do (for j:1 thru length(first(tt[i])) do (if(last(tt[item])=first(tt[i])[j]) then first(tt[i])[j]:tt[item][1]))), first(last(tt)))\$ /*------------*/ %in: call_expr_tree(a^2+b^3+c^4); %out: ["+",["^",c,4],["^",b,3],["^",a,2]] /*------------*/ %in: tt:call_expr_tree((z+y+k+ll)^4+a^2+b^3+c^4+sin(s+f)); %out: ["+",["^",["+",z,y,ll,k],4],[sin,["+",s,f]],["^",c,4],["^",b,3],["^",a,2]] ________________________________ This shall give a expression tree sort of output. I tried searching a lot but there is no example I could find that could tell how trees are represented in functional languages, though there are plenty of examples for c/java etc. So, I tried this approach. In case someone knows how trees are implemented in functional languages, please share some link/details. __________________________________ /*These methods were discussed earlier but I am keeping it here to prevent the effort of re-search(in case one tries). It also has a subtle difference than earlier usage */ /*------------*/ assign_positions(lis):=block([ltemp2:[],count:-1],for item in lis do if(listp(item)) then (push([assign_positions(item), [count:count+1]],ltemp2)) else (push([item,[count:count+1]],ltemp2)) ,reverse(ltemp2))\$ /*------------*/ call_from_inside(lis):=block([olast:[],temp:0,final:[]],olast:from_inside(lis),reverse(final))\$ /*------------*/ from_inside(lis):=block([count:0],for item in lis do (if(atom(first(item))) then (if(olast=[]) then (push(item,final)) else (push([first(item), flatten(endcons(last(item),reverse(olast))) ],final))) else (push(last(item),olast), from_inside(first(item)),pop(olast))))\$ ​/*------------*/ ​%in: call_from_inside(assign_positions(tt)); %out: [["+",[0]],["^",[1,0]],["+",[1,1,0]],[z,[1,1,1]],[y,[1,1,2]],[ll,[1,1,3]],[k,[1,1,4]],[4,[1,2]],[sin,[2,0]],["+",[2,1,0] ],[s,[2,1,1]],[f,[2,1,2]],["^",[3,0]],[c,[3,1]],[4,[3,2]],["^",[4,0]],[b,[4,1]],[3,[4,2]],["^",[5,0]],[a,[5,1]],[2,[5,2]]]​ /* To see if it rhymes with "part" addressing, expr:(z+y+k+ll)^4+a^2+b^3+c^4+sin(s+f); part(expr,2,1,2); => f part(expr,2,1,0); => + ___________________________________ Which shows that results are consistent. Here addressing it upto leaf level, so a user can easily make out what's maximum address available to be used. The output is "depth-first" and it shouldn't be difficult to read it "breadth-first" too based on positions. It can also help find other stats on tree say depth,size etc. Here count for assignment is from "0" because of operators enlisted in lists while in case of simple lists discussed earlier it is from 1 as "[" need not be enlisted separately. _____________________________________ /* Collecting subtrees from main tree */ call_collect_subtrees(lis):=block([temp:[]],collect_subtrees(lis),push(lis,temp))\$ /*------------*/ collect_subtrees(lis):=block(for item in lis do if(listp(item)) then (push(item,temp),collect_subtrees(item)) else push(item,temp))\$ /*------------*/ %in:: call_collect_subtrees(tt); %out:: [["+",["^",["+",z,y,ll,k],4],[sin,["+",s,f]],["^",c,4],["^",b,3],["^",a,2]],2,a,"^",["^",a,2],3,b,"^",["^",b,3],4,c,"^",["^",c,4],f,s,"+",["+", s,f],sin,[sin,["+",s,f]],4,k,ll,y,z,"+",["+",z,y,ll,k],"^",["^",["+",z,y,ll,k],4],"+"] /* This will help in checking tree membership and specially if someone implements pattern sort of functionality no need to recurse through tree every time. ______________________________________ /*After someone has made some changes to the list, there is need to regenerate the expression */ call_create_exp(lis):=block([count:0,prev:[],tt1:lis,n_tt1],prev:tt1, create_expr_outwards(tt1), while(prev#tt1) do (prev:tt1,create_expr_outwards(tt1)),tt1)\$ /*---------*/ create_expr_outwards(lis):=block([], if(listp(lis) and sublist(lis,listp)=[]) then tt1:subst(apply(first(lis),rest(lis)),lis,tt1) else (for item in lis do if(listp(item))then (create_expr_outwards(item))))\$ /*---------*/ %in :: f1:call_expr_tree(sin(x+y)*'integrate(x,x)) %out:: ["*",[integrate,x,x],[sin,["+",y,x]]] %in:: subst(call_expr_tree(cos(w+d+diff(tan(x),x))),call_expr_tree(y+x),f1); %out:: ["*",[integrate,x,x],[sin,[cos,["+",["^",[sec,x],2],w,d]]]] %in:: call_create_exp(%); %out:: integrate(x,x)*sin(cos(sec(x)^2+w+d)) ___________________________________________ I have been suggested at times to write in lisp but I find it problematic to add appropriate headers at places in lisp code to make it compatible to Maxima though I am trying. Please try these once and suggest improvements. I find these useful, can we use them in share with more modifications/additions needed? There could be an experimental code in share that users can contribute to and others can use at their own risk :P and suggest modifications !. -- ​-----​ Regards, Pankaj Sejwal ________________________________________ "The more I read, the more I acquire, the more certain I am that I know nothing.” - Voltaire ```
 Re: [Maxima-discuss] Assigning positions to an expression's parts From: Pankaj Sejwal - 2014-08-12 03:21:14 Attachments: Message as HTML ```​Thanks for trying it and finding bugs. Fix to both these bugs is in the function being called. /*--------------*/ call_expr_tree(lis):=block([final:[],curr_exp], expr_tree(lis), if(final#[]) then (final:map(lambda([x], [cons(first(first(x)),last(first(x))),last(x)]),final), finalize_list(final)) else lis)\$ /*---------------*/ Initially I couldn't understand x[1] assignment bug until I realized that Maxima treats x[1] and first(x) differently. x[1] notation opens door to global assignment while first(x) will stay a read only operation. Its was something worth learning and subtle. Now, call_expr_tree(a+b); => ["+",a,b] x[1]:1\$ /*x[1] removed with first(x) and this assignment stays out of scope for the function.*/ On Mon, Aug 11, 2014 at 10:53 PM, Barton Willis wrote: > Bugs (doesn't handle base case of recursion correctly?) > > > (%i2) call_expr_tree(1); > last: empty argument. > #0: finalize_list(tt=[])(tree.mac line 14) > > > OK: > > (%i3) call_expr_tree(a+b); > (%o3) ["+",b,a] > > > (%i4) x[1] : 5; > (%o4) 5 > > > Not OK (fix this with a local, I think) > > (%i5) call_expr_tree(a+b); > first: argument must be a non-atomic expression; found > both curr_exp and final are global variables--I think you could *greatly *simplify > your code and eliminate these > > globals too. > ​ -- Regards, Pankaj Sejwal ____________________________________________ "The more I read, the more I acquire, the more certain I am that I know nothing.” - Voltaire ```
 Re: [Maxima-discuss] Assigning positions to an expression's parts From: Barton Willis - 2014-08-12 10:28:38 Attachments: Message as HTML ```You might try something like: (%i1) tree(e) := if mapatom(e) then e else(cons(op(e), map('tree,args(e))))\$ (%i2) tree(1); (%o2) 1 (%i3) tree(-x),inflag : true; (%o3) ["*",-1,x] (%i4) tree(-x),inflag : false; (%o4) ["-",x] (%i5) tree(x[1]); (%o5) x[1] --Barton ```
 Re: [Maxima-discuss] Assigning positions to an expression's parts From: Pankaj Sejwal - 2014-08-18 05:22:45 Attachments: Message as HTML ```this is a better approach, in fact the correct one !. But I had to do all the circus because I have learned mostly from documentation, there is not even a single example on "mapatom" in maxima doc so I didn't know its usage. There is a strong need to redocument some parts of official documentation. There have been some discussions in recent past but throughput wasn't shared/discussed ever after. On Tue, Aug 12, 2014 at 3:58 PM, Barton Willis wrote: > You might try something like: > > > (%i1) tree(e) := if mapatom(e) then e else(cons(op(e), > map('tree,args(e))))\$ > > > (%i2) tree(1); > (%o2) 1 > > > (%i3) tree(-x),inflag : true; > (%o3) ["*",-1,x] > > > (%i4) tree(-x),inflag : false; > (%o4) ["-",x] > > > (%i5) tree(x[1]); > (%o5) x[1] > > > > --Barton > > > -- Regards, Pankaj Sejwal _____________________________________________________________________ "The more I read, the more I acquire, the more certain I am that I know nothing.” - Voltaire ```
 Re: [Maxima-discuss] Assigning positions to an expression's parts From: Stavros Macrakis (Σταῦρος Μακράκης) - 2014-08-18 18:16:05 Attachments: Message as HTML ```​There's lots about our documentation that can be improved, but this particular case seems quite clear: Returns true if and only if expr is treated by the mapping routines as an atom. "Mapatoms" are atoms, numbers (including rational numbers), and subscripted variables. This seems ​pretty clear to me (especially in combination with the definition of atom). I'm not sure what examples would add, but... mapatom true: theta, %pi, 1, 1/2, 0.3, 0.3b0, a[i], "hello" mapatom false: iq+1, y^2, 2^(1/3), sin(q) all atoms are mapatoms some mapatoms are not atoms: 2/3, a[i] On Mon, Aug 18, 2014 at 1:21 AM, Pankaj Sejwal wrote: > this is a better approach, in fact the correct one !. But I had to do all > the circus because I have learned mostly from documentation, there is not > even a single example on "mapatom" in maxima doc so I didn't know its usage. > > There is a strong need to redocument some parts of official documentation. > There have been some discussions in recent past but throughput wasn't > shared/discussed ever after. > > > On Tue, Aug 12, 2014 at 3:58 PM, Barton Willis wrote: > >> You might try something like: >> >> >> (%i1) tree(e) := if mapatom(e) then e else(cons(op(e), >> map('tree,args(e))))\$ >> >> >> (%i2) tree(1); >> (%o2) 1 >> >> >> (%i3) tree(-x),inflag : true; >> (%o3) ["*",-1,x] >> >> >> (%i4) tree(-x),inflag : false; >> (%o4) ["-",x] >> >> >> (%i5) tree(x[1]); >> (%o5) x[1] >> >> >> >> --Barton >> >> >> > > > -- > Regards, > Pankaj Sejwal > _____________________________________________________________________ > "The more I read, the more I acquire, the more certain I am that I know > nothing.” - > Voltaire > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Maxima-discuss mailing list > Maxima-discuss@... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss > > ```
 Re: [Maxima-discuss] Assigning positions to an expression's parts From: Barton Willis - 2014-08-18 20:48:32 Attachments: Message as HTML ```In addition to the user documentation, you might like to work through some of the documents written by Ted Woolet: http://www.csulb.edu/~woollett/ , in particular, see Maxima by Example. -Barton ```
 Re: [Maxima-discuss] Assigning positions to an expression's parts From: Gunter Königsmann - 2014-08-20 05:44:22 Attachments: Message as HTML ```+1 from me for adding the following examples to the documentation knowing that the docu is a *reference manual* and actually quite big already: > mapatom true: theta, %pi, 1, 1/2, 0.3, 0.3b0, a[i], "hello" > mapatom false: iq+1, y^2, 2^(1/3), sin(q) > all atoms are mapatoms > some mapatoms are not atoms: 2/3, a[i] > Didn't know about a string being a mapatom (even if it feels completely logical once you know it and maxima always is good for suprising you by acting logical even where you wouldn't actually expect it) - and currently you need to have enough experience with atoms to instantly see the fact that 2/3 is a mapatom but not an atom when reading the manual entry for "mapatom". Kind regards, Gunter. ```
 Re: [Maxima-discuss] Assigning positions to an expression's parts From: Raymond Toy - 2014-08-18 16:57:53 ```>>>>> "Pankaj" == Pankaj Sejwal writes: Pankaj> this is a better approach, in fact the correct one !. But Pankaj> I had to do all the circus because I have learned mostly Pankaj> from documentation, there is not even a single example on Pankaj> "mapatom" in maxima doc so I didn't know its usage. If documentation is lacking or missing, please file a bug if you can. This doesn't mean it will get fixed, but at least it will be easier to find in the bug tracker than some random email message that also discusses other things. Ray ```