214
$\begingroup$

There have already been some questions about some undocumented functionality in Mathematica. Such as (please add to these lists!)

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", which can now be found archived here.


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

$\endgroup$
12
  • 6
    $\begingroup$ 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. $\endgroup$
    – Eric
    Commented Jan 27, 2012 at 15:45
  • 1
    $\begingroup$ J.M. mentioned Internal`FromPiecewise in (27254) if anyone feels like writing an answer about it. $\endgroup$
    – Mr.Wizard
    Commented Apr 13, 2015 at 17:07
  • $\begingroup$ @Kuba, Is it possible to edit this question to the style of community wiki? $\endgroup$
    – xyz
    Commented May 7, 2015 at 8:23
  • 1
    $\begingroup$ I don't know. No need for that on the other hand, this is a good question. $\endgroup$
    – Kuba
    Commented May 7, 2015 at 8:25
  • 8
    $\begingroup$ I would add Internal`AbsSquare. So much time lost computing the square root in Abs or Norm just to undo it a moment later in quantum mechanical calculations. $\endgroup$
    – The Vee
    Commented Apr 4, 2016 at 15:49

26 Answers 26

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

    Update: These are documented since 10.2.

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

    Update: Since version 8 we have some documented clipboard functions.

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

  • Internal`Deflatten[] 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]:= Internal`Deflatten[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!

    Update: Version 9.0 introduced the documented equivalent ArrayReshape.


  • Image capture start/stop IMAQ`StartCamera[] and IMAQ`StopCamera[] 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. Internal`RealValuedNumericQ 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.

    • Experimental`SystemOptionsEditor[] 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.

$\endgroup$
2
  • 1
    $\begingroup$ I cannot for the life of me figure out what you mean by "The functions to set and read these options are not undocumented, but the options themselves unfortunately are." There's likely a typo which I can't figure out; would you kindly fix? Thanks. $\endgroup$
    – QuantumDot
    Commented Oct 5, 2016 at 2:06
  • $\begingroup$ @QuantumDot "are not undocumented" means "are documented". So, it means we know how to set options, but unfortunately do not know what those options mean. $\endgroup$ Commented Jun 8, 2018 at 17:19
59
$\begingroup$

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

MathLink`CallFrontEnd[FrontEnd`UndocumentedCrashFrontEndPacket[]]

Works as advertised! :D

$\endgroup$
5
  • 3
    $\begingroup$ That make my day! :D $\endgroup$
    – ybeltukov
    Commented Jan 19, 2014 at 22:33
  • 14
    $\begingroup$ OMG! I thought you were kidding... $\endgroup$
    – Silvia
    Commented Jun 19, 2014 at 19:14
  • $\begingroup$ I wonder how it was discovered, can't find it in Names["*`*"] $\endgroup$
    – btwiuse
    Commented Jan 13, 2017 at 3:34
  • 1
    $\begingroup$ @navigaid see this: mathematica.stackexchange.com/questions/13451/… $\endgroup$
    – b3m2a1
    Commented Jul 31, 2017 at 21:13
  • $\begingroup$ Oh wow ok I thought I was just crazy (I am but still) $\endgroup$ Commented Jun 11, 2019 at 3:39
57
$\begingroup$

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 the lecture A New Mathematica Programming Style by Kris Carlson.

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:

Example of a TableView

For the recent version 10.3,TableView cannot work normaly.

Example of TableView not working in version 10.3

$\endgroup$
3
  • $\begingroup$ 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 $\endgroup$
    – acl
    Commented Jan 29, 2012 at 1:23
  • 5
    $\begingroup$ 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. $\endgroup$ Commented May 12, 2015 at 12:15
  • 3
    $\begingroup$ As per a talk at WTC '18 I believe TableView might be coming back in 12.x. $\endgroup$
    – Carl Lange
    Commented Dec 11, 2018 at 23:58
56
$\begingroup$

Sequential With

From Daniel Lichtblau's comment there is a new undocumented syntax for With introduced sometime after version 10.1 that allows:

With[{a = 0}, {a = a + 1}, {a = a + 1}, a]
2

Delayed With, Block, and Module

These scoping constructs support the use of := in definitions which allows one to handle unevaluated expressions.

With[{x := 2 + 2}, Trace[x]]
Block[{x := 2 + 2}, Trace[x]]
Module[{x := 2 + 2}, Trace[x]]
{2 + 2, 4}

{x, 2 + 2, 4}

{x$6064, 2 + 2, 4}

Examples:

  • I find this most useful in With since it inserts definitions into held expressions.
    I commonly use this for in-place modification of DownValues:

     a[1] = Pi;
     a[2] = E;
    
     With[{dv := DownValues[a]},  dv = dv /. {1 -> 3};]
    
      a[3]   (*  out=  π  *)
    
  • Kuba finds it very useful for writing readable controllers definitions.

    E.g.

    asso = <|"nested" -> <|"key" -> <|
        "spec" -> <|"a" -> 1, "b" ->  0|>
    |>|>|>;
    
    With[{
      a := asso["nested", "key", "spec", "a"],
      b := asso["nested", "key", "spec", "b"]
      },
     DynamicModule[{},
       Column@{
        Slider@Dynamic[a],
        Slider[Dynamic[b, {Automatic, (a = b^2) &}]],
        Dynamic@asso
        }
     ]
    
    ]
    

The earliest Stack Exchange usage of this that I can find is a post by Szabolcs.

I implemented a similar syntax in my listWith function which is itself an extension of With.

$\endgroup$
6
  • $\begingroup$ Is just the example unfortunately chosen? It seems to me that it works the same without With. DownValues[a] = DownValues[a] /. {1 -> 3}; a[3] $\endgroup$
    – BoLe
    Commented Aug 3, 2016 at 11:55
  • $\begingroup$ @Kuba I think I usually make Dynamic part of the definition in that case? Does that fail in your typical application? edit: Actually I remember that I use both, e.g. (88458). Would you care to edit this answer to include your example? $\endgroup$
    – Mr.Wizard
    Commented Aug 3, 2016 at 12:06
  • $\begingroup$ @Kuba Thanks for the example! $\endgroup$
    – Mr.Wizard
    Commented Aug 3, 2016 at 12:10
  • 1
    $\begingroup$ As an added variant, I often need to create random option values, and delayed With is perfect for this, e.g. AxesLabel -> With[{x := RandomChoice[{None, Automatic, "North"}]}, RandomChoice[{x, {x, x}}]]. $\endgroup$
    – rcollyer
    Commented Aug 30, 2016 at 14:52
  • 4
    $\begingroup$ Testing. It's combinatorically impossible to cover all combinations, and you hope they're independent, we all know that isn't strictly true. So, for some tests, I'll generate random sets of options and see what blows up. Often it is the only way to get coverage. $\endgroup$
    – rcollyer
    Commented Aug 31, 2016 at 12:52
51
$\begingroup$

Update

Since version 11.2, this function is now buried in a deeper context: NumericalMath`NSequenceLimit[].


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.87775364950904`5.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.

$\endgroup$
8
  • $\begingroup$ 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"]? $\endgroup$
    – Simon
    Commented Jan 28, 2012 at 3:38
  • 1
    $\begingroup$ Yes, it's the method behind the "WynnEpsilon" options of NSum[]/NProduct[]. $\endgroup$ Commented Jan 28, 2012 at 3:47
  • 1
    $\begingroup$ 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. $\endgroup$ Commented Oct 7, 2015 at 11:21
  • $\begingroup$ @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... $\endgroup$ Commented Oct 7, 2015 at 11:32
  • $\begingroup$ It is worth mentioning that despite its N prefix the function works on symbolic sequences as well, e.g. NumericalMath`NSequenceLimit[{a0, a1, a2, a3, a4, a5}]. $\endgroup$ Commented Jun 7, 2018 at 6:13
50
$\begingroup$

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
         % // Developer`PolyLogSimplify

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}
$\endgroup$
46
$\begingroup$

System`

The default value for the overhang parameter k (3rd argument) in ListCorrelate is None.

Internal` Predicates

Internal`LinearQ[expr, var] yields True if expr is a polynomial of exactly order one in var, and yields False otherwise.

Internal`RationalFunctionQ[expr,var] returns True if expr is a rational function of the symbol var, and returns False otherwise. Internal`RationalFunctionQ[expr,{var1, var2,...}] checks that expr is rational in each of the var_i. (ref)

Internal`RealValuedNumberQ[expr] yields True if expr is a real-valued number, and False otherwise.

Internal`RealValuedNumericQ[expr] yields True if expr is a real-valued numeric quantity, and False otherwise.

Internal`DependsOnQ[expr, form] yields True if a subexpression in expr matches form (excluding heads) and mathematically depends on form, and yields False otherwise. Takes a third argument (True/False, but behavior seems to be independent of choice) but seems to include heads also (ref)

Internal`EPolyQ[expr,var] yields True if expr is a polynomial in var and is in expanded form with respect to var. (New in 11.2)

Internal`ExceptionFreeQ[expr] yields True if expr evaluates to something that contains Infinity, DirectedInfinity, or Indeterminate, and yields False otherwise.

Internal`FundamentalDiscriminantQ[expr] yields True if expr is a fundamental discriminant Integer with the exception of 1, and False otherwise.

Internal`GregorianLeapYearQ[expr] yields True if the expr is an integer that corresponds to a leap year of the Gregorian Calendar, and False otherwise.

Internal`LiterallyOccurringQ[expr, form] yields True if a subexpression in expr explicitly matches form, ignoring any Attributes of heads that might ordinarily influence the pattern matcher, and yields False otherwise.

Internal`LiterallyAbsentQ[expr, form] yields True if no subexpression in expr matches form, and yields False otherwise.

Internal`TestIntegerQ[number, form] yields {number, True} if number is an Integer, and {number, False} otherwise.

Internal`WouldBeNumericQ[expr, {var_1, var_2, ...}] yields True if expr would become a numeric quantity if the var_i were all numeric quantities, and False otherwise.

Internal`PatternFreeQ[expr] yields True if expr does not contain any of {Alternatives, Blank, BlankNullSequence, BlankSequence, Except, Longest, Optional, OptionsPattern, OrderlessPatternSequence, PatternSequence, Repeated, RepeatedNull, Shortest}, and False otherwise.

Internal`PatternPresentQ[expr] yields True if expr contains any of {Alternatives, Blank, BlankNullSequence, BlankSequence, Except, Longest, Optional, OptionsPattern, OrderlessPatternSequence, PatternSequence, Repeated, RepeatedNull, Shortest}, and False otherwise.

Internal`PolynomialFunctionQ[expr, var] yields True if expr is a polynomial in var, and yields False otherwise. InternalPolynomialFunctionQ[expr, {var1, var2,...}] yields Trueif expr is a polynomial in all var_i, and yieldsFalse` otherwise. (more info)

Internal`RadicalMemberQ[rad, {poly1, poly2, ...}] tests whether rad belongs to the radical of the polynomial ideal generated by poly1, poly2,... (ref)

Internal`SyntacticNegativeQ[expr] gives True if expr has a minus sign vague... needs to be clarified (application)


Other Internal`'s

Internal`BinomialPrimePowerDecomposition[n,m] gives a Internal`FactoredNumber object containing the list of prime factors of the binomial coefficient (n,m) together with their exponents.

Internal`ConditionalValueBody[inputHead,{test1, test2, ...},{{msgName1,arg1A,arg1B,...},{msgName2,arg2A,arg2B,...},...},body] evaluates each of the test_i in turn and if any yields False, immediately generates the corresponding inputHead::msgName_i Message with arguments arg_iA, arg_iB,... and returns Fail; otherwise evaluates body.

Internal`CompareNumeric[prec, a, b] returns -1, 0, or 1 according to whether a is less, equal, or greater than b when compared at the precision of a or b (whichever is less) minus prec decimal digits of "tolerance". It is the fundamental operation underlying Less, Equal, Greater, LessEqual etc. for finite-precision numeric types. (ref) (more info)

Internal`DiracGammaMatrix[n, "Metric" -> {list of +/-1}, "Basis" -> ("Dirac"/"Chiral")] returns the nth Dirac Gamma matrix.

Internal`ListMin[matrix] returns matrix with rows that has all elements greater or equal to elements of another removed. (ref)

Internal`Metric is an option to Internal`DiracGammaMatrix.

Internal`JoinOrFail[list1, list2] returns the list formed by appending list2 to the end of list1.

Internal`PerfectPower[integer] gives the list of integers {n,p} such that integer is n^p.

Internal`RiccatiSolve[{a, b}, {q, r}] solves the continuous time algebraic Riccati equation. (this is a documented System function)

Internal`DiscreteRiccatiSolve[{a, b}, {q, r}] solves the discrete time algebraic Riccati equation. (this is a documented System function)

Internal`MakePolynomial[expr] returns the form of expr in terms of new variables, such that expr is polynomial in the new variables. (ref)

Internal`ToEquivalenceClass[expr, toll] replaces the floating point numbers in expr with their equivalence class representatives according to the specified tolerance toll (ref).


System`Utilities`

System`Utilities`ExprLookupAdd[expr] stores expr to memory and returns an integer (not machine sized) key for retrieval.

System`Utilities`ExprLookup[integer] returns the corresponding expr if int is a valid integer key, and returns $Failed otherwise.

System`Utilities`SymbolList[expr] returns a list of atomic Symbols (including heads) in expr.
System`Utilities`SymbolList[expr, f] applies f to each Symbol before evaluating them. System`Utilities`SymbolList[expr, f, {"Context1`", ...}] omits symbols belonging to contexts Context1` , etc.

System`Utilities`Hash* (12 functions) (more info)


Some more stuff

Reduce`FreeVariables[expr] returns a List of Symbols in expr (more info). Unclear. See this for discussion.

GroupTheory`Tools`Multisets[list, n] evaluates to a list of multisets of size n with elements drawn from list (so, repetitions are allowed, but order is irrelevant). For example, GroupTheoryToolsMultisets[{a, b, c}, 2] yields {{a,a},{a,b},{a,c},{b,b},{b,c},{c,c}} (as in this answer).

GroupTheory`Tools`MultiSubsets[list, {n, m}], if n + m = Length(list), gives the set of subsets of exactly n elements appended to the set of subsets of exactly m elements in reverse order. (equivalent to MultiSubsets[list_, {n, m}] /; Length[list] == n + m := Join @@@ Transpose[{Subsets[list, {m}, Binomial[n + m, n]], Reverse[Subsets[list, {n}, -Binomial[n + m, n]]]}] and not much faster) To figure out: What if n + m ≠ Length(list)?

GroupTheory`Tools`PartitionRagged[list, {n1, n2, ...}] seems to be equivalent to Internal`PartitionRagged[list, {n1, n2, ...}], but works even if n1 + n2 ...Length[list].

GroupTheory`Tools`IntegerPartitionCounts[n] returns a list of lists corresponding to number (counts) of integers appearing in each partition. (the correspondence with IntegerPartitions[n] appears to be reversed).

GroupTheory`Tools`ConsecutiveReplace[expr,{patt1->list1, patt2->list2,...}] replaces elements of expr (Head usually List) that match patt1, patt2, ... with elements of list1, list2 ... in the order they appear in expr. If any of the list1, list2, ... are exhausted, it wraps around.

Integrate`InverseIntegrate[expr, {x, x0, x1}] performs the definite integration by attempting various substitutions of the form u == g[x] where g[x] is an expression in the integrand. (ref) (application) (application)

$\endgroup$
2
  • $\begingroup$ Note that RationalFunctionQ works on trig expressions such as Internal`RationalFunctionQ[Tan[x] + 1/(Csc[x] - 1), {Sin[x], Cos[x]}]. It does not work on all expressions equivalent to a rational function though; for instance, Internal`RationalFunctionQ[Sin[2 ArcTan[x]], x]. $\endgroup$
    – Michael E2
    Commented Oct 15, 2019 at 20:47
  • $\begingroup$ Is GroupTheory`Tools`ConsecutiveReplace of no use? (Does "Consecutive" mean "Repeated"?) $\endgroup$
    – user688486
    Commented Nov 8, 2023 at 7:43
45
$\begingroup$

Internal`PartitionRagged

This one has a usage statement!

Internal`PartitionRagged[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 *)
Internal`PartitionRagged[Range[14], {3, 5, 2, 3}]
Internal`PartitionRagged[Range[14], {3, 5, 2, 3}]

Internal`S1, Internal`S2, Internal`P2

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],
    Internal`S1[x] + Internal`S2[x] + Internal`P2[x] + PrimePi[x^(1/3)] - 1
  }
]
{50847534, 50847534}

Internal`Square

??Internal`Square
(* Attributes[Internal`Square] = {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 = Internal`Square[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 *)
Internal`Square @ Internal`Square @ lis; // RepeatedTiming
(* 0.15 seconds *)
$\endgroup$
9
  • 1
    $\begingroup$ +1, It is very convenient to utilize Internal`PartitionRagged[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}}*) $\endgroup$
    – xyz
    Commented May 11, 2015 at 7:49
  • 1
    $\begingroup$ @ShutaoTang regarding PartitionRagged I like my own implementation better as it does things PartitionRagged does not. I hope you will give it a look. $\endgroup$
    – Mr.Wizard
    Commented May 14, 2015 at 15:43
  • $\begingroup$ @Mr.Wizard, I have known your neat implementation last year. $\endgroup$
    – xyz
    Commented May 15, 2015 at 3:25
  • $\begingroup$ @ShutaoTang Okay. :-) $\endgroup$
    – Mr.Wizard
    Commented May 15, 2015 at 3:28
  • $\begingroup$ 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:) $\endgroup$
    – xyz
    Commented May 16, 2015 at 0:53
44
$\begingroup$

Internal`InheritedBlock

Internal`Localizedblock

Internal`Bag

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

Internal`RationalNoReduce

Internal`Periodicals

Internal`StringToDouble

Internal`Bag, Internal`StuffBag, Internal`BagPart

Compile`GetElement

Internal`FromPiecewise

Internal`DeleteTrailingZeros

$\endgroup$
3
  • 1
    $\begingroup$ For Internal`Bag, 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. $\endgroup$
    – rm -rf
    Commented May 11, 2015 at 3:16
  • $\begingroup$ @TheToad, OK, I got it. $\endgroup$
    – xyz
    Commented May 11, 2015 at 5:23
  • $\begingroup$ There's also Internal`ToPiecewise, a sort inverse to FromPiecewise: Piecewise[{{1, x < 0}, {2, x < 3}}, 5] // Internal`FromPiecewise // Apply@Internal`ToPiecewise $\endgroup$
    – Michael E2
    Commented Jun 27 at 14:43
31
+100
$\begingroup$

Compile`InnerDo

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 Compile`InnerDo!

f1 = Compile[{{x}},
      Module[{a}, a = x; Compile`InnerDo[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:

enter image description here


Compile`Mod1

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 Compile`Mod1.

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

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

Compile`DLLFunctionLoad / Compile`DLLLoad

These seem to perform the same functions as LibraryFunctionLoad:

fun1 = LibraryFunctionLoad["demo", "demo_I_I", {Integer}, Integer]
fun2 = Compile`DLLFunctionLoad["demo", "demo_I_I", {Integer}, Integer]
fun1[10] == fun2[10]
(* True *)
$\endgroup$
30
$\begingroup$

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?

For Fold and FoldList the two-parameter syntax existed but was undocumented in versions 9.0 through 10.0.1: Shorter syntax for Fold and FoldList?

$\endgroup$
26
$\begingroup$

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>
$\endgroup$
1
  • 1
    $\begingroup$ 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. $\endgroup$
    – jmlopez
    Commented May 27, 2012 at 7:00
25
$\begingroup$

System`Private`*Entry* functions

Since version 10.0 System`Private`SetNoEntry and System`Private`EntryQ functions are available.

System`Private`SetNoEntry

Changes internal representation of given expression so that it is considered atomic, it returns "atomized" version of expression. This change affects all references to given expression, but not new expressions even if they are the same.

ClearAll[f, x, y, tmp];
tmp = tmp2 = f[x, y];
System`Private`SetNoEntry@tmp (* f[x, y] *)

Ordinary f[x, y] is not atomic, but all references to f[x, y] that was passed to SetNoEntry are considered atomic:

f[x, y] // AtomQ (* False *)
tmp // AtomQ (* True *)
tmp2 // AtomQ (* True *)

Those expressions are still considered same:

tmp === f[x, y] (* True *)

Head of expression (part 0) is accessible but not other parts:

tmp // Head
(* f *)
tmp[[0]]
(* f *)
tmp[[2]]
(* Part::partd: Part specification f[x,y][[2]] is longer than depth of object. *)
(* f[x, y][[2]] *)

Part accessing/modifying functions treat it as other atomic objects, so they either complain:

Append[tmp, z]
(* Append::normal: Nonatomic expression expected at position 1 in Append[f[x,y],z]. *)
(* Append[f[x, y], z] *)

or ignore our expression:

ReplacePart[tmp, 1 -> z]
(* f[x, y] *)

Pattern matching works as before and can still "go inside" this expression:

Replace[tmp, head_[arg1_, arg2_] :> {head, arg1, arg2}]
(* {f, x, y} *)

I've learned about this function from Leonid's answer to "Make my data-structure atomic" post.

System`Private`NoEntryQ

Tests whether given expression was set as "no entry" expression:

tmp = f[x, y];
tmp // System`Private`NoEntryQ (* False *)
System`Private`SetNoEntry@tmp;
tmp // System`Private`NoEntryQ (* True *)

Some built-in atomic data structures use this mechanism, e.g. SparseArrays evaluate to "no entry" atomic form:

SparseArray@{0, 1} // Unevaluated // System`Private`NoEntryQ (* False *)
SparseArray@{0, 1} // System`Private`NoEntryQ (* True *)

Since version 10.4 there are five additional "Entry-related" functions.

System`Private`EntryQ

Is the opposite of NoEntryQ:

tmp = f[x, y];
tmp // System`Private`EntryQ (* True *)
System`Private`SetNoEntry@tmp;
tmp // System`Private`EntryQ (* False *)

System`Private`HoldSetNoEntry

System`Private`HoldNoEntryQ

System`Private`HoldEntryQ

Are variants of SetNoEntry, NoEntryQ and EntryQ with HoldAllComplete attribute.

System`Private`ConstructNoEntry

Creates new "no-entry" expression using first argument as head, and rest of arguments as arguments of created expression:

System`Private`ConstructNoEntry[f, x, y] (* f[x, y] *)
% // System`Private`NoEntryQ (* True *)
$\endgroup$
1
  • 1
    $\begingroup$ Interesting. Sadly there doesn't seem to be a SetEntry that un-atomize an expression… $\endgroup$
    – xzczd
    Commented Jun 27, 2022 at 11:48
23
$\begingroup$

Not sure if a new question should be started, anyway, here's some undocumented syntax (sorted alphabetically):

Collect

Collect accepts a 4th argument:

Undocumented fourth parameter of Collect; how long has it been there?

Compile

Indexed variable can be used as independent variable of Compiled function:

<< CompiledFunctionTools`
cf = Compile[a[1], Sin@a[1]];
cf // CompilePrint
(* cf is fully compiled *)

D

D[expr] evaluates to expr.

Derivative

Derivative[][u] evaluates to u.

ErrorListPlot

1

ErrorBar isn't necessary if there are only symmetric y error bars:

What's the simplest way to plot an ErrorListPlot with only y error bars?

2

PlusMinus(±) can be used in ErrorListPlot:

https://mathematica.stackexchange.com/a/77553/1871

Exit/Quit/Return

Exit and Quit can work without brackets, Return can work without brackets when it's inside a dialog:

Lists for built-in functions that can work without brackets

FindRoot

it owns a simple syntax for function relationship that returns number or list of number:

Mapping multiple functions

https://mathematica.stackexchange.com/a/163268/1871

FindRoot[x \[Function] Sin[x] + Exp[x], {0}]
(* {-0.588533} *)
FindRoot[{x, y} \[Function] {Exp[x - 2] - y, y^2 - x}, {{1}, {1}}]
(* {0.019026, 0.137935} *)

ListPlot/ListLinePlot

They can handle InterpolatingFunction directly since v9:

Easy way to plot ODE solutions from NDSolve?

NDSolve/NDSolveValue/ParametricNDSolve

1

The 1st argument can be a nested list, no Flatten or Join is needed:

eq = y''[x] + Sin[y[x]] y[x] == 0;
bc = {y[0] == 1, y'[0] == 0};

NDSolve[{eq, bc}, y, {x, 0, 30}]

2

The 2nd argument can almost be anything:

NDSolveValue[{y'[x] == y@x Cos[x + y@x], y@0 == 1}, y[x] + y'[x] + Sin[x], {x, 0, 30}]

3

"Coordinates" sub-option of TensorProductGrid can be set in the range:

grid = {0, 1, 1.1, 3.2, 2.1, 4.6, 5};

seq = Sequence[{D[u[t, x], t] == D[u[t, x], x, x], u[0, x] == 0, u[t, 0] == Sin[t], 
    u[t, 5] == 0}, u, {t, 0, 10}];

NDSolve[seq, Flatten@{x, grid}] == 
 NDSolve[seq, {x, 0, 5}, 
  Method -> {"MethodOfLines", 
    "SpatialDiscretization" -> {"TensorProductGrid", "Coordinates" -> grid}}]
(* True *)

NSolve

The 1st argument doesn't need to be equation(s):

polys = {x^2 + y^2 - 1, 2 x + 3 y - 4};
NSolve[polys, {x, y}]

Part

a[[]], or equivalently Part[a], evaluates to a.

PlotRange

PlotRange can be a function, which returns the plot range of Graphics/Graphics3D:

Plot[Sin[x], {x, 0, 6 Pi}]
% // Head
(* Graphics *)
%% // PlotRange
(* {{0., 18.8496}, {-0.999999, 0.999999}} *)
Plot3D[x^2 + y^2, {x, -2, 2}, {y, -2, 2}] // PlotRange
% // Head
(* Graphics3D *)
%% // PlotRange
(* {{-2., 2.}, {-2., 2.}, {0., 8.}} *)

RandomReal/RandomInteger

First argument of them can be a distribution. See:

RandomReal in combination with NormalDistribution

Reduce/Solve

The 3rd argument can be a list of variables to be eliminated instead of a domain.

For example, Solve[{x == y + 1, y == 2}, {x}, {y}] evaluates to {{x -> 3}}, whereas Solve[{x == y + 1, y == 2}, {x}] evaluates to {}.

This syntax is almost hidden since v8. (Mentioned in this answer.)

ReplacePart

Undocumented since v6:

ReplacePart[{a, b, c, d, e}, xxx, 3]
(* {a, b, xxx, d, e} *)
ReplacePart[{a, b, c, d, e}, xx, {{2}, {5}}]
(* {a, xx, c, d, xx} *)

You need the syntax if you want to compile them because Rule isn't compilable:

error when defining a compiled function with ReplacePart

SumConvergence

The option value of Method can be a user-defined function:

https://mathematica.stackexchange.com/a/163329/1871

Table

Table[a] evaluates to a.

$\endgroup$
7
  • 1
    $\begingroup$ Pure functions as arguments to FindRoot are shown in this earlier Q&A: mathematica.stackexchange.com/q/25745/4999 $\endgroup$
    – Michael E2
    Commented Jan 8, 2018 at 17:00
  • 1
    $\begingroup$ Unprotect[PlotRange]; ClearAttributes[PlotRange, ReadProtected]; ??PlotRange then we can see the definition of PlotRange $\endgroup$ Commented Jul 20, 2023 at 6:57
  • $\begingroup$ @xzczd With regard to Function[Null, ...], the three argument form is actually documented. It's specifically the use of Null in the two argument form that is undocumented. To me, saying that Null is a valid first argument at all strongly suggests that Null in the two argument form is valid, so I think it's kind of a stretch to say that this form is truly undocumented. $\endgroup$
    – lericr
    Commented Aug 10, 2023 at 13:14
  • $\begingroup$ @lericr I've edited the statement a bit. Feel free to directly edit it, it's a community wiki :) . $\endgroup$
    – xzczd
    Commented Aug 10, 2023 at 13:40
  • $\begingroup$ @domen …May I ask why you've rollbacked to Revision 15? $\endgroup$
    – xzczd
    Commented Aug 10, 2023 at 16:05
22
$\begingroup$

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

enter image description here

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.

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$
    – user21
    Commented Oct 15, 2015 at 11:32
  • $\begingroup$ @user21 I think now with new V10 functional TetGenLink is no longer relevant. $\endgroup$
    – ybeltukov
    Commented Oct 15, 2015 at 18:05
21
$\begingroup$

Undocumented option PlotPoints->{n,{p}} (see Specific initial sample points for 3D plots for discussion).

with 2(!) parameters n (number of points or Automatic) and p (list of critical points)

example

f[x_?NumericQ] := Piecewise[{{1, x == 1}, {0, True}}];
Plot[f[x], {x, 0, 1.1}, PlotPoints -> {Automatic, { 1}}]

enter image description here

$\endgroup$
19
$\begingroup$

Simplify`PWToUnitStep:

f[z_] := Piecewise[{{0, 0 < z < 30}, {1, 30 < z < 60}, {0, 60 < z < 120}, {-1, 120 < z < 150}}]

Simplify`PWToUnitStep@f[z]

-(1 - UnitStep[120 - z]) (1 - UnitStep[-150 + z]) + (1 - UnitStep[30 - z]) (1 - UnitStep[-60 + z])

$\endgroup$
2
  • 2
    $\begingroup$ And it has an inverse too! Let s = Simplify`PWToUnitStep @ f[z] then you can get back to the Piecewise with FullSimplify[s]. $\endgroup$
    – bill s
    Commented Dec 14, 2016 at 20:21
  • 3
    $\begingroup$ @bill, or use PiecewiseExpand[]. $\endgroup$ Commented Dec 15, 2016 at 1:53
12
$\begingroup$

LabeledSlider is a version of Slider first mentioned by @ybeltukov in Can Manipulate controls have the option Appearance -> "Labeled" by default?.

If you find yourself expanding the sliders in manipulate in order to see the value, just use this form in order to see the value without having to expand the slider:

Manipulate[x, {x, 1, 10, LabeledSlider}]

Mathematica graphics

$\endgroup$
11
$\begingroup$

Internal`WithLocalSettings

This function (ref#1, ref#2, ref#3) can be used to ensure that some clean-up code will always be executed, even if an abort or other non-local exit occurs within some protected code. To illustrate:

Internal`WithLocalSettings[
  Print["opening a file"]
, Print["doing something with the file"]
; Abort[]
; Print["never gets here"]
, Print["closing the file"]
]

(* During evaluation of In[1]:= opening a file
   During evaluation of In[1]:= doing something with the file
   During evaluation of In[1]:= closing the file
   Out[1]= $Aborted
*)

Earlier versions of this function did not handle Catch/Throw properly, but this has been corrected and the function now seems to the most reliable way to protect against the unwinding of the evaluation stack.

Please note that since WL 12.2, WithCleanup is available. It has similar functionality and is documented although currently tagged as "Experimental".

CheckAll

In a similar vein, the CheckAll function (ref) ensures that a function is called whenever a body of code was exited, whether normally or abnormally. Unlike Internal`WithLocalSettings, the handler code completely intercepts the exit. To illustrate:

CheckAll["normal exit", myHandlerFunction]
(* myHandlerFunction["normal exit", Hold[]] *)

CheckAll[Throw[3], myHandlerFunction]
(* myHandlerFunction[$Aborted, Hold[Throw[3]]] *)

The second example shows how the handler function is informed about the exact nature of the exit. It is up to that function to decide whether to re-evaluate the expression that triggered the exit, thus continuing to pass control up the stack.

$\endgroup$
10
$\begingroup$

Internal`GetIteratorLength

Internal`GetIteratorLength[it] returns the length (= number of iterations to be performed) of a standard iterator it such as is used in Table.

Internal`GetIteratorLength[{x, 3, 10}]
(*  8  *)

Internal`GetIteratorLength[{x, 3, 10, 0.27}]
(*  26  *)

Internal`GetIteratorLength[{x, {3, 4, 7}}]
(*  3  *)

Internal`GetIteratorLength[{4}]
(*  4  *)
$\endgroup$
5
  • $\begingroup$ Could you elaborate more? I don't see the connection between the inputs and outputs. $\endgroup$
    – Greg Hurst
    Commented Jan 7, 2022 at 16:20
  • $\begingroup$ @ChipHurst The number of iterations to be performed is returned (= length of Table if used in Table[]). Does that answer your question? $\endgroup$
    – Michael E2
    Commented Jan 7, 2022 at 17:29
  • $\begingroup$ Aha I finally see it now. Thanks! $\endgroup$
    – Greg Hurst
    Commented Jan 7, 2022 at 17:42
  • $\begingroup$ Length[Table[(* anything except Nothing *), {x, 3, 10}]] is 8 for example. $\endgroup$
    – Greg Hurst
    Commented Jan 7, 2022 at 17:43
  • 1
    $\begingroup$ @ChipHurst Right, a fencepost problem. And if you use Nothing, Table will actually create a list of length 8, but afterwards Nothing causes List to contract. E.g. Table[Nothing, {x, 3, 10}] // Trace. $\endgroup$
    – Michael E2
    Commented Jan 7, 2022 at 18:58
8
$\begingroup$

Region`Mesh`MeshNearestCellIndex

It basically does what it says. See here for one of its applications.

Random`Private`MapThreadMin and Random`Private`MapThreadMax

https://mathematica.stackexchange.com/a/3131

https://mathematica.stackexchange.com/a/164614

Random`Private`PositionsOf

https://mathematica.stackexchange.com/a/166540

https://mathematica.stackexchange.com/a/164614

$\endgroup$
8
$\begingroup$

ValueTrack`CollectTrackEvent

This helps with figuring out what caused a Dynamic to update:

a = 1;
f[x_] := a x^2
ValueTrack`CollectTrackEvent[True]

Dynamic[{ValueTrack`CollectTrackEvent[], f[2]}]
(* {{Hold[a, HoldComplete[a, 1, 2, OwnValues], {909089}]}, 8} *)

