From: Stavros M. <mac...@al...> - 2022-07-10 01:15:12
|
Use a=b to test structural equality. equal(a,b) is for mathematical equality, and is unknown (not false) in the absence of assertions (assume) about a and b. On Sat, Jul 9, 2022, 16:57 Eduardo Ochs <edu...@gm...> wrote: > Hi, > > I need a little more help... > This works nicely: > > foo1 : lambda([a, b], 10*a + b); > xreduce(foo1, [2, 3, 4, 5]); > xreduce(foo1, [2, 3, 4, 5], 9); > foo(a, [b]) := xreduce(foo1, b, a); > foo(9, 2, 3, 4, 5); > > It yields: > > (%i1) foo1 : lambda([a, b], 10*a + b); > (%o1) lambda([a, b], 10 a + b) > (%i2) xreduce(foo1, [2, 3, 4, 5]); > (%o2) 2345 > (%i3) xreduce(foo1, [2, 3, 4, 5], 9); > (%o3) 92345 > (%i4) foo(a, [b]) := xreduce(foo1, b, a); > (%o4) foo(a, [b]) := xreduce(foo1, b, a) > (%i5) foo(9, 2, 3, 4, 5); > (%o5) 92345 > > Then I tried to replace foo1 by this: > > foo1 : lambda([o, action], > if equal(action, op) then op(o) > elseif equal(action, args) then args(o) > else args(o)[action]); > > I was expecting to get this: > > foo(a+b*c, op) -> op(a+b*c) > foo(a+b*c, args) -> args(a+b*c) > foo(a+b*c, 2) -> args(a+b*c)[2] > foo(a+b*c, 2, 1) -> args(args(a+b*c)[2])[1] > > but my foo1 is broken - both foo(a+b*c, op) and foo1(a+b*c, op) return > "+", but foo1(a+b*c, args) and foo(a+b*c, 1) both return unevaluated > "if ..."s. How do I fix that? How do I force the evaluation of that > if? > > Thanks in advance! > Eduardo Ochs > http://angg.twu.net/eev-maxima.html > > > _______________________________________________ > Maxima-discuss mailing list > Max...@li... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss > |