# What are some useful, undocumented Mathematica functions?

Also, other questions and answers that contained undocumented functions

Along with the "Undocumented (or scarcely documented) Features" segment of the What is in your Mathematica tool bag? question.

Szabolcs also maintains a list of Mathematica tricks which contains a list of "undocumented stuff".

So, what undocumented functions do you know and how do you use them? (Added useful information is maybe how you discovered the functions and any version dependence.)

-

## migrated from stackoverflow.comJan 27 '12 at 15:08

This question came from our site for professional and enthusiast programmers.

I guess I have to state the obvious here and that is using undocumented functions/options can break with major or even minor mathematica upgrades. My advice is to stay away unless you like to experiment and have a lot of time on your hands. – Eric Jan 27 '12 at 15:45
J.M. mentioned InternalFromPiecewise in (27254) if anyone feels like writing an answer about it. – Mr.Wizard Apr 13 at 17:07
@Kuba, Is it possible to edit this question to the style of community wiki? – Shutao TANG May 7 at 8:23
I don't know. No need for that on the other hand, this is a good question. – Kuba May 7 at 8:25
@Kuba, Thanks, I use Mathematica in my study everyday and I like Mathematica and StackSxchange which give me knowledge and happy.:) – Shutao TANG May 7 at 8:31

• LongestCommonSequencePositions and LongestCommonSubsequencePositions Their use is analogous to LongestCommon(Sub)sequence but they return the position of the first match instead.

• ClipboardNotebook[] can be used to access the clipboard. NotebookGet@ClipboardNotebook[] will give a Notebook expression with the current contents of the clipboard. I use this for pre-processing data before it is pasted (e.g. in the table paste palette). I am not sure if this can be used for copying at all---I use the Front End's Copy function directly for that (through FrontEndTokenExecute)

• PolynomialForm[] allows changing the order in which polynomial terms are printed by setting the option TraditionalOrder -> True

In[1]:= PolynomialForm[1+x+x^2, TraditionalOrder->True]
Out[1]= x^2+x+1

• POST request: In version 8 Import has experimental support for the POST HTTP request method. Example usage for uploading an image to imgur:

Import["http://api.imgur.com/2/upload", "XML",
"RequestMethod" -> "POST",
"RequestParameters" -> {"key" -> apikey, "image" -> image}]


