# Tag Info

83

In version 10.1, I've built something like Spelunk into GeneralUtilities. To use it, run Needs["GeneralUtilities"] PrintDefinitions[symbol]; This will pop up a window that shows all definitions of symbol. Here is a short summary of features: The window shows code cells containing all DownValues, OwnValues, UpValues, SubValues, and Attributes of a ...

58

From inspection, some investigation and ruebenko's help, what I've found so far is that InterpolatingFunction has the following underlying structure: InterpolatingFunction[ domain, (* or min/max of grid for each dimension *) List[ version, (* 3 in Mathematica 7, 4 from 8 onwards *) ...

36

I can add to Mr.Wizards' answer that when InputForm is wrapped by any head like List (// InputForm // List) or by SequenceForm the output is much more readable because in this case it is represented in StandardForm instead of pure textual representation (and still avoids the evaluation leaks of StandardForm!). StandardForm allows semantic selection by double-...

34

I can now offer a solution which leverages the full power of the code formatter, in its new, more robust form. Load the formatter: Import["https://raw.github.com/lshifr/CodeFormatter/master/CodeFormatter.m"] Some examples: CodeFormatterSpelunk[RunThrough] CodeFormatterSpelunk[PacletManagerCreatePaclet] In the last example, using MakeBoxes would ...

32

Using StringPatternPatternConvert we can find the regexp into which Mathematica converts the original string expression: StringPatternPatternConvert[Except["b"] .. ~~ "b"][[1]] "(?ms)(?:[^b])+b" The only difference as compared to the direct semantic translation is that the negated character class [^b] is enclosed by redundant non-capturing group (?: … )....

26

Since nobody has mentioned it yet... V8 introduced the undocumented flag Debug$ExamineCode. When it is set to true, the information functions will display the definitions of ReadProtected symbols: Debug$ExamineCode = True ??BinLists It is sometimes useful to suppress some of the internal package names to make it easier to scan the definitions. Here is ...

26

You can control how the Jacobian is calculated via the Jacobian option: Grid[Module[{s = 0, e = 0}, {#, FindRoot[ArcTan[1000 Cos[x]], {x, 1}, StepMonitor :> s++, EvaluationMonitor :> e++, Jacobian -> #, Method -> {"Newton"}], "Steps" -> s, "Evaluations" -> e }] & /@ {"Symbolic", "FiniteDifference"}] ...

26

In the Mathematica book (5th edition), Stephen Wolfram writes the following (sec. 1.12.4): The Software Engineering of Mathematica Mathematica is one of the more complex software systems ever constructed. Its source code is written in a combination of C and Mathematica, and for Version 5, the code for the kernel consists of about 1.5 million ...

26

Ok, I failed to find a duplicate so here is my comment: I don't know how Nothing is internally implemented but you can do something like this with UpValues: nothing /: {a___, nothing, b___} := {a, b}

24

If you want to have a description of the method used by a given ClassifierFunction you can do: ClassifierInformation[myclassifier, "MethodDescription"] Also, the methods used are quite classic, so you can easily find documentation on the web. If you want to know why Classify uses a given model there is a simple answer: Classify tries to find the model ...

24

This post contains several code blocks, you can copy them easily with the help of importCode. As mentioned in the comment above, the answer is hidden in this tutorial. Given the tutorial is a bit obscure, I'd like to retell the relevant part in an easier to understand way. For illustration, let's consider the following initial value problem (IVP):  2 y'...

23

It looks like the blend colours can be extracted with: DataPacletsColorDataDumpgetColorSchemeData["SunsetColors"][[5]] (* {RGBColor[0., 0., 0.], RGBColor[0.372793, 0.1358, 0.506503], RGBColor[0.788287, 0.259816, 0.270778], RGBColor[0.979377, 0.451467, 0.0511329], RGBColor[1., 0.682688, 0.129771], RGBColor[1., 0.882236, 0.491094], RGBColor[1., 1., ...

22

Prologue Some five years ago I have asked exactly this question to the Wolfram support people. Below I have taken their respective answers (one sentence for each Method) but have added a lot of further reading. Finally, in an Add-On I demonstrate my own implementation of Rosenfeld's 1971 variant of a 2D thinning algorithm, in order to let you compare a few ...

22

20

It is using the zlib format followed by Base64 coding, and then preceding the resulting string with "1:". So to use it externally, you can strip the "1:", do Base64 decoding, and feed the result of that to a zlib decoder. However what you get out may not be immediately useful. I compressed the result of D[x^x, {x,9}], like one of the examples in the ...

20

After a bit of poking around, it looks like the binary format is pretty simple to parse. Mark Adler's answer is correct - the strings Compress[] returns are just zlib-compressed data. If you have Python installed, this function should take a compressed string and return the actual serialized bytes: pyDecompress[c_] := StringDrop[StringDrop[StringTrim[...

20

The definition used (motivated by exterior calculus) is as follows: Given a rectangular array $a$ of depth $n$, with dimensions $\{d, ..., d\}$ (so there are $n$ $d$'s) and a list $x = \{x_1, ..., x_d\}$ of variables, then Curl[a, x] == (-1)^n (n+1) HodgeDual[Grad[a, x], d] If $a$ has depth $n$, then Grad[a, x] has depth $n+1$, and therefore HodgeDual[...

18

Reposting my answer from here (its relevant part about SparseArray) The anatomy of sparse arrays We start with a generally useful API for construction and deconstruction of SparseArray objects: ClearAll[spart, getIC, getJR, getSparseData, getDefaultElement, makeSparseArray]; HoldPattern[spart[SparseArray[s___], p_]] := {s}[[p]]; getIC[s_SparseArray] := ...

18

I know this isn't exactly what you want, but just a stupid idea: ClearAll[newf]; points = RandomReal[1, {1000000}];(*we have lots of points...*) nf = Nearest[points];(*... and the corresponding NearestFunction*) newf[oldf_, newpoints_List] := (Nearest[Union[oldf[#], Nearest[newpoints][#]], #] &); newf[nf, {3, 4, 5}][1.98] Edit Here is a version that ...

18

Using Accumulate for 20,000,000 size list. Time < 1 Hour Your timings seem way too high. On my PC, Accumulate on an 20.000.000-element packed array takes about 50ms. A For loop (not compiled!) needs about one minute for 20 million values. My PC may be fast, but not that fast. Make sure your array contains only machine-precision reals and is packed. ...

18

As indicated in the comments, machine-precision linear algebra operations in Mathematica use the Intel MKL library optimized implementation of BLAS/LAPACK. That is the case for all platforms where MKL is available: Windows, Linux and Mac OS X (there will be no obvious MKL library files present in the layout on OS X in versions 10.1 through 11.2 due to ...

18

The Experimental function FindFormula[] at the moment is using a combination of different methods: it combines non linear regression with Markov chain Monte Carlo methods (e.g. Metropolis–Hastings algorithm). In the future (possibly in V$10.3$) there will be an option allowing the user to choose which method to use.

18

Note: fix is broken since v11.3, a new question has been started aiming at upgrade it. Here's my approach for fixing the difference order. The key idea is modifying the NDSolveFiniteDifferenceDerivativeFunction inside NDSolveStateData directly: Clear[tosameorder, fix] tosameorder[state_NDSolveStateData, order_] := state /. a_NDSolve...

18

In my view, the Mathematica front end would have needed a complete rewrite a long time ago to be in a shape where it can compete with modern UI's. Looking at MATLAB, it's clear that you always find things that are even more out-of-date. Also, I don't want to say that you can't create beautiful content inside a notebook. However, especially the capabilities ...

17

Unfortunately the Method option is not documented in detail on the NonlinearModelFit documentation page. To summarize what we know so far (comments, documentation, etc.): NonlinearModelFit can either use numerical local optimization, or numerical global optimization. Local optimization is the same as used by FindMinimum and related functions. The ...

17

First answer Ok, Simon Woods killed the fun but I was already wiriting this: spec = List @@@ Table[ ColorData["SunsetColors", i] , {i, 0, 1, .001}] // Transpose; ListLinePlot[spec, ImageSize -> 900, PlotStyle -> {Red, Green, Blue}, BaseStyle -> Thick] Here we can see how colors are changing across 0-1. ...

17

So I think the docs are mostly clear, if hard to visualize. Here's my version of such a table: { "Numerics" -> { "Negative Integer" -> -1, "Zero" -> 0, "Positive Integer" -> 1, "Negative Float" -> N@-\[Pi], "Positive Float" -> N@\[Pi], "Symbolic Constant (Pi)" -> \[Pi], "...

17

According to the documentation of Image3D, "an interactive color function editor is available via the Image3D contextual (right-click) menu". (And yes! I only found it after reading your question!) And you can get the explicit function by clicking the "Copy Function" button. Blend[{ {0., RGBColor[0.05635, 0.081, 0.07687, 0.00343663]}, {0.1, ...

17

TLDR: If you run into performance issues related to symbol names, rename your symbols such that SystemPrivateGetContentCode returns different values for each symbol you use. Details: I guess that the irregular performance of FreeQ is related to the indexing method used by Mathematica to speed-up pattern matching and evaluation. By indexing I mean ...

16

This is an incomplete answer; I will continue it tomorrow. Work In Progress: errors may abound. Preamble hat-tip to Leonid For the variations with custom test or ordering functions we can snoop on applications of that function to deduce the algorithm that is used. In the case of the default methods we must rely on observed complexity and guesswork ...

Only top voted, non community-wiki answers of a minimum length are eligible