Linked Questions

603 votes
19 answers

Where can I find examples of good Mathematica programming practice?

I consider myself a pretty good Mathematica programmer, but I'm always looking out for ways to either improve my way of doing things in Mathematica, or to see if there's something nifty that I haven't ...
42 votes
3 answers

Is there a name for #1@#2&?

Why does the pure function # @ #2 & have no name? I'm asking because sometimes I find inelegant to write expressions like ...
Kuba's user avatar
  • 137k
13 votes
5 answers

How to deal with recursion formula in Mathematica?

In engineering problems, I am always seeing many recursion formula. For instance, In the book "The NURBS book", I discovered many recursion formula Fibonacci $$f(...
xyz's user avatar
  • 625
29 votes
1 answer

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? ...
user's user avatar
  • 1,897
19 votes
3 answers

What is the most efficient way to map a linked list?

In order to work with lists effectively using common recursive patterns from functional programming, it's often most convenient to worked with the "linked list" representation, that looks like this: <...
Pillsy's user avatar
  • 18.5k
13 votes
4 answers

How to pass a list of arguments into HoldAll

I have a list of arguments (which in reality is lengthy): arguments = {a, b, c} arguments2 = {a_, b_, c_} f[Sequence@@arguments2] := a + b + c Note: It seems ...
Emerson's user avatar
  • 1,217
7 votes
3 answers

String templating

I am pretty new to string processing in Mathematica. But I'm having some problems in doing simple string template filling to my mind elegantly. For example when doing export for my answer here, one of ...
joojaa's user avatar
  • 790
4 votes
1 answer

Display level of recursion of a recursive function during execution

Given a recursive function, is there some simple way to display or store the value of recursion or "how many levels deep" the function is at a given time? For instance, if we wrote the recursive ...
iwantmyphd's user avatar
1 vote
1 answer

How do I define a function that uses a recurrence relation? [duplicate]

I know how to define functions other than the ones that use a recurrence relation to calculate the $n$-th term of a sequence. How would such a function be constructed?
user60620's user avatar
1 vote
1 answer

Why do I get an error message when for this type of recursion?

When I type the following code: mus[] = 0; mus[x__] := First[List[x]] + mus[Rest[List[x]]] What one would think would happen is that if, ...
I would like to remain anon.'s user avatar
5 votes
1 answer

Recursion and safety of SetAttributes[Function, SequenceHold]

Compare the timings below N@Timing@Block[ {iii = 0}, Nest[ {#[[1]] + 1, Plus[#[[1]], 1, (#[[1]] + 1)*#[[2]]]} & , {0, 1}, 5000 ] ] ...
Jacob Akkerboom's user avatar
1 vote
1 answer

Recursion evaluate Table power exceeded limit

I wrote 2 simple recursive functions for calculating the power of a table. pol3[Tb_List, n_Integer?Positive] := If[n == 1, Tb, Tb.pol3[Tb, n - 1]] and ...
npap's user avatar
  • 11