# Tagged Questions

Questions about Mathematica's functional programming style, including the use of pure functions (Function[], #, &) and functions such as Map, Apply, Nest, and Through.

826 views

### What's the cleanest functional-programming style way to perform this list operation?

I am looking for the correct method for accomplishing the unknown piece in the following code snippet: rolls = Tuples[Range[1, 4], {2}] ...
793 views

### Replace For-loop with functional code

I am very new to Mathematica. I have code written using for loops. I want to rewrite it using Map/Thread but I am not sure how ...
596 views

### How to find first list element that differs from average of N previous elements by more than a given amount?

Given a list of real numbers, I need to write a function that returns the value of the first element in the list that differs from the mean of the previous $N$ elements by greater than $P$ standard ...
420 views

### NestList with a list inside?

I'm new to Mathematica, and was looking for more efficient ways to implement the Do loop below. a, ...
272 views

### Overlapping pure functions

Let say I need and option for Plot: RegionFunction -> (-6 < #2 < 6 &) But I also want those ...
148 views

### DownValues for Built-in Functions

N.B. I have bitten the bullet, and I am going through Leonid Shifrin's "Mathematica Programming: An Advanced Introduction." (Which needs no introduction in this forum) One question I have: could one ...
484 views

### How to nest the output of FindRoot in a table of Derivative evaluations?

I am using ParametericNDSolveValue to numerically solve an ODE system, which I then use to find the definite integral of one of the variables in the solution for different values of a parameter. Here ...
252 views

### Using Through to evaluate complex expressions

Suppose we're given the expression f*g+h, where f,g,h are all pure functions. How can we evaluate this expression on some ...
300 views

### Why are we so sure about Map results?

I do abuse it often but when I have faced this feature first time I was really suprised: i = 0; (i++; # - i) & /@ Range[5] {0, 0, 0, 0, 0} What am I ...
142 views

### Composition with Apply

Composition is sometimes useful for clarity of a code. For the same purpose I try to Apply(@@) functions as often as it is ...
105 views

### Optimized subset algorithm implementation

I was reading a paper from Mathematica Journal.It mentions a code for calculating subsets. ...
147 views

### Scripting a visual comparison between the derivative and some finite scheme

I want to make an application where I can specify a function $f:\mathbb R\to \mathbb R$ and a dynamic value $n$ and get the function $\frac{f(x+\frac{1}{n})-f(x)}{\frac{1}{n}}$. I moreover want to ...
172 views

### Applying a function of several arguments to the rows of a matrix

I have a user-defined function which takes three vectors as input. Suppose that is like this: f[a_, b_, u_] := Total[a*Total[u]^b] Usually I have vectors for <...
46 views

### Using anonymous functions instead of module or block. Bad idea? [duplicate]

Here is an example function which returns True if a point p is on an (open) line segment (A, B) assuming that Orientation[A, p, B] returns 0 if the three points are collinear: ...
156 views

### Why is this code in functional style is slower than procedural style?

I know that in Mathematica a functional programming style is often more efficient than procedural style programming using For loops. But the code shown below seems ...
1k views

### Going full functional (Haskell style)

I'm trying to define some notation so that Mathematica code would be more functional, similar to Haskell (just for fun): currying, lambdas, infix operator to function conversion, etc.. And I have some ...
334 views

### Arbitrary depth patterns/rules

Temporary message: I am now really confused. I am not sure how using Power and Unevaluated together works in the examples below. While answering this question, I stumbled upon the following. We ...
284 views

### Computing distance matrix for a list

Using functional programming in Mathematica, how can I compute a distance matrix for every element in a list of matrices... The distance would be computed between the item in the list and a "target ...
104 views

### given n lists, get list of applications of function to n-tuples

Is there a built in function or an easy rule to do the following transformation? H[{A[0], A[1], ...},{B[0], B[1], ...},...] into ...
413 views

### Transform a list of functions to a composition

How do I apply a list of functions in a nested way? Example: functionList = {f1,f2,f3} RequiredCommand[functionList,Pi] such that the required command returns ...
3k views

### Programming a numerical method in the functional style

I am new to Mathematica and I would like to learn a bit more about functional programming. At the moment I have assignments like programming different numerical methods (for integration: ...
338 views

### Update a function avoiding infinite recursion

I am quite new to Mathematica and not completely familiar with functional programming. I am currently working with a function (call it foo) and wish to change its behaviour, for example, by adding 1 ...
402 views

### Defining a function to determine when convergence is guaranteed

I'm investigating how many iterations are needed for a particular orbit to reach a fixed point of a function. Since I have many functions to test, I want to define a function in Mathematica that will ...
238 views

### Issue with ListConvolve

I am a new Mathematica user, learning the intricacies of functional programming. I have issues withe applying a function over a moving list. My function seems to work and give correct results but it ...
615 views

### How to transform Do loop to more efficient codes?

I'm new to Mathematica. Here is my original program: How to rewrite the Do part? ...
453 views

### Variant of the cutting-stock problem in Mathematica

I'm pretty new to Mathematica and am trying to learn to solve problems in a functional way. The problem I was solving was to list the ways in which I could sum elements from a list (with repetitions), ...