itsme

764 Reputation

14 Badges

16 years, 241 days

MaplePrimes Activity


These are replies submitted by itsme

i come across some version of this a lot. Also, things often fail to simplify (in this way) if they're inside a sqrt.

 

@ecterrab 

Thanks Edgardo.

>>lprint(Typesetting:-Typeset(%)), not lprint(Typesetting:-Typeset(r))

sure, thanks. Yes I had that in there earlier, but somehow deleted in the final worksheet I uploaded. At the bottom I do see/show what the Typeset for looks like for the AntiCommutator - it ain't pretty ;-)

>>  Now on the core of your reply: your latex/AntiCommutator does not work because there exists a print/AntiCommutator that takes precedence; probably shouldn't. 

Yes.. this is no big deal, now that you've mentioned to unset `print/function`, but indeed, one could just have latex() check if `latex/function` is user-defined and if so, use it without consulting `print/function` first. At the very least having this be explicitly stated in the help section could be useful. 

>>  do these two things unassign(print/AntiCommutator), and if you previously called latex with the same input (as you do in your worksheet), remember to latex(AntiCommutator(b__1, b__2), forget),

Yes, great - that works (below i set no caching globally).

There is, however, something i don't quite understand going on when the breaklines option is set (shown below)... but at least things seem to work when i leave it set to false.  

thx.

restart:

with(Physics):

 

#Physics:-Version(); # 1385

Setup(quantumoperators = {sigma__x, sigma__y, sigma__z, rho, b__1, b__2, b__3}, mathematicalnotation = true);

[mathematicalnotation = true, quantumoperators = {b__1, b__2, b__3, rho, sigma__x, sigma__y, sigma__z}]

(1)

 

setup some options that one might use.

(note we set no caching)

latex:-Settings(
    usecolor = true,
    leavespaceafterfunctionname = false,
    spaceaftersqrt = false,
    powersoftrigonometricfunctions= computernotation,
    leavespaceafterfunctionname = true,
    cacheresults = false,  # passing forget should not be needed now.
    breaklines=false, # FOR NOW
    linelength=300
);

[usecolor = true, leavespaceafterfunctionname = false, spaceaftersqrt = false, powersoftrigonometricfunctions = computernotation, leavespaceafterfunctionname = true, cacheresults = false, breaklines = false, linelength = 300]

(2)

r:=AntiCommutator(b__1, b__2);

Physics:-AntiCommutator(b__1, b__2)

(3)

`print/AntiCommutator`:=`print/AntiCommutator`;

`latex/AntiCommutator`:= proc(a,b)
sprintf(" dummy123 (%s), (%s) ", cat("", latex(a, output = string)), cat("", latex(b, output = string)));
end proc:

`print/AntiCommutator`

(4)

great - this works!

latex(r);

 dummy123 (b_{\textcolor{olive}{1}}), (b_{\textcolor{olive}{2}})

 

change breaklines to true

latex:-Settings(
    usecolor = true,
    leavespaceafterfunctionname = false,
    spaceaftersqrt = false,
    powersoftrigonometricfunctions= computernotation,
    leavespaceafterfunctionname = true,
    cacheresults = false,
    breaklines=true, # CHANGE THIS
    linelength=300
);

[usecolor = true, leavespaceafterfunctionname = false, spaceaftersqrt = false, powersoftrigonometricfunctions = computernotation, leavespaceafterfunctionname = true, cacheresults = false, breaklines = true, linelength = 300]

(5)

