From: Eduardo O. <edu...@gm...> - 2024-07-12 07:12:37
|
Hi list, "op" and "args" don't distinguish between a(b) and a[b]: (%i1) [o:a(b),op(o),args(o)]; (%o1) [a(b), a, [b]] (%i2) [o:a[b],op(o),args(o)]; (%o2) [a , a, [b]] b (%i3) what do I need to use to distinguish them? Why I'm asking: there are several kinds of expressions that this program - <http://anggtwu.net/eev-maxima.html#luatree> - doesn't handle well... I'm trying to fix it. Thanks in advance! Eduardo =) |
From: Barton W. <wi...@un...> - 2024-07-12 09:21:57
|
Try using subvarp; for example (%i3) subvarp(a[b]); (%o3) true (%i4) subvarp(a(b)); (%o4) false The user documentation: Function: subvarp (expr) Returns true if expr is a subscripted variable, for example a[i]. --Barton ________________________________ From: Eduardo Ochs <edu...@gm...> Sent: Friday, July 12, 2024 02:12 To: <max...@li...> <max...@li...> Subject: [Maxima-discuss] a(b), a[b], op, args Caution: Non-NU Email Hi list, "op" and "args" don't distinguish between a(b) and a[b]: (%i1) [o:a(b),op(o),args(o)]; (%o1) [a(b), a, [b]] (%i2) [o:a[b],op(o),args(o)]; (%o2) [a , a, [b]] b (%i3) what do I need to use to distinguish them? Why I'm asking: there are several kinds of expressions that this program - <http://anggtwu.net/eev-maxima.html#luatree> - doesn't handle well... I'm trying to fix it. Thanks in advance! Eduardo =) |
From: Robert D. <rob...@gm...> - 2024-07-12 16:40:42
|
On Fri, Jul 12, 2024 at 12:13 AM Eduardo Ochs <edu...@gm...> wrote: > "op" and "args" don't distinguish between a(b) and a[b]: > > (%i1) [o:a(b),op(o),args(o)]; > (%o1) [a(b), a, [b]] > (%i2) [o:a[b],op(o),args(o)]; > (%o2) [a , a, [b]] > b > (%i3) > > what do I need to use to distinguish them? In the luatree code, try changing atom(something) to mapatom(something) -- atom(a[b]) returns false but mapatom(a[b]) returns true. In addition to stuff like a[b], you may wish to cover stuff like a[b](x, y), a(b)(x, y), a[b](x, y)(z), which are all legitimate Maxima expressions ... I guess you just need to be prepared for op(something) returning a non-mapatom. All the best, Robert |
From: Barton W. <wi...@un...> - 2024-07-12 16:58:46
|
Maybe a bit related: Here is a link to code that checks a Maxima expression for missing simp flags and a few other defects. (%i11) :lisp(msetq \$xxx '((%sin simp) ((%sin) 7))))$ (%i11) check_expression(xxx,true); Bad expression: expr = sin(7) ; reason = missing\-simp\-flag (%o11) false (%i12) :lisp(msetq \$xxx '((%sin simp) ((%sin simp) 7))))$ (%i12) check_expression(xxx,true); (%o12) done (%i13) :lisp(msetq \$xxx (/ 5 7)) (%i13) check_expression(xxx,true); Bad expression: expr = 5/7 ; reason = cl\-rational (%o13) false --Barton ________________________________ From: Robert Dodier <rob...@gm...> Sent: Friday, July 12, 2024 11:40 To: Eduardo Ochs <edu...@gm...> Cc: <max...@li...> <max...@li...> Subject: Re: [Maxima-discuss] a(b), a[b], op, args Caution: Non-NU Email On Fri, Jul 12, 2024 at 12:13 AM Eduardo Ochs <edu...@gm...> wrote: > "op" and "args" don't distinguish between a(b) and a[b]: > > (%i1) [o:a(b),op(o),args(o)]; > (%o1) [a(b), a, [b]] > (%i2) [o:a[b],op(o),args(o)]; > (%o2) [a , a, [b]] > b > (%i3) > > what do I need to use to distinguish them? In the luatree code, try changing atom(something) to mapatom(something) -- atom(a[b]) returns false but mapatom(a[b]) returns true. In addition to stuff like a[b], you may wish to cover stuff like a[b](x, y), a(b)(x, y), a[b](x, y)(z), which are all legitimate Maxima expressions ... I guess you just need to be prepared for op(something) returning a non-mapatom. All the best, Robert _______________________________________________ Maxima-discuss mailing list Max...@li... https://urldefense.com/v3/__https://lists.sourceforge.net/lists/listinfo/maxima-discuss__;!!PvXuogZ4sRB2p-tU!GIOUxUD0ek3EgbEcZRR9CUWfnr2fnCG28G2JZNZ2kyl9KOfTqo6YGgtyQHuxTBtBZDF-JzjkaANgKZ97QA8y1w$ |
From: Barton W. <wi...@un...> - 2024-07-12 17:26:15
|
...oh, the link: https://github.com/barton-willis/check_maxima_expression --Barton ________________________________ From: Barton Willis via Maxima-discuss <max...@li...> Sent: Friday, July 12, 2024 11:58 To: Robert Dodier <rob...@gm...>; Eduardo Ochs <edu...@gm...> Cc: <max...@li...> <max...@li...> Subject: Re: [Maxima-discuss] a(b), a[b], op, args Caution: Non-NU Email Maybe a bit related: Here is a link to code that checks a Maxima expression for missing simp flags and a few other defects. (%i11) :lisp(msetq \$xxx '((%sin simp) ((%sin) 7))))$ (%i11) check_expression(xxx,true); Bad expression: expr = sin(7) ; reason = missing\-simp\-flag (%o11) false (%i12) :lisp(msetq \$xxx '((%sin simp) ((%sin simp) 7))))$ (%i12) check_expression(xxx,true); (%o12) done (%i13) :lisp(msetq \$xxx (/ 5 7)) (%i13) check_expression(xxx,true); Bad expression: expr = 5/7 ; reason = cl\-rational (%o13) false --Barton ________________________________ From: Robert Dodier <rob...@gm...> Sent: Friday, July 12, 2024 11:40 To: Eduardo Ochs <edu...@gm...> Cc: <max...@li...> <max...@li...> Subject: Re: [Maxima-discuss] a(b), a[b], op, args Caution: Non-NU Email On Fri, Jul 12, 2024 at 12:13 AM Eduardo Ochs <edu...@gm...> wrote: > "op" and "args" don't distinguish between a(b) and a[b]: > > (%i1) [o:a(b),op(o),args(o)]; > (%o1) [a(b), a, [b]] > (%i2) [o:a[b],op(o),args(o)]; > (%o2) [a , a, [b]] > b > (%i3) > > what do I need to use to distinguish them? In the luatree code, try changing atom(something) to mapatom(something) -- atom(a[b]) returns false but mapatom(a[b]) returns true. In addition to stuff like a[b], you may wish to cover stuff like a[b](x, y), a(b)(x, y), a[b](x, y)(z), which are all legitimate Maxima expressions ... I guess you just need to be prepared for op(something) returning a non-mapatom. All the best, Robert _______________________________________________ Maxima-discuss mailing list Max...@li... https://urldefense.com/v3/__https://lists.sourceforge.net/lists/listinfo/maxima-discuss__;!!PvXuogZ4sRB2p-tU!GIOUxUD0ek3EgbEcZRR9CUWfnr2fnCG28G2JZNZ2kyl9KOfTqo6YGgtyQHuxTBtBZDF-JzjkaANgKZ97QA8y1w$ |
From: Eduardo O. <edu...@gm...> - 2024-07-12 18:01:06
|
Ok, this test works: # In a shell rm -Rfv /tmp/check_maxima_expression/ cd /tmp/ git clone https://github.com/barton-willis/check_maxima_expression cd /tmp/check_maxima_expression/ /* In Maxima */ load("/tmp/check_maxima_expression/check-expression-p.lisp"); :lisp(msetq \$xxx '((%sin simp) ((%sin) 7))))$ check_expression(xxx,true); :lisp(msetq \$xxx '((%sin simp) ((%sin simp) 7))))$ check_expression(xxx,true); :lisp(msetq \$xxx (/ 5 7)) check_expression(xxx,true); What do you think of copying your tests from https://sourceforge.net/p/maxima/mailman/message/58794646/ to the README.md? [[]], Eduardo On Fri, 12 Jul 2024 at 14:26, Barton Willis <wi...@un...> wrote: > ...oh, the link: > https://github.com/barton-willis/check_maxima_expression > > --Barton > ------------------------------ > *From:* Barton Willis via Maxima-discuss < > max...@li...> > *Sent:* Friday, July 12, 2024 11:58 > *To:* Robert Dodier <rob...@gm...>; Eduardo Ochs < > edu...@gm...> > *Cc:* <max...@li...> < > max...@li...> > *Subject:* Re: [Maxima-discuss] a(b), a[b], op, args > > Caution: Non-NU Email > > > Maybe a bit related: Here is a link to code that checks a Maxima > expression for missing simp flags and a few other defects. > > (%i11) :lisp(msetq \$xxx '((%sin simp) ((%sin) 7))))$ > > (%i11) check_expression(xxx,true); > Bad expression: expr = sin(7) ; reason = missing\-simp\-flag > (%o11) false > > (%i12) :lisp(msetq \$xxx '((%sin simp) ((%sin simp) 7))))$ > > (%i12) check_expression(xxx,true); > (%o12) done > > (%i13) :lisp(msetq \$xxx (/ 5 7)) > (%i13) check_expression(xxx,true); > > Bad expression: expr = 5/7 ; reason = cl\-rational > (%o13) false > > > > --Barton > ------------------------------ > *From:* Robert Dodier <rob...@gm...> > *Sent:* Friday, July 12, 2024 11:40 > *To:* Eduardo Ochs <edu...@gm...> > *Cc:* <max...@li...> < > max...@li...> > *Subject:* Re: [Maxima-discuss] a(b), a[b], op, args > > Caution: Non-NU Email > > > On Fri, Jul 12, 2024 at 12:13 AM Eduardo Ochs <edu...@gm...> > wrote: > > > "op" and "args" don't distinguish between a(b) and a[b]: > > > > (%i1) [o:a(b),op(o),args(o)]; > > (%o1) [a(b), a, [b]] > > (%i2) [o:a[b],op(o),args(o)]; > > (%o2) [a , a, [b]] > > b > > (%i3) > > > > what do I need to use to distinguish them? > > In the luatree code, try changing atom(something) to > mapatom(something) -- atom(a[b]) returns false but mapatom(a[b]) > returns true. > > In addition to stuff like a[b], you may wish to cover stuff like > a[b](x, y), a(b)(x, y), a[b](x, y)(z), which are all legitimate Maxima > expressions ... I guess you just need to be prepared for op(something) > returning a non-mapatom. > > All the best, > > Robert > > > _______________________________________________ > Maxima-discuss mailing list > Max...@li... > > https://urldefense.com/v3/__https://lists.sourceforge.net/lists/listinfo/maxima-discuss__;!!PvXuogZ4sRB2p-tU!GIOUxUD0ek3EgbEcZRR9CUWfnr2fnCG28G2JZNZ2kyl9KOfTqo6YGgtyQHuxTBtBZDF-JzjkaANgKZ97QA8y1w$ > |
From: Eduardo O. <edu...@gm...> - 2024-07-12 18:09:53
|
Hi Robert - Fixed! See: https://github.com/edrx/luatree/blob/main/luatree2.mac Example: (%i1) load("~/luatree/luatree2.mac")$ (%i2) luatree (a(b,c))$ a__. | | b c (%i3) luatree (a[1][2](b,c))$ ap_________.__. | | | [_]_____. b c | | [_]__. 2 | | a 1 (%i4) luatree (a[1][2](b,c)(d))$ ap_______________. | | ap_________.__. d | | | [_]_____. b c | | [_]__. 2 | | a 1 (%i5) [[]], E. On Fri, 12 Jul 2024 at 13:40, Robert Dodier <rob...@gm...> wrote: > On Fri, Jul 12, 2024 at 12:13 AM Eduardo Ochs <edu...@gm...> > wrote: > > > "op" and "args" don't distinguish between a(b) and a[b]: > > > > (%i1) [o:a(b),op(o),args(o)]; > > (%o1) [a(b), a, [b]] > > (%i2) [o:a[b],op(o),args(o)]; > > (%o2) [a , a, [b]] > > b > > (%i3) > > > > what do I need to use to distinguish them? > > In the luatree code, try changing atom(something) to > mapatom(something) -- atom(a[b]) returns false but mapatom(a[b]) > returns true. > > In addition to stuff like a[b], you may wish to cover stuff like > a[b](x, y), a(b)(x, y), a[b](x, y)(z), which are all legitimate Maxima > expressions ... I guess you just need to be prepared for op(something) > returning a non-mapatom. > > All the best, > > Robert > |
From: Stavros M. <mac...@gm...> - 2024-07-15 22:44:10
|
Here's a little quick-and-dirty code to show the internal form of a Maxima expression as a functional expression. Of course, you could just look at the Lisp.... Examples: show_expression( -2/3*(a-b)/(b*sqrt(5)) ) <<< with inflag:false (default), show the user-friendly version => sub(div(mul(2, add(a, sub(b))), mul(3, xsqrt(5), b))) It uses function names for operators. show_expression( -2/3*(a-b)/(b*sqrt(5)) ),inflag:true; <<< with inflag:true, show the actual internal version => mul(rat(- 2, 3), power(5, rat(- 1, 2)), add(a, mul(- 1, b)), power(b, - 1)) grind(%), linel=30. << pretty-print -- choose linel to control appearance => mul(rat(-2,3), power(5,rat(-1,2)), add(a,mul(-1,b)), power(b,-1))$ It shows verb-functions as V*name* and noun-functions as N*name*. show_expression('[integrate(x,x), 'integrate(x,x)]); => list(Vintegrate(x, x), Nintegrate(x, x)) It doesn't do anything special for *if, do*, etc. since the internal form is just a list of arguments: show_expression('(if a then b else c)) => Vif(a, b, true, c) show_expression('(for i thru 4 do print(i))) => Vdo(i, false, false, false, 4, false, Vprint(i)) show_expression('(for i:2 thru 4 while i^2 < 10 do print(i))) => Vdo(i, 2, false, false, 4, greatereq(power(i, 2), 10), Vprint(i)) show_expression('(for i:2 step 1/2 thru 4 while i^2 < 10 do print(i))) => Vdo(i, 2, rat(1, 2), false, 4, greatereq(power(i, 2), 10), Vprint(i)) show_expression('(for i:2 thru 4 next i+1/3 while i^2 < 10 do print(i))) => Vdo(i, 2, false, add(i, rat(1, 3)), 4, greatereq(power(i, 2), 10), Vprint(i)) show_expression('(for i in [a,b,c] do print(i))) => Vdo_in(i, list(a, b, c), false, false, false, false, Vprint(i)) ---------------- /* Show Maxima expression in explicit form. For example, with inflag:false (the default): show_expression((a[3]-3)/sqrt(5)) => f/(plus(subsc(a,3),-3),sqrt(5)) with inflag:true (to show the internal form): show_expression(a[3]/sqrt(5)) => f*(f^(5,rat(-1,2)),subsc(a,3)) */ show_expression(ex):= if atom(ex) then ex elseif subvarp(ex) then funmake('subsc,cons(op(ex),[maplist(show_expression,args(ex))])) elseif ratnump(ex) then funmake('rat,[first(ex),second(ex)]) elseif mapatom(ex) then ex elseif member(part(ex,0), show_special) then funmake(show_expression_name[part(ex,0)], maplist(show_expression,args(ex))) elseif not(atom(part(ex,0))) then funmake('apply,[show_expression(part(ex,0)),maplist(show_expression,args(ex))]) else block([pex:part(ex,0)], funmake(concat(if nounify(pex)=pex then 'N else 'V,pex), maplist(show_expression,args(ex))))$ show_special: []$ for i in '[["+",add], ["-",minus], ["*",mul], ["^",power], ["/",div], [".",ncmul], ["^^", ncpower], ["[",list], ["{",set], [":",assign], ["::",varassign], [":=",define], ["::=",definemac] ["'",quote], ["(",prog], ["=",equal], ["#",notequal], [">",greaterp],[">=", greatereq], ["<", lessp], ["<=",lesseq], ["!",factorial], ["@",field] ] do (show_expression_name[first(i)]: second(i), push(first(i),show_special)); On Fri, Jul 12, 2024 at 2:10 PM Eduardo Ochs <edu...@gm...> wrote: > Hi Robert - > Fixed! See: > https://github.com/edrx/luatree/blob/main/luatree2.mac > > Example: > > (%i1) load("~/luatree/luatree2.mac")$ > (%i2) luatree (a(b,c))$ > a__. > | | > b c > (%i3) luatree (a[1][2](b,c))$ > ap_________.__. > | | | > [_]_____. b c > | | > [_]__. 2 > | | > a 1 > (%i4) luatree (a[1][2](b,c)(d))$ > ap_______________. > | | > ap_________.__. d > | | | > [_]_____. b c > | | > [_]__. 2 > | | > a 1 > (%i5) > > [[]], E. > > > > On Fri, 12 Jul 2024 at 13:40, Robert Dodier <rob...@gm...> > wrote: > >> On Fri, Jul 12, 2024 at 12:13 AM Eduardo Ochs <edu...@gm...> >> wrote: >> >> > "op" and "args" don't distinguish between a(b) and a[b]: >> > >> > (%i1) [o:a(b),op(o),args(o)]; >> > (%o1) [a(b), a, [b]] >> > (%i2) [o:a[b],op(o),args(o)]; >> > (%o2) [a , a, [b]] >> > b >> > (%i3) >> > >> > what do I need to use to distinguish them? >> >> In the luatree code, try changing atom(something) to >> mapatom(something) -- atom(a[b]) returns false but mapatom(a[b]) >> returns true. >> >> In addition to stuff like a[b], you may wish to cover stuff like >> a[b](x, y), a(b)(x, y), a[b](x, y)(z), which are all legitimate Maxima >> expressions ... I guess you just need to be prepared for op(something) >> returning a non-mapatom. >> >> All the best, >> >> Robert >> > _______________________________________________ > Maxima-discuss mailing list > Max...@li... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss > |
From: Eduardo O. <edu...@gm...> - 2024-08-12 02:59:37
|
Hi Stavros, I just tested your function show_expression from https://sourceforge.net/p/maxima/mailman/message/58795759/ on factorized numbers and on three flavors of power series: plain, "trunc", and "taylor"... it turned out that "inflag:true", is enough to make factorized numbers be displayed correctly - as products of powers - but your show_expression doesn't have support for telling if a power series would be displayed with a "...", with a "/T/", or both. Would that be easy to fix? Here is the code: --snip--snip-- show_expression(ex):= if atom(ex) then ex elseif subvarp(ex) then funmake('subsc,cons(op(ex),[maplist(show_expression,args(ex))])) elseif ratnump(ex) then funmake('rat,[first(ex),second(ex)]) elseif mapatom(ex) then ex elseif member(part(ex,0), show_special) then funmake(show_expression_name[part(ex,0)], maplist(show_expression,args(ex))) elseif not(atom(part(ex,0))) then funmake('apply,[show_expression(part(ex,0)),maplist(show_expression,args(ex))]) else block([pex:part(ex,0)], funmake(concat(if nounify(pex)=pex then 'N else 'V,pex), maplist(show_expression,args(ex))))$ show_special: []$ for i in '[["+",add], ["-",minus], ["*",mul], ["^",power], ["/",div], [".",ncmul], ["^^", ncpower], ["[",list], ["{",set], [":",assign], ["::",varassign], [":=",define], ["::=",definemac] ["'",quote], ["(",prog], ["=",equal], ["#",notequal], [">",greaterp],[">=", greatereq], ["<", lessp], ["<=",lesseq], ["!",factorial], ["@",field] ] do (show_expression_name[first(i)]: second(i), push(first(i),show_special)); a : factor(1000); "shows a as 2^3 * 5^3"$ show_expression(a), inflag:true; "shows a as 2^3 * 5^3"$ show_expression(a); "shows a as 8 * 125"$ linel : 100; b1 : 1 + 2*x + 2*x^2 + 4/3*x^3; b2 : trunc(b1); "has a ..."$ b3 : taylor(exp(2*x), x, 0, 3); "has a ... and a /T/"$ show_expression(b1); show_expression(b1), inflag:true; show_expression(b2); show_expression(b2), inflag:true; show_expression(b3); show_expression(b3), inflag:true; --snip--snip-- ...and the relevant part of the output: --snip--snip-- (%i22) b1 : 1 + 2*x + 2*x^2 + 4/3*x^3; 3 4 x 2 (%o22) ──── + 2 x + 2 x + 1 3 (%i23) b2 : trunc(b1); "has a ..."$ 3 2 4 x (%o23) 1 + 2 x + 2 x + ──── + . . . 3 (%i25) b3 : taylor(exp(2*x), x, 0, 3); "has a ... and a /T/"$ 3 2 4 x (%o25)/T/ 1 + 2 x + 2 x + ──── + . . . 3 (%i27) show_expression(b1); (%o27) add(div(mul(4, power(x, 3)), 3), mul(2, power(x, 2)), mul(2, x), 1) (%i28) show_expression(b1), inflag:true; (%o28) add(1, mul(2, x), mul(2, power(x, 2)), mul(rat(4, 3), power(x, 3))) (%i29) show_expression(b2); (%o29) add(1, mul(2, x), mul(2, power(x, 2)), div(mul(4, power(x, 3)), 3)) (%i30) show_expression(b2), inflag:true; (%o30) add(1, mul(2, x), mul(2, power(x, 2)), mul(rat(4, 3), power(x, 3))) (%i31) show_expression(b3); (%o31) add(1, mul(2, x), mul(2, power(x, 2)), div(mul(4, power(x, 3)), 3)) (%i32) show_expression(b3), inflag:true; (%o32) mul(rat(1, 3), add(3, mul(6, x), mul(6, power(x, 2)), mul(4, power(x, 3)))) (%i33) --snip--snip-- Cheers =), Eduardo Ochs http://anggtwu.net/eev-maxima.html On Mon, 15 Jul 2024 at 19:43, Stavros Macrakis <mac...@gm...> wrote: > Here's a little quick-and-dirty code to show the internal form of a Maxima > expression as a functional expression. > Of course, you could just look at the Lisp.... > > Examples: > > show_expression( -2/3*(a-b)/(b*sqrt(5)) ) <<< with > inflag:false (default), show the user-friendly version > => sub(div(mul(2, add(a, sub(b))), mul(3, xsqrt(5), b))) > > It uses function names for operators. > > show_expression( -2/3*(a-b)/(b*sqrt(5)) ),inflag:true; > <<< with inflag:true, show the actual internal version > => mul(rat(- 2, 3), power(5, rat(- 1, 2)), add(a, mul(- 1, b)), > power(b, - 1)) > > grind(%), linel=30. << pretty-print -- choose linel to control > appearance > => > > mul(rat(-2,3), > power(5,rat(-1,2)), > add(a,mul(-1,b)), > power(b,-1))$ > > > It shows verb-functions as V*name* and noun-functions as N*name*. > > show_expression('[integrate(x,x), 'integrate(x,x)]); > => list(Vintegrate(x, x), Nintegrate(x, x)) > > It doesn't do anything special for *if, do*, etc. since the internal form > is just a list of arguments: > > show_expression('(if a then b else c)) > => Vif(a, b, true, c) > > show_expression('(for i thru 4 do print(i))) > => Vdo(i, false, false, false, 4, false, Vprint(i)) > > show_expression('(for i:2 thru 4 while i^2 < 10 do print(i))) > => Vdo(i, 2, false, false, 4, greatereq(power(i, 2), 10), Vprint(i)) > > show_expression('(for i:2 step 1/2 thru 4 while i^2 < 10 do print(i))) > => Vdo(i, 2, rat(1, 2), false, 4, greatereq(power(i, 2), 10), > Vprint(i)) > > show_expression('(for i:2 thru 4 next i+1/3 while i^2 < 10 do print(i))) > => Vdo(i, 2, false, add(i, rat(1, 3)), 4, greatereq(power(i, 2), 10), > Vprint(i)) > > show_expression('(for i in [a,b,c] do print(i))) > => Vdo_in(i, list(a, b, c), false, false, false, false, Vprint(i)) > > > ---------------- > > /* Show Maxima expression in explicit form. > > For example, with inflag:false (the default): > > show_expression((a[3]-3)/sqrt(5)) => f/(plus(subsc(a,3),-3),sqrt(5)) > > with inflag:true (to show the internal form): > > show_expression(a[3]/sqrt(5)) => f*(f^(5,rat(-1,2)),subsc(a,3)) > > */ > > show_expression(ex):= > if atom(ex) then ex > elseif subvarp(ex) then > funmake('subsc,cons(op(ex),[maplist(show_expression,args(ex))])) > elseif ratnump(ex) then funmake('rat,[first(ex),second(ex)]) > elseif mapatom(ex) then ex > elseif member(part(ex,0), show_special) > then funmake(show_expression_name[part(ex,0)], > maplist(show_expression,args(ex))) > elseif not(atom(part(ex,0))) > then > funmake('apply,[show_expression(part(ex,0)),maplist(show_expression,args(ex))]) > else block([pex:part(ex,0)], > funmake(concat(if nounify(pex)=pex then 'N else 'V,pex), > maplist(show_expression,args(ex))))$ > > show_special: []$ > for i in > '[["+",add], ["-",minus], ["*",mul], ["^",power], ["/",div], > [".",ncmul], ["^^", ncpower], > ["[",list], ["{",set], > [":",assign], ["::",varassign], > [":=",define], ["::=",definemac] > ["'",quote], ["(",prog], > ["=",equal], ["#",notequal], [">",greaterp],[">=", greatereq], ["<", > lessp], ["<=",lesseq], > ["!",factorial], ["@",field] > ] > do (show_expression_name[first(i)]: second(i), > push(first(i),show_special)); > > > > On Fri, Jul 12, 2024 at 2:10 PM Eduardo Ochs <edu...@gm...> > wrote: > >> Hi Robert - >> Fixed! See: >> https://github.com/edrx/luatree/blob/main/luatree2.mac >> >> Example: >> >> (%i1) load("~/luatree/luatree2.mac")$ >> (%i2) luatree (a(b,c))$ >> a__. >> | | >> b c >> (%i3) luatree (a[1][2](b,c))$ >> ap_________.__. >> | | | >> [_]_____. b c >> | | >> [_]__. 2 >> | | >> a 1 >> (%i4) luatree (a[1][2](b,c)(d))$ >> ap_______________. >> | | >> ap_________.__. d >> | | | >> [_]_____. b c >> | | >> [_]__. 2 >> | | >> a 1 >> (%i5) >> >> [[]], E. >> >> >> >> On Fri, 12 Jul 2024 at 13:40, Robert Dodier <rob...@gm...> >> wrote: >> >>> On Fri, Jul 12, 2024 at 12:13 AM Eduardo Ochs <edu...@gm...> >>> wrote: >>> >>> > "op" and "args" don't distinguish between a(b) and a[b]: >>> > >>> > (%i1) [o:a(b),op(o),args(o)]; >>> > (%o1) [a(b), a, [b]] >>> > (%i2) [o:a[b],op(o),args(o)]; >>> > (%o2) [a , a, [b]] >>> > b >>> > (%i3) >>> > >>> > what do I need to use to distinguish them? >>> >>> In the luatree code, try changing atom(something) to >>> mapatom(something) -- atom(a[b]) returns false but mapatom(a[b]) >>> returns true. >>> >>> In addition to stuff like a[b], you may wish to cover stuff like >>> a[b](x, y), a(b)(x, y), a[b](x, y)(z), which are all legitimate Maxima >>> expressions ... I guess you just need to be prepared for op(something) >>> returning a non-mapatom. >>> >>> All the best, >>> >>> Robert >>> >> _______________________________________________ >> Maxima-discuss mailing list >> Max...@li... >> https://lists.sourceforge.net/lists/listinfo/maxima-discuss >> > |
From: Stavros M. <mac...@gm...> - 2024-08-15 01:19:36
|
It's certainly possible to have Taylor expressions display with "..." or whatever. Although if you really want to see the internal form of CREs, including Taylor expressions, it gets pretty messy. For example, rat(exp(x)/(x+1)) is represented internally as ((MRAT SIMP ($X ((MEXPT SIMP) $%E $X)) (#:X223 #:X200)) (#:X200 1 1) #:X223 1 1 0 1) x How much of that structure do you want to preserve? Why bother with show_expression at all? -s On Sun, Aug 11, 2024 at 7:59 PM Eduardo Ochs <edu...@gm...> wrote: > Hi Stavros, > > I just tested your function show_expression from > > https://sourceforge.net/p/maxima/mailman/message/58795759/ > > on factorized numbers and on three flavors of power series: plain, > "trunc", and "taylor"... it turned out that "inflag:true", is enough > to make factorized numbers be displayed correctly - as products of > powers - but your show_expression doesn't have support for telling if > a power series would be displayed with a "...", with a "/T/", or both. > > Would that be easy to fix? > > Here is the code: > > --snip--snip-- > show_expression(ex):= > if atom(ex) then ex > elseif subvarp(ex) then > funmake('subsc,cons(op(ex),[maplist(show_expression,args(ex))])) > elseif ratnump(ex) then funmake('rat,[first(ex),second(ex)]) > elseif mapatom(ex) then ex > elseif member(part(ex,0), show_special) > then funmake(show_expression_name[part(ex,0)], > maplist(show_expression,args(ex))) > elseif not(atom(part(ex,0))) > then > funmake('apply,[show_expression(part(ex,0)),maplist(show_expression,args(ex))]) > else block([pex:part(ex,0)], > funmake(concat(if nounify(pex)=pex then 'N else 'V,pex), > maplist(show_expression,args(ex))))$ > > show_special: []$ > for i in > '[["+",add], ["-",minus], ["*",mul], ["^",power], ["/",div], > [".",ncmul], ["^^", ncpower], > ["[",list], ["{",set], > [":",assign], ["::",varassign], > [":=",define], ["::=",definemac] > ["'",quote], ["(",prog], > ["=",equal], ["#",notequal], [">",greaterp],[">=", greatereq], > ["<", lessp], ["<=",lesseq], > ["!",factorial], ["@",field] > ] > do (show_expression_name[first(i)]: second(i), > push(first(i),show_special)); > > a : factor(1000); "shows a as 2^3 * 5^3"$ > show_expression(a), inflag:true; "shows a as 2^3 * 5^3"$ > show_expression(a); "shows a as 8 * 125"$ > > linel : 100; > b1 : 1 + 2*x + 2*x^2 + 4/3*x^3; > b2 : trunc(b1); "has a ..."$ > b3 : taylor(exp(2*x), x, 0, 3); "has a ... and a /T/"$ > show_expression(b1); > show_expression(b1), inflag:true; > show_expression(b2); > show_expression(b2), inflag:true; > show_expression(b3); > show_expression(b3), inflag:true; > --snip--snip-- > > ...and the relevant part of the output: > > --snip--snip-- > (%i22) b1 : 1 + 2*x + 2*x^2 + 4/3*x^3; > 3 > 4 x 2 > (%o22) ──── + 2 x + 2 x + 1 > 3 > (%i23) b2 : trunc(b1); "has a ..."$ > 3 > 2 4 x > (%o23) 1 + 2 x + 2 x + ──── + . . . > 3 > (%i25) b3 : taylor(exp(2*x), x, 0, 3); "has a ... and a /T/"$ > 3 > 2 4 x > (%o25)/T/ 1 + 2 x + 2 x + ──── + . . . > 3 > (%i27) show_expression(b1); > (%o27) add(div(mul(4, power(x, 3)), 3), mul(2, power(x, 2)), > mul(2, x), 1) > (%i28) show_expression(b1), inflag:true; > (%o28) add(1, mul(2, x), mul(2, power(x, 2)), mul(rat(4, 3), > power(x, 3))) > (%i29) show_expression(b2); > (%o29) add(1, mul(2, x), mul(2, power(x, 2)), div(mul(4, power(x, > 3)), 3)) > (%i30) show_expression(b2), inflag:true; > (%o30) add(1, mul(2, x), mul(2, power(x, 2)), mul(rat(4, 3), > power(x, 3))) > (%i31) show_expression(b3); > (%o31) add(1, mul(2, x), mul(2, power(x, 2)), div(mul(4, power(x, > 3)), 3)) > (%i32) show_expression(b3), inflag:true; > (%o32) mul(rat(1, 3), add(3, mul(6, x), mul(6, power(x, 2)), mul(4, > power(x, 3)))) > (%i33) > --snip--snip-- > > Cheers =), > Eduardo Ochs > http://anggtwu.net/eev-maxima.html > > On Mon, 15 Jul 2024 at 19:43, Stavros Macrakis <mac...@gm...> wrote: > >> Here's a little quick-and-dirty code to show the internal form of a >> Maxima expression as a functional expression. >> Of course, you could just look at the Lisp.... >> >> Examples: >> >> show_expression( -2/3*(a-b)/(b*sqrt(5)) ) <<< with >> inflag:false (default), show the user-friendly version >> => sub(div(mul(2, add(a, sub(b))), mul(3, xsqrt(5), b))) >> >> It uses function names for operators. >> >> show_expression( -2/3*(a-b)/(b*sqrt(5)) ),inflag:true; >> <<< with inflag:true, show the actual internal version >> => mul(rat(- 2, 3), power(5, rat(- 1, 2)), add(a, mul(- 1, b)), >> power(b, - 1)) >> >> grind(%), linel=30. << pretty-print -- choose linel to control >> appearance >> => >> >> mul(rat(-2,3), >> power(5,rat(-1,2)), >> add(a,mul(-1,b)), >> power(b,-1))$ >> >> >> It shows verb-functions as V*name* and noun-functions as N*name*. >> >> show_expression('[integrate(x,x), 'integrate(x,x)]); >> => list(Vintegrate(x, x), Nintegrate(x, x)) >> >> It doesn't do anything special for *if, do*, etc. since the internal >> form is just a list of arguments: >> >> show_expression('(if a then b else c)) >> => Vif(a, b, true, c) >> >> show_expression('(for i thru 4 do print(i))) >> => Vdo(i, false, false, false, 4, false, Vprint(i)) >> >> show_expression('(for i:2 thru 4 while i^2 < 10 do print(i))) >> => Vdo(i, 2, false, false, 4, greatereq(power(i, 2), 10), Vprint(i)) >> >> show_expression('(for i:2 step 1/2 thru 4 while i^2 < 10 do print(i))) >> => Vdo(i, 2, rat(1, 2), false, 4, greatereq(power(i, 2), 10), >> Vprint(i)) >> >> show_expression('(for i:2 thru 4 next i+1/3 while i^2 < 10 do print(i))) >> => Vdo(i, 2, false, add(i, rat(1, 3)), 4, greatereq(power(i, 2), 10), >> Vprint(i)) >> >> show_expression('(for i in [a,b,c] do print(i))) >> => Vdo_in(i, list(a, b, c), false, false, false, false, Vprint(i)) >> >> >> ---------------- >> >> /* Show Maxima expression in explicit form. >> >> For example, with inflag:false (the default): >> >> show_expression((a[3]-3)/sqrt(5)) => f/(plus(subsc(a,3),-3),sqrt(5)) >> >> with inflag:true (to show the internal form): >> >> show_expression(a[3]/sqrt(5)) => f*(f^(5,rat(-1,2)),subsc(a,3)) >> >> */ >> >> show_expression(ex):= >> if atom(ex) then ex >> elseif subvarp(ex) then >> funmake('subsc,cons(op(ex),[maplist(show_expression,args(ex))])) >> elseif ratnump(ex) then funmake('rat,[first(ex),second(ex)]) >> elseif mapatom(ex) then ex >> elseif member(part(ex,0), show_special) >> then funmake(show_expression_name[part(ex,0)], >> maplist(show_expression,args(ex))) >> elseif not(atom(part(ex,0))) >> then >> funmake('apply,[show_expression(part(ex,0)),maplist(show_expression,args(ex))]) >> else block([pex:part(ex,0)], >> funmake(concat(if nounify(pex)=pex then 'N else 'V,pex), >> maplist(show_expression,args(ex))))$ >> >> show_special: []$ >> for i in >> '[["+",add], ["-",minus], ["*",mul], ["^",power], ["/",div], >> [".",ncmul], ["^^", ncpower], >> ["[",list], ["{",set], >> [":",assign], ["::",varassign], >> [":=",define], ["::=",definemac] >> ["'",quote], ["(",prog], >> ["=",equal], ["#",notequal], [">",greaterp],[">=", greatereq], ["<", >> lessp], ["<=",lesseq], >> ["!",factorial], ["@",field] >> ] >> do (show_expression_name[first(i)]: second(i), >> push(first(i),show_special)); >> >> >> >> On Fri, Jul 12, 2024 at 2:10 PM Eduardo Ochs <edu...@gm...> >> wrote: >> >>> Hi Robert - >>> Fixed! See: >>> https://github.com/edrx/luatree/blob/main/luatree2.mac >>> >>> Example: >>> >>> (%i1) load("~/luatree/luatree2.mac")$ >>> (%i2) luatree (a(b,c))$ >>> a__. >>> | | >>> b c >>> (%i3) luatree (a[1][2](b,c))$ >>> ap_________.__. >>> | | | >>> [_]_____. b c >>> | | >>> [_]__. 2 >>> | | >>> a 1 >>> (%i4) luatree (a[1][2](b,c)(d))$ >>> ap_______________. >>> | | >>> ap_________.__. d >>> | | | >>> [_]_____. b c >>> | | >>> [_]__. 2 >>> | | >>> a 1 >>> (%i5) >>> >>> [[]], E. >>> >>> >>> >>> On Fri, 12 Jul 2024 at 13:40, Robert Dodier <rob...@gm...> >>> wrote: >>> >>>> On Fri, Jul 12, 2024 at 12:13 AM Eduardo Ochs <edu...@gm...> >>>> wrote: >>>> >>>> > "op" and "args" don't distinguish between a(b) and a[b]: >>>> > >>>> > (%i1) [o:a(b),op(o),args(o)]; >>>> > (%o1) [a(b), a, [b]] >>>> > (%i2) [o:a[b],op(o),args(o)]; >>>> > (%o2) [a , a, [b]] >>>> > b >>>> > (%i3) >>>> > >>>> > what do I need to use to distinguish them? >>>> >>>> In the luatree code, try changing atom(something) to >>>> mapatom(something) -- atom(a[b]) returns false but mapatom(a[b]) >>>> returns true. >>>> >>>> In addition to stuff like a[b], you may wish to cover stuff like >>>> a[b](x, y), a(b)(x, y), a[b](x, y)(z), which are all legitimate Maxima >>>> expressions ... I guess you just need to be prepared for op(something) >>>> returning a non-mapatom. >>>> >>>> All the best, >>>> >>>> Robert >>>> >>> _______________________________________________ >>> Maxima-discuss mailing list >>> Max...@li... >>> https://lists.sourceforge.net/lists/listinfo/maxima-discuss >>> >> |
From: Stavros M. <mac...@gm...> - 2024-08-15 01:15:47
|
One problem with integer factorizations is that they are pseudo-simplified: normally, Maxima does not allow 2^3 as a simplified expression, but *factor* cheats and marks the expression as simplified, even though it isn't. That means that it gives strange results if you try to manipulate it: qq:factor(24) => 2^3*3 qq+1 => 2^3*3 + 1 qq/2 => 4*3 << not 2^2*3 qq/3 => 2^3*3/3 <<< !!! qq^2 => 576 sqrt(qq) => 2^(3/2)*sqrt(3) sqrt(24) => 2*sqrt(6) << Not the same In particular, *part* doesn't work as expected with the result of *factor*: part(qq,1) => 8 The clean way to process factorizations programmatically is with *ifactors*. Binding *simp* to *false* within *show_expression* lets it handle the results of *factor*. You can certainly bind *inflag *to *true* to get the real internal representation, where *x/y* is *mul(x,power(y,-1))*. Up to you. (separate response for Taylor) On Sun, Aug 11, 2024 at 7:59 PM Eduardo Ochs <edu...@gm...> wrote: > Hi Stavros, > > I just tested your function show_expression from > > https://sourceforge.net/p/maxima/mailman/message/58795759/ > > on factorized numbers and on three flavors of power series: plain, > "trunc", and "taylor"... it turned out that "inflag:true", is enough > to make factorized numbers be displayed correctly - as products of > powers - but your show_expression doesn't have support for telling if > a power series would be displayed with a "...", with a "/T/", or both. > > Would that be easy to fix? > > Here is the code: > > --snip--snip-- > show_expression(ex):= > if atom(ex) then ex > elseif subvarp(ex) then > funmake('subsc,cons(op(ex),[maplist(show_expression,args(ex))])) > elseif ratnump(ex) then funmake('rat,[first(ex),second(ex)]) > elseif mapatom(ex) then ex > elseif member(part(ex,0), show_special) > then funmake(show_expression_name[part(ex,0)], > maplist(show_expression,args(ex))) > elseif not(atom(part(ex,0))) > then > funmake('apply,[show_expression(part(ex,0)),maplist(show_expression,args(ex))]) > else block([pex:part(ex,0)], > funmake(concat(if nounify(pex)=pex then 'N else 'V,pex), > maplist(show_expression,args(ex))))$ > > show_special: []$ > for i in > '[["+",add], ["-",minus], ["*",mul], ["^",power], ["/",div], > [".",ncmul], ["^^", ncpower], > ["[",list], ["{",set], > [":",assign], ["::",varassign], > [":=",define], ["::=",definemac] > ["'",quote], ["(",prog], > ["=",equal], ["#",notequal], [">",greaterp],[">=", greatereq], > ["<", lessp], ["<=",lesseq], > ["!",factorial], ["@",field] > ] > do (show_expression_name[first(i)]: second(i), > push(first(i),show_special)); > > a : factor(1000); "shows a as 2^3 * 5^3"$ > show_expression(a), inflag:true; "shows a as 2^3 * 5^3"$ > show_expression(a); "shows a as 8 * 125"$ > > linel : 100; > b1 : 1 + 2*x + 2*x^2 + 4/3*x^3; > b2 : trunc(b1); "has a ..."$ > b3 : taylor(exp(2*x), x, 0, 3); "has a ... and a /T/"$ > show_expression(b1); > show_expression(b1), inflag:true; > show_expression(b2); > show_expression(b2), inflag:true; > show_expression(b3); > show_expression(b3), inflag:true; > --snip--snip-- > > ...and the relevant part of the output: > > --snip--snip-- > (%i22) b1 : 1 + 2*x + 2*x^2 + 4/3*x^3; > 3 > 4 x 2 > (%o22) ──── + 2 x + 2 x + 1 > 3 > (%i23) b2 : trunc(b1); "has a ..."$ > 3 > 2 4 x > (%o23) 1 + 2 x + 2 x + ──── + . . . > 3 > (%i25) b3 : taylor(exp(2*x), x, 0, 3); "has a ... and a /T/"$ > 3 > 2 4 x > (%o25)/T/ 1 + 2 x + 2 x + ──── + . . . > 3 > (%i27) show_expression(b1); > (%o27) add(div(mul(4, power(x, 3)), 3), mul(2, power(x, 2)), > mul(2, x), 1) > (%i28) show_expression(b1), inflag:true; > (%o28) add(1, mul(2, x), mul(2, power(x, 2)), mul(rat(4, 3), > power(x, 3))) > (%i29) show_expression(b2); > (%o29) add(1, mul(2, x), mul(2, power(x, 2)), div(mul(4, power(x, > 3)), 3)) > (%i30) show_expression(b2), inflag:true; > (%o30) add(1, mul(2, x), mul(2, power(x, 2)), mul(rat(4, 3), > power(x, 3))) > (%i31) show_expression(b3); > (%o31) add(1, mul(2, x), mul(2, power(x, 2)), div(mul(4, power(x, > 3)), 3)) > (%i32) show_expression(b3), inflag:true; > (%o32) mul(rat(1, 3), add(3, mul(6, x), mul(6, power(x, 2)), mul(4, > power(x, 3)))) > (%i33) > --snip--snip-- > > Cheers =), > Eduardo Ochs > http://anggtwu.net/eev-maxima.html > > On Mon, 15 Jul 2024 at 19:43, Stavros Macrakis <mac...@gm...> wrote: > >> Here's a little quick-and-dirty code to show the internal form of a >> Maxima expression as a functional expression. >> Of course, you could just look at the Lisp.... >> >> Examples: >> >> show_expression( -2/3*(a-b)/(b*sqrt(5)) ) <<< with >> inflag:false (default), show the user-friendly version >> => sub(div(mul(2, add(a, sub(b))), mul(3, xsqrt(5), b))) >> >> It uses function names for operators. >> >> show_expression( -2/3*(a-b)/(b*sqrt(5)) ),inflag:true; >> <<< with inflag:true, show the actual internal version >> => mul(rat(- 2, 3), power(5, rat(- 1, 2)), add(a, mul(- 1, b)), >> power(b, - 1)) >> >> grind(%), linel=30. << pretty-print -- choose linel to control >> appearance >> => >> >> mul(rat(-2,3), >> power(5,rat(-1,2)), >> add(a,mul(-1,b)), >> power(b,-1))$ >> >> >> It shows verb-functions as V*name* and noun-functions as N*name*. >> >> show_expression('[integrate(x,x), 'integrate(x,x)]); >> => list(Vintegrate(x, x), Nintegrate(x, x)) >> >> It doesn't do anything special for *if, do*, etc. since the internal >> form is just a list of arguments: >> >> show_expression('(if a then b else c)) >> => Vif(a, b, true, c) >> >> show_expression('(for i thru 4 do print(i))) >> => Vdo(i, false, false, false, 4, false, Vprint(i)) >> >> show_expression('(for i:2 thru 4 while i^2 < 10 do print(i))) >> => Vdo(i, 2, false, false, 4, greatereq(power(i, 2), 10), Vprint(i)) >> >> show_expression('(for i:2 step 1/2 thru 4 while i^2 < 10 do print(i))) >> => Vdo(i, 2, rat(1, 2), false, 4, greatereq(power(i, 2), 10), >> Vprint(i)) >> >> show_expression('(for i:2 thru 4 next i+1/3 while i^2 < 10 do print(i))) >> => Vdo(i, 2, false, add(i, rat(1, 3)), 4, greatereq(power(i, 2), 10), >> Vprint(i)) >> >> show_expression('(for i in [a,b,c] do print(i))) >> => Vdo_in(i, list(a, b, c), false, false, false, false, Vprint(i)) >> >> >> ---------------- >> >> /* Show Maxima expression in explicit form. >> >> For example, with inflag:false (the default): >> >> show_expression((a[3]-3)/sqrt(5)) => f/(plus(subsc(a,3),-3),sqrt(5)) >> >> with inflag:true (to show the internal form): >> >> show_expression(a[3]/sqrt(5)) => f*(f^(5,rat(-1,2)),subsc(a,3)) >> >> */ >> >> show_expression(ex):= >> if atom(ex) then ex >> elseif subvarp(ex) then >> funmake('subsc,cons(op(ex),[maplist(show_expression,args(ex))])) >> elseif ratnump(ex) then funmake('rat,[first(ex),second(ex)]) >> elseif mapatom(ex) then ex >> elseif member(part(ex,0), show_special) >> then funmake(show_expression_name[part(ex,0)], >> maplist(show_expression,args(ex))) >> elseif not(atom(part(ex,0))) >> then >> funmake('apply,[show_expression(part(ex,0)),maplist(show_expression,args(ex))]) >> else block([pex:part(ex,0)], >> funmake(concat(if nounify(pex)=pex then 'N else 'V,pex), >> maplist(show_expression,args(ex))))$ >> >> show_special: []$ >> for i in >> '[["+",add], ["-",minus], ["*",mul], ["^",power], ["/",div], >> [".",ncmul], ["^^", ncpower], >> ["[",list], ["{",set], >> [":",assign], ["::",varassign], >> [":=",define], ["::=",definemac] >> ["'",quote], ["(",prog], >> ["=",equal], ["#",notequal], [">",greaterp],[">=", greatereq], ["<", >> lessp], ["<=",lesseq], >> ["!",factorial], ["@",field] >> ] >> do (show_expression_name[first(i)]: second(i), >> push(first(i),show_special)); >> >> >> >> On Fri, Jul 12, 2024 at 2:10 PM Eduardo Ochs <edu...@gm...> >> wrote: >> >>> Hi Robert - >>> Fixed! See: >>> https://github.com/edrx/luatree/blob/main/luatree2.mac >>> >>> Example: >>> >>> (%i1) load("~/luatree/luatree2.mac")$ >>> (%i2) luatree (a(b,c))$ >>> a__. >>> | | >>> b c >>> (%i3) luatree (a[1][2](b,c))$ >>> ap_________.__. >>> | | | >>> [_]_____. b c >>> | | >>> [_]__. 2 >>> | | >>> a 1 >>> (%i4) luatree (a[1][2](b,c)(d))$ >>> ap_______________. >>> | | >>> ap_________.__. d >>> | | | >>> [_]_____. b c >>> | | >>> [_]__. 2 >>> | | >>> a 1 >>> (%i5) >>> >>> [[]], E. >>> >>> >>> >>> On Fri, 12 Jul 2024 at 13:40, Robert Dodier <rob...@gm...> >>> wrote: >>> >>>> On Fri, Jul 12, 2024 at 12:13 AM Eduardo Ochs <edu...@gm...> >>>> wrote: >>>> >>>> > "op" and "args" don't distinguish between a(b) and a[b]: >>>> > >>>> > (%i1) [o:a(b),op(o),args(o)]; >>>> > (%o1) [a(b), a, [b]] >>>> > (%i2) [o:a[b],op(o),args(o)]; >>>> > (%o2) [a , a, [b]] >>>> > b >>>> > (%i3) >>>> > >>>> > what do I need to use to distinguish them? >>>> >>>> In the luatree code, try changing atom(something) to >>>> mapatom(something) -- atom(a[b]) returns false but mapatom(a[b]) >>>> returns true. >>>> >>>> In addition to stuff like a[b], you may wish to cover stuff like >>>> a[b](x, y), a(b)(x, y), a[b](x, y)(z), which are all legitimate Maxima >>>> expressions ... I guess you just need to be prepared for op(something) >>>> returning a non-mapatom. >>>> >>>> All the best, >>>> >>>> Robert >>>> >>> _______________________________________________ >>> Maxima-discuss mailing list >>> Max...@li... >>> https://lists.sourceforge.net/lists/listinfo/maxima-discuss >>> >> |
From: Richard F. <fa...@gm...> - 2024-08-15 16:29:38
|
If you expect Maxima to continually retain a factorization like 2^3 through various simplifications, you have to turn off the simplifier, which pretty much breaks the whole system. If you want to see the factors and multiplicities, do this: :lisp (trace nratfact). If you want to acquire a result that gives prime factors and multiplicities in some structure that does not disappear, that structure might look like ... factorlist([2,3], [3,1}) for 2^3*3^1 or 24. It would be quite easy to make an alternative version of nratfact, or consider *factorlist(r) := psubst([ "^"="[","*"="[" ], factor(r));* which, for factorlist(24) gives [[2,3],3]. (sorry, if you want 3 to appear as 3^1 or [3,1] you'll have to write another line of code. As for the show expression task, here's a simpler piece of code for most of the task.. *showit(r):=psubst(psubstlist,r);* where *psubstlist: [ "^"=Power, "*"=Times, "+"=Plus, "/"=Div]; (*etc etc for all operators of interest . Maybe choose other names *)* I think that the graphical tree representation of expressions may be of some brief explanatory use, but the prefix expression version is, for me, much more appealing. Thus *showit (rat(x+1)^2);* returns *Plus(Power(x,2),Times(2,x),1)* RJF On Wed, Aug 14, 2024 at 6:15 PM Stavros Macrakis <mac...@gm...> wrote: > One problem with integer factorizations is that they are > pseudo-simplified: normally, Maxima does not allow 2^3 as a simplified > expression, but *factor* cheats and marks the expression as simplified, > even though it isn't. That means that it gives strange results if you try > to manipulate it: > > qq:factor(24) => 2^3*3 > qq+1 => 2^3*3 + 1 > > <big snip> |
From: Stavros M. <mac...@gm...> - 2024-08-15 17:12:01
|
As I said in my post: The clean way to process factorizations programmatically is with *ifactors*. ifactors(10!) => [[2, 8], [3, 4], [5, 2], [7, 1]] No reason to call internal functions or futz around with the output of *factor*, which is not designed for programmatic use. -s On Thu, Aug 15, 2024 at 9:29 AM Richard Fateman <fa...@gm...> wrote: > > If you expect Maxima to continually retain a factorization like 2^3 > through various simplifications, > you have to turn off the simplifier, which pretty much breaks the whole > system. > > If you want to see the factors and multiplicities, do this: > :lisp (trace nratfact). > > If you want to acquire a result that gives prime factors and > multiplicities in some structure that > does not disappear, that structure might look like ... factorlist([2,3], > [3,1}) for 2^3*3^1 or 24. > It would be quite easy to make an alternative version of nratfact, or > consider > > > *factorlist(r) := psubst([ "^"="[","*"="[" ], factor(r));* > > which, for factorlist(24) gives [[2,3],3]. > (sorry, if you want 3 to appear as 3^1 or [3,1] you'll have to write > another line of code. > > As for the show expression task, here's a simpler piece of code for most > of the task.. > *showit(r):=psubst(psubstlist,r);* > where > > > *psubstlist: [ "^"=Power, "*"=Times, "+"=Plus, "/"=Div]; (*etc etc > for all operators of interest . Maybe choose other names *)* > > I think that the graphical tree representation of expressions may be of > some brief explanatory use, but > the prefix expression version is, for me, much more appealing. Thus > *showit (rat(x+1)^2);* > returns > *Plus(Power(x,2),Times(2,x),1)* > > > RJF > > On Wed, Aug 14, 2024 at 6:15 PM Stavros Macrakis <mac...@gm...> > wrote: > >> One problem with integer factorizations is that they are >> pseudo-simplified: normally, Maxima does not allow 2^3 as a simplified >> expression, but *factor* cheats and marks the expression as simplified, >> even though it isn't. That means that it gives strange results if you try >> to manipulate it: >> >> qq:factor(24) => 2^3*3 >> qq+1 => 2^3*3 + 1 >> >> <big snip> > > |
From: Eduardo O. <edu...@gm...> - 2024-08-17 20:54:57
|
Hi all, sorry for the delay - we're at the end of the semester here, with lots of tests to prepare and to mark... and this will be a partial answer - I haven't tried all of your suggestions yet. Anyway... My questions about the internal representation of the objects returned by "factor", "trunc" and "taylor" were not because I need to do something "practical" with these objects in the near future - I was asking them just because my mental model of Maxima objects is still very incomplete, and when I ask these questions here I usually get answers that help me a lot. The documentation for "trunc", at (info "(maxima)trunc") https://maxima.sourceforge.io/docs/manual/maxima_141.html#trunc says: Annotates the internal representation of the general expression <expr> so that it is displayed as if its sums were truncated Taylor series. <expr> is not otherwise modified. The snippet below shows some ways of exploring these annotations - I'm guessing that "annotations" is the correct term: a1 : a*b; a2 : factor(100); b1 : 23 + 45*x; b2 : trunc(b1); /* has a ... */ b3 : taylor(b1, x, 0, 1); /* has a ... and a /T/ */ ratp(b1); /* false */ ratp(b2); /* false */ ratp(b3); /* true */ to_lisp(); #$a*b$ ; ((MTIMES SIMP) $A $B) #$a1$ ; ((MTIMES SIMP) $A $B) #$a2$ ; ((MTIMES SIMP FACTORED) ((MEXPT SIMP) 2 2) ((MEXPT SIMP) 5 2)) #$b1$ ; ((MPLUS SIMP) 23 ((MTIMES SIMP) 45 $X)) #$b2$ ; ((MPLUS SIMP TRUNC) 23 ((MTIMES SIMP) 45 $X)) #$b3$ ; ((MRAT SIMP ... TRUNC) PS ...) (car #$b2$) ; (MPLUS SIMP TRUNC) (cdar #$b2$) ; (SIMP TRUNC) (cddar #$b2$) ; (TRUNC) (to-maxima) There is a simple way to detect "taylorness" from Maxima - we can use "ratp" - but I couldn't find a simple way to detect "truncness", or "factoredness"... my guess is that if, and when, I decide that some of these annotations are important in my programs that represent Maxima objects as trees, then I will have write some Lisp to interpret the "cdar"s or the "cddar"s of these objects to see if they have any annotations that are worth showing... and "worth showing" is something that obviously depends on the context, and in many cases just adding a way to indicate that "this object has non-trivial annotations" would be enough. Anyway, these annotations look very important, but the only places in the manual in which I remember seeing them mentioned clearly are here, (info "(maxima)Introduction to Simplification") https://maxima.sourceforge.io/docs/manual/maxima_45.html that points to this paper, in which they are called "flags", https://people.eecs.berkeley.edu/~fateman/papers/intro5.txt https://maxima.sourceforge.io/misc/Fateman-Salz_Simplifier_Paper.pdf and here: (info "(maxima)Introduction to Lists") https://maxima.sourceforge.io/docs/manual/maxima_20.html Are there standard functions to inspect them _from Maxima_? Any pointers, comments, recommendations? Thanks in advance, and, again, sorry for not having digested all the material in your previous answers _yet_... =/ Eduardo Ochs http://anggtwu.net/eev-maxima.html On Thu, 15 Aug 2024 at 14:11, Stavros Macrakis <mac...@gm...> wrote: > As I said in my post: > > The clean way to process factorizations programmatically is with > *ifactors*. > > ifactors(10!) => [[2, 8], [3, 4], [5, 2], [7, 1]] > > > No reason to call internal functions or futz around with the output of > *factor*, which is not designed for programmatic use. > > -s > > > On Thu, Aug 15, 2024 at 9:29 AM Richard Fateman <fa...@gm...> wrote: > >> >> If you expect Maxima to continually retain a factorization like 2^3 >> through various simplifications, >> you have to turn off the simplifier, which pretty much breaks the whole >> system. >> >> If you want to see the factors and multiplicities, do this: >> :lisp (trace nratfact). >> >> If you want to acquire a result that gives prime factors and >> multiplicities in some structure that >> does not disappear, that structure might look like ... factorlist([2,3], >> [3,1}) for 2^3*3^1 or 24. >> It would be quite easy to make an alternative version of nratfact, or >> consider >> >> >> *factorlist(r) := psubst([ "^"="[","*"="[" ], factor(r));* >> >> which, for factorlist(24) gives [[2,3],3]. >> (sorry, if you want 3 to appear as 3^1 or [3,1] you'll have to write >> another line of code. >> >> As for the show expression task, here's a simpler piece of code for most >> of the task.. >> *showit(r):=psubst(psubstlist,r);* >> where >> >> >> *psubstlist: [ "^"=Power, "*"=Times, "+"=Plus, "/"=Div]; (*etc etc >> for all operators of interest . Maybe choose other names *)* >> >> I think that the graphical tree representation of expressions may be of >> some brief explanatory use, but >> the prefix expression version is, for me, much more appealing. Thus >> *showit (rat(x+1)^2);* >> returns >> *Plus(Power(x,2),Times(2,x),1)* >> >> >> RJF >> >> On Wed, Aug 14, 2024 at 6:15 PM Stavros Macrakis <mac...@gm...> >> wrote: >> >>> One problem with integer factorizations is that they are >>> pseudo-simplified: normally, Maxima does not allow 2^3 as a simplified >>> expression, but *factor* cheats and marks the expression as simplified, >>> even though it isn't. That means that it gives strange results if you try >>> to manipulate it: >>> >>> qq:factor(24) => 2^3*3 >>> qq+1 => 2^3*3 + 1 >>> >>> <big snip> >> >> > |
From: Stavros M. <mac...@gm...> - 2024-08-17 22:04:36
|
taylorp(taylor(1,x,0,1)) => true On Sat, Aug 17, 2024, 16:54 Eduardo Ochs <edu...@gm...> wrote: > Hi all, > > sorry for the delay - we're at the end of the semester here, with lots > of tests to prepare and to mark... and this will be a partial answer - > I haven't tried all of your suggestions yet. Anyway... > > My questions about the internal representation of the objects returned > by "factor", "trunc" and "taylor" were not because I need to do > something "practical" with these objects in the near future - I was > asking them just because my mental model of Maxima objects is still > very incomplete, and when I ask these questions here I usually get > answers that help me a lot. > > The documentation for "trunc", at > > (info "(maxima)trunc") > https://maxima.sourceforge.io/docs/manual/maxima_141.html#trunc > > says: > > Annotates the internal representation of the general expression > <expr> so that it is displayed as if its sums were truncated Taylor > series. <expr> is not otherwise modified. > > The snippet below shows some ways of exploring these annotations - I'm > guessing that "annotations" is the correct term: > > a1 : a*b; > a2 : factor(100); > b1 : 23 + 45*x; > b2 : trunc(b1); /* has a ... */ > b3 : taylor(b1, x, 0, 1); /* has a ... and a /T/ */ > ratp(b1); /* false */ > ratp(b2); /* false */ > ratp(b3); /* true */ > to_lisp(); > #$a*b$ ; ((MTIMES SIMP) $A $B) > #$a1$ ; ((MTIMES SIMP) $A $B) > #$a2$ ; ((MTIMES SIMP FACTORED) ((MEXPT SIMP) 2 2) ((MEXPT SIMP) 5 > 2)) > #$b1$ ; ((MPLUS SIMP) 23 ((MTIMES SIMP) 45 $X)) > #$b2$ ; ((MPLUS SIMP TRUNC) 23 ((MTIMES SIMP) 45 $X)) > #$b3$ ; ((MRAT SIMP ... TRUNC) PS ...) > (car #$b2$) ; (MPLUS SIMP TRUNC) > (cdar #$b2$) ; (SIMP TRUNC) > (cddar #$b2$) ; (TRUNC) > (to-maxima) > > There is a simple way to detect "taylorness" from Maxima - we can use > "ratp" - but I couldn't find a simple way to detect "truncness", or > "factoredness"... my guess is that if, and when, I decide that some of > these annotations are important in my programs that represent Maxima > objects as trees, then I will have write some Lisp to interpret the > "cdar"s or the "cddar"s of these objects to see if they have any > annotations that are worth showing... and "worth showing" is something > that obviously depends on the context, and in many cases just adding a > way to indicate that "this object has non-trivial annotations" would > be enough. > > Anyway, these annotations look very important, but the only places in > the manual in which I remember seeing them mentioned clearly are here, > > (info "(maxima)Introduction to Simplification") > https://maxima.sourceforge.io/docs/manual/maxima_45.html > > that points to this paper, in which they are called "flags", > > https://people.eecs.berkeley.edu/~fateman/papers/intro5.txt > https://maxima.sourceforge.io/misc/Fateman-Salz_Simplifier_Paper.pdf > > and here: > > (info "(maxima)Introduction to Lists") > https://maxima.sourceforge.io/docs/manual/maxima_20.html > > Are there standard functions to inspect them _from Maxima_? Any > pointers, comments, recommendations? > > Thanks in advance, and, again, sorry for not having digested all the > material in your previous answers _yet_... =/ > > Eduardo Ochs > http://anggtwu.net/eev-maxima.html > > > On Thu, 15 Aug 2024 at 14:11, Stavros Macrakis <mac...@gm...> wrote: > >> As I said in my post: >> >> The clean way to process factorizations programmatically is with >> *ifactors*. >> >> ifactors(10!) => [[2, 8], [3, 4], [5, 2], [7, 1]] >> >> >> No reason to call internal functions or futz around with the output of >> *factor*, which is not designed for programmatic use. >> >> -s >> >> >> On Thu, Aug 15, 2024 at 9:29 AM Richard Fateman <fa...@gm...> >> wrote: >> >>> >>> If you expect Maxima to continually retain a factorization like 2^3 >>> through various simplifications, >>> you have to turn off the simplifier, which pretty much breaks the whole >>> system. >>> >>> If you want to see the factors and multiplicities, do this: >>> :lisp (trace nratfact). >>> >>> If you want to acquire a result that gives prime factors and >>> multiplicities in some structure that >>> does not disappear, that structure might look like ... >>> factorlist([2,3], [3,1}) for 2^3*3^1 or 24. >>> It would be quite easy to make an alternative version of nratfact, or >>> consider >>> >>> >>> *factorlist(r) := psubst([ "^"="[","*"="[" ], factor(r));* >>> >>> which, for factorlist(24) gives [[2,3],3]. >>> (sorry, if you want 3 to appear as 3^1 or [3,1] you'll have to write >>> another line of code. >>> >>> As for the show expression task, here's a simpler piece of code for most >>> of the task.. >>> *showit(r):=psubst(psubstlist,r);* >>> where >>> >>> >>> *psubstlist: [ "^"=Power, "*"=Times, "+"=Plus, "/"=Div]; (*etc etc >>> for all operators of interest . Maybe choose other names *)* >>> >>> I think that the graphical tree representation of expressions may be of >>> some brief explanatory use, but >>> the prefix expression version is, for me, much more appealing. Thus >>> *showit (rat(x+1)^2);* >>> returns >>> *Plus(Power(x,2),Times(2,x),1)* >>> >>> >>> RJF >>> >>> On Wed, Aug 14, 2024 at 6:15 PM Stavros Macrakis <mac...@gm...> >>> wrote: >>> >>>> One problem with integer factorizations is that they are >>>> pseudo-simplified: normally, Maxima does not allow 2^3 as a simplified >>>> expression, but *factor* cheats and marks the expression as >>>> simplified, even though it isn't. That means that it gives strange results >>>> if you try to manipulate it: >>>> >>>> qq:factor(24) => 2^3*3 >>>> qq+1 => 2^3*3 + 1 >>>> >>>> <big snip> >>> >>> >> |
From: Stavros M. <mac...@gm...> - 2024-08-17 22:30:02
|
Honestly, I've never used the *trunc* function and I wonder why anyone would. After all, it has no effect on subsequent manipulations: trunc(x+1) => 1+x+... trunc(x+1)+1 => x+2 How could it? Maxima doesn't know to what degree it's truncated. I'll guess that it's used simply for nice output as a last step. As for the factored flag, this should have no user-visible effect. It just helps Maxima not re-factor something that's already factored. And I'll repeat that using pseudo-simplified expressions like the output of factor(24) is a hack. At your level of understanding, I don't know why you'd want to translate the taylor internal form into something "user-friendly"; the sexpression is probably the best way to examine it. On Sat, Aug 17, 2024 at 6:04 PM Stavros Macrakis <mac...@gm...> wrote: > taylorp(taylor(1,x,0,1)) => true > > > On Sat, Aug 17, 2024, 16:54 Eduardo Ochs <edu...@gm...> wrote: > >> Hi all, >> >> sorry for the delay - we're at the end of the semester here, with lots >> of tests to prepare and to mark... and this will be a partial answer - >> I haven't tried all of your suggestions yet. Anyway... >> >> My questions about the internal representation of the objects returned >> by "factor", "trunc" and "taylor" were not because I need to do >> something "practical" with these objects in the near future - I was >> asking them just because my mental model of Maxima objects is still >> very incomplete, and when I ask these questions here I usually get >> answers that help me a lot. >> >> The documentation for "trunc", at >> >> (info "(maxima)trunc") >> https://maxima.sourceforge.io/docs/manual/maxima_141.html#trunc >> >> says: >> >> Annotates the internal representation of the general expression >> <expr> so that it is displayed as if its sums were truncated Taylor >> series. <expr> is not otherwise modified. >> >> The snippet below shows some ways of exploring these annotations - I'm >> guessing that "annotations" is the correct term: >> >> a1 : a*b; >> a2 : factor(100); >> b1 : 23 + 45*x; >> b2 : trunc(b1); /* has a ... */ >> b3 : taylor(b1, x, 0, 1); /* has a ... and a /T/ */ >> ratp(b1); /* false */ >> ratp(b2); /* false */ >> ratp(b3); /* true */ >> to_lisp(); >> #$a*b$ ; ((MTIMES SIMP) $A $B) >> #$a1$ ; ((MTIMES SIMP) $A $B) >> #$a2$ ; ((MTIMES SIMP FACTORED) ((MEXPT SIMP) 2 2) ((MEXPT SIMP) 5 >> 2)) >> #$b1$ ; ((MPLUS SIMP) 23 ((MTIMES SIMP) 45 $X)) >> #$b2$ ; ((MPLUS SIMP TRUNC) 23 ((MTIMES SIMP) 45 $X)) >> #$b3$ ; ((MRAT SIMP ... TRUNC) PS ...) >> (car #$b2$) ; (MPLUS SIMP TRUNC) >> (cdar #$b2$) ; (SIMP TRUNC) >> (cddar #$b2$) ; (TRUNC) >> (to-maxima) >> >> There is a simple way to detect "taylorness" from Maxima - we can use >> "ratp" - but I couldn't find a simple way to detect "truncness", or >> "factoredness"... my guess is that if, and when, I decide that some of >> these annotations are important in my programs that represent Maxima >> objects as trees, then I will have write some Lisp to interpret the >> "cdar"s or the "cddar"s of these objects to see if they have any >> annotations that are worth showing... and "worth showing" is something >> that obviously depends on the context, and in many cases just adding a >> way to indicate that "this object has non-trivial annotations" would >> be enough. >> >> Anyway, these annotations look very important, but the only places in >> the manual in which I remember seeing them mentioned clearly are here, >> >> (info "(maxima)Introduction to Simplification") >> https://maxima.sourceforge.io/docs/manual/maxima_45.html >> >> that points to this paper, in which they are called "flags", >> >> https://people.eecs.berkeley.edu/~fateman/papers/intro5.txt >> https://maxima.sourceforge.io/misc/Fateman-Salz_Simplifier_Paper.pdf >> >> and here: >> >> (info "(maxima)Introduction to Lists") >> https://maxima.sourceforge.io/docs/manual/maxima_20.html >> >> Are there standard functions to inspect them _from Maxima_? Any >> pointers, comments, recommendations? >> >> Thanks in advance, and, again, sorry for not having digested all the >> material in your previous answers _yet_... =/ >> >> Eduardo Ochs >> http://anggtwu.net/eev-maxima.html >> >> >> On Thu, 15 Aug 2024 at 14:11, Stavros Macrakis <mac...@gm...> >> wrote: >> >>> As I said in my post: >>> >>> The clean way to process factorizations programmatically is with >>> *ifactors*. >>> >>> ifactors(10!) => [[2, 8], [3, 4], [5, 2], [7, 1]] >>> >>> >>> No reason to call internal functions or futz around with the output of >>> *factor*, which is not designed for programmatic use. >>> >>> -s >>> >>> >>> On Thu, Aug 15, 2024 at 9:29 AM Richard Fateman <fa...@gm...> >>> wrote: >>> >>>> >>>> If you expect Maxima to continually retain a factorization like 2^3 >>>> through various simplifications, >>>> you have to turn off the simplifier, which pretty much breaks the whole >>>> system. >>>> >>>> If you want to see the factors and multiplicities, do this: >>>> :lisp (trace nratfact). >>>> >>>> If you want to acquire a result that gives prime factors and >>>> multiplicities in some structure that >>>> does not disappear, that structure might look like ... >>>> factorlist([2,3], [3,1}) for 2^3*3^1 or 24. >>>> It would be quite easy to make an alternative version of nratfact, or >>>> consider >>>> >>>> >>>> *factorlist(r) := psubst([ "^"="[","*"="[" ], factor(r));* >>>> >>>> which, for factorlist(24) gives [[2,3],3]. >>>> (sorry, if you want 3 to appear as 3^1 or [3,1] you'll have to write >>>> another line of code. >>>> >>>> As for the show expression task, here's a simpler piece of code for >>>> most of the task.. >>>> *showit(r):=psubst(psubstlist,r);* >>>> where >>>> >>>> >>>> *psubstlist: [ "^"=Power, "*"=Times, "+"=Plus, "/"=Div]; (*etc >>>> etc for all operators of interest . Maybe choose other names *)* >>>> >>>> I think that the graphical tree representation of expressions may be of >>>> some brief explanatory use, but >>>> the prefix expression version is, for me, much more appealing. Thus >>>> *showit (rat(x+1)^2);* >>>> returns >>>> *Plus(Power(x,2),Times(2,x),1)* >>>> >>>> >>>> RJF >>>> >>>> On Wed, Aug 14, 2024 at 6:15 PM Stavros Macrakis <mac...@gm...> >>>> wrote: >>>> >>>>> One problem with integer factorizations is that they are >>>>> pseudo-simplified: normally, Maxima does not allow 2^3 as a simplified >>>>> expression, but *factor* cheats and marks the expression as >>>>> simplified, even though it isn't. That means that it gives strange results >>>>> if you try to manipulate it: >>>>> >>>>> qq:factor(24) => 2^3*3 >>>>> qq+1 => 2^3*3 + 1 >>>>> >>>>> <big snip> >>>> >>>> >>> |
From: Eduardo O. <edu...@gm...> - 2024-08-17 22:22:17
|
Thanks!!! A quick question... The source of taylorp in simp.lisp is very clear: (defmfun $taylorp (x) (and (not (atom x)) (eq (caar x) 'mrat) (member 'trunc (cdar x)) t)) but :lisp (describe '$taylorp) says "Symbol-plist: ... TRANSLATED -> T ...". What does the "translated" mean in this case? I took a quick look at all the occurences of "translate" in the info manual and I got the impression that translated functions come from Maxima functions, but I grepped the sources and I didn't find a possible Maxima source for this $taylorp... Cheers, TIA, etc, Eduardo On Sat, 17 Aug 2024 at 19:04, Stavros Macrakis <mac...@gm...> wrote: > taylorp(taylor(1,x,0,1)) => true > > > On Sat, Aug 17, 2024, 16:54 Eduardo Ochs <edu...@gm...> wrote: > >> Hi all, >> >> sorry for the delay - we're at the end of the semester here, with lots >> of tests to prepare and to mark... and this will be a partial answer - >> I haven't tried all of your suggestions yet. Anyway... >> >> My questions about the internal representation of the objects returned >> by "factor", "trunc" and "taylor" were not because I need to do >> something "practical" with these objects in the near future - I was >> asking them just because my mental model of Maxima objects is still >> very incomplete, and when I ask these questions here I usually get >> answers that help me a lot. >> >> The documentation for "trunc", at >> >> (info "(maxima)trunc") >> https://maxima.sourceforge.io/docs/manual/maxima_141.html#trunc >> >> says: >> >> Annotates the internal representation of the general expression >> <expr> so that it is displayed as if its sums were truncated Taylor >> series. <expr> is not otherwise modified. >> >> The snippet below shows some ways of exploring these annotations - I'm >> guessing that "annotations" is the correct term: >> >> a1 : a*b; >> a2 : factor(100); >> b1 : 23 + 45*x; >> b2 : trunc(b1); /* has a ... */ >> b3 : taylor(b1, x, 0, 1); /* has a ... and a /T/ */ >> ratp(b1); /* false */ >> ratp(b2); /* false */ >> ratp(b3); /* true */ >> to_lisp(); >> #$a*b$ ; ((MTIMES SIMP) $A $B) >> #$a1$ ; ((MTIMES SIMP) $A $B) >> #$a2$ ; ((MTIMES SIMP FACTORED) ((MEXPT SIMP) 2 2) ((MEXPT SIMP) 5 >> 2)) >> #$b1$ ; ((MPLUS SIMP) 23 ((MTIMES SIMP) 45 $X)) >> #$b2$ ; ((MPLUS SIMP TRUNC) 23 ((MTIMES SIMP) 45 $X)) >> #$b3$ ; ((MRAT SIMP ... TRUNC) PS ...) >> (car #$b2$) ; (MPLUS SIMP TRUNC) >> (cdar #$b2$) ; (SIMP TRUNC) >> (cddar #$b2$) ; (TRUNC) >> (to-maxima) >> >> There is a simple way to detect "taylorness" from Maxima - we can use >> "ratp" - but I couldn't find a simple way to detect "truncness", or >> "factoredness"... my guess is that if, and when, I decide that some of >> these annotations are important in my programs that represent Maxima >> objects as trees, then I will have write some Lisp to interpret the >> "cdar"s or the "cddar"s of these objects to see if they have any >> annotations that are worth showing... and "worth showing" is something >> that obviously depends on the context, and in many cases just adding a >> way to indicate that "this object has non-trivial annotations" would >> be enough. >> >> Anyway, these annotations look very important, but the only places in >> the manual in which I remember seeing them mentioned clearly are here, >> >> (info "(maxima)Introduction to Simplification") >> https://maxima.sourceforge.io/docs/manual/maxima_45.html >> >> that points to this paper, in which they are called "flags", >> >> https://people.eecs.berkeley.edu/~fateman/papers/intro5.txt >> https://maxima.sourceforge.io/misc/Fateman-Salz_Simplifier_Paper.pdf >> >> and here: >> >> (info "(maxima)Introduction to Lists") >> https://maxima.sourceforge.io/docs/manual/maxima_20.html >> >> Are there standard functions to inspect them _from Maxima_? Any >> pointers, comments, recommendations? >> >> Thanks in advance, and, again, sorry for not having digested all the >> material in your previous answers _yet_... =/ >> >> Eduardo Ochs >> http://anggtwu.net/eev-maxima.html >> >> >> On Thu, 15 Aug 2024 at 14:11, Stavros Macrakis <mac...@gm...> >> wrote: >> >>> As I said in my post: >>> >>> The clean way to process factorizations programmatically is with >>> *ifactors*. >>> >>> ifactors(10!) => [[2, 8], [3, 4], [5, 2], [7, 1]] >>> >>> >>> No reason to call internal functions or futz around with the output of >>> *factor*, which is not designed for programmatic use. >>> >>> -s >>> >>> >>> On Thu, Aug 15, 2024 at 9:29 AM Richard Fateman <fa...@gm...> >>> wrote: >>> >>>> >>>> If you expect Maxima to continually retain a factorization like 2^3 >>>> through various simplifications, >>>> you have to turn off the simplifier, which pretty much breaks the whole >>>> system. >>>> >>>> If you want to see the factors and multiplicities, do this: >>>> :lisp (trace nratfact). >>>> >>>> If you want to acquire a result that gives prime factors and >>>> multiplicities in some structure that >>>> does not disappear, that structure might look like ... >>>> factorlist([2,3], [3,1}) for 2^3*3^1 or 24. >>>> It would be quite easy to make an alternative version of nratfact, or >>>> consider >>>> >>>> >>>> *factorlist(r) := psubst([ "^"="[","*"="[" ], factor(r));* >>>> >>>> which, for factorlist(24) gives [[2,3],3]. >>>> (sorry, if you want 3 to appear as 3^1 or [3,1] you'll have to write >>>> another line of code. >>>> >>>> As for the show expression task, here's a simpler piece of code for >>>> most of the task.. >>>> *showit(r):=psubst(psubstlist,r);* >>>> where >>>> >>>> >>>> *psubstlist: [ "^"=Power, "*"=Times, "+"=Plus, "/"=Div]; (*etc >>>> etc for all operators of interest . Maybe choose other names *)* >>>> >>>> I think that the graphical tree representation of expressions may be of >>>> some brief explanatory use, but >>>> the prefix expression version is, for me, much more appealing. Thus >>>> *showit (rat(x+1)^2);* >>>> returns >>>> *Plus(Power(x,2),Times(2,x),1)* >>>> >>>> >>>> RJF >>>> >>>> On Wed, Aug 14, 2024 at 6:15 PM Stavros Macrakis <mac...@gm...> >>>> wrote: >>>> >>>>> One problem with integer factorizations is that they are >>>>> pseudo-simplified: normally, Maxima does not allow 2^3 as a simplified >>>>> expression, but *factor* cheats and marks the expression as >>>>> simplified, even though it isn't. That means that it gives strange results >>>>> if you try to manipulate it: >>>>> >>>>> qq:factor(24) => 2^3*3 >>>>> qq+1 => 2^3*3 + 1 >>>>> >>>>> <big snip> >>>> >>>> >>> |
From: Stavros M. <mac...@gm...> - 2024-08-17 22:38:59
|
Normally, the *translated* property means that the function was defined using *translate*. I have no idea why functions originally defined in Lisp have this flag. This is intentional (defmfun/ commac.lisp): ;; I (rtoy) think we can consider all defmfun's as translated functions. (defprop ,function t translated) but I have no idea of the rationale. This seems wrong -- for example, (mget '$cons 'mexpr) => nil, unlike a genuine translated function, where it is the Maxima definition of the function. Ray? -s On Sat, Aug 17, 2024 at 6:22 PM Eduardo Ochs <edu...@gm...> wrote: > Thanks!!! > A quick question... > The source of taylorp in simp.lisp is very clear: > > (defmfun $taylorp (x) > (and (not (atom x)) > (eq (caar x) 'mrat) > (member 'trunc (cdar x)) t)) > > but > > :lisp (describe '$taylorp) > > says "Symbol-plist: ... TRANSLATED -> T ...". > > What does the "translated" mean in this case? I took a quick look at > all the occurences of "translate" in the info manual and I got the > impression that translated functions come from Maxima functions, but I > grepped the sources and I didn't find a possible Maxima source for > this $taylorp... > > Cheers, TIA, etc, > Eduardo > > > On Sat, 17 Aug 2024 at 19:04, Stavros Macrakis <mac...@gm...> wrote: > >> taylorp(taylor(1,x,0,1)) => true >> >> >> On Sat, Aug 17, 2024, 16:54 Eduardo Ochs <edu...@gm...> wrote: >> >>> Hi all, >>> >>> sorry for the delay - we're at the end of the semester here, with lots >>> of tests to prepare and to mark... and this will be a partial answer - >>> I haven't tried all of your suggestions yet. Anyway... >>> >>> My questions about the internal representation of the objects returned >>> by "factor", "trunc" and "taylor" were not because I need to do >>> something "practical" with these objects in the near future - I was >>> asking them just because my mental model of Maxima objects is still >>> very incomplete, and when I ask these questions here I usually get >>> answers that help me a lot. >>> >>> The documentation for "trunc", at >>> >>> (info "(maxima)trunc") >>> https://maxima.sourceforge.io/docs/manual/maxima_141.html#trunc >>> >>> says: >>> >>> Annotates the internal representation of the general expression >>> <expr> so that it is displayed as if its sums were truncated Taylor >>> series. <expr> is not otherwise modified. >>> >>> The snippet below shows some ways of exploring these annotations - I'm >>> guessing that "annotations" is the correct term: >>> >>> a1 : a*b; >>> a2 : factor(100); >>> b1 : 23 + 45*x; >>> b2 : trunc(b1); /* has a ... */ >>> b3 : taylor(b1, x, 0, 1); /* has a ... and a /T/ */ >>> ratp(b1); /* false */ >>> ratp(b2); /* false */ >>> ratp(b3); /* true */ >>> to_lisp(); >>> #$a*b$ ; ((MTIMES SIMP) $A $B) >>> #$a1$ ; ((MTIMES SIMP) $A $B) >>> #$a2$ ; ((MTIMES SIMP FACTORED) ((MEXPT SIMP) 2 2) ((MEXPT SIMP) 5 >>> 2)) >>> #$b1$ ; ((MPLUS SIMP) 23 ((MTIMES SIMP) 45 $X)) >>> #$b2$ ; ((MPLUS SIMP TRUNC) 23 ((MTIMES SIMP) 45 $X)) >>> #$b3$ ; ((MRAT SIMP ... TRUNC) PS ...) >>> (car #$b2$) ; (MPLUS SIMP TRUNC) >>> (cdar #$b2$) ; (SIMP TRUNC) >>> (cddar #$b2$) ; (TRUNC) >>> (to-maxima) >>> >>> There is a simple way to detect "taylorness" from Maxima - we can use >>> "ratp" - but I couldn't find a simple way to detect "truncness", or >>> "factoredness"... my guess is that if, and when, I decide that some of >>> these annotations are important in my programs that represent Maxima >>> objects as trees, then I will have write some Lisp to interpret the >>> "cdar"s or the "cddar"s of these objects to see if they have any >>> annotations that are worth showing... and "worth showing" is something >>> that obviously depends on the context, and in many cases just adding a >>> way to indicate that "this object has non-trivial annotations" would >>> be enough. >>> >>> Anyway, these annotations look very important, but the only places in >>> the manual in which I remember seeing them mentioned clearly are here, >>> >>> (info "(maxima)Introduction to Simplification") >>> https://maxima.sourceforge.io/docs/manual/maxima_45.html >>> >>> that points to this paper, in which they are called "flags", >>> >>> https://people.eecs.berkeley.edu/~fateman/papers/intro5.txt >>> https://maxima.sourceforge.io/misc/Fateman-Salz_Simplifier_Paper.pdf >>> >>> and here: >>> >>> (info "(maxima)Introduction to Lists") >>> https://maxima.sourceforge.io/docs/manual/maxima_20.html >>> >>> Are there standard functions to inspect them _from Maxima_? Any >>> pointers, comments, recommendations? >>> >>> Thanks in advance, and, again, sorry for not having digested all the >>> material in your previous answers _yet_... =/ >>> >>> Eduardo Ochs >>> http://anggtwu.net/eev-maxima.html >>> >>> >>> On Thu, 15 Aug 2024 at 14:11, Stavros Macrakis <mac...@gm...> >>> wrote: >>> >>>> As I said in my post: >>>> >>>> The clean way to process factorizations programmatically is with >>>> *ifactors*. >>>> >>>> ifactors(10!) => [[2, 8], [3, 4], [5, 2], [7, 1]] >>>> >>>> >>>> No reason to call internal functions or futz around with the output of >>>> *factor*, which is not designed for programmatic use. >>>> >>>> -s >>>> >>>> >>>> On Thu, Aug 15, 2024 at 9:29 AM Richard Fateman <fa...@gm...> >>>> wrote: >>>> >>>>> >>>>> If you expect Maxima to continually retain a factorization like 2^3 >>>>> through various simplifications, >>>>> you have to turn off the simplifier, which pretty much breaks the >>>>> whole system. >>>>> >>>>> If you want to see the factors and multiplicities, do this: >>>>> :lisp (trace nratfact). >>>>> >>>>> If you want to acquire a result that gives prime factors and >>>>> multiplicities in some structure that >>>>> does not disappear, that structure might look like ... >>>>> factorlist([2,3], [3,1}) for 2^3*3^1 or 24. >>>>> It would be quite easy to make an alternative version of nratfact, or >>>>> consider >>>>> >>>>> >>>>> *factorlist(r) := psubst([ "^"="[","*"="[" ], factor(r));* >>>>> >>>>> which, for factorlist(24) gives [[2,3],3]. >>>>> (sorry, if you want 3 to appear as 3^1 or [3,1] you'll have to write >>>>> another line of code. >>>>> >>>>> As for the show expression task, here's a simpler piece of code for >>>>> most of the task.. >>>>> *showit(r):=psubst(psubstlist,r);* >>>>> where >>>>> >>>>> >>>>> *psubstlist: [ "^"=Power, "*"=Times, "+"=Plus, "/"=Div]; (*etc >>>>> etc for all operators of interest . Maybe choose other names *)* >>>>> >>>>> I think that the graphical tree representation of expressions may be >>>>> of some brief explanatory use, but >>>>> the prefix expression version is, for me, much more appealing. Thus >>>>> *showit (rat(x+1)^2);* >>>>> returns >>>>> *Plus(Power(x,2),Times(2,x),1)* >>>>> >>>>> >>>>> RJF >>>>> >>>>> On Wed, Aug 14, 2024 at 6:15 PM Stavros Macrakis <mac...@gm...> >>>>> wrote: >>>>> >>>>>> One problem with integer factorizations is that they are >>>>>> pseudo-simplified: normally, Maxima does not allow 2^3 as a simplified >>>>>> expression, but *factor* cheats and marks the expression as >>>>>> simplified, even though it isn't. That means that it gives strange results >>>>>> if you try to manipulate it: >>>>>> >>>>>> qq:factor(24) => 2^3*3 >>>>>> qq+1 => 2^3*3 + 1 >>>>>> >>>>>> <big snip> >>>>> >>>>> >>>> |
From: Raymond T. <toy...@gm...> - 2024-08-18 00:09:18
|
On Sat, Aug 17, 2024, 3:40 PM Stavros Macrakis <mac...@gm...> wrote: > Normally, the *translated* property means that the function was defined > using *translate*. > > I have no idea why functions originally defined in Lisp have this flag. > This is intentional (defmfun/ commac.lisp): > > ;; I (rtoy) think we can consider all defmfun's as translated > functions. > (defprop ,function t translated) > > but I have no idea of the rationale. This seems wrong -- for example, > (mget '$cons 'mexpr) => nil, unlike a genuine translated function, where it > is the Maxima definition of the function. > I'm not really sure, but I think many of the original functions before conversion to defmfun, had the translated property already. So I just made defmfun do that automatically. Is have to do some code archeology to figure this out. If possible. > > Ray? > > -s > > On Sat, Aug 17, 2024 at 6:22 PM Eduardo Ochs <edu...@gm...> > wrote: > >> Thanks!!! >> A quick question... >> The source of taylorp in simp.lisp is very clear: >> >> (defmfun $taylorp (x) >> (and (not (atom x)) >> (eq (caar x) 'mrat) >> (member 'trunc (cdar x)) t)) >> >> but >> >> :lisp (describe '$taylorp) >> >> says "Symbol-plist: ... TRANSLATED -> T ...". >> >> What does the "translated" mean in this case? I took a quick look at >> all the occurences of "translate" in the info manual and I got the >> impression that translated functions come from Maxima functions, but I >> grepped the sources and I didn't find a possible Maxima source for >> this $taylorp... >> >> Cheers, TIA, etc, >> Eduardo >> >> >> On Sat, 17 Aug 2024 at 19:04, Stavros Macrakis <mac...@gm...> >> wrote: >> >>> taylorp(taylor(1,x,0,1)) => true >>> >>> >>> On Sat, Aug 17, 2024, 16:54 Eduardo Ochs <edu...@gm...> wrote: >>> >>>> Hi all, >>>> >>>> sorry for the delay - we're at the end of the semester here, with lots >>>> of tests to prepare and to mark... and this will be a partial answer - >>>> I haven't tried all of your suggestions yet. Anyway... >>>> >>>> My questions about the internal representation of the objects returned >>>> by "factor", "trunc" and "taylor" were not because I need to do >>>> something "practical" with these objects in the near future - I was >>>> asking them just because my mental model of Maxima objects is still >>>> very incomplete, and when I ask these questions here I usually get >>>> answers that help me a lot. >>>> >>>> The documentation for "trunc", at >>>> >>>> (info "(maxima)trunc") >>>> https://maxima.sourceforge.io/docs/manual/maxima_141.html#trunc >>>> >>>> says: >>>> >>>> Annotates the internal representation of the general expression >>>> <expr> so that it is displayed as if its sums were truncated Taylor >>>> series. <expr> is not otherwise modified. >>>> >>>> The snippet below shows some ways of exploring these annotations - I'm >>>> guessing that "annotations" is the correct term: >>>> >>>> a1 : a*b; >>>> a2 : factor(100); >>>> b1 : 23 + 45*x; >>>> b2 : trunc(b1); /* has a ... */ >>>> b3 : taylor(b1, x, 0, 1); /* has a ... and a /T/ */ >>>> ratp(b1); /* false */ >>>> ratp(b2); /* false */ >>>> ratp(b3); /* true */ >>>> to_lisp(); >>>> #$a*b$ ; ((MTIMES SIMP) $A $B) >>>> #$a1$ ; ((MTIMES SIMP) $A $B) >>>> #$a2$ ; ((MTIMES SIMP FACTORED) ((MEXPT SIMP) 2 2) ((MEXPT SIMP) >>>> 5 2)) >>>> #$b1$ ; ((MPLUS SIMP) 23 ((MTIMES SIMP) 45 $X)) >>>> #$b2$ ; ((MPLUS SIMP TRUNC) 23 ((MTIMES SIMP) 45 $X)) >>>> #$b3$ ; ((MRAT SIMP ... TRUNC) PS ...) >>>> (car #$b2$) ; (MPLUS SIMP TRUNC) >>>> (cdar #$b2$) ; (SIMP TRUNC) >>>> (cddar #$b2$) ; (TRUNC) >>>> (to-maxima) >>>> >>>> There is a simple way to detect "taylorness" from Maxima - we can use >>>> "ratp" - but I couldn't find a simple way to detect "truncness", or >>>> "factoredness"... my guess is that if, and when, I decide that some of >>>> these annotations are important in my programs that represent Maxima >>>> objects as trees, then I will have write some Lisp to interpret the >>>> "cdar"s or the "cddar"s of these objects to see if they have any >>>> annotations that are worth showing... and "worth showing" is something >>>> that obviously depends on the context, and in many cases just adding a >>>> way to indicate that "this object has non-trivial annotations" would >>>> be enough. >>>> >>>> Anyway, these annotations look very important, but the only places in >>>> the manual in which I remember seeing them mentioned clearly are here, >>>> >>>> (info "(maxima)Introduction to Simplification") >>>> https://maxima.sourceforge.io/docs/manual/maxima_45.html >>>> >>>> that points to this paper, in which they are called "flags", >>>> >>>> https://people.eecs.berkeley.edu/~fateman/papers/intro5.txt >>>> https://maxima.sourceforge.io/misc/Fateman-Salz_Simplifier_Paper.pdf >>>> >>>> and here: >>>> >>>> (info "(maxima)Introduction to Lists") >>>> https://maxima.sourceforge.io/docs/manual/maxima_20.html >>>> >>>> Are there standard functions to inspect them _from Maxima_? Any >>>> pointers, comments, recommendations? >>>> >>>> Thanks in advance, and, again, sorry for not having digested all the >>>> material in your previous answers _yet_... =/ >>>> >>>> Eduardo Ochs >>>> http://anggtwu.net/eev-maxima.html >>>> >>>> >>>> On Thu, 15 Aug 2024 at 14:11, Stavros Macrakis <mac...@gm...> >>>> wrote: >>>> >>>>> As I said in my post: >>>>> >>>>> The clean way to process factorizations programmatically is with >>>>> *ifactors*. >>>>> >>>>> ifactors(10!) => [[2, 8], [3, 4], [5, 2], [7, 1]] >>>>> >>>>> >>>>> No reason to call internal functions or futz around with the output of >>>>> *factor*, which is not designed for programmatic use. >>>>> >>>>> -s >>>>> >>>>> >>>>> On Thu, Aug 15, 2024 at 9:29 AM Richard Fateman <fa...@gm...> >>>>> wrote: >>>>> >>>>>> >>>>>> If you expect Maxima to continually retain a factorization like 2^3 >>>>>> through various simplifications, >>>>>> you have to turn off the simplifier, which pretty much breaks the >>>>>> whole system. >>>>>> >>>>>> If you want to see the factors and multiplicities, do this: >>>>>> :lisp (trace nratfact). >>>>>> >>>>>> If you want to acquire a result that gives prime factors and >>>>>> multiplicities in some structure that >>>>>> does not disappear, that structure might look like ... >>>>>> factorlist([2,3], [3,1}) for 2^3*3^1 or 24. >>>>>> It would be quite easy to make an alternative version of nratfact, or >>>>>> consider >>>>>> >>>>>> >>>>>> *factorlist(r) := psubst([ "^"="[","*"="[" ], factor(r));* >>>>>> >>>>>> which, for factorlist(24) gives [[2,3],3]. >>>>>> (sorry, if you want 3 to appear as 3^1 or [3,1] you'll have to write >>>>>> another line of code. >>>>>> >>>>>> As for the show expression task, here's a simpler piece of code for >>>>>> most of the task.. >>>>>> *showit(r):=psubst(psubstlist,r);* >>>>>> where >>>>>> >>>>>> >>>>>> *psubstlist: [ "^"=Power, "*"=Times, "+"=Plus, "/"=Div]; (*etc >>>>>> etc for all operators of interest . Maybe choose other names *)* >>>>>> >>>>>> I think that the graphical tree representation of expressions may be >>>>>> of some brief explanatory use, but >>>>>> the prefix expression version is, for me, much more appealing. Thus >>>>>> *showit (rat(x+1)^2);* >>>>>> returns >>>>>> *Plus(Power(x,2),Times(2,x),1)* >>>>>> >>>>>> >>>>>> RJF >>>>>> >>>>>> On Wed, Aug 14, 2024 at 6:15 PM Stavros Macrakis <mac...@gm...> >>>>>> wrote: >>>>>> >>>>>>> One problem with integer factorizations is that they are >>>>>>> pseudo-simplified: normally, Maxima does not allow 2^3 as a simplified >>>>>>> expression, but *factor* cheats and marks the expression as >>>>>>> simplified, even though it isn't. That means that it gives strange results >>>>>>> if you try to manipulate it: >>>>>>> >>>>>>> qq:factor(24) => 2^3*3 >>>>>>> qq+1 => 2^3*3 + 1 >>>>>>> >>>>>>> <big snip> >>>>>> >>>>>> >>>>> _______________________________________________ > Maxima-discuss mailing list > Max...@li... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss > |
From: Raymond T. <toy...@gm...> - 2024-08-18 00:37:09
|
On 8/17/24 5:09 PM, Raymond Toy wrote: > > > On Sat, Aug 17, 2024, 3:40 PM Stavros Macrakis <mac...@gm...> wrote: > > Normally, the *translated* property means that the function was > defined using *translate*. > > I have no idea why functions originally defined in Lisp have this > flag. This is intentional (defmfun/ commac.lisp): > > ;; I (rtoy) think we can consider all defmfun'sas translated > functions. > (defprop ,function t translated) > > but I have no idea of the rationale. This seems wrong -- for > example, (mget '$cons 'mexpr) => nil, unlike a genuine translated > function, where it is the Maxima definition of the function. > > I'm not really sure, but I think many of the original functions before > conversion to defmfun, had the translated property already. So I just > made defmfun do that automatically. Is have to do some code archeology > to figure this out. If possible. Ah. Found this message: |commit 96e28268b5129b566a517499d31b5ae3c9d28285 Author: rtoy <rtoy> Date: Thu Dec 8 18:21:41 2005 +0000 Add the TRANLATED property for every function defined by defmfun. Then translated code doesn't have to mfunction-call these functions, but can call them directly. (Makes the code easier to read.) | Does not using |mfunction-call| really matter? Don’t know. I rarely use |translate|. > > Ray? > > -s > > On Sat, Aug 17, 2024 at 6:22 PM Eduardo Ochs > <edu...@gm...> wrote: > > Thanks!!! > A quick question... > The source of taylorp in simp.lisp is very clear: > > (defmfun $taylorp (x) > (and (not (atom x)) > (eq (caar x) 'mrat) > (member 'trunc (cdar x)) t)) > > but > > :lisp (describe '$taylorp) > > says "Symbol-plist: ... TRANSLATED -> T ...". > > What does the "translated" mean in this case? I took a quick > look at > all the occurences of "translate" in the info manual and I got the > impression that translated functions come from Maxima > functions, but I > grepped the sources and I didn't find a possible Maxima source for > this $taylorp... > > Cheers, TIA, etc, > Eduardo > > > On Sat, 17 Aug 2024 at 19:04, Stavros Macrakis > <mac...@gm...> wrote: > > taylorp(taylor(1,x,0,1)) => true > > > On Sat, Aug 17, 2024, 16:54 Eduardo Ochs > <edu...@gm...> wrote: > > Hi all, > > sorry for the delay - we're at the end of the semester > here, with lots > of tests to prepare and to mark... and this will be a > partial answer - > I haven't tried all of your suggestions yet. Anyway... > > My questions about the internal representation of the > objects returned > by "factor", "trunc" and "taylor" were not because I > need to do > something "practical" with these objects in the near > future - I was > asking them just because my mental model of Maxima > objects is still > very incomplete, and when I ask these questions here I > usually get > answers that help me a lot. > > The documentation for "trunc", at > > (info "(maxima)trunc") > https://maxima.sourceforge.io/docs/manual/maxima_141.html#trunc > > says: > > Annotates the internal representation of the general > expression > <expr> so that it is displayed as if its sums were > truncated Taylor > series. <expr> is not otherwise modified. > > The snippet below shows some ways of exploring these > annotations - I'm > guessing that "annotations" is the correct term: > > a1 : a*b; > a2 : factor(100); > b1 : 23 + 45*x; > b2 : trunc(b1); /* has a ... */ > b3 : taylor(b1, x, 0, 1); /* has a ... and a /T/ */ > ratp(b1); /* false */ > ratp(b2); /* false */ > ratp(b3); /* true */ > to_lisp(); > #$a*b$ ; ((MTIMES SIMP) $A $B) > #$a1$ ; ((MTIMES SIMP) $A $B) > #$a2$ ; ((MTIMES SIMP FACTORED) ((MEXPT SIMP) 2 > 2) ((MEXPT SIMP) 5 2)) > #$b1$ ; ((MPLUS SIMP) 23 ((MTIMES SIMP) 45 $X)) > #$b2$ ; ((MPLUS SIMP TRUNC) 23 ((MTIMES SIMP) 45 > $X)) > #$b3$ ; ((MRAT SIMP ... TRUNC) PS ...) > (car #$b2$) ; (MPLUS SIMP TRUNC) > (cdar #$b2$) ; (SIMP TRUNC) > (cddar #$b2$) ; (TRUNC) > (to-maxima) > > There is a simple way to detect "taylorness" from > Maxima - we can use > "ratp" - but I couldn't find a simple way to detect > "truncness", or > "factoredness"... my guess is that if, and when, I > decide that some of > these annotations are important in my programs that > represent Maxima > objects as trees, then I will have write some Lisp to > interpret the > "cdar"s or the "cddar"s of these objects to see if > they have any > annotations that are worth showing... and "worth > showing" is something > that obviously depends on the context, and in many > cases just adding a > way to indicate that "this object has non-trivial > annotations" would > be enough. > > Anyway, these annotations look very important, but the > only places in > the manual in which I remember seeing them mentioned > clearly are here, > > (info "(maxima)Introduction to Simplification") > https://maxima.sourceforge.io/docs/manual/maxima_45.html > > that points to this paper, in which they are called > "flags", > > https://people.eecs.berkeley.edu/~fateman/papers/intro5.txt > https://maxima.sourceforge.io/misc/Fateman-Salz_Simplifier_Paper.pdf > > and here: > > (info "(maxima)Introduction to Lists") > https://maxima.sourceforge.io/docs/manual/maxima_20.html > > Are there standard functions to inspect them _from > Maxima_? Any > pointers, comments, recommendations? > > Thanks in advance, and, again, sorry for not having > digested all the > material in your previous answers _yet_... =/ > > Eduardo Ochs > http://anggtwu.net/eev-maxima.html > > > On Thu, 15 Aug 2024 at 14:11, Stavros Macrakis > <mac...@gm...> wrote: > > As I said in my post: > > The clean way to process factorizations > programmatically is with *ifactors*. > > ifactors(10!) => [[2, 8], [3, 4], [5, 2], [7, 1]] > > > No reason to call internal functions or futz > around with the output of *factor*, which is not > designed for programmatic use. > > -s > > > On Thu, Aug 15, 2024 at 9:29 AM Richard Fateman > <fa...@gm...> wrote: > > > If you expect Maxima to continually retain a > factorization like 2^3 through various > simplifications, > you have to turn off the simplifier, which > pretty much breaks the whole system. > > If you want to see the factors and > multiplicities, do this: > :lisp (trace nratfact). > > If you want to acquire a result that gives > prime factors and multiplicities in some > structure that > does not disappear, that structure might look > like ... factorlist([2,3], [3,1}) for > 2^3*3^1 or 24. > It would be quite easy to make an alternative > version of nratfact, or consider > > *factorlist(r) := psubst([ "^"="[","*"="[" ], > factor(r)); > * > > which, for factorlist(24) gives [[2,3],3]. > (sorry, if you want 3 to appear as 3^1 or > [3,1] you'll have to write another line of code. > > As for the show expression task, here's a > simpler piece of code for most of the task.. > *showit(r):=psubst(psubstlist,r);* > where > > *psubstlist: [ "^"=Power, "*"=Times, > "+"=Plus, "/"=Div]; (*etc etc for all > operators of interest . Maybe choose other > names *) > * > > I think that the graphical tree representation > of expressions may be of some brief > explanatory use, but > the prefix expression version is, for me, much > more appealing. Thus > *showit (rat(x+1)^2);* > returns > *Plus(Power(x,2),Times(2,x),1)* > > > RJF > > On Wed, Aug 14, 2024 at 6:15 PM Stavros > Macrakis <mac...@gm...> wrote: > > One problem with integer factorizations is > that they are pseudo-simplified: normally, > Maxima does not allow 2^3 as a simplified > expression, but *factor* cheats and marks > the expression as simplified, even though > it isn't. That means that it gives strange > results if you try to manipulate it: > > qq:factor(24) => 2^3*3 > qq+1 => 2^3*3 + 1 > > <big snip> > > _______________________________________________ > Maxima-discuss mailing list > Max...@li... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss > |