Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MakeBoxes for Submanifold #2

Open
chakravala opened this issue Oct 19, 2021 · 7 comments
Open

MakeBoxes for Submanifold #2

chakravala opened this issue Oct 19, 2021 · 7 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested

Comments

@chakravala
Copy link
Owner

chakravala commented Oct 19, 2021

Currently, there is an issue regarding how MakeBoxes displays Submanifold elements having Symbol coefficients.

If MakeBoxes is used on the Coefficient of the Submanifold, then for the a symbol it is printed as $CellContext`a.

V = Submanifold[MetricSignature["+++"]];
v = Submanifold[V,0];
a*v[1]+v[2]

Additionally, I would like to use InterpretationBox[Selectable -> ...] but I have not successfully implemented that yet.

@chakravala chakravala added help wanted Extra attention is needed good first issue Good for newcomers question Further information is requested labels Oct 19, 2021
@chakravala chakravala added this to the Symbolic geometric algebra milestone Oct 19, 2021
@chakravala chakravala added this to To do in Differential Geometric Algebra via automation Oct 19, 2021
@chakravala
Copy link
Owner Author

chakravala commented Oct 27, 2021

Resolving my MakeBoxes issue requires figuring out how to bypass this bug (@okofish @maxitg ?):

MyFun[MyThing[x_]] := x;
MyThing /: MakeBoxes[s_MyThing, StandardForm] :=  MakeBoxes[MyFun[s], StandardForm];
MyThing[1]

When MyThing[1] is displayed, the following recursion error results:

$RecursionLimit::reclim2: Recursion depth of 4096 exceeded during evaluation of MakeBoxes[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[MyFun[<<1>>]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]],<<12>>].

One possible workaround is

MyThing /: MakeBoxes[MyThing[x_], StandardForm] :=  MakeBoxes[x, StandardForm]

However, I'd prefer if I could create this by calling MyFun instead of doing it like this. Is any other way possible?

@okofish
Copy link

okofish commented Oct 27, 2021

MakeBoxes is HoldAllComplete; does using ToBoxes on the RHS do what you want?

MyThing /: MakeBoxes[s_MyThing, StandardForm] := ToBoxes[MyFun[s], StandardForm]

@chakravala
Copy link
Owner Author

Indeed, ToBoxes resolves this, thank you very much!

@okofish
Copy link

okofish commented Oct 28, 2021

You're welcome!

@chakravala
Copy link
Owner Author

Do you (e.g. @okofish) happen to know if there is a way to detect if an expression needs to be wrapped in parenthesis before being displayed as a subexpression? For example, -x*y does not need parenthesis for -x but (z-x)*y does require parenthesis for z-x. Given either -x or z-x, I would like to be able to determine if parenthesis are needed.

@chakravala
Copy link
Owner Author

Alright, 09ed0a7#diff-a2c244be0060c3069d6f099d31408ae79a518d514b74163ea30eb589c747ac96R62-R67 resolves parenthesizing of Coefficient elements. Now, only remaining open questions are regarding InterpretationBox behavior.

@okofish
Copy link

okofish commented Oct 28, 2021

It sounds like you solved the parentheses issue, but some ideas anyways:

  • PrecedenceForm lets you customize the automatic insertion of parentheses during typesetting by overriding the precedence value of a subexpression.
  • Prefix, Infix, and Postfix also let you customize precedence of an expression typeset in *fix notation; I think these have the same effect as PrecedenceForm.
  • The undocumented function Precedence (see ?Precedence for usage) appears to let you check the precedence value of a typeset expression or of a symbol. This could be used to manually parenthesize a subexpression based on its precedence and the precedence of the head of the surrounding expression.
  • The SyntaxForm option also does something with operator precedence but I don't really understand it.

Random note: this documentation page is a good read about precedence of built-in syntax, including the arcane variety.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested
Development

No branches or pull requests

2 participants