a = 2;

ValueTrack`CollectTrackEvent[False]

The functionality is enabled using ValueTrack`CollectTrackEvent[True] and disabled again using ValueTrack`CollectTrackEvent[False]. While it is enabled, ValueTrack`CollectTrackEvent[] will return a list of value changes that were tracked by some Dynamic (while disabled, it will return Null). Some notes:

  • ValueTrack`CollectTrackEvent[] will return the list of all value changes since the last time it was called. It does not matter which Dynamic was updated, you simply get one long list.

  • The format seems to be

    {{sym_, update_, {boxIDs__}}...}
    

    where sym is the symbol causing the update, update is a description of the update (which part was updated, old and new value, type of value). The format seems to be the same as for the "ValueChange" handler. Finally, boxIDs is a list of IDs of the DynamicBox expressions updated by that value change.

Credit goes to Kyle Martin (WRI) for showing this to me. - Thanks again!

There's also ValueTrack`GetTrackingState and ValueTrack`SetTrackingState, but I don't know what they do

$\endgroup$
6
$\begingroup$

It is mentioned in a comment, but unless I missed something only there, and I think it deserves small entry.

   ?? Internal`AbsSquare

internal

With

cmplx = RandomVariate[NormalDistribution[], {10^8, 2}] . {1, I};
ntrnl = Internal`AbsSquare[cmplx]; // RepeatedTiming // First
fnctn = Abs[cmplx]^2; // RepeatedTiming // First

out1

out2

LinearAlgebra`Private`ZeroArrayQ[Chop[ntrnl - fnctn]]

true

$\endgroup$
4
$\begingroup$

DispatchQ

A Curiosity: What is DispatchQ?

DispatchQ returns True if applied to a Dispatch object, so it is useful for identifying Dispatch objects.

Mathematica autofill shows the function DispatchQ. It does not appear in the Mathematica Documentation Center. Except for the question linked above, a search for DispatchQ on the Mathematica Stack Exchange comes up with nothing, and a Google search for "DispatchQ" reveals nothing relating to Mathematica.

Compile`SetIterate

What Does Compile`SetIterate Do?

Compile`SetIterate sets an iterator.

The list of compilable functions (given by Compile`CompilerFunctions[] // Sort) shows Compile`SetIterate. It does not appear in the Mathematica Documentation Center. Moreover, except for the question linked above and for references to merely the list of compilable functions, a search for Compile`SetIterate on the Mathematica Stack Exchange comes up with nothing and a Google search for Compile`SetIterate reveals nothing I can see relating to Mathematica.

$\endgroup$
4
$\begingroup$
?SpecialFunctions`*

img

Special mention for the harmonic polylogarithm and multiple polylogarithm. They seem to be in accord to the definitions of hep-ph/9905237 and hep-ph/0410259 respectively.

SpecialFunctions`HarmonicPolyLog[{1, -2, 3, 0}, 0.7]
SpecialFunctions`MultiplePolyLog[{1, -2, 3, 0}, {0.7, 1, 1, 1}]

-0.25112

-0.25112

Some caution is needed, though. For example in performing Series expansion we have to use FunctionExpand or FullSimplify in the even cases, but not in the odd.

Series[PolyLog[2, 1 - x], {x, 0, 1}] // Normal
Series[SpecialFunctions`HarmonicPolyLog[{2}, 1 - x] // 
   FunctionExpand, {x, 0, 1}] // Normal
Series[SpecialFunctions`HarmonicPolyLog[{2}, 1 - x] // 
   FullSimplify[#, Assumptions -> 0 <= x <= 1] &, {x, 0, 1}] // Normal

π^2/6 + x (-1 + Log[x])

but

Series[SpecialFunctions`HarmonicPolyLog[{2}, 1 - x], {x, 0, 
   2}] // Normal
Series[SpecialFunctions`HarmonicPolyLog[{2}, 1 - x], {x, 0, 
   2}] // Normal

π^2/6 + (-2 I π x - I π x^2 - 2/3 I π x^3) Floor[-( Arg[x]/(2 π))] - I x (-I + 2 π + I Log[x]) - 1/4 I x^2 (-I + 4 π + 2 I Log[x])

Note that // FullSimplify[#, Assumptions -> 0 <= x <= 1] & after the expansion leads to a difference of

-I π x (2 + x)

I found this here

$\endgroup$
2
$\begingroup$
ComplexAnalysis`BranchCuts[InverseFunction[Cos][z], z]

(Re[z]<-1&&Im[z]==0)||(1<Re[z]&&Im[z]==0)


To help with this problem, I made a simple extension. Now it's super easy to discover them.

https://github.com/asukaminato0721/mmacompletion

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.