Questions about the use of built-in Mathematica functions, including pure functions.

learn more… | top users | synonyms

125
votes
7answers
5k views

What are the use cases for different scoping constructs?

Mathematica includes three functions that I know of which can be used to effectively (if not actually) define a variable and give it a value within a local scope: ...
98
votes
8answers
8k views

List of compilable functions

Is there somewhere a list on the functions that Compile can compile, or the cases in which a particular function can be compiled that I haven't found? I'd be glad ...
63
votes
2answers
2k views

Flatten command: matrix as second argument

One thing I could never wrap my head around is how Flatten works when provided with a matrix as the second argument, and the Mathematica help isn't particularly ...
62
votes
3answers
2k views

Automatically generating a dependency graph of an arbitrary Mathematica function?

Has anyone written a function to pull the function dependencies of a function? That is, it would be nice to have a function that returns a list of function dependencies as a set of rules, terminating ...
55
votes
4answers
3k views

Using a PatternTest versus a Condition for pattern matching

My last question to the site resulted in several answers that involve using pattern matching in Mathematica, a feature I wasn't very familiar with at the time. I am currently reading Mathematica ...
55
votes
4answers
2k views
52
votes
2answers
6k views

What is the difference between Reduce and Solve?

Solve and Reduce both can be used for solving equations. Just by working with them, I know there are some differences between ...
42
votes
2answers
4k views

What is so special about Prime?

When we try to evaluate Prime on big numbers (e.g. 10^13) we encounter the following issue : ...
35
votes
2answers
923 views

Why is the new PositionIndex horribly slow?

This issue has largely been mitigated in 10.0.1. New timings for the final test below are: ...
32
votes
5answers
1k views

Why is there no PositionFunction in Mathematica?

Too often I have seen the programs of inexperienced users greatly slowed by using Position in an iterative fashion, when far faster would have been to compute a ...
32
votes
2answers
1k views

Variable naming changes everything

Bug fixed in 10.0.0 I am having a rather unusual problem I do not understand with Mathematica where renaming one of the variables of my function causes the function to stop "working". Here is the ...
30
votes
4answers
526 views

How can the behavior of InterpolationOrder->0 be controlled?

In ListPlot and Interpolation, the option InterpolationOrder->0 uses two different ...
29
votes
3answers
716 views

Parentheses in pure functions: # & vs. ( # &)

I've been using Mathematica for years, and over time I have developed the habit of using: Select[data, (# == 1 &)] instead of ...
28
votes
2answers
849 views

Is there a name for #1@#2&?

Why does the pure function # @ #2 & have no name? I'm asking because sometimes I find inelegant to write expressions like ...
28
votes
2answers
875 views

Strange ::usage behavior in v9

Bug fixed in 9.0.1 Something has gone wrong with usage in Mathematica 9. Would someone tell me how to fix it? I define a function ...
27
votes
5answers
2k views

Are there “All” and “Any” functions in Mathematica?

In Python, there is a function all which returns true if all of its arguments are true, and any which returns true if at least ...
26
votes
2answers
2k views

Implementing continuous phase/Arg function

In MATLAB there's a function called phase that is just like our Listable friend Arg, but ...
25
votes
1answer
281 views

What does Internal`InheritedBlock do?

What does the function Internal`InheritedBlock do? How is it different from the regular Block?
25
votes
2answers
819 views

Block attributes of Equal

I answered “Equating matrices (or higher order tensors) element-wise” with: ...
24
votes
4answers
622 views

Enforcing correct variable bindings and avoiding renamings for conflicting variables in nested scoping constructs

Using global variables the following turns an "expression" into a Function: expr = 2 x; Function[x, Evaluate[expr]] Of course ...
23
votes
3answers
1k views

How to load a package without naming conflicts?