let's see what we get:
(we get a global wrap in \textit?? is this expected? escaping is also very different now. i was expecting just some \\ somewhere in the generated latex,

but maybe maple does a lot more when adding breaklines?

latex(r);  

\textit{\,dummy123\,(b\_\{{\backslash}textcolor\{olive\}\{1\}\}),\,(b\_\{{\backslash}textcolor\{olive\}\{2\}\})\,}

 

 

set breaklines=false again

latex:-Settings(
    usecolor = true,
    leavespaceafterfunctionname = false,
    spaceaftersqrt = false,
    powersoftrigonometricfunctions= computernotation,
    leavespaceafterfunctionname = true,
    cacheresults = false,
    breaklines=false, # CHANGE THIS
    linelength=300
);

[usecolor = true, leavespaceafterfunctionname = false, spaceaftersqrt = false, powersoftrigonometricfunctions = computernotation, leavespaceafterfunctionname = true, cacheresults = false, breaklines = false, linelength = 300]

(6)

thigns are ok.

latex(r);

 dummy123 (b_{\textcolor{olive}{1}}), (b_{\textcolor{olive}{2}})

 

 

Download latex_custom.mw

@ecterrab 

As always, thanks for your quick answer Edgardo!
... although I find it somewhat confusing.

I think you're saying that I can't see a function that does the "direct" maple expression to latex-string conversion, because those don't exit (anymore?); maple thinks of displaying its expressions in terms of Typsetting objects, which are then converted to latex themselves by the latex command.

What's not clear to me is if I should still be able to define (i.e. overwrite) my own version of what the latex output should look like for commands that maple already knows (i.e. say AntiCommutator from the Physics package) directly as shown in the examples doc page i linked? i.e via defining latex/AntiCommutator and having it output a latex string.
 If so, I'm clearly doing something wrong, as that does not work for me for AntiCommutator - please see worksheet below.

I get that there are probably good reasons, but would personally prefer to define the latex output directly and not think in terms of maple's Typesetting (especially given it's not all documented, as you say).

restart:

 

with(Physics):

 

#Physics:-Version(); # 1385

Setup(quantumoperators = {sigma__x, sigma__y, sigma__z, rho, b__1, b__2, b__3}, mathematicalnotation = true);

[mathematicalnotation = true, quantumoperators = {b__1, b__2, b__3, rho, sigma__x, sigma__y, sigma__z}]

(1)

try modifying example from docs:

`latex/BesselJ` := proc(a,b)
    sprintf("{ {\\rm DUMMY}_{%s}(%s) }",cat("", latex(a, output = string)), cat("", latex(b, output = string)))
end proc:

ok this works:

latex(BesselJ(2,7)); #ok - updated version works

{ {\rm DUMMY}_{2}(7) }

 

 

define something with anticommutator

r:=AntiCommutator(b__1, b__2);

Physics:-AntiCommutator(b__1, b__2)

(2)

latex(r); #default

\left[b_{\textcolor{olive}{1}},b_{\textcolor{olive}{2}}\right]_{+}

 

let's try to manually change the latex output for AnitCommutator into some dummy string

`latex/AntiCommutator`:= proc(a,b)
sprintf(" dummy123 (%s), (%s) ", cat("", latex(a, output = string)), cat("", latex(b, output = string)));
end proc:

 

this doesn't work; default still used.

latex(AntiCommutator(b__1, b__2)); #doesnt work

\left[b_{\textcolor{olive}{1}},b_{\textcolor{olive}{2}}\right]_{+}

 

 

Try defining a custom Anticommutator, and later its own latex representation

Anticommutator:=proc(a,b)
AntiCommutator(a,b)
end;

proc (a, b) Physics:-AntiCommutator(a, b) end proc

(3)

`latex/Anticommutator`:= proc(a,b)
sprintf(" dummy123 (%s), (%s) ", cat("", latex(a, output = string)), cat("", latex(b, output = string)));
end proc:

this doesn't work (clearly Physics:-AntiCommutator is the thing that is eventually evaluated by latex()))

latex(Anticommutator(b__1, b__2));

\left[b_{\textcolor{olive}{1}},b_{\textcolor{olive}{2}}\right]_{+}

 

this does... but not quite what I was hoping.

latex('Anticommutator(b__1, b__2)');

 dummy123 (b_{\textcolor{olive}{1}}), (b_{\textcolor{olive}{2}})

 

 

ok, for fun, let's try looking at the Typset of a command:

r;

Physics:-AntiCommutator(b__1, b__2)

(4)

Typesetting:-Typeset(%); #should I be seeing something else?

"[`b__1`,`b__2`][+]"

(5)

Try this:

Typesetting:-Typeset(%AntiCommutator(b__1, b__2));

0, "%1 is not a command in the %2 package", _Hold, Typesetting

(6)

none of the above shows anything interesting. Perhaps one has to use the pallets? (i try to avoid that as if my life depended on it   ;-)

 

