# Tag Info

20

As explained by Michael Pilat you cannot create your own compound operators with custom precedence. (You could conceivably write your own parser as Leonid has worked on, or attempt to coerce the Box form with CellEvaluationFunction.) You can however use an existing operator with the desired precedence. Looking at the table Colon appears to be a good ...

17

The short answer is don't do it. Really, it's just not a good idea. You can use other symbols, such as \[CapitalIota] which looks almost exactly like I and is entered with EscIEsc. If you're really determined you could substitute symbols using $PreRead and MakeBoxes but again I don't recommend it. For example: MakeBoxes[I, _] := "\[ImaginaryJ]" ... 17 Maybe I miss the point here, but FullForm[x ↗ y] gives UpperRightArrow[x,y]. This is described in the documentation to UpperRightArrow and since this symbol is not protected and has not built-in meaning, you can just define it the way you like: UpperRightArrow[x_, y_] := FooBar[x, y] and this instantly gives you Update: As answer to Jacobs ... 14 Some people make good use of the Notation package but I have never been very successful with it. A good reason to learn a little about MakeBoxes and TemplateBox. The following MakeBoxes definition will format your expression. MyHead /: MakeBoxes[MyHead[a_, b_], form : (StandardForm | TraditionalForm) : StandardForm] := InterpretationBox[#1, #2] & ... 14 You can use Symbolize, from the Notation package following the tutorial as you did. Then, just take the precaution of writing the pattern with its head explicit, such as: Pattern[xr, _] The problem is that Mathematica can't interpret the short notation for patterns (xr_ for example) if it has a box structure before the "_" 13 A general idea as to how this can be done in a consistent way is explained in the help documents under NonCommutativeMultiply. The thing is that you want to use your operators in an algebraic notation, and that's what that page discusses. If, on the other hand, you're happy with a more formal Mathematica notation, then you would have the easier task of ... 12 Yes you can, with limitations. You have at least three different ways to make an assignment to a subscripted symbol a0 : make a rule for Subscript make a rule for a "symbolize" a0 using the Notation package/palette In each case below, when I write e.g. Subscript[a, 1] this can also be entered as a1 by typing a then Ctrl+_ then 1. When you write: ... 11 I can't answer how the association is made for the built-in operators, but I can show how to add your own. If your symbol is already an operator you can do this simply as halirutan showed. This question may be a duplicate of How can one define an infix operator with an arbitrary unicode character? but since it admits a simpler interpretation I shall not ... 10 Currying I don't know if it is possible to make all functions work in the Currying form (h[x1][x2][..]) but it is at least possible to extend Hold behavior to all arguments which natively that pattern will not have. I will copy my favorite method which was posted here by Grisha Kirilin: SetAttributes[f, HoldAllComplete] f[a_, b_, c_] := Hold[a, b, c] ... 10 You can get the syntax highlighting that you desire by modifying your UnicodeCharacters.tr file, though I don't know how advisable this practice is. For example, adding: 0x20B0 \[PennyOp] ($penny$) Infix 155 None 5 5 I can use EscpennyEsc to enter: I am not aware of documentation of the format of this file but as ... 10 Something like this f = D[#, x] + D[#, y] + z # & seems to work. Use as follows: f[x ψ[x, y, z]] to give$x \psi ^{(0,1,0)}(x,y,z)+x \psi ^{(1,0,0)}(x,y,z)+x z \psi (x,y,z)+\psi (x,y,z)$8 You may wish to use the Notation package. It lets you do these things fairly easily. I'd copy and paste some examples but they don't really copy and paste well. Read through the tutorials and you'll see some examples of how to do this. You may also be interested in the Vector Analysis package. 8 The Notation package is the most convenient way to define new notation(s). <<Notation Define an infix notation. You can use the palette that the 'Notation package pops up to do this. InfixNotation[ParsedBoxWrapper["\[UpperRightArrow]"], FooBar] Check that the infix notation maps to the correct FullForm expression. x \[UpperRightArrow] y // ... 7 Why does this not show up in a ?Global* query? Because you set a definition to CirclePlus which is in the System context How can I set the Attributes for this operation to be Flat so it is associative? SetAttributes[CirclePlus, Flat] But now redefine your function so it can take any number of arguments CirclePlus[stuff___] := Print@{stuff} Do I need ... 7 What I usually suggest for such cases is to use custom environments, inside which you can change the rules of the game. Here is a lexical one for your case: ClearAll[withNCTimes]; SetAttributes[withNCTimes, HoldAll]; withNCTimes[code_] := Unevaluated[code] /. Times -> NonCommutativeMultiply so that withNCTimes[a*b*c] (* a**b**c *) and here is ... 7 Perhaps: uu := u[x, y, z, t] uu[x_, y_, z_, t_] := u[x, y, z, t] So that D[uu, t] // InputForm (* - >Derivative[0, 0, 0, 1][u][x, y, z, t] *) and Dt[uu, t] // InputForm (* -> Derivative[0, 0, 0, 1][u][x, y, z, t] + Dt[z, t]*Derivative[0, 0, 1, 0][u][x, y, z, t] + Dt[y, t]*Derivative[0, 1, 0, 0][u][x, y, z, t] + Dt[x, ... 7 Instead of using the Notation package, you can achieve the translation by doing the following: MakeExpression[RowBox[{x_, "⟗", y_}], StandardForm] := MakeExpression[ RowBox[{"FlatJoin", "[", x, ",", y, "]"}], StandardForm ] This takes care of the input translation. Now it's possible to enter expressions like 1 ⟗ (3 + 4 ⟗ 2) and have ... 6 What you are really looking for is InputAutoReplacements. If I understand your question correctly you are looking for a simple/quick way to input mildly complex strings of characters. In your example you want to find an easy way to input$\beta$. But there is no point in creating another symbol beta, since the 2 symbols are meant to always be "equivalent" ... 6 Unfortunately, this is not possible directly, at least as far as I know. The error message you are getting is just a manifestation of it. You are using UpValues, which have a fundamental limitation that they can only be attached to symbols on a level no deeper than 1. I discussed this more in my answer to this question. Redefining built-in functions, OTOH, ... 5 After some further thought and exploration, it seems like this is a perfect use of the newish (version 6 and up) Defer wrapper. Adding the following rules to Pair seems to do exactly what I'm looking for: Pair /: Format[list : Pair[_, _]] := With[{args = Normal@list}, Defer[LinkedList[##]] & @@ args]; Pair /: Format[Pair[]] := Defer[Nil]; Then: ... 5 I see in your question that you would rather not use MakeBoxes but I think this might be worth a try. Pair /: MakeBoxes[linkedList : Pair[i_, p_Pair], fmt_] := TagBox[ToBoxes[LinkedList @@ Flatten[linkedList]], InterpretTemplate[Pair[i, p] &], Editable -> False, Selectable -> True, SelectWithContents -> True] The InterpretTemplate ... 5 So (I guess that) the problem occurs because Notation[LHS \[DoubleLongLeftRightArrow] RHS] converts the LHS into boxes, where OverBar[x] is OverscriptBox[x,"_"]. It then interprets the underscore as a Blank (_), which it tries to match up with a pattern on the RHS. I'm sure that I've used the Notation package with OverBars before and have not had troubles ... 5 For a single Function T this is pretty easy: T[i_, i_] /; ! NumberQ[i] := Sum[T[j, j], {j, 3}] A quick test gives: In[7]:= T[i, i] Out[7]= T[1, 1] + T[2, 2] + T[3, 3] If you want to always sum over two equal indices for several functions, this might need some extra work though. 5 Interesting question. I don't have much experience with this sort of thing so I imagine there is a better way but this is what I could hack together at the moment: frac[lst_List] := Column[ Column /@ Partition[Riffle[lst, \[HorizontalLine]], 2, 2, -1, {}], Alignment -> Center, Spacings -> 0] {"x", 200, Integrate[Sin[x^2], x]} // frac Here ... 5 Probably best to use something like Fold and get used to functional style eqn[n_] := TraditionalForm[Fold[#1 <> " < " <> ToString[Subscript[d, #2], StandardForm] &, "0", Range[n]]] 4 It doesn't recurse because you are using a definition of Notation (from the Notation package) that is restricted to parsing: This means that you will have to explicitly ShiftReturn for the notation to take effect. Notice the following: You can achieve what you want using straightforward definitions instead: Clear@WW WW[a__, Verbatim[Alternatives][b_, ... 4 I would not think that either of the methods you mentioned is good enough. Notation package is more or less limited to the FrontEnd (although one can come up with some hacks to make it work also in packages), while overloading Set is generally a bad idea. Having in mind your particular application, something like this may work: ClearAll[makePoint]; ... 4 That's how I finally defined haskell operators: rapply[x_] := x rapply[x_, y__] := x[rapply[y]] InfixNotation[ParsedBoxWrapper["|"], rapply] lapply[x_] := x lapply[x__, y_] := lapply[x][y] InfixNotation[ParsedBoxWrapper["\[SmallCircle]"], lapply] InfixNotation[ParsedBoxWrapper["\[CenterDot]"], Composition] Now$\circ$,$\dot{}{}\$ and | act exactly like ...

4

You can use something like this dx /: MakeBoxes[dx[a_], fmt_] := RowBox[{FractionBox["\[PartialD]", "\[PartialD]x"], MakeBoxes[a, fmt], "=", MakeBoxes[#, fmt] &@D[a, x]}]; dx[Sin[x]] dx[Sin[x]] // TraditionalForm I prefer MakeBoxes but it also can be implemented with Format ClearAll[dx] Format[dx[a_]] := ...

3

Please let me know if I didn't understand correctly. What if you used a Subscript wrapping a Superscript instead of a Subsuperscript? Subscript[Superscript[x, 4], 2] Its TeXForm gives x^4{}_2. Does that render as you want? EDIT Does this work? yourTeXForm[expr_] := ConvertTeXBoxesToTeX[ToBoxes[expr], "BoxRules" -> {StyleBox[t_, op : ...

Only top voted, non community-wiki answers of a minimum length are eligible