From: Richard F. <fa...@gm...> - 2022-08-25 19:31:05
|
Is it display 2d or not? what if the entries in the expressions have raised exponents or dropped subscripts? If you eliminated the blank lines, there will be potential ambiguity. Is it so hard to avert your eyes from the left/right bracketing characters that you must eliminate them? What do you do if one of the entries is too long to fit on a single line of your display? Philosophically speaking, Maxima / Macsyma code was written in a kind of data-directed way, before it became such a big deal -- object orientedness, that is. So there is a program attached to the symbol $matrix called dim-$matrix. If you want to look at the lisp code, you can see how it was done. It is not the case that everything is declarative or object-oriented in nature, though. So some code might have to be copied over, to write a new program to do whatever it is you had in mind. If you know lisp, that might be easy. or if you wish to learn it, that might be an educational opportunity! On Thu, Aug 25, 2022 at 9:18 AM Leo Butler <Leo...@um...> wrote: > On Wed, Aug 24 2022, Eduardo Ochs <edu...@gm...> wrote: > > > On Wed, 24 Aug 2022 at 14:25, Leo Butler <Leo...@um...> > wrote: > > > >> On Tue, Aug 23 2022, Eduardo Ochs <edu...@gm...> wrote: > >> > >> > Hi list, > >> > > >> > I am trying to learn how to define new operators that have "nice" > >> > representations in LaTeX and in display2d. Here is the example on > >> > which I am working. I want > >> > > >> > Eq5(aa, bb, cc, dd, ee) > >> > > >> > to be displayed as: > >> > > >> > aa = bb > >> > = cc > >> > = dd > >> > = ee > >> > > >> > To configure its LaTeX output I simply adapted the example in the > >> > section about "texput" here, > >> > > >> > (info "(maxima)Functions and Variables for TeX Output") > >> > > >> > and I wrote this: > >> > > >> > texEq5(ex) := > >> > block([a,b,c,d,e], [a,b,c,d,e] : args (ex), > >> > concat("\\begin{array}{rcl}", > >> > tex1(a), "&=&", tex1(b), "\\\\", > >> > "&=&", tex1(c), "\\\\", > >> > "&=&", tex1(d), "\\\\", > >> > "&=&", tex1(e), "\\\\", > >> > "\\end{array}")); > >> > texput(Eq5, texEq5); > >> > tex(Eq5(aa, bb, cc, dd, ee)); > >> > > >> > Here's the output of the last line above, indented by hand: > >> > > >> > $$\begin{array}{rcl} > >> > {\it aa} &=& {\it bb} \\ > >> > &=& {\it cc} \\ > >> > &=& {\it dd} \\ > >> > &=& {\it ee} \\ > >> > \end{array} > >> > $$ > >> > > >> > This was easy to do, and works great. But I couldn't find much > >> > documentation on how to configure how display2d displays "Eq5" > >> > objects. I was only able to write this prototype for the first step: > >> > > >> > MatrixEq5(ex) := > >> > block([a,b,c,d,e], [a,b,c,d,e] : args (ex), > >> > matrix([a,"=",b],["","=",c],["","=",d],["","=",e]))$ > >> > > >> > If I run this > >> > > >> > MatrixEq5(Eq5(aa, bb, cc, dd, ee)); > >> > > >> > the output is: > >> > > >> > [ aa = bb ] > >> > [ ] > >> > [ = cc ] > >> > [ ] > >> > [ = dd ] > >> > [ ] > >> > [ = ee ] > >> > > >> > So, questions: > >> > > >> > 1) How can I get rid of the outer "[]"s? > >> > 2) How can I get rid of the blank lines? > >> > 3) How can I make Eq5 objects be displayed with MatrixEq5? > >> > 4) Where can I find docs and examples about this? > >> > > >> > Thanks in advance! =) > >> > Eduardo Ochs > >> > http://angg.twu.net/eev-maxima.html > >> > >> It depends on how ambitious your goals are, but the alt-display package > >> is probably what you want. > >> > >> To elaborate: suppose that you want to print Eq5(...) using some > >> function printEq5; other things should just be printed as is. You can > >> define a custom printer that checks an expression to see if its op has a > >> custom printer; if so, dispatch that; otherwise, use the default. > >> > >> Here is a working POC: > >> > >> (%i1) > >> define_alt_display(ochs_display(form), > >> > >> block([alt_display1d:false,alt_display2d:false,x:second(form),p], > >> if mapatom(x) then displa(form) else if > >> (p:get(op(x),display2d_printer))#false then > >> p(form) else twod_display(form))) $ > >> > >> (%i2) printEq5(x) := block([a:args(second(x))], printf(true,"BANG!~%~a > ~{= > >> ~a ~}~%!GNAB",first(a), rest(a))) $ > >> > >> (%i3) put(Eq5,printEq5,display2d_printer) $ > >> > >> (%i4) Eq5(aa,bb); > >> BANG! > >> aa = bb > >> !GNAB > >> > >> (%i5) Eq5(aa,bb,cc,dd,ee); > >> BANG! > >> aa = bb = cc = dd = ee > >> !GNAB > >> > >> (%i6) 1/2+x; > >> 1 > >> (%o6) x + - > >> 2 > >> > >> > >> Leo > > > > > > Hi Leo, > > > > your code looks like the right way to go, but it doesn't work here... > > does it need something that is in your init file? > > > > First attempt: > > > > (%i1) define_alt_display(ochs_display(form), > > block([alt_display1d:false,alt_display2d:false,x:second(form),p], > > if mapatom(x) then displa(form) else if > > (p:get(op(x),display2d_printer))#false then > > p(form) else twod_display(form)))$ > > > > second: argument must be a non-atomic expression; found form > > -- an error. To debug this try: debugmode(true); > > (%i2) > > > > Second attempt: > > > > (%i1) load("alt-display.mac")$ > > > > (%i2) define_alt_display(ochs_display(form), > > block([alt_display1d:false,alt_display2d:false,x:second(form),p], > > if mapatom(x) then displa(form) else if > > (p:get(op(x),display2d_printer))#false then > > p(form) else twod_display(form)))$ > > > > (%i3) printEq5(x) := block([a:args(second(x))], > > printf(true,"BANG!~%~a ~{= ~a ~}~%!GNAB",first(a), rest(a)))$ > > > > (%i4) put(Eq5,printEq5,display2d_printer)$ > > > > Apologies, before %i5 you need to also enter: > > display2d : true $ /* set default */ > set_alt_display(2,ochs_display); > > Leo > > > (%i5) Eq5(aa,bb); > > (%o5) Eq5(aa, bb) > > (%i6) Eq5(aa,bb,cc,dd,ee); > > (%o6) Eq5(aa, bb, cc, dd, ee) > > (%i7) 1/2+x; > > 1 > > (%o7) x + - > > 2 > > (%i8) > > > > Thanks in advance =/, > > Eduardo > > _______________________________________________ > Maxima-discuss mailing list > Max...@li... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss > |