Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
38

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: ...


32

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 ...


27

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 comment I ...


24

You can get the syntax highlighting that you desire by modifying your UnicodeCharacters.tr file (path given by System`Dump`unicodeCharactersTR), 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 ...


23

UpArrow[a_, n_Integer] := Nest[a^# &, 1, n] then UpArrow[4, 3] or 4 \[UpArrow] 3 To complete this method you may wish to add an input alias: AppendTo[CurrentValue[$FrontEndSession, InputAliases], "up" -> "\[UpArrow]"]; Now EscupEsc will enter \[UpArrow]. Change $FrontEndSession to $FrontEnd and run it only once to make the change persist ...


22

Updated to include both unary and binary operators One idea is to use the usage message of a symbol as a clue that it has a special display form, probably with no built-in meaning. For example: ?TildeTilde The following 2 functions check the usage message of a symbol to see if it contains "displays as" or "formats as", and then weeds out those symbols ...


21

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 ...


21

Corrected to use SubscriptBox as Rojo showed and Kvothe commented, fixing binding. Rojo shows a way in Is it possible to define custom compound assignment operators like ⊕= similar to built-ins +=, *= etc? MakeExpression[RowBox[{f_, SubscriptBox["/@", n_], expr_}], StandardForm] := MakeExpression @ RowBox[{"Map", "[", f, ",", expr, ",", "{", n, "}", "]"}...


20

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]" ...


20

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 I learned from this post by Grisha Kirilin: SetAttributes[f, HoldAllComplete] f[a_, b_, c_] := Hold[a, ...


19

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] & ...


19

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 ...


19

Update As pointed out by @Edmund, my initial answer didn't work with hex numbers starting with an integer. To fix that, I included an initial \[DiscretionaryHyphen] character, and then I drop that character when converting to a number using FromDigits (my first update used x, but I like this new approach better): CurrentValue[EvaluationNotebook[], ...


16

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 "_"


16

Agree with other answers, this is a bad idea (why, precisely do you want to do this?), but in the spirit of encouraging unmaintainable write-once read-never code, here's my entry into the freak show: $NewSymbol = If[StringMatchQ[#, "f" ~~ NumberString], ToExpression[# <> "[x_]=x+" <> StringDrop[#, 1]]] &; Remove["f*"]; ...


15

You cannot simply type Symbolize[...] which you should probably know from an error message you should be getting. For example what you have in your question gives: Symbolize[Subscript[q, 1],Subscript[q, 2]] To see why you get this message you can use show expression to see what is being pasted via the palette: From this we can see that Symbolize makes use ...


14

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)$


14

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 // ...


13

Verbeia is right. An alternative notation is to use escpdesc which gives a partial derivative; thus, typing escpdesc ctrl-t followed by f[x,t] will give the derivative of f with respect to its second argument. For instance, this is a valid way to specify a differential equation: This is closer to what you're after than D[f[x,t],t], for instance.


13

The possibility to insert operators and functions as you know them from mathematics is not possible for all things. Usually, you find the special input possibilities on the reference page of the function in the Details section. See for instance the documentation of Integrate. For Binomial there seems to be no such 2d input, because as you already found out, ...


13

You can use the Notation package. It requires a GUI palette though. Needs["Notation`"] Once you have this package loaded, you can use the template to define: Notation[+[x___] ==> Plus[x___]] and then +[1,2,3] (* 6 *) Similarly, Notation[*[x___] ==> Times[x___]] and so *[2,3,4] (* 24 *) Note: A * typed as the first character of a cell ...


13

I'm not aware of a simple one, but perhaps you could make your own? The following is not great because it requires you to enter CenterDot as Esc+.+Esc, and you can't control the precedence, but depending on your use-case, it might be useful. In addition, you can use whatever built-in symbol with no built-in meaning you want: CenterDot[f_, a_] := Map[f, a, {...


12

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 Mathematica ...


12

Just to be clear, I think this is a terrible idea but nevertheless, a question has been posed for which there is a simple answer: ClearAll@fn SetAttributes[fn, HoldAll] fn[h_[x_]] /; StringMatchQ[SymbolName@h, "f" ~~ DigitCharacter ..] := First@StringCases[SymbolName@h, "f" ~~ d : DigitCharacter .. :> x + ToExpression@d] fn[...


12

The big issue here is that ∈ is a system defined symbol and messing with it in this way can have all manner of unintended consequences. You don't know what is using it behind the scenes. If you really need to then you can use Infix notion on your own in function. in[form_, list_] := MemberQ[list, form] Select[test, #~in~find &] (* {3, 4} *) Or you ...


11

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["∘"], lapply] InfixNotation[ParsedBoxWrapper["·"], Composition] Now $\circ$, $\dot{}{}$ and | act exactly like haskell's space, . and $ ...


11

Use upvalues. You don't want || to change its behavior except when it's operating on impedances. So, use a wrapper (z[ ], say) around the quantities that represent impedances, and associate upvalues with the wrapper. This lets you redefine how standard operators work on the wrapped values: z[a_] || z[b_] ^= z[1/(1/a + 1/b)]; z[a_] + z[b_] ^= z[a + b]; a_ z[...


11

One approach is to the use that Notation Package's AddInputAlias function to setup an alias that will convert Esc 0x Esc to 16^^ when you type it. First load the notation package with Needs["Notation`"] You can then view all the active notation aliases with ActiveInputAliases[] One of these in the list is an input alias to add input alias (addia). ...


10

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.


10

For a start, f[x,y]^(0,1) isn't the same as f^(0,1)[x,y]. But the real reason is that these expressions are very different in meaning, as revealed by their FullForm: D[f[x, y], y] // FullForm Derivative[0,1][f][x,y] versus (and I had to use a simple symbolic expression as the exponent to show what was going on: f[x,y]^z//FullForm Power[f[x,y],z] ...


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