(Of course you'll need to insert your API key and a properly encoded image, as shown in the answer I linked to above.)

• InternalDeflatten[] will reconstruct higher dimensional tensor from a flat list. Example:

In[1]:= arr = {{1, 2}, {3, 4}}
Out[1]= {{1, 2}, {3, 4}}

In[2]:= flatArr = Flatten[arr]
Out[2]= {1, 2, 3, 4}

In[3]:= InternalDeflatten[flatArr, Dimensions[arr]]
Out[3]= {{1, 2}, {3, 4}}


Warning: If the dimensions passed to it don't match the length of the flat array, this will crash the kernel!

• Image capture start/stop IMAQStartCamera[] and IMAQStopCamera[] start and stop the webcam.

• Undocumented interesting contexts to dig through: Internal, Experimental, Language, NotebookTools (similar to what the AuthorTools package offers), IMAQ (IMage AQcuisition)

There are lots of functions in these contexts, generally undocumented, but sometimes with self-explanatory names (e.g. InternalRealValuedNumericQ seems obvious). Note that these functions might change in later versions. Some of the ones listed by ?Internal* are even from old versions and no longer work in M- 8.

Some functions from Language are described here.

• SystemOptions[] The functions to set and read these options are not undocumented, but the options themselves unfortunately are.

• ExperimentalSystemOptionsEditor[] In version 8 this gives a GUI for viewing/setting system options.

• "TableCompileLength" (and other similar options from the "CompileOptions") section set the length of a Table above which it attempts to compile its argument.

Example: SystemOptions["CompileOptions" -> "TableCompileLength"] will show that the default value is 250.

• "SparseArrayOptions" -> {"TreatRepeatedEntries" -> 1}

Setting this option to 1 will cause repeated entries to be summed up when creating a sparse array. See an example use and explanation here.

In[1]:= Normal@SparseArray[{2 -> 1, 4 -> 1}]
Out[1]= {0, 1, 0, 1}

In[2]:= Normal@SparseArray[{2 -> 1, 4 -> 1, 2 -> 1}]
Out[2]= {0, 1, 0, 1}

In[3]:= SetSystemOptions["SparseArrayOptions" -> {"TreatRepeatedEntries" -> 1}]

In[4]:= Normal@SparseArray[{2 -> 1, 4 -> 1, 2 -> 1}]
Out[4]= {0, 2, 0, 1}


This MathGroup thread has some interesting information too.

-

Thinking about a recent answer made me wonder exactly which functions in Mathematica use Assumptions. You can find the list of System functions that use that Option by running

Reap[Do[Quiet[If[Options[Symbol[i], Assumptions]=!={}, Sow[i], Options::optnf]],
{i, DeleteCases[Names["System*"], _?(StringMatchQ[#, "$"~~__] &)]}]][[2, 1]]  which (can be more elegantly written using list comprehension and) returns (in version 8) {"ContinuedFractionK", "Convolve", "DifferenceDelta", "DifferenceRootReduce", "DifferentialRootReduce", "DirichletTransform", "DiscreteConvolve", "DiscreteRatio", "DiscreteShift", "Expectation", "ExpectedValue", "ExponentialGeneratingFunction", "FinancialBond", "FourierCoefficient", "FourierCosCoefficient", "FourierCosSeries", "FourierCosTransform", "FourierSequenceTransform", "FourierSeries", "FourierSinCoefficient", "FourierSinSeries", "FourierSinTransform", "FourierTransform", "FourierTrigSeries", "FullSimplify", "FunctionExpand", "GeneratingFunction", "Integrate", "InverseFourierCosTransform", "InverseFourierSequenceTransform", "InverseFourierSinTransform", "InverseFourierTransform", "InverseZTransform", "LaplaceTransform", "Limit", "PiecewiseExpand", "PossibleZeroQ", "PowerExpand", "Probability", "ProbabilityDistribution", "Product", "Refine", "Residue", "Series", "SeriesCoefficient", "Simplify", "Sum", "SumConvergence", "TimeValue", "ToRadicals", "TransformedDistribution", "ZTransform"}  You can similarly look for functions that take assumptions that are not in the System context and the main ones you find are in Names["Developer*Simplify*"] which are (adding "Developer" to the context path) {"BesselSimplify", "FibonacciSimplify", "GammaSimplify", "HolonomicSimplify", "PolyGammaSimplify", "PolyLogSimplify", "PseudoFunctionsSimplify", "ZetaSimplify"}  These are all specialized simplification routines that are not called by Simplify but are called by FullSimplify. However, sometimes FullSimplify can take too long on large expressions and I can imagine calling these specialized routines would be useful. Here's a simple usage example In[49]:= FunctionsWolfram["10.08.17.0012.01"] /. Equal -> Subtract // Simplify % // DeveloperPolyLogSimplify Out[49]= -Pi^2/6 + Log[1 - z] Log[z] + PolyLog[2, 1 - z] + PolyLog[2, z] Out[50]= 0  (The FunctionsWolfram code is described here) Another interesting assumption related context I noticed was Assumptions. Once again, appending "Assumptions" to the $ContextPath, Names["Assumptions*"] returns the functions

{"AAlgebraicQ", "AAssumedIneqQ", "AAssumedQ", "ABooleanQ",
"AComplexQ", "AEvaluate", "AEvenQ", "AImpossibleIneqQ", "AInfSup",
"AIntegerQ", "AllAssumptions", "AMathIneqs", "AMod", "ANegative",
"ANonNegative", "ANonPositive", "AOddQ", "APositive", "APrimeQ",
"ARationalQ", "ARealIfDefinedQ", "ARealQ", "ASign", "AssumedFalse",
"AUnequalQ", "AWeakSign", "ImpliesQ"}


These contain assumption aware versions of some standard system functions, e.g.

In[22]:= Assuming[Element[x, Integers], {IntegerQ[x], AIntegerQ[x]}]
Assuming[x > 0, {Positive[x], APositive[x]}]

Out[22]= {False, True}

Out[23]= {Positive[x], True}

-

One undocumented function I find useful is Precedence

For example:

{#, Precedence@#} & /@ {Plus, Minus, Times, Power, Apply, Map, Factor,
Prefix, Postfix, Infix} // TableForm


giving:

Plus    310.
Minus   480.
Times   400.
Power   590.
Apply   620.
Map     620.
Factor  670.
Prefix  640.
Postfix 70.
Infix   630.


Precedence is described in a lecture A New Mathematica Programming Style by Kris Carlson available here

Edit

One from about a year ago, which was then considered 'under development', is TableView. I wonder what has happened to it?

For example:

Array[Subscript[a, ##] &, {4, 3}] // TableView


giving:

-
I was thinking of adding Precedence here. Luckily I noticed your answer. Appropriately enough, I learned of this from a comment you made to a question on stackoverflow. +1 – acl Jan 29 '12 at 1:23
At a Wolfram Training Course in April '15 we were advised that TableView was being deprecated and not to use it as it caused frequent Kernel crashes. Its been deleted from the help, although curiously still gives a hit for ListPicker. – Gordon Coale May 12 at 12:15

I quite like SequenceLimit[] myself; it is a function that numerically estimates the limit of a sequence by applying the Shanks transformation (as embodied in Wynn's $\varepsilon$ algorithm). The method is a particularly nice generalization of the probably more well-known Aitken $\delta^2$ transformation for accelerating the convergence of a sequence. Another way of looking at it is that if one applies the Shanks transformation to a sequence whose terms correspond to partial sums of a power series, the transformation gives the results corresponding to the diagonal Padé approximants formed from the partial sums.

Enough preamble, and let's see an example. Consider the sequence of iterates to the cosine's fixed point:

seq = NestList[Cos, N[1, 30], 20];


and let's generate the number for comparison purposes:

dottie = x /. FindRoot[x == Cos[x], {x, 3/4}, WorkingPrecision -> 40]
0.7390851332151606416553120876738734040134


Compare:

Last[seq]
0.739184399771493638624201453905348

% - dottie
0.000099266556332996968889366231475


with

SequenceLimit[seq]
0.7390851332151606416553149654

% - dottie
2.877753649509045.313591998048321*^-24


It can be seen here that applying the Shanks transformation to the sequence of iterates gave a result which had more good digits than any of the iterates themselves. This is the power of the function SequenceLimit[].

As with any powerful tool, however, some care is needed in its use. Consider for instance this example:

seq = N[Accumulate[((-1)^Range[0, 30]) Range[0,30]!], 30];


We have generated here a rather violently divergent sequence of partial sums $\sum\limits_k (-1)^k k!$. One would rightly be wary of trying to derive results from a sequence like this, but SequenceLimit[] manages to do something, even if it does spit out a warning:

SequenceLimit[seq]
SequenceLimit::seqlim: The general form of the sequence could not be determined, and the result may be incorrect. >>
0.596347362

% - (-E ExpIntegralEi[-1])
0.*10^-10


and in fact the result can be justified through analytic continuation. However, that the algorithm can give unexpected results for divergent sequences is something to be mindful and careful of.

-
Interesting, it has a usage message, but is not in the documentation - it's also in the System  context, which is rare for undocumented functions. Do you think it forms the backend for NSum[..., Method -> "WynnEpsilon"]? – Simon Jan 28 '12 at 3:38
Yes, it's the method behind the "WynnEpsilon" options of NSum[]/NProduct[]. – J. M. Jan 28 '12 at 3:47
This answer of mine mathematica.stackexchange.com/questions/95126/… has implementations of the Shanks transformation and Richardson extrapolation. I really wanted to include Richardson extrapolation in NSum, but got involved in NIntegrate ... By the way, the original author of NSum (Jerry Keiper) implemented his own modifications of the Wynn Epsilon algorithm. – Anton Antonov Oct 7 at 11:21
@Anton, it does seem unfortunate that Keiper did not mention his modifications, as you say, of the Wynn algorithm. In any event: I note that your implementation of Shanks does not use the "rhombus rule", and your implementation of Richardson extrapolation does not exploit the recurrence's "triangular" nature. You might consider looking at this... – J. M. Oct 7 at 11:32

The following simulates Mathematica's behaviour after using it for more than 24 hrs.

MathLinkCallFrontEnd[FrontEndUndocumentedCrashFrontEndPacket[]]


-
That make my day! :D – ybeltukov Jan 19 '14 at 22:33
OMG! I thought you were kidding... – Silvia Jun 19 '14 at 19:14

### InternalBag

• Bag creates an expression bag, optionally with preset elements.
• BagPart obtains parts of an expression bag, similar to Part for ordinary expressions. It can also be used on the lhs, e.g. to reset a value. StuffBag appends elements to the end of a bag.
• We also have a BagLength, which is useful for iterating over a bag.

### InternalFromPiecewise

-
For InternalBag, you should credit Daniel Lichtblau for that explanation, not me. As I noted in my post, that was just a quote from DL's answer which you linked to in the line above. Unrelated note: Using @username to ping people in an answer won't actually ping them. @-mentions don't work in answers. – R. M. May 11 at 3:16
@TheToad, OK, I got it. – Shutao TANG May 11 at 5:23

## CompileInnerDo

This is the one that initially struck me as interesting since I use compiled functions quite a lot. From the documentation of Do:

Unless an explicit Return is used, the value returned by Do is Null.

But that doesn't seem to be the case for CompileInnerDo!

f1 = Compile[{{x}},
Module[{a}, a = x; CompileInnerDo[a++, {i, 10^8}]]
]

f2 = Compile[{{x}},
Module[{a}, a = x; Do[a++, {i, 10^8}]]
]

f1[0] // AbsoluteTiming
(* 1.63 seconds, 99999999 *)

f2[0] // AbsoluteTiming
(* 1.63 seconds, Null *)


Essentially it adds an extra line into the result of CompilePrint:

## CompileMod1

Seems to be just that, and is listable. In fact, if you write a compilable function that contains Mod[x, 1] then it gets compiled down to CompileMod1.

f1 = Compile[{{x}}, CompileMod1[x]];
f2 = Compile[{{x}}, Mod[x, 1]];

Needs["CompiledFunctionTools"];
CompilePrint@f1 == CompilePrint@f2
(* True *)


## CompileDLLFunctionLoad / CompileDLLLoad

These seem to perform the same functions as LibraryFunctionLoad:

fun1 = LibraryFunctionLoad["demo", "demo_I_I", {Integer}, Integer]
fun2 = CompileDLLFunctionLoad["demo", "demo_I_I", {Integer}, Integer]
fun1[10] == fun2[10]
(* True *)

-

### InternalPartitionRagged

This one has a usage statement!

InternalPartitionRagged[Range[14], {3, 5, 2, 4}]

{{1, 2, 3}, {4, 5, 6, 7, 8}, {9, 10}, {11, 12, 13, 14}}


Note that Length[list] must equal n1 + ... + nk.

(* changed the last 4 to 3 *)
InternalPartitionRagged[Range[14], {3, 5, 2, 3}]

InternalPartitionRagged[Range[14], {3, 5, 2, 3}]


### InternalS1, InternalS2, InternalP2

Is it possible to have a documentation of these frequently-used functions with the help of the users in this community?

These guy's aren't frequently used (and probably aren't used at all), but they're really mysterious looking.

After reading this paper, I realized they're submethods used in computing PrimePi.

With[{x = 10^9},
{
PrimePi[x],
InternalS1[x] + InternalS2[x] + InternalP2[x] + PrimePi[x^(1/3)] - 1
}
]

{50847534, 50847534}


### InternalSquare

??InternalSquare
(* Attributes[InternalSquare] = {Listable, NumericFunction, Protected} *)


Test it with a list:

list = RandomReal[{0, 100}, 10^8];

r1 = list*list; // RepeatedTiming
(* 0.118 seconds *)
r2 = list^2; // RepeatedTiming
(* 0.191 seconds *)
r3 = InternalSquare[list]; // RepeatedTiming
(* 0.121 seconds *)


The advantage of this function seems to come when computing higher powers on a list:

lis = RandomReal[{0, 1}, 10^7];

lis*lis*lis*lis; // RepeatedTiming
(* 0.55 seconds *)
lis^4; // RepeatedTiming
(* 0.21 seconds *)
InternalSquare @ InternalSquare @ lis; // RepeatedTiming
(* 0.15 seconds *)

-
+1, It is very convenient to utilize InternalPartitionRagged[Range[# (# + 1)/2], Range@#] &[5] to achieve the following lists (*{{1}, {2, 3}, {4, 5, 6}, {7, 8, 9, 10}, {11, 12, 13, 14, 15}}*) – Shutao TANG May 11 at 7:49
@ShutaoTang regarding PartitionRagged I like my own implementation better as it does things PartitionRagged does not. I hope you will give it a look. – Mr.Wizard May 14 at 15:43
@Mr.Wizard, I have known your neat implementation last year. – Shutao TANG May 15 at 3:25
@ShutaoTang Okay. :-) – Mr.Wizard May 15 at 3:28
Thank you very much. It's really hard for me to decide whose answer is the best one. Since @blochwave is the first answer, I give this bounty to his answer. I'm sorry, I can only vote up for yours:) – Shutao TANG May 16 at 0:53

No so much a function as an option...

Problem: You embedd a CDF on a web page but the content is rendered as grey boxes.

Cause: This is a security issue, the same as when you open a notebook with dynamic content from an untrusted path on your computer.

Solution: On your desktop you are asked if you want to enable dynamic content. You press the button and everything in your notebook works. By using the "option" {fullscreen:'true'} an embedded CDF will open in "full screen mode" meaning that the enabled content warning will appear and therefore provide your viewers with the button to enable dynamic content.

Usage:

<script src="http://www.wolfram.com/cdf-player/plugin/v2.1/cdfplugin.js" type="text/javascript">
</script>
<script type="text/javascript">
var cdf = new cdf_plugin();
cdf.embed("http://path.to/myCDF.cdf", 500, 600,{fullscreen:'true'});
</script>

-
Hey Mike, I found this very useful. Could you write an answer to my question found here? I tried what you mentioned here and it seems it could work, but now I face another problem, my CDF now says Initialization timed out after I click on the button to enable the dynamic content. – jmlopez May 27 '12 at 7:00

### Properties for SparseArray and InterpolatingFunction objects

SparseArray objects can accept a range of Properties (or Methods) that allow the efficient extraction of certain information, most commonly "AdjacencyLists" or "NonzeroPositions" as a frequently faster alternative to Position. I started this answer to detail them but as it grew I came to believe that it needs a Q&A of its own, so I posted one:

Likewise InterpolatingFunction also supports a number of Methods which I have detailed here:

## Undocumented parameters

For Normal: Is there a way to control which special forms Normal converts?

For Return and Break: Is there a Break[] equivalent for short-circuiting in Table?

-

### TetGen

Mathematica has a nice library TetGenLink to produce irregular 3D meshes. Original TetGen has a lot of features and not all of them available by TetGenLink. One of the features is the setting up the vertex metrics to produce non-uniform grids

Fortunately, the corresponding function is implemented but not documented

TetGenSetPointMetricTensors[tetGenInstance, {{x1, y1, z1}, {x2, y2, z2}, ...}]


The mesh size depends only on the first element of the tensors (x1, x2, x3, ...).

### Fractions

Beveled fractions ${}^a/_b$ available with the undocumented option Beveled in the FractionBox.

### TextRecognize

"SegmentationMode" option can improve TextRecognize.

-
I only saw this now: The reason it's not documented is that I never could come up with a use case for this TetGen function. If you could point that out to me then it could be documented. – user21 Oct 15 at 11:32
@user21 I think now with new V10 functional TetGenLink is no longer relevant. – ybeltukov Oct 15 at 18:05