# Tag Info

1

This answer is also not direct answer because there is no Module or While but it is good to know that construct: f[n_Integer /; n>0] := f[n] = f[n - 1]/(6 n) + n! f[0] = 7 More here

3

Since you are interested in learning different ways to write this, here is one that avoids using "variables" entirely, thus removing the need for Module: fnw[i_Integer] := Last @ NestWhile[{# + 1, 1/(6 #) #2 + #!} & @@ # &, {1, 7}, #[[1]] <= i &] An expression such as #[[1]] <= i & is a pure function with a single parameter ...

3

You mean this? fw[i_Integer] := Module[{n = 0, last = 7}, While[++n <= i, last = 1/(6 n) last + n!; ]; last]

2

Using a technique discussed in this answer, here's how you might define the "tribonacci" numbers/polynomials recursively: SetAttributes[Tribonacci, Listable]; Tribonacci[0, x_] := 0; Tribonacci[1, x_] := 1; Tribonacci[2, x_] := x^2; Tribonacci[n_Integer, x_] := Module[{al, xl}, Set @@ Hold[Tribonacci[n, xl_], Expand[xl^2 Tribonacci[n - 1, xl] + xl ...

1

Clear[t]; t[n_] := x^2*t[n - 1] + x*t[n - 2] + t[n - 3]; t[0] := 0; t[1] := 1; t[2] := x^2; t[3] := x^4 + x; The above equations are the definition of the Tribonacci polynomials. To print some elements of Tribonacci sequence; Table[Expand[t[i]], {i, 0, 5}]

3

Here's one way to define the series: Clear[f]; f[n_] := f[n - 1] + f[n - 2] + f[n - 3]; f[1] = 1; f[2] = 1; f[3] = 1; Now you can get any f f[10] gives the answer 105. Similarly, if you want to define the polynomials, you could set up a recursion Clear[g]; g[n_] := x^2 g[n - 1] + x g[n - 2] + g[n - 3]; g[0] = 0; g[1] = 1; g[2] = x^2; Now you can ...

6

This is definitely a bug. It seems that the problem is caused because you increment the argument by two (your recurrence has c[k] and c[k+2]). This results in two cases (even and odd), as can be seen by your Maple output, and Mathematica apparently does not know how to deal with this properly. One way around this is to substitute the variables so that the ...

4

Graham, Knuth, and Patashnik in their book Concrete Mathematics (pages 118 and 150) discuss the Farey series. Their recurrence does not require finding Subsets, computing the elements in order starting with $0/1$ and $1/n$. Although very fast, Subsets can use too much memory when very large $n$ are required, as for some PE problems. ...

5

Here's a functional way to use the property (the property, which has been removed from the original question, was $N'/D' = N/D + 1/D'D$ or equivalently $N'D-D'N=1$): farey1[n_] := NestWhileList[ With[{num0 = Numerator[#], den0 = Denominator[#]}, First @ Minimize[{num/den, num den0 - num0 den == 1 && 1 <= den <= n && 1 ...

5

Here's a way to exploit the mediant property of the Farey series. To calculate the mediant: med[{a_, b_}] := (Numerator[a] + Numerator[b])/(Denominator[a] + Denominator[b]); Then the Farey series is: farey[n_] := farey[n] = DeleteCases[ Riffle[ farey[n - 1], med /@ Partition[farey[n - 1], 2, 1]], _?(Denominator[#] > n &)]; with initial ...

4

Note, this can be solved in general form. Start as RSolve[{G[n, k] == G[n + 1, k - 1] + G[n + 2, k - 2]}, G[n, k], {n, k}] You have two unknown functions C(1)[x] and C(2)[x] that you can find using your boundary conditions. Apply your initial conditions G[n,0]: A[n_] = C[1][n] /. Solve[n == (-(1/2) - Sqrt[5]/2)^n C[1][n] + (-(1/2) + Sqrt[5]/2)^ ...

5

You can always define the recursive function yourself and use memoizing to speed up computation: g[n_, 0] := g[n, 0] = n; g[n_, 1] := g[n, 1] = n^2; g[n_, k_] := g[n, k] = g[n + 1, k - 1] + g[n + 2, k - 2]; Table[g[n, k], {k, 0, 10}, {n, 0, 10}] // TableForm

Top 50 recent answers are included