Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options questions only not deleted user 2048

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

1 vote
0 answers
95 views

Different ways to program a recursive algorithm

Construct f (a numeric function) which takes multiple arguments with the following property: The single argument case $f(x_1)$ is meaningless, and the two-argument function $f(x_1,x_2)$ is the base c …
QuantumDot's user avatar
  • 19.8k
3 votes
0 answers
170 views

How to ScanThread and ScanIndexed?

Why are there MapThread and MapIndexed but no analogous functions for Scan? What is the recommended way to Scan over a pair of datasets (ScanThread), or over an ordered dataset (ScanIndexed)? Edit …
QuantumDot's user avatar
  • 19.8k
3 votes
2 answers
98 views

Fast functional method for multiplying duplication numbers in a large list

Consider a list of symbols: mySet = {a, b, b, c, a, b, c, d}; I would like to form the product of duplication numbers. In the example above, I have 2 a's, 3 b's, 2 c's and 1 d. So the result I ne …
QuantumDot's user avatar
  • 19.8k
3 votes
1 answer
45 views

Mapping also for one element (or telling it how to do so if head got changed)

Some code generates a polynomial, and has the form: expr = Plus[a[i],b[i],c[i],d[i]] I need to apply f to each term. To do this, I use Map: Map[f, expr] (* f[a[i]] + f[b[i]] + f[c[i]] + f[d[i]] …
QuantumDot's user avatar
  • 19.8k
0 votes
2 answers
115 views

How do I tell pattern searcher the order in which to search for patterns given in general form?

I have a really long sequence of Symbols inside a function, say nonCommute[a,b,c,e,e,f,g,b,i,j], and I am implementing a recursive algorithm using RepeatedReplace with the rule: rule = nonCommute[lef …
QuantumDot's user avatar
  • 19.8k
1 vote
3 answers
119 views

How to distribute but skipping one level

I would like to write a Rule that mimics built-in Distribute[], but one that distributes Plus over a function f, while skipping a level (which for me, has head=List). Here are examples of what I need …
QuantumDot's user avatar
  • 19.8k
1 vote
1 answer
55 views

Low level built-in function to transpose expression (not array) [closed]

I have an expression like this F[G[1, b], G[3, y], G[4, y], G[5, u]] that I would like to Transpose to obtain G[F[1, 3, 4, 5], F[b, y, y, u]] Since Transpose doesn't act on expressions (with hea …
QuantumDot's user avatar
  • 19.8k
8 votes
3 answers
767 views

How to organize expression by symbols (like Collect), but apply different functions to each ...

I want to mimic the functionality of Collect[expr, {vars}, func], but with the following modification: The function f that is applied to each coefficient is different, and depends on which variable i …
QuantumDot's user avatar
  • 19.8k
2 votes
1 answer
102 views

How to program MapList? [closed]

I would like to know if there is a nice functional way to code up a MapList which applies f to each element of expr and returns a list of the results obtained. Here is my implementation: MapList[f_, …
QuantumDot's user avatar
  • 19.8k
5 votes
1 answer
76 views

Functional iteration of list of functions

I'm getting completely stumped on writing a function makeIterate that constructs an iterated structure out of a list of functions e.g. {f, g, h} and a list of corresponding arguments {d1, d2, d3} (sam …
QuantumDot's user avatar
  • 19.8k
2 votes
1 answer
342 views

Optimizing my code to generate symmetric tensors

I have written code that does carries out the following task: Construct a fully symmetric rank-$P$ "tensor" out of a collection of user-input rank-1 vectors, and a rank-2 symmetric tensor $h$. The n …
QuantumDot's user avatar
  • 19.8k
2 votes
2 answers
345 views

How to implement fast series multiplication

I need to generalize the SeriesData object for my own purposes. One of the things I need to do is to reimplement code to multiply product of series. I've made two attempts at this, and both of them a …
QuantumDot's user avatar
  • 19.8k
7 votes
3 answers
743 views

How to get "Signature" of each element of "Permutation" output

I need to sum over all possible permutations, multiplied by the Signature of each permutation of a given list of symbols. But, I don't know how to determine the Signature of each particular permutati …
QuantumDot's user avatar
  • 19.8k
2 votes
0 answers
68 views

How would you rewrite these procedurally coded internal routines in functional form?

I came across the following two internal functions SimplifyDump`AbsToSign and SimplifyDump`SignToAbs that have been written procedurally. Here are the source codes: AbsToSign[expr] attempts to co …
QuantumDot's user avatar
  • 19.8k
2 votes
1 answer
74 views

Searching for symbol except within subexpressions with a particular Head

I would like to write a searcher like FreeQ that looks for a Symbol (or Head) in an expression, but confines its search outside of subexpressions that have a particular Head. Because expr can get hug …
QuantumDot's user avatar
  • 19.8k

15 30 50 per page