Creating New Notations in Mathematica

Jason Harris

Introduction

Mathematica 3.0 and 4.0 understand most standard mathematical notations such as integrals, sums, products, etc. But in many mathematical fields, particularly pure mathematics, a variety of additional specific notations are used. The programmability of input and output in Mathematica makes it possible to introduce these kinds of notations, and to integrate them into your work.

The Notation package provides a variety of utilities allowing you to flexibly and extensively create and add your own notations to a Mathematica session. The full documentation for the package can be found here. Without the Notation package creating and defining your own notations can be laborious and problematic.

A Simple Example

a(Subscript[⊕, n + m])b  //  FullForm

gplus[α,  β,  Γ]

Notation for the Wigner 3j Symbol

The Wigner 3j Symbol is used in the coupling of angular momenta in quantum mechanics. The 3j symbol is a more symmetric form of a corresponding Clebsch-Gordon coefficient. This section creates a notation for 3j symbols and illustrates the use of this notation with a few simple examples.

This notation consists of a 3×2 GridBox with round braces subscripted by 3j. There are many other notational forms that could have been chosen including ones with hidden TagBoxes.

(Subscript[(({{j, j + (1/2), (1/2)}, {m, -m - (1/2), (1/2)}})), 3  𝒿])

HoldForm @ 
      ThreeJSymbol[{j, m}, {j + 1/2, -m - 1/2}, {1/2, 1/2}]

This notation for the Wigner 3j symbol can now be freely used in calculations, greatly increasing readability in certain cases. Furthermore, for ease of input we can add an input-alias for the Wigner 3j symbol to the current notebook.

A blank template of a Wigner 3j symbol can now be created by typing Esc3jEsc in any input cell.

The following is a short example illustrating an identity involving the Wigner 3j symbol.

(Overscript[u, ⇀]) . (Overscript[v, ⇀]) \[Cross] (Overscript[w, ⇀])  // 
      Expand

There are many ways to represent spherical tensors. The following is a simple, though not general approach.

((Overscript[u, ⇀]) . 
            (Overscript[v, ⇀]) \[Cross] (Overscript[w, ⇀])  == -I(Sqrt[6])(∑_(i = -1)^1)(∑_(j = -1)^1) (∑_(k = -1)^1)(Subscript[u, i])(Subscript[v, j])(Subscript[w, k])  (Subscript[(({{1, 1, 1}, {i, j, k}})), 3  𝒿]) )//Simplify

Bras, Kets and Operators in Quantum Mechanics

The following illustrates a notational system for the Dirac bra-ket notation used in quantum mechanics.

Modify Parenthesize and FullForm

The following code is used to fix the formatting of tag boxes and full form. This correction is not central to the points being illustrated in this notebook, but is necessary for correct formatting.

Declare the notation for Operators, Bras and Kets

The following notations for bras, kets, and brakets depend on specific styles that have been added to the style sheet of this notebook. These styles are necessary to give the bras, kets and brakets the correct visual and structural properties.

Ket[ψ]

Bra[ψ]

⟨a, ψ\[VerticalSeparator]ϕ⟩//FullForm

Entering Bras and Kets

To enter complex templates consisting of tag boxes and other underlying structures it is desirable to add input aliases to the current notebook. Creating input aliases for bras and kets is a perfect illustration of this.

⟨(Subscript[ψ, 𝒻])\[VerticalSeparator]·\(ℋ\&^\)·\[VerticalSeparator](Subscript[ψ, 𝒾])⟩

Toy Calculations

What follows are some toy definitions and calculations to illustrate the functionality of the notation defined for Bras and Kets.

\(X\&^\)·\[VerticalSeparator]\(x\_X\&^, s\_S\&^, l\_\(L\_z\)\&^\)⟩

\(S\&^\)·\[VerticalSeparator]\(x\_X\&^, s\_S\&^, l\_\(L\_z\)\&^\)⟩

\(\(L\_z\)\&^\)·\[VerticalSeparator]\(x\_X\&^, s\_S\&^, l\_\(L\_z\)\&^\)⟩

\(\(L\_z\)\&^\)·\(S\&^\)·\(X\&^\)·\[VerticalSeparator]\(x\_X\&^, s\_S\&^, l\_\(L\_z\)\&^\)⟩

⟨\(r\_X\&^\)\[VerticalSeparator]·\(X\&^\)·\(X\&^\)·\[VerticalSeparator]\(x\_X\&^\)⟩

\[VerticalSeparator]\(r\_X\&^\)⟩·⟨\(r\_X\&^\)\[VerticalSeparator]

