# Tag Info

3

Pushing @Igor's one step further: ds[foo_] := (z[x] /. DSolve[{z'[x] == foo, z[0] == 1}, z[x], x])[[1]] f = FindSequenceFunction@Apart@NestList[ds, 1 + x, 10] (* (E^x Gamma[1 + #1, x])/Gamma[1 + #1] & *) Apart@Nest[ds, 1 + x, 3] == Apart@FunctionExpand@f[4] (* True*)

6

DSolve[{z'[x] == 1+x, z[0]==1}, z[x], x] But it is not clear what you mean by "you need to find $f(x, n).$" You mean, a closed form for any $n$? Or? In any case, to get it for any fixed $n,$ you can use: ds[foo_] := (z[x] /. DSolve[{z'[x] == foo, z[0] == 1}, z[x], x])[[1]] Nest[ds, 1+x, n] For example: Nest[ds, 1 + x, 50] Gives you: $$... 1 seq = Table[-2^-n (2^(1 + n) LerchPhi[2, 2, 1 + n] - PolyLog[2, 2]), {n, 25}] // Simplify; seqFunc[n_] = FindSequenceFunction[seq][n] // Simplify -2 LerchPhi[2, 2, 1 + n] + 2^-n PolyLog[2, 2] seqFunc2[n_] = (a/c)*seqFunc[n - 1] + (b/d)/n^2 // Simplify; recur = {f[n] == (a/c) f[n - 1] + (b/d)/n^2, f[1] == seqFunc[1]} /. Simplify[ ... 3 Once you have several consecutive triples {f[n-1],f[n],1/n^2}, the coefficients can be found by a NullSpace computation. seq = ExpandAll[ FunctionExpand[ Table[-2^-n (2^(1 + n) LerchPhi[2, 2, 1 + n] - PolyLog[2, 2]), {n, 1, 20}]]]; n = 2; tuples = MapIndexed[Join[#1, {1/(#2[[1]] + 1)^2}] &, Partition[seq, n, 1]] (* Out[563]= {{1, 3/4, ... 2 Using the identity:$$\Phi (z,s,a)=\frac{\Phi (z,s,a-1)-\left((a-1)^2\right)^{-s/2}}{z} First we define two recursive functions: rGexp[0] = -1/4 (Pi^2 - 6 Log[2]^2)/3; rGexp[n_] := 1/2 rGexp[n - 1] rlp[0] = LerchPhi[1/2, 2, 0]; rlp[n_] := 1/2 rlp[n + 1] + 1/(n)^2 Then we add them: rSeq[n_] := rlp[-n] + rGexp[n] Simplify@Table[rSeq[n], {n, 1, 10}] ...

4

flatten and flattenblock themselves provide an example of how Module and Block differ in behaviour: flatten[{a, {result}}] (* {a, result} *) flattenblock[{a, {result}}] (* {a} *) It is easy to imagine flattenblock being called from within another function that uses the symbol result as a variable name. The results would likely be unexpected. It is ...

3

Here is a refactoring of celtschk's code; it is both shorter and faster: f[{1}] = 2; f[{_}] = 0; f[x_List] /; Min[x] < 0 = 0; mem : f[{_, x__}] := mem = ({x} - 1).Table[f @ MapAt[# - 1 &, {x}, i], {i, Length @ {x}}] Test: {4, 6, 5, 8, 5, 2, 5, 1, 5, 9, 0, 5, 3, 5, 2, 7, 3} // f // AbsoluteTiming {1.312075, 22727314469007948800}

6

I'd let the pattern matcher do most of the work. First, the recursion start: f[{1}] = 2 f[{_}] = 0 Now the actual recursion: f[{x_, rest__}] := f[{x, rest}] = If[Min[{x,rest}]<0, 0, ({rest}-1).Table[f[ReplacePart[{rest}, k -> ({rest}[[k]]-1)]], ...

Top 50 recent answers are included