Tag Info

New answers tagged

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)]], ...


1

Beware of "formal power series" of this type. I have an example of a very competent mathematics professional that led him into ?? land. Concerning your question let's look at the condition $a_0=0\cdot a_{-1} $ which is off the end but doesn't matter because it sets $a_0 = 0$ But by recursion this sets all $a_x = 0 $ So the relation can only be ...


11

foo = With[{f = #0}, (# /. {p___, a, b, c, q___} :> Join[{p, "abc"}, f @ {q}])] & lst = {1, 2, a, b, c, 3, {4, a, b, c}, 5}; foo@lst (* {1, 2, "abc", 3, {4, "abc"}, 5} *) This works because With automatically renames the patterns used in RuleDelayed since both are scoping constructs. Other constructs can be used as well such as RuleDelayed itself: ...


3

The RSolve result is bogus. You can simply plug into the recurrence relation to see that it's not satisfied. It's easy to roll your own, though. I guess the relationship between $q_1$ and $q_2$ can be expressed as q2[q1_] = q2 /. Solve[q2^2 + 3 q2 + 2 q2*q1 - 6 q1 + q1^2 == 0, q2] (* Out: {(-3 - 2 q1 - 3 Sqrt[1 + 4 q1])/2, (-3 - 2 q1 + 3 Sqrt[1 + 4 ...


2

A fix For s, you could use s = x \[Function] Piecewise[{{Cos[x], -Pi/2 <= Mod[x, 2 π, -π] <= Pi/2}}]; Integrate[s[t], {t, -8, 6}] (* 5 + Sin[6] *) The problem The problem with the original ff and s is that the function calls itself. Now consider ff[t] or s[t]. None of the conditions will evaluate to False so "the Piecewise function is returned ...


1

You could define your function as f[x_] := 2 Mod[x, 1] then Integrate[f[x], {x, 0, 5}] yields 5 (as expect 5 triangles of area 1) To plot: Plot[f[x], {x, -4, 4}, Exclusions -> None]



Top 50 recent answers are included