for fun let's see the typesetting inolved in our object:

lprint(Typesetting:-Typeset(r));  # ok that doesn't work, r does not get evaluated.

Typesetting:-mi("r")

 

lprint(Typesetting:-Typeset(AntiCommutator(b__1, b__2)));  #yikes

Typesetting:-msub(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi("b__1"
,foreground = "olive")),Typesetting:-mrow(Typesetting:-mi("b__2",foreground =
"olive")),open = "[",close = "]"),Typesetting:-mo("+",
Typesetting:-msemantics = "PhysicsAntiCommutator"))

 

Download latex_custom.mw

@ecterrab 

Thanks Edgardo.

Installing from a GUI indeed does work.

(for whatever it's worth, i usually install the updates from the terminal - and in the past, things have worked)

 

 

@tomleslie 

According to the info on the web:

"This is the Physics package update, which includes improvements to existing functionality, fixes, and the latest new developments, in the Physics, Differential Equations and Mathematical Functions areas."

So in principle, even when not loaded explicilty, I would read that the version of the package itself may affect maple's behavior (related to differential equations, and hence I would think integration (?))

Of course I have no idea, if the version used is even remotely related to the problem here, but you seem to show that it may be perhaps.

@nm  I assume you filed a bug report about this? would be great to make sure the devs are aware of this issues...

your update is even more interesting.

i tried that on my machine (linux): repeating the run many tims, under various loads (full, minor, mid), but cannot reproduce it.

i don't know if it could be related, but have you tried updating the Physics package?

Also deleting any custum stuff you may have installed/setup (i.e say in the ~/maple folder - whatever that is on windows)?

i also cannot reproduce this problem (on linux); but somethign is clearly different - the forms of the solutions are not the same.

 

 

@nm 

I took your comment:

"It should leave the Latex as is, no matter how long it is, and let the actual Latex compilation phase worry about this. "

to mean that the latex command should not do any line breaking, but my bad if I misunderstood your point, or took it out of context.

If you're saying that it's good to have line-breaking as something that can be controlled by the user (which the code effectively does make possible), then we're saying the same thing.

@nm 

just to weight in on this discussion as I'm also a heavy latex() user. 

>> It should leave the Latex as is, no matter how long it is, and let the the actual Latex compilation phase worry about this. 

I would think there should always be an option that allows one to turn off any potential line wrapping - that I agree with. For me, setting linelength large enough has (so far) always worked well.

But I completely disagree with you that an option to do this should not be available. The problem of course is that, in general, getting this kind of automatic linewrapping for arbitrary expressions to *always* work at maple-to-latex conversion time (as opposed to compile time) is next to impossible because one would have to know something about the size of the actual rendered expressions relative to the expected page size, etc. 

    However for simple expressions (where it's "easy" to get it right), I can see this being quite useful... using third party text-wrapping packages is often painful, there can be conflicts, may require separate installation, and from my experience, a least, may still not always work correctly. 

Also, sometimes just having long expressions "preformatted" the right way is just useful visually when editing complicated documents - for me anyway.

great!... thanks for posting @ecterrab !

 

thanks for your post @Preben Alsholm 

what you propose doesn't really work (in general)... note that if, say, expr->5*expr, the substitution rule has to be adjusted (the point here would be for one to not have to do that - i.e., if expressions are long and complicated, this process becomes very tedious)

I'm basically suggesting that it would be good if algsubs would work with operators, in the way it does with non-operator quantities.

@The function 

while it's not related to your problem here, just fyi... "restart" should always be executed separately from anything else (i.e. on its own line).

Otherwise, can get  undefined behavior - see docs.

Thanks for posting. 

I personally find the noncommutative algebra of the Physics package very useful. Especially along with the SortProducts functionality, which can basically completely trivialize some really painful/tedious/boring calculations.

I have tried using operators inside matrices some years ago (that would have been more than 6 or 7 years for sure), and things were somewhat broken back then, but it's great to see from your worksheet that this functionality has now been fixed... 

 

thanks a lot for the useful info and the physics package update @ecterrab 

I have certainly not appreciated this point  - it's good to know for the future!

1 2 3 4 5 6 7 Last Page 1 of 18