# Tag Info

Accepted

### What makes mathematica a "functional programming language"?

On the Wolfram web site there is a description of the Wolfram Language (WL) entitled Notes for Programming Language Experts. At time of writing, it lists 47 attributes of WL including Functional. It ...
• 69.1k

### Analogies to Help New Users

Imho some important things to translate between Matlab and Mathematica: "everything is a matrix (or inefficient)" vs. "everything is an expression" indexing into arrays: ...

### Why is Unevaluated[#]& different from Unevaluated?

I thought that for any function f we could use "f" interchangeably with "f[#]&". That ...
• 236k

### Cleanest way to take a[b[c]] to a[b][c]

test = a[b[c[d]]]; Fold[ Construct, (* or Compose, see [1] *) Level[test, {-1}, Heads -> True] ] a[b][c][d] [1] - ...
• 137k
Accepted

### Why use pure functions?

Think of it as a macro. It shortens up your code. It stops your namespace from being polluted with extra function definitions. In some cases it can be faster than defining an auxiliary function. I ...
• 36.3k
Accepted

### Iterate over # without needing to define a variable

f = Thread @* List; f[n0, {n1, n2, n3, n4, n5}] {{n0, n1}, {n0, n2}, {n0, n3}, {n0, n4}, {n0, n5}} If you have to use ...
• 397k
Accepted

### What is the fastest method to set the diagonals of a matrix to 1?

Edit A "one-line" way without any C source code: ...
• 27.6k

### How to map and sum a list fast?

AbsoluteTiming[Total[Range[1, 100000000]^2]] (* {26.0686, 333333338333333350000000} *) or ...
• 6,438

### Puzzle — 20 People to consume 20 units of food under constraints

Just write the problem literally and use Reduce ...
• 16.8k
Accepted

### Puzzle — 20 People to consume 20 units of food under constraints

We can do this more efficiently using IntegerPartitions: Counts /@ IntegerPartitions[20, {20}, {1, 3, 4}/2] ...
• 272k
Accepted

### Pseudo-currying in one line

EDIT: Modified to cover situation when an argument is a List Use Fold ...
• 160k

General My (biased) view on monads is that they are loudly advertised in Haskell and F#, but I kind of do not see what is the big deal. (Granted, similar things are said about OOP Design Patterns, ...
• 37.9k

### Pseudo-currying in one line

The deprecated (but valid) function HeadCompose basically does just that: ...
• 272k

### Puzzle — 20 People to consume 20 units of food under constraints

Another solution: Select[FrobeniusSolve[{20, 15, 5}, 200], Total[#] == 20 &] ...
• 70.8k
Accepted

### Is there a way to do this with Mathematica shorthand notation?

You could use the operator form of Map instead: SecondFn @ Map[FirstFn] @ {2, 3, 5} SecondFn[{FirstFn[2], FirstFn[3], FirstFn[5]}] or ...
• 131k
Accepted

### Why is Unevaluated[#]& different from Unevaluated?

The two are not equivalent. Even if f lacks special attributes. Assuming no special attributes are present, a function's arguments are always evaluated before the ...
• 1,317

### Function that does for Map what Through does for Apply?

One option is to use the forking operator {fn1, fn2, ...} from the Query sublanguage: ...
• 69.1k

### What is the fastest method to set the diagonals of a matrix to 1?

A long comment...I'm using V13.1, Mac M1 Pro, which might matter... First, I would point out the "About" section of the profile of user @WReach. Toward the end, the question "Why don't ...
• 237k

### What is the fastest method to set the diagonals of a matrix to 1?

It is pretty fast to use LibraryLink, making sure the memory is shared between the library and the Mathematica kernel. Note that you need a C compiler. C code: ...
• 12.2k
Accepted

### How best to simulate n-body systems in a functional way?

In version 12.0 you can use NBodySimulation for that: ...
• 40k

### Why is Unevaluated[#]& different from Unevaluated?

The head Unevaluated is a symbol with the HoldAllComplete attribute. The head ...
• 13.8k
Accepted

### Meaning of ## #

Plus[## #] & is the same as Plus[Times[##, #1]], which always computes to the same as the simpler ...
• 236k

### Iterate over # without needing to define a variable

Best on packed arrays... ...
• 237k

### Functional style using lazy lists?

I recently published a lazy list package on GitHub, so I might as well show it off here: https://github.com/ssmit1986/lazyLists Installation instructions can be found on the GitHub landing page ...
• 23.8k
Accepted

### Function to draw densely interconnected layers in graph (e.g., neural net)

This one constructs an AdjacencyMatrix that can be input to AdjacencyGraph: ...
• 397k
Accepted

### How to build private function with built-in function's option

New analysis (in v10.1) For your newly stated goal: If I don't want to build a new function.I just wanna change the GeneralUtilities`BenchmarkPlot's default ...
• 272k

### Is there a way to do this with Mathematica shorthand notation?

FirstFn /@ a // SecondFn SecondFn[{FirstFn[2], FirstFn[8], FirstFn[5]}]
• 31k
Accepted

• 30.1k

### How to map and sum a list fast?

To overcome the memory issues, let's store as few data in the memory as possible: out = 0; Do[out = out + i^2, {i, 1, 100000000}]; // AbsoluteTiming out {58....
• 24k