# Using mathematical notation

Is it possible to write this function in mathematica exactly as shown, and then run the expression on a dataset?

Please note I know that there are several other ways to do this. I am only interested in knowing how to compute it(if its possible) using notation that you would find in a text book.

• This question would benefit from some attempt to actually do this in Mathematica and Mr. Wizard's answer raises important issues. Still, I've up voted it, because trying this kind of thing helped my entry into the Mathematica universe. I think it could also help others. Not the most efficient way to use Mathematica, but interesting none the less. Sep 26, 2013 at 14:34

The meaning of the subscript is not pre-defined in Mathematica. In this instance it is used to grab an element of a dataset, but it could be used as an adjective like Subscript[F, gravity]. To use the subscript notation you could use

<< Notation
Notation[ParsedBoxWrapper[SubscriptBox["x_", "i_"]] ⟺ ParsedBoxWrapper[RowBox[{"x_", "[[", "i_", "]]"}]]]


Then you could write a block of code which implements the procedure with whichever dataset is assigned to x at the moment of evaluation.

x = RandomReal[{0, 1}, 30];


Note N is a built-in function, so we will use [ScriptCapitalN] instead

\[ScriptCapitalN] = Length@x;
μ = 1/\[ScriptCapitalN] \!$$\*SubsuperscriptBox[\(∑$$, $$i = 1$$, $$\[ScriptCapitalN]$$]\*SubscriptBox[$$x$$, $$i$$]\);
σ = Sqrt[1/\[ScriptCapitalN] \!$$\*SubsuperscriptBox[\(∑$$, $$i = 1$$, $$\[ScriptCapitalN]$$]\*SuperscriptBox[$$(\*SubscriptBox[\(x$$, $$i$$] - μ)\), $$2$$]\)];


A little less "exactly as written", you could reinforce the idea that each of these quantities depends on the dataset by making them functions.

ClearAll[\[ScriptCapitalN], μ, σ];
\[ScriptCapitalN][x_] := Length@x;
μ[x_] := 1/\[ScriptCapitalN][x] \!$$\*SubsuperscriptBox[\(∑$$, $$i = 1$$, $$\[ScriptCapitalN][x]$$]\*SubscriptBox[$$x$$, $$i$$]\);
σ[x_] := Sqrt[1/\[ScriptCapitalN][x] \!$$\*SubsuperscriptBox[\(∑$$, $$i = 1$$, $$\[ScriptCapitalN][x]$$]\*SuperscriptBox[$$(\*SubscriptBox[\(x$$, $$i$$] - μ[x])\), $$2$$]\)];
σ@x


• In a teaching setting, I would use this for small data sets so students see how the computer is just doing tedious hand calculations very quickly. Then I would introduce large data sets so the computer hangs. This is because functions are being called over and over unnecessarily. Ie, our implementation is inefficient. Then I would introduce the built-in functions, as efficient implementations for the same calculations. Sep 26, 2013 at 8:03
• This is great! Thank you! Sep 27, 2013 at 6:27

It matters if this about entering the expression (function), or displaying the expression. (Please clarify.)

If it is about entering the expression you will find that while you can get close in many cases it will not be exact, and also that there are ambiguities that must be resolved with more definite coding. Generally speaking I would recommend that you do not attempt this and instead enter functions in the most native Mathematica format.

If it is about display, e.g. TraditionalForm, then you can use things like Interpretation, and your own MakeBoxes or Format` definitions.