For questions about defining recursive functions, recursive algorithms and solving recursive equations (e.g, with `RSolve`)
32
votes
2answers
9k views
How can I use Mathematica's graph functions to cheat at Boggle?
This question is inspired by a Stack Overflow question that I decided to solve using Mathematica. In addition to Mathematica, I thought I'd use some of the new version's graph-related functionality, ...
30
votes
4answers
997 views
How can I implement dynamic programming for a function with more than one argument?
Dynamic programming is a technique for avoiding the repeated computation of the same values in a recursive program. Each value computed is immediately stored. If the value is needed again, it is ...
20
votes
4answers
543 views
What tools can help in realizing tail recursion?
I had nice discussions with Leonid and Rojo that got me interested in tail recursion. Tail recursion is not always easy to realize with Mathematica, so it would be nice to have some tools to help with ...
6
votes
5answers
214 views
How to nest my own “times” function to get powers
I have a "times" function. I'd like to create a power function using it. It should look like this for an 6th power:
...
2
votes
2answers
91 views
Recursion doesn't happen any more or doesn't happen correctly if I store the recursive relationship in a variable first
I know the following code will form a recursion:
Clear["Global`*"]
u[i_, n_] := u[i - 1, n] + u[i, n - 1]
u[0, n_] := n
u[i_, 0] := i
u[2, 2]
(* => 8 *)
But ...
12
votes
3answers
297 views
How to clear parts of a memoized function?
I have a function of two variables, e.g.:
f[a_, b_] := f[a, b] = something f[a - 1, b - 1] etc
With the above code I used the concept of memoization to speed up ...
9
votes
6answers
1k views
Recursive function with if-statement
I am trying to represent the following function definition in Mathematica:
$$\begin{align*}
f(1)&=1 \\ f(2n)&= \begin{cases}f(n) & \text{if}\space n\equiv0\pmod{2} \\ 2f(n) & ...
3
votes
1answer
446 views
Solve pair of recurrence relations
[Corrected equations and added simple example]
Can you solve a system of (loosely) coupled recurrence relations like this in Mathematica somehow?
...
5
votes
1answer
167 views
Build recursion in parallel?
Problem
Let's define a simple recursion.
f[1] = 1;
f[n_] := f[n] = f[n - 1]*n;
If I evaluate f in parallel
...
4
votes
2answers
114 views
Update a function avoiding infinite recursion
I am quite new to Mathematica and not completely familiar with functional programming. I am currently working with a function (call it foo) and wish to change its behaviour, for example, by adding 1 ...
0
votes
2answers
168 views
Recursion on a moving window
I need to apply some computations to a moving window of $N$ items in a time series and I am struggling with doing recursion and shifting the considered window.
To illustrate, please consider the ...