# Show how Mathematica defines a function

Is there a way to show how Mathematica defines a function, such as

In: Something[Sqrt], Out: Sqrt[x] -> x^(1/2)


As far as I understand it the command Definition[] should do the job, but unfortunately it does not work on built in functions. I am asking because more complicated functions than Sqrt, such as for example the JacobiAmplitude[], are not well documented in the Help section, and give different results with different programs.

Since I got a solution containing those functions which are not defined uniformly everywhere, I would need to know how to interpret the output generally so I could do the calculation with pencil and on paper if I had to .

I tried to reconstruct the definitions myself with the informations given at NIST, and I got this far:

That gives the same results like the built in functions for some ranges, but not for others; also it takes literally hours to compute the definitions I defined myself, even when I let the sum run to a small finite value instead of infinity.

The built in JacobiAmplitude[] in contrast evaluates in a few seconds and for all given input values, so I assume I'm doing something wrong with my own definitions.

• 1. Using the integral definition directly for the complete elliptic integral is not the most efficient way for numerical evaluation; EllipticK[] is built-in, or if you must, ArithmeticGeometricMean[]. EllipticNomeQ[] is also built-in, and the most efficient algorithm also depends on the AGM. 2. The series for the Jacobian amplitude you are displaying has very limited numerical utility. 3. Note that Mathematica uses the parameter $m$ instead of the modulus $k$ as the second argument for the elliptic integrals and elliptic functions. – J. M. is in limbo Apr 12 '16 at 17:57
• 4. Since a good amount of JacobiAmplitude[] is implemented as top-level code, PrintDefinitions[] from the GeneralUtilities  package can be revealing. – J. M. is in limbo Apr 12 '16 at 18:00
• Have you looked at MathematicalFunctionData introduced in v10.3 (with ToEntity as demonstrated on its documentation)? I believe this is very much what you're looking for, and trying to extract this information from the way Mathematica actually works is probably a relatively futile effort in comparison. – kirma Apr 12 '16 at 18:01
• MathematicalFunctionData["JacobiAmplitude", "SeriesRepresentations"] works fine, thanks – Yukterez Apr 13 '16 at 20:03

This isn't necessarily how these functions are implemented, but MathematicalFunctionData gives a way to access definitions that are equivalent to the ones Mathematica uses.

(* There are a total of 348 functions to choose from *)
Length[functions = MathematicalFunctionData[]]

348

functions[[1]]["Definition"]

{Function[{\[FormalX]},
Inactivate[
ConditionalExpression[
Abs[\[FormalX]] == \[FormalX], \[FormalX] \[Element] Reals && \[FormalX] >= 0]]],
Function[{\[FormalX]},
Inactivate[
ConditionalExpression[
Abs[\[FormalX]] == -\[FormalX], \[FormalX] \[Element] Reals && \[FormalX] < 0]]],
Function[{\[FormalZ]},
Inactivate[
Abs[\[FormalZ]] == Sqrt[Re[\[FormalZ]]^2 + Im[\[FormalZ]]^2]]]}


We can process the output to make it more readable:

MakeBoxes[formattedConditionalExpression[expr_, cond_], form_] :=
MakeBoxes[Row[{expr, Text@Style["  for  ", GrayLevel[0.5]], cond}], form]

prettyDefinition[f_Entity] :=
Column[
Activate[HoldForm /@ fromFunction[f["Definition"]]] /.
ConditionalExpression -> formattedConditionalExpression,
Spacings -> 1

SetAttributes[fromFunction, Listable];
fromFunction[HoldPattern[Function][vars_List, body_]] := standarize[body]

standarize = With[{hash = Dispatch[Thread[Rule[ToExpression /@ CharacterRange["\[FormalA]", "\[FormalZ]"], ToExpression /@ CharacterRange["a", "z"]]]]},
# /. hash&
]

prettyDefinition[Entity["MathematicalFunction", "BesselY"]]


There are other representations you can access too (like integral, sum, etc) through EntityValue. There are 50 different properties for mathematical functions:

Length[EntityProperties[Entity["MathematicalFunction", "BesselY"]]]

50
`