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

0
votes
1answer
91 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): ...
0
votes
0answers
31 views

How to use OptionValue inside a pure function [duplicate]

I want to define a function with OptionsPattern as argument which returns a pure function using OptionValue: ...
16
votes
2answers
416 views

Pure function with attributes of arbitrary number of arguments: Is it possible?

Mathematica allows to define pure function, like Function[{a, b},Length[Unevaluated@a]{b}][1+2,2+3] (* ==> {0} *) Pure functions in Mathematica can take an ...
1
vote
1answer
85 views

Optimization of the solution to an ODE

Apologies if this is obvious -- I'm very new to Mathematica. I'm trying to minimize the solution to an ODE with respect to a variable. The following code generates the solution to the ODE, ...
0
votes
0answers
43 views

Greatest common denominator command. Can you explain why this command works?

Can you explain how this function works? mysteryFunction := Fold[#/#2 /. {n_~_~_ -> #/n, _ -> #2} &, #, {##}] &
1
vote
1answer
111 views

Evaluate pure function through round brackets

In have some matrices of pure functions or numbers which I multiply by other matrices or vectors. I would like the functions to be evaluated in the result, but all that I get is something like this: <...
21
votes
7answers
1k views

Using patterns in pure functions

Pure functions may be handy if you don't want to assign your function a name. For example I would calculate $x(x-1)$ for some numbers $x$ by ...
1
vote
2answers
343 views

Solving pure functions

I've been trying to use Solve with pure functions to receive function efinition and then use it with Map , to obtain results from mapping function to some data. Here is example ...
4
votes
2answers
145 views

Automatic generation of pure function

My main problem consist in the creation of a sort function which wolud be used inside SortBy. Introduction The principle of the sort to apply is the following (...
15
votes
4answers
964 views

Can you plot pure function without specifying variable?

Given a pure function, e.g. f=Sin[#]&, it is possible to plot it with introducing an arbitrary local variable, e.g., ...
1
vote
0answers
80 views

Matching All Functions [duplicate]

Is there any way to match all functions? There's an existing answer for matching functions of one parameter (_@_) but it doesn't work for trying to test if a symbol ...
1
vote
1answer
68 views

How to force evaluation inside the body of a pure function?

For example, I'm writing a function to scale my list of numbers into a specific range. It goes like ...
6
votes
1answer
122 views

Select with test function that depends on #

I'm trying to teach myself to use pure functions and slots as much as possible. Here is my problem. I have a list: ...
0
votes
4answers
108 views

How to use Select according to a list of criteria to produce a list of subsets of another list obeying those criteria [duplicate]

The code Print[Select[{1, 4, 3, 9}, Mod[#, 3] == 0 &]]; Print[Select[{1, 4, 3, 9}, Mod[#, 3] == 1 &]]; Print[Select[{1, 4, 3, 9}, Mod[#, 3] == 2 &]] ...
0
votes
2answers
472 views

Expansion in Basis Functions

I am trying to create an expansion of the form f[x,y]->Sum[Cn[x] y^n,{n,1,order}] To replace the function f by the ...
25
votes
2answers
1k views

Is there any way to define pure functions with optional arguments?

For example consider the following function: Function[{u,v},u^2+v^4] Is there anyway to define default values for the variables ...
1
vote
0answers
142 views

Variable naming conventions for nested pure functions [closed]

My understanding is that for nesting pure functions, one should use the explicit version of pure functions. I would like to know the best way of making it readable for people. I currently have ...
4
votes
1answer
85 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
45 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 ...
22
votes
1answer
981 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
1answer
103 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
85 views

How to get the values out of Alternatitves? [closed]

Saying we have something like: SomeFunction[ ... { Alternatives[1, 2, 3] :> "something" } ... ] How can I know if ...
1
vote
0answers
33 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 ...
0
votes
1answer
99 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: ...
0
votes
0answers
54 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 ...
1
vote
2answers
66 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}} ...
6
votes
3answers
320 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]]}
5
votes
1answer
320 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
54 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 ...
1
vote
2answers
40 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
79 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
237 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? ...
8
votes
1answer
310 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 ...
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 ...
4
votes
1answer
129 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
83 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
165 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
152 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
279 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 <...
0
votes
1answer
90 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 ...
1
vote
1answer
74 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: ...
1
vote
1answer
75 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 ...
41
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 ...
17
votes
2answers
505 views

Using several anonymous functions mixed together

This works: list // BarChart[#[[2]], ChartLabels -> DateString @@@ #[[1]], ChartStyle -> "Pastel"] & This doesn't: ...
4
votes
0answers
52 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
86 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 ...
2
votes
1answer
94 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. ...
5
votes
2answers
130 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 ...