# Tag Info

42

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

39

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

37

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

25

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

23

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

19

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

19

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

18

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

17

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

16

Major update at the bottom. First part may be obsolescent. 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]; ...

16

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

15

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

15

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

14

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

14

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

14

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

12

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 === "\"") :> ...

12

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

11

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

11

I've always considered the "suitable for symbolic manipuation" line to be a bit of truth wrapped in marketing speak and not meant to mean anything mathematically precise. The documentation center guides and tutorials are good examples of hyperbole in technical documentation (see for instance, the opening lines in Mathematical Typesetting). Coming to the ...

11

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

10

I can only direct you to Some Notes on Internal Implementation: Differentiation and Integration Differentiation uses caching to avoid recomputing partial results. For indefinite integrals, an extended version of the Risch algorithm is used whenever both the integrand and integral can be expressed in terms of elementary functions, ...

10

I like to use properties like those in SparseArray and I find subvalues very useful for defining and accessing them. This is best used with a dummy head. The following is some code pulled out from one of my packages and modified. I've defined func here to be a minimal example of what your actual function might look like. Clear[func, myHead] func[str_] := ...

10

Yes, they are considered pseudo-listable. Often they are implemented with something similar to f[x_, a_List] := f[x, #]& /@ a

9

I think this works correctly: ClearAll[min, doMin]; min[x_] := doMin[x] // Reap // Last // Flatten // Reverse // FromDigits; doMin[x_] := With[ {d = Range[9]^2}, If[ x > 81, Sow@ConstantArray[9, IntegerPart[x/81]]; doMin[Mod[x, 81]], Sow@Sqrt@Select[d, # >= x &, 1]]]; min[100] // AbsoluteTiming {0.001005, 59} ...

8

(nextPrime[#1] = #2) & @@@ {{-3, 2}, {-2, 2}, {-1, 2}, {0, 2}, {1, 2}, {2, 3}}; nextPrime[n_Integer?EvenQ] := nextPrime[n - 1]; nextPrime[n_Integer] /; PrimeQ[n + 2] := n + 2; nextPrime[n_Integer] := nextPrime[n + 2] nextPrime[n_ /; n \[Element] Reals] := nextPrime[Floor@n]

8

Since there are two parts to your question. I will address the one directly dealing with Binomial. For the purposes of discrete mathematics, the binomial is defined through its generating function: $$(1+x)^{\alpha} = \sum_{m=0}^\infty \binom{\alpha}{m} x^m$$ It makes evaluations of sums using generating functions much easier if the sum were to run ...

8

It uses a resultant computation. The idea is this. We are given algebraic numbers $x$ and $y$, where $p(x)=0$ and $q(y)=0$ are the minimal polynomials. We want to find the defining polynomial for $z=x+y$. We use $p(x)=p(z-y)$ and $q(y)$, and eliminate $y$ using the classical method of resultants. Here is how it would go for your example. p[x_] := #^5 - # - ...

8

It's quite easy to show that Fold doesn't use the memory that would be required to store intermediate results. \$HistoryLength = 0; big = Range[1*^7]; ByteCount[big] MaxMemoryUsed[] //N 40000124 5.49458*10^7 Fold[# + 1 &, big, Range@100]; MaxMemoryUsed[] //N 1.34909*10^8 FoldList by comparison (with a much shorter Range): FoldList[# + ...

8

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

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