A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

# Questions tagged [pure-function]

Questions about implementing or applying functions which: (1) always yield the same result for the same input, (2) are independent of outside information, and (3) produce no side effects.

179 questions
Filter by
Sorted by
Tagged with
217 views

### Using Through with SlotSequence

I have an expression consisting of a few pure functions added together like so: f+g+h I want to add the bodies of these functions together and make that a pure ...
411 views

### Use Map with multiple arguments over a nested list

I noticed there are a few similar questions to mine on here, but I couldn't figure out how to accomplish this mapping. I have sets of data I want to plot, which represent intensity and frames, and I ...
654 views

### How to write an operator that acts on pure function (to give another pure function)

I would like to write an operator oper that acts on a pure function f with an undetermined number of arguments, with the syntax <...
162 views

### Sum of Integers with a Pure Function

How would I find the sum of an argument, with the constraint that they are all integers (so if the argument contains a non-integer value, the function will not evaluate). I came up with these two: ...
136 views

### Pure Function that adds all arguments

the question asks to create a pure function that adds any number of arguments. Is the following acceptable? sum := Plus[##] & It does work, but can it be considered a pure function? I felt like ...
2k views

...
79 views

### How-to implement iteration over a result of an iteration in a functional way

I have a pure function f:= #1 * #2 * #3 &; Which I can invoke in a following way: f[#,2,3]& /@ {1,2,3} Which ...
3k views

### Memoization with pure functions?

Is this possible? If I have a simple function, say: f=If[#>0,1,2]& then for each value of # this will re-evaluate f right? Is it possible to define a ...
60 views

### What makes items with head Function different?

I apologize beforehand for the muddleheadedness of this question. It reflects the fact that I'm trying to interpret outward "behaviors" of Mathematica expressions without having any understanding of ...
101 views

### Interpreting Mathematica output or producing cleaner output [closed]

Could someone please explain what the following would look like in standard math notation (or explain to me what this means): ...
141 views

### Expressing a definite integral as pure function with the upper-bound as it argument

Suppose i have an integral which has a closed form, $\quad \quad \int_{a}^{b} f(x) dx=F(a,b)$ I want to use output function $F$ as a pure function, like ...
74 views

### Wrong autogenerated package from notebook containing #key and Part as subscript

Bug introduced in 10.0.0 and persisting through 10.1.0 or later Mathematica v10.1.0, under Windows 8.1 x64 Mathematica v10.0.2, under Windows 1) Define a function in an initialization cell: ...
141 views

### Use of parenthesis and pure function

I had read that when using a pure-function it was a good general practice to enclose the function and the associated ampersand in parenthesis. (#^2 &)[a] I ...
2k views

### What are the cool kids talking about when they use ##&[]? [duplicate]

All the cool kids are apparently using ##&[] for Unevaluated @ Sequence[] but I have no idea what either means. ...
196 views

### Conflict with variables in pure functions

Consider the following snippet of code. Clear[f, g] f[x_] := Function[{i}, x]; g[h_] := Module[{Z}, Z[i_] := Print[h]; Print[h]; Z[1]; ]; When ...
999 views

### How to programmatically covert a function-like rule to a pure function?

Is there a programmatic way to convert a Mathematica rule that acts like a typical mathematical function of one variable into the equivalent pure function? For example, the code should convert ...
112 views

### Using Solve without introducing extra variables

First post here. I've tried searching for an answer for this for a few days now, but it seems the search terms (solve, slot, etc) are too generic to be helpful. I'm struggling with understanding how ...
198 views

### Patterns for destructuring “Function” function arguments

I want to define a function for finding a Jacobian matrix of pure vector function of vector argument. I try ...
547 views

### Functional equivalent of a For loop referring to consecutive elements in a list

I have implemented this function which smooths the values in a list by, if it encounters a zero, replacing this entry by the average of its two neighbours (apart from the first and last values of the ...
421 views

### How to make a symbolic vector into a pure function?

As part of a set of functions to implement a steepest descent algorithm I created my own n dimensional gradient function. It is defined as follows: ...
462 views

### Pure function, one slot refers to List-position

I used all my google-fu trying to find how to make this work; read the docs as well. What have I missed? I feel sure this can't be a new question, but I can't find anything Here is is: ...
102 views

### How to Fold (FoldList) this in a more compact (efficient) way?

Example code: x = Table[something[i], {i, 5}] Table[Fold[f1[#1, f2[#2, a], a] &, x[[i]], {c1, c2, c3}], {i, Length[x]}] This above is just an example. I ...
1k views

### What happens when you divide by ##?

I've been playing around with sequences a bit. In particular with using ## with unary and binary operators. Let's start simple, the following all make some kind of ...
190 views

### How to make a density plot with composed functions [closed]

I want to create a monochromatic density plot of the E-field around an optical vortex. To do this I've written ...
232 views

### What does the expression “Total[funca[a,#] & /@ #] & /@ {x,y}” possibly mean?

Can the expression be simplified as "Total[funca[a,#]] & /@ {x,y}"? What does the double of "& /@" mean? Where can I find some reference? Updated According to Mr.Wizard's answer, I now know ...
565 views

### Why does the documentation call functions “pure”?

Clearly, functions in mathematica are not pure functions according to the definition on Wikipedia (no side effects - basically implementabe with table lookups): ...
155 views

### Why is B /. h -> #2 & not a pure function?

I am trying to plot the energy surface of the mean field Ising model, but I am running into a problem with setting the MeshFunctions for the plot. ...
469 views

### Operate over list of pure functions

I have list of pure functions (All functions are InterpolatingFunction) i.e {{a, b}, {c, d}, {e, f}, ...} and I would like ...
46 views

### How can I mix // with a function of two arguments? [duplicate]

I often find myself using // when playing around with expressions, but it is always cumbersome to have to switch to the full notation just to apply a function of ...
369 views

### Syntax for Table with a pure function

I have: g = #1^2 + a #2^3 / #1 & Now I wish to make a Table evaluating this from 1 ...
318 views

### Algebraic expressions on pure functions

I would like to know how to perform algebraic operations with pure functions. Simple version: Here's a silly toy model: I want to transform the algebraic expression Sin*Cos into the function ...
245 views

### How can I make a “self-referential” replacement operation self-contained?

Fairly often I find use for replacement rules that call themselves on the right-hand side of the rule, e.g.: ...
965 views

### Why is either Listable or HoldFirst not working?

Starting with a fresh kernel, I evaluate the following: ...
336 views

### Mma10 mystery: Failure of pure function substitution with Interpretation?

Bug introduced in 10.0.0 and fixed in 10.0.1 I had code to display with subscripts from Displaying index as subscript on output: e.g. C[i] -> C_i with Notation[...] or Interpretation[..]? which is ...
81 views

### How can I change the scoping of a pure function returned by a function in a package?

I have written a small Mathematica package that contains a module that solves some differential equation with initial conditions. Suppose that the solution to this differential equation defines some ...
607 views

### How to use multiple pure functions correctly?

I have used Mathematica for two years.And usually,I can use single pure function(#&) rightly.However,for the use of multiple pure function,I always make all ...
1k views

### How to find all symbols in an expression and perform an operation on them?

========== motivation =========== Suppose, for example, I have an incoming expression like m = (3-I)x + 4(x y)/(Cos[y]) I want to find all the symbols in ...
220 views

### Correct slot assignment when mapping from different lists using pure function

Given expr = u == a1 + a2 x + a3 y; and uRep = {u1, u2, u3}; xyRep = {{x1, y1}, {x2, y2}, {x3, y3}}; I'd like to generate ...
170 views

### Why is Chop ignored in Plot?

I want to plot multiple functions with the same settings side-by-side, so I use the pure function construct (for clarity, I only use one function in this example) ...
384 views

### Requiring NumericQ in Pure Function

Potential duplicate, but doesn't seem to solve my problem: Using patterns in pure functions I have a function that returns an InterpolatingFunction, and it works ...
149 views

### Third syntax version of LogitModelFit: unexpected result of “BestFit”

The third listed syntax version of LogitModelFit allows one to specify input in a simple way: Only a design matrix (with a row of values of the explanatory input ...
134 views

### Define a function that returns a function with a variable number of arguments

Previously, I've defined a function with a variable number of arguments with the following method. ...
473 views

### How to exchange two arguments?

Recently, I have being using Mathematica to write my undergraduate paper. I want to use two pattern lists such as { A -> a, B -> b, c -> C, ....} and ...
139 views

### What is happening in Map[Function[x, x^2], a + b + c] from the Pure Function tutorial

The Pure Function tutorial gives an example: Map[Function[x, x^2], a + b + c]. I would expect the output to be (a + b + c)^2, ...
214 views

### Slot (#) interfering with evaluation

In the following I am using one function makeFunc to assemble two functions a[t] and b[t] to ...
146 views

### How to input pure function to package?

I would like to input a pure function into a custom written package, but am running into a variety of errors. The package I have created is as follows: ...
174 views

### Replacement rules in combination with pure functions to make a change of variables

I have defined my function in this way w = f[r,Θ] ; After some calculations i obtained my results with respect to the previous function. For instance: ...
128 views

### Recursion when randomizing elements in a list

I want to randomize certain elements of a list; Since the code list = {a, b, c, d, e, f, g}; list[[{1, 3, 5}]] = RandomSample@list[[{1, 3, 5}]]; list works fine, ...