From: Eduardo O. <edu...@gm...> - 2024-07-12 04:04:21
|
Hi all! Thanks a lot! Robert, these two ideas are helping me a lot: > by calling macroexpand on the macro calls of interest, e.g. > because makelist > has nonstandard evaluation, and something got evaluated too much or > too little -- did I guess correctly? These ones not yet, but I have todo-listed them =P: > You might be able to get the results you want from the built-in > functions create_list (which allows iterating over two or more > variables) and genmatrix (which allows iterating over two variables). Stavros: I hope that I'll understand your suggestion tomorrow! Viktor: wow, same - why do the ev work there but not in the caller? Todo-listed!!! All: my original question was a mess, sorry! I was mostly looking for ways to understand how my macros worked by decomposing their execution into several smaller steps... I found the output of "trace" confusing, but I a few hours ago I just rewrote the macros of my original question to make them use a single makelist, as this, mklist_(xs, expr) := buildq([xs,expr], makelist(expr, splice(xs)))$ aroundx0_ (expr) := buildq([expr], mklist_([x,x0-1,x0+1], expr))$ mklist (xs, expr) ::= mklist_(xs, expr)$ aroundx0 (expr) ::= aroundx0_ (expr)$ and I tried: mklist([x,2,4], 10*x); aroundx0 (10*x); a : '(aroundx0(10*x)); b : apply('macroexpand, [a]); c : apply('macroexpand, [b]); d : ev(b); which is much better than what I had before... and I found this super-neat example in the reference manual: [a:b,b:c,c:d,d:e]; a; ev(a); ev(ev(a)); ev(ev(ev(a))); ev(ev(ev(ev(a)))); Apparently in my macros only evaluation matters, not simplification... and that simplifies things a bit. I will have a free evening tomorrow, and I will try to understand that, fix my code, and produce some diagrams. Thanks and more soon! =) Eduardo On Fri, 12 Jul 2024 at 00:40, Viktor T. Toth <vt...@vt...> wrote: > Dear Eduardo, > > Perhaps this sheds some light on what you ran into: > > (%i1) mkmatrix0(xs, ys, expr) := > buildq([xs,ys,expr], > apply(matrix, > makelist(makelist(expr, splice(xs)), > splice(ys))))$ > > (%i2) mkmatrix (xs, ys, expr) ::= mkmatrix0 (xs, ys, expr)$ > (%i3) aroundx0y0(expr) ::= mkmatrix ([x,0,3], [y,0,3], expr)$ > (%i4) aroundx0y0([x,y]); > [ [x, y] [x, y] [x, y] [x, y] ] > [ ] > [ [x, y] [x, y] [x, y] [x, y] ] > (%o4) [ ] > [ [x, y] [x, y] [x, y] [x, y] ] > [ ] > [ [x, y] [x, y] [x, y] [x, y] ] > (%i5) aroundx0y0(expr) ::= mkmatrix ([x,0,3], [y,0,3], ev(expr))$ > (%i6) aroundx0y0([x,y]); > [ [0, 0] [1, 0] [2, 0] [3, 0] ] > [ ] > [ [0, 1] [1, 1] [2, 1] [3, 1] ] > (%o6) [ ] > [ [0, 2] [1, 2] [2, 2] [3, 2] ] > [ ] > [ [0, 3] [1, 3] [2, 3] [3, 3] ] > > As Robert remarked, it has to do with how macros evaluate (or not) their > arguments. > > > Viktor > > > > On 7/11/2024 4:32 PM, Eduardo Ochs wrote: > > Hi list, > > > > can anyone help me to understand what is happening in the program > > below? > > > > mkmatrix0(xs, ys, expr) := > > buildq([xs,ys,expr], > > apply(matrix, > > makelist(makelist(expr, splice(xs)), > > splice(ys))))$ > > > > mkmatrix (xs, ys, expr) ::= mkmatrix0 (xs, ys, expr)$ > > > > Dx : x - x0; > > Dy : y - y0; > > [x0,y0] : [3,2]; > > mkmatrix ([x,0,x0+1], [y,y0+1,0,-1], [x,y]); > > mkmatrix ([x,0,x0+1], [y,y0+1,0,-1], ev([Dx,Dy])); > > a : mkmatrix ([x,x0-1,x0+1], [y,y0+1,y0-1,-1], [x,y]); > > b : mkmatrix ([x,x0-1,x0+1], [y,y0+1,y0-1,-1], ev([Dx,Dy])); > > > > aroundx0y0(expr) ::= mkmatrix ([x,x0-1,x0+1], [y,y0+1,y0-1,-1], expr)$ > > > > c : aroundx0y0([x,y]); > > d : aroundx0y0(ev([Dx,Dy])); > > > > I was expecting that a and c would return the same matrix, and b and d > > would return the same (other) matrix, but no... in the lines that > > calculate a and b the symbols x and y are become bound variables > > inside the two "makelist"s, but in the lines that calculate c and d > > the x and the y don't change... > > > > Thanks in advance! > > [[]], Eduardo... > > > > > > > > _______________________________________________ > > Maxima-discuss mailing list > > Max...@li... > > https://lists.sourceforge.net/lists/listinfo/maxima-discuss > |