\[VerticalSeparator]\(r\_X\&^\)⟩·⟨\(r\_X\&^\)\[VerticalSeparator]·\[VerticalSeparator]\(x\_X\&^\)⟩

ℏ \[VerticalSeparator]\(x\_X\&^, l\_\(L\_z\)\&^\)⟩//FullForm

Angular Momentum

This subsection contains some simple definitions and calculations to illustrate angular momentum and raising and lowering operators in quantum mechanics.

\(\(J\_+\)\&^\)·\[VerticalSeparator]\(3\_J\&^, 0\_J\&^\)⟩

To progress further we must add some basic properties to our NonCommutativeTimes. The following is a crude implementation of multiple linearity over addition and multiple linearity over constants, however it is sufficient for the purpose of illustration. The following rules state that constants can be factored out of a NonCommutativeTimes expression, and that NonCommutativeTimes distributes over addition.

\(\(J\_+\)\&^\)·\(\(J\_-\)\&^\)·\[VerticalSeparator]\(j\_J\&^, m\_J\&^\)⟩

In angular momentum theory the operator (J^2)has the eigenvalue j (j + 1) (ℏ^2) on eigenstates of angular momentum. It is usually a textbook calculation to show that the operator (J^2)can be decomposed into operators involving \(\(J\_+\)\&^\), \(\(J\_-\)\&^\) and \(\(J\_z\)\&^\). Let us verify that this is the case.

\((1\/2\ \((\(J\_+\)\&^·\(J\_-\)\&^ + \(J\_-\)\&^·\(J\_+\)\&^)\) + \(J\_z\)\&^·\(J\_z\)\&^)\)·\[VerticalSeparator]\(j\_J\&^, m\_J\&^\)⟩

Simplify @ %

For those that know enough about quantized angular momentum it is evident that the calculation above shows that (J^2) is equivalent to \(\((\(1\/2\) \((\(J\_+\)\&^·\(J\_-\)\&^ + \(J\_-\)\&^·\(J\_+\)\&^)\) + \(J\_z\)\&^·\(J\_z\)\&^)\)\).

Let us extend our implementation of angular momentum a little further and note that the eigenstates of angular momentum are orthogonal.

We can now evaluate the decomposition of  (J^2) between different eigenstates of angular momentum.

⟨\(k\_J\&^, n\_J\&^\)\[VerticalSeparator]·\((1\/2\ \((\(J\_+\)\&^·\(J\_-\)\&^ + \(J\_-\)\&^·\(J\_+\)\&^)\) + \(J\_z\)\&^·\(J\_z\)\&^)\)·\[VerticalSeparator]\(j\_J\&^, m\_J\&^\)⟩//Simplify

Finally, for illustration let us calculate an expression involving products of operators between eigenstates.

⟨\(k\_J\&^, n\_J\&^\)\[VerticalSeparator]·\(\(J\_+\)\&^\)·\(\(J\_z\)\&^\)·\((\(J\_-\)\&^ + \(J\_+\)\&^)\)·\[VerticalSeparator]\(3\_J\&^, 0\_J\&^\)⟩

Category Theory Diagrams

Some of the most complicated notation found anywhere occurs in category theory. This section gives some simple examples of how category theory diagrams can be set up as notations in Mathematica. The following example comes from the section on natural transformations in Birkhoff and MacLane's Algebra.

({{𝒮[X], (Overscript[→, (Subscript[τ, X])]), 𝒯[X]}, {↓𝒮[f], co, ↓𝒯[f]}, {𝒮[Y], (Overscript[→, (Subscript[τ, Y])]), 𝒯[Y]}})  /. SquareCommutativeDiagram  ->  view

({{𝒮[X], (Overscript[→, (Subscript[τ, X])]), 𝒯[X]}, {↓𝒮[f], co, ↓𝒯[f]}, {𝒮[Y], (Overscript[→, (Subscript[τ, Y])]), 𝒯[Y]}})  /. {𝒮 -> 𝒰,  τ -> σ,  
        Y -> Z}

A look at the rules

Notation[ ({{a_, (Overscript[→, f_]), b_}, {↓g_, co, ↓h_}, {c_, (Overscript[→, m_]), d_}})  ⟺
  SquareCommutativeDiagram[
              a_  (Overscript[→ , f])_ b_,  
              a_  (Overscript[→ , g])_ c_,  
              c_  (Overscript[→ , m])_ d_,  
              b_  (Overscript[→ , h])_ d_] ,
	Action ->  PrintNotationRules]