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.

learn more… | top users | synonyms

4
votes
1answer
75 views

Creating a list of unevaluated pure functions with Apply

Suppose I have a list list with length L and a function ...
0
votes
1answer
41 views

Deciphering Coding Shortcuts [duplicate]

I'm having trouble deciphering why the following couple of expressions evaluate the way they do. #&@@ This returns the first value of a list. Why? Naïvely I ...
1
vote
1answer
89 views

How to write this code as a pure function? [duplicate]

The code has three places with same variable ls. So I think it would be possible to write it as a pure function. ...
1
vote
0answers
32 views

Why is `g[#1, #2] &` different from `g[##] &` for a function with two variables in this example? [duplicate]

If we only consider functions with two variables, I expect g[#1, #2] & is the same as g[##] &. But in the following ...
1
vote
2answers
65 views

Translating syntax of a pure function

I have a matrix in complex exponential form. I want to factor out the complex exponential form and then express the inside in the a+i*b form. For example: \begin{bmatrix} e^{i \frac{\pi}{4}} ...
1
vote
0answers
81 views

How to get the values out of Alternatitves?

Saying we have something like: SomeFunction[ ... { Alternatives[1, 2, 3] :> "something" } ... ] How can I know if ...
6
votes
3answers
301 views

How can I create currying functions using pure function syntax?

For example how can I write In: pureFunctionSyntax[myF] /@ {7, 3} Out: {myF[7, Log[7]], myF[3, Log[3]]}
4
votes
1answer
283 views

Why does #0[[1]] &[] output 0?

When a pure function accesses the first element of itself, 0 is output. What is the logic behind this, or is there any?
3
votes
3answers
49 views

How to use pattern matching to apply a function to specific elements of a matrix

I have a 3x3 matrix testweightedgraph = {{{}, {p, q, pq, pq}, {}}, {{p, q, pq, pq}, {q}, {}}, {{}, {}, {}}}; whose elements are (possibly empty) lists. I would ...
0
votes
1answer
96 views

Replace variable with # and pass function body as an argument to a function

I have a very simple problem, which I would like to make a bit general, but none of my naive approaches have worked yet. This is what I want to do step by step: Define a parameter: ...
22
votes
1answer
928 views

Is it possible to reference “self” from a pure function?

This would calculate the factorial of 6, if the "self" was the function itself. Is there something that could allow this? ...
1
vote
2answers
32 views

“Nonatomic expression” error when identifying certain positions in a list [duplicate]

Please can anyone help ? I have a list of sets, and I am trying to find the positions in that list of those sets which are subsets of a given set. (Here I am ignoring the distinction between lists and ...
0
votes
1answer
70 views

Working with functionals [closed]

I am trying to work with functionals in Mathematica, this means that I want to define a function of a function. I defined my function of a function as: ...
0
votes
4answers
141 views

Cases vs Select, Pattern vs Pure function [duplicate]

What is the difference between having Cases with selection condition presented by pattern and a with pure function as condition? ...
4
votes
1answer
108 views

Substitute a function's definition for its name

I'm having trouble with a function which is supposed to work on another function. Simplified version: ...
1
vote
1answer
67 views

Pure “Select” function over matrix

I have several lists of tuples in the following shape: l1 = {{1, 134}, {2, 314}, {3, 164}} I do want to select, from each list, list elements fulfilling a ...
4
votes
5answers
159 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 ...
2
votes
1answer
98 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 ...
7
votes
5answers
252 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 ...
1
vote
1answer
56 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: ...
0
votes
1answer
79 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 ...
7
votes
5answers
547 views
1
vote
1answer
71 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 ...
39
votes
2answers
2k 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 ...
0
votes
0answers
52 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 ...
0
votes
0answers
68 views

Interpreting Mathematica output or producing cleaner output

Could someone please explain what the following would look like in standard math notation (or explain to me what this means): ...
2
votes
1answer
72 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 ...
4
votes
0answers
49 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: ...
2
votes
1answer
87 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 ...
27
votes
2answers
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. ...
4
votes
2answers
112 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 ...
0
votes
0answers
47 views

Having trouble reading this output (pure functions) [duplicate]

I'm after decoupling some odes and trying to solve them using mathematica but my output is in terms of Functions and InverseFuntions and I'm afraid I have no idea how to translate the output into ...
9
votes
2answers
683 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 ...
1
vote
0answers
81 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 ...
2
votes
1answer
91 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 ...
7
votes
3answers
386 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 ...
2
votes
3answers
184 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: ...
1
vote
4answers
180 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: ...
0
votes
0answers
59 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 ...
15
votes
2answers
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 ...
0
votes
2answers
81 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 ...
0
votes
1answer
103 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 ...
10
votes
1answer
330 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): ...
0
votes
1answer
116 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. ...
9
votes
3answers
363 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 ...
0
votes
0answers
42 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 ...
5
votes
4answers
161 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 ...
3
votes
5answers
205 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 ...
5
votes
1answer
202 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.: ...
2
votes
1answer
720 views

Why is either Listable or HoldFirst not working?

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