This question applies to any package, but I encountered this problem while working with graphs. There are symbols in the Combinatorica package (such as ...
23
votes
3answers
1k views

Visualisation of a recursive function

Is there a way to nicely visualize recursive functions? (diagrams/plots) More specifically I'm looking for a way to make contrast (visually) between e.g. the cosine function which if continuously ...
23
votes
2answers
19k views

How to express trigonometric equation in terms of of given trigonometric function?

How can I express a trigonometric equation / identity in terms of a given trigonometric function? using following trigonometric identities ...
23
votes
2answers
503 views

Why is Query so much slower than Part?

Time for another of these(1),(2) as yet another new-in-10 function appears to have poor performance compared to older alternatives. This time: Query appears to be ...
22
votes
3answers
833 views

DeleteDuplicatesBy is not performing as I'd hoped. Am I missing something?

Déjà vu: a new-in-v10 function should provide a better solution to an old problem, but my enthusiasm is curbed when I run timings. This time the function is ...
22
votes
1answer
457 views

Why does list assignment with a packed array result in unpacked values?

Bug introduced in 5.2 or earlier and fixed in 10.1.0 This is another question on the design choices in Mathematica. I understand that without direct reply from the developers it may not be ...
21
votes
3answers
486 views

Is there a bug in Pick?

I wanted to use the Pick function with a condition. But there seems to be an issue here. Take a look at this: ...
21
votes
1answer
511 views

Shorter syntax for Fold and FoldList?

I find it tedious to write out the following: a = {1, 2, 3, 4}; Fold[f, First @ a, Rest @ a] f[f[f[1, 2], 3], 4] It ...
20
votes
1answer
387 views

What is PointForm?

I stumbled across a function called PointForm but the only documentation I can find is the pop-up line offered by autocomplete, which contains the same information ...
19
votes
8answers
692 views

Applying And to lists of Booleans

I'd like to take {True,True,False} and {True,False,False} and apply And to get ...
19
votes
5answers
1k views

Moving maximum function?

How can I construct a moving maximum function? For example, if I have a list of 12 values: { 5, 6, 9, 3, 2, 6, 7, 8, 1, 1, 4, 7 } and I want to maximize over 3 ...
19
votes
4answers
798 views

Accessing list elements by name

First, a bit of a long introduction to my problem: I only have a few weeks of Mathematica experience. I am creating a mathematica application that calculates some material properties of steel based ...
19
votes
1answer
217 views

How to get Cases to wrap results in an arbitrary head?

A number of functions provide for results to be wrapped in an arbitrary head. This is very important in cases where the results should not be evaluated. Take ...
19
votes
2answers
233 views
19
votes
1answer
303 views

What does “EquationalLogic`FindCounterexample[]” do?

I found the undocumented EquationalLogic`FindCounterexample[] by browsing the lists of available symbols, but I have no clue about its purpose. The name is ...
18
votes
3answers
751 views

Can someone explain this snippet: (#[#] &)[#[#][#] &]

A friend showed me this snippet of code today: (#[#] &)[#[#][#] &] I can sort of see that we're constructing an anonymous function that takes a function ...
18
votes
3answers
3k views

Plotting piecewise function with distinct colors in each section

I have a piecewise function that I would like to plot but I was wondering if it is possible that each part of the function that is plotted when its corresponding condition is true be plotted with a ...
18
votes
2answers
1k views

Scan vs. Map vs. Apply

I cannot understand the difference between Apply, Scan, and Map. I have tried to play with ...
18
votes
2answers
4k views

Is there an equivalent to MATLAB's linspace? [duplicate]

Does Mathematica have an equivalent to Matlab's linspace? I want to make a list with "start", "stop" and "number of points". What is the neatest way of doing this?
18
votes
1answer
376 views

What are SparseArray Properties? How and when should they be used?

A strange undocumented form of SparseArray is increasingly used in answers on this site: ...
18
votes
1answer
245 views

Default behaviour of Hash[expr] and hashing in different versions of Mathematica

In different versions of Mathematica, Wolfram silently changed the behaviour of Hash when the algorithm is not specified explicitly ...
17
votes
5answers
7k views

How to find the domain and range of a function with Mathematica?

I'm studying calculus and in some exercises I am asked to find the domain and range of a function. Does Mathematica have already a built-in function for this? I can imagine some ways of doing so, ...
17
votes
2answers
467 views

Using several anonymous functions mixed together

This works: list // BarChart[#[[2]], ChartLabels -> DateString @@@ #[[1]], ChartStyle -> "Pastel"] & This doesn't: ...
17
votes
2answers
333 views

Why doesn't a Composition[] hold its arguments and what can be done about it?

Now that Composition (also RightComposition) has shorthand syntax I am more inclined to use it, however what I feel should be ...
17
votes
2answers
2k views

Sum or Product with Exclusions

Is there a built-in feature for handling things like: $$\sum_{\substack{i=0\\i\ne j}}^n\frac{a-a_i}{a_i-a_j}$$ and $$\prod_{\substack{i=0\\i\ne j}}^n\frac{a-a_i}{a_i-a_j}$$ or should I work out some ...
17
votes
0answers
258 views

Performance problems in new Sequence functions

The new-in-10.1 Sequence* family of functions should provide newly optimized methods for handling sequence problems. Happily in some cases they do! For example ...
16
votes
4answers
8k views

Finding Limits in several variables

Is there a way to find a limit of a multivariable function, like $$\lim_{(x,y)\to (0,0)} f(x,y)$$ with Mathematica? When $f$ is continuous, we can use $$\lim_{(x,y)\to (0,0)} ...
16
votes
6answers
2k views

Max of a table/list with indeterminate values

Suppose I have a Table: tab = {1., 2., 3., Indeterminate} When I type Max[tab] I get ...
16
votes
2answers
246 views

Where is the old option TraceInternal->True?

Already at least in version 2 (I think), the function Solve calls the function Roots. At that time, I had a rather dirty trick, that still works, to verify this: ...
16
votes
3answers
334 views

How to keep some of the results of the NestList

I'm using some iterative arithmetics to calculate wave propagation with the help of NestList. I have to use a small step size for iteration to guarantee the accuracy, which lead to too much data (e.g, ...