# Tag Info

## Hot answers tagged implementation-details

59

Link to the code on GitHub I have been using this. It's mostly Leonid's code from the stackoverflow question you linked to, but it uses Definition instead of DownValues. Symbol names are printed without any context, but the full symbol name is put into a Tooltip so you can always find out what context a symbol is in. Update FullDefinition[symbol] claims ...

47

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

46

Interpolation function methods Interpolation supports two methods: Hermite interpolation (default, or Method->"Hermite") B-spline interpolation (Method->"Spline") Hermite method I really can't find any good reference to Hermite method within Mathematica's documentation. Instead, I recommend you to take a look at this Wikipedia article. The ...

46

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

34

It is interesting to compare the Plot algorithms of Mathematica 5.2 and Mathematica 6+. Based on acl's code: In Mathematica 5.2 we get: Plot[Sow[x]; Sin[x], {x, 0, 10}, DisplayFunction -> (Null &)] // Reap // Last // Last // ListPlot In Mathematica 7.0.1: Plot[Sow[x]; Sin[x], {x, 0, 10}] // Reap // Last // Last // ListPlot One can see ...

31

I think you can actually see (most of) what Mathematica is doing by using Trace[..., TraceInternal -> True]. For example, Select[Flatten[ Trace[NDSolve[y'[x] == x && y[0] == 0, y, {x, 0, 6}], TraceInternal -> True]], ! FreeQ[#, Method | NDSolveMethodData] &] shows the DE was evaluated using NDSolveLSODA and Newton's method. (I ...

29

I've completely overhauled my answer. I believe this now answers the questions posed (why mma thinks the violet line is the derivative of IntegerPart'[x]). Let's first look at ND, simply because its internals are easier to access and we may obtain some insight. Try: Needs["NumericalCalculus"] nd[x_, opts___] := ND[IntegerPart[u], u, x, opts] Manipulate[ ...

29

I can add to Mr.Wizards' answer that when InputForm is wrapped by any head like List (// InputForm // List) the output is much more readable because in this case it is represented in StandardForm instead of pure textual representation. StandardForm allows semantic selection by double-clicking, wraps the code by window width, highlights the brackets etc. From ...

26

What you observed seems to be an instance of the general behavior of the pattern-matcher when used with what I call "syntactic patterns" - patterns which only reflect the rigid structure of an expression, like e.g. _f. The speed-up with respect to the scanning is because the main evaluation loop is avoided - for FreeQ and MemberQ, the scannng is done all ...

25

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

25

Evaluation stops when there is no definition in place whose pattern matches the expression being evaluated. Conversely, evaluation will continue as long as there is a matching definition. Thus, if I have this definition: zot[x_] := zot[x] and I evaluate zot[1], the evaluation will never terminate even though the expression never changes. (Well, in ...

25

If the problem is that a symbolic argument is passed, you can avoid it thus: ClearAll[sin]; sin[x_?NumericQ] := Module[{}, Print[x]; Sin[x] ] which simply defines sin so that it only matches for numeric arguments. To see what it does, try sin[3.] and sin[x] and notice that the second evaluates to itself, as the definition above does not match. You ...

25

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

24

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"}] ...

20

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

19

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

19

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

18

Major update at the bottom. First part may be obsolete. A brute force approach: Define a function that provides a measure of the difference between the automatically adjusted image and an image with given contrast, brightness and gamma adjustments (for now, this only works for images that are made of a raster of color triplets): ClearAll[f]; f[c_?...

16

After some work and clarification from Leonid it becomes clear this is a case where SubValues is the exact solution. As this answer points out SubValues are patterns of the form food[d][f] := a; which is the correct form for accessing parts of an "data-like" object since the sub value has access to the containing expression parts. Now to build on a ...

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

16

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.

15

I would just use strings, for all their fragility: ClearAll[print]; print[sym_, {conts_String}] := With[{altptrn = Alternatives @@ Reverse[SortBy[{conts}, StringLength]]}, Print@StringReplace[ToString[InputForm@FullDefinition@sym], (x : (_ | "") ~~ altptrn ~~ y : (_ | "")) /; ! (x === "\"" && y === "\"") :> StringJoin[...

15

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] := ...

15

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

15

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

15

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

15

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

14

As Danny points out, you can find the list of licensed software using the "About Mathematica..." box, available under the Mathematica menu on my Macintosh and under the Help menu for a PC. As a dialog box, that Notebook is not searchable and a bit inconvenient to work with. If we open it with a text editor and examine the contents, we find that the cells ...

14

Update: The answer below is for Mathematica 9 or earlier. Since version 10, Finite Element Methods are included: https://reference.wolfram.com/language/FEMDocumentation/tutorial/FiniteElementOverview.html The methods NDSolve uses are documented in detail here: Advanced Numerical Differential Equation Solving in Mathematica This section says that ...

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