Questions about Mathematica's functional programming style, including the use of pure functions (Function[], #, &) and functions such as Map, Apply, Nest, and Through.
14
votes
3answers
349 views
Using pure functions in Table
I need a table with the elements made of pure functions and list elements. This is a simplified example:
I need a list as:
...
-1
votes
1answer
120 views
GatherBy Option to group results?
How can GatherBy be programmed to take an option to group results as follows:
...
2
votes
3answers
138 views
Using Nest inside NestList
I need results like this:
{Cos[Cos[x]], Sin[Cos[Cos[x]]],Cos[Cos[Sin[Cos[Cos[x]]]]],
Sin[Cos[Cos[Sin[Cos[Cos[x]]]]]], ... }
I've tried to use ...
13
votes
3answers
188 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, ...
2
votes
3answers
152 views
Ways to change an explicit function into a pure function
I'm trying to use FixedPoint to solve a transcendental equations, but the first argument of the FixedPoint should be a pure ...
11
votes
2answers
310 views
What's the most “functional” way to do Cholesky decomposition?
I can do Cholesky in a procedural style, such as:
...
10
votes
0answers
221 views
How can I trace a functional expression's evaluation visually?
Ok, so the goal is to visualize the execution of this expression
foo /@ {3 + 1, bar /@ {1 + 2, {4 + 7}}}
in the following fashion using nested rectangles with ...
16
votes
1answer
278 views
Prefix operator with low precedence
The question is simple, but I will elaborate on the background as well for those interested in the idea:
How to define a new operator with specified precedence value?
Background
Mathematica was ...
12
votes
2answers
322 views
5
votes
1answer
162 views
Composite graphics with Row, Column, data aggregation and layout control
This chromogram shown here
represents data (mouse activity patterns during visits) for ~20 physicians in a study, each of which may have a variable number of visits in the study (physicians are color ...
4
votes
1answer
182 views
8
votes
2answers
176 views
Cases[data,Colon[key,_]] vs. Cases[data,key:_] toward XPath, XQuery
Exploring methods to index and search tree-structured key:value pairs via named-entity index (key paths) as opposed to Position-based indexing.
Using Rule as ...
8
votes
3answers
316 views
Can this code be written in a more functional style
Referencing this question, I wonder if the following code can be written more concisely using a functional style, i.e. without For loops or ...
16
votes
2answers
573 views
Does every Symbol in Mathematica induce a monad?
From my question about types in Mathematica, I assume that every Symbol in Mathematica is a type if it appears as a Head of some ...
11
votes
2answers
402 views
Using a list of tuples in a pure function
I want to use a list of tuples within a function to make assignments.
Say I want to make assignments of the form
value[i,j] = val
What I have is a list of ...
3
votes
1answer
240 views
Explanation on why Compile statement works only if input and output sizes work
I found the following code:
Compile[{{m, _Real, 2}}, Fourier[m]][Table[N[i - j], {i, 4}, {j, 4}]]
which doesn't work correctly. But the following was posted as a ...
15
votes
1answer
222 views
Are there advantages to using additional arguments of common functions rather than alternative ways of calculating with lists?
(Apologies for the long question title.)
One of the interesting, if sometimes confusing, things about Mathematica is that there is always more than one way to do things. Even intermediate users can ...
21
votes
6answers
870 views
Can this be written well, without loops?
Inspired by this question I would like to know if the following code can be written without explicit loops (For, While, etc.) in a clean, efficient and non-contrived way. I have been unable to do so.
...
14
votes
4answers
539 views
Is there a more elegant and efficient way to write brainf*** style loops in Mathematica?
I'm having some fun writing a brainf*** interpreter in Mathematica. See this wiki article for more info. It works nicely but I'd like to find an elegant, preferably functional, way to handle the ...
13
votes
3answers
480 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 ...
6
votes
1answer
321 views
How to solve this iteration in the functional programming way?
I am trying to come up with a functional programming method to calculate a list of replacements, that depend on previous replacements. Since there is always a finite number of steps, I would like to ...
50
votes
7answers
1k views
Functional style using lazy lists?
Let's say I want to answer the question "what are the first 400 palindromic prime numbers?"
The first approach that comes to my mind from the set of languages that I know is to use some sort of lazy ...
