New answers tagged

0

For the second time I shall recommend that you adopt a different method to recursive patterns. This method has demonstrable advantages of efficiency, brevity and evaluation control. The needed code: test[{_String, {___String}, {___String} | _?test | {__?test}}] = True; _test = False; Borrowing belisarius's examples for testing: lst // test ...


1

When recursion is involved I'm always tempted to use Fold. It pretty much imitates memoization, since it stores all previous values. conw[n_] := Module[{}, fc[x_List, m_] := Append[x, (x[[x[[m - 1]]]] + x[[m - x[[m - 1]]]])]; If[0 < n <= 2, ConstantArray[1, n], Fold[fc, {1, 1}, Range[3, n]]] ]; conw[10] (* {1, 1, 2, 2, 3, 4, 4, 4, ...


2

There are two ways to go about this problem. The heads on approach is to simply run a function which does what you ask for; conwayschallenge[n_] := If[n == 1 || n == 2, 1, conwayschallenge[conwayschallenge[n - 1]] + conwayschallenge[n - conwayschallenge[n - 1]]] However, you will find that this is very slow. conwayschallenge[25]//Timing --> ...


0

One more possibility would be to directly manipulate lists of coefficients of polynomials. To do that, we need to define a few required operations: SetAttributes[{add, mult}, Orderless]; add[c1_?VectorQ, c2_?VectorQ] := Total[PadRight[{c1, c2}]]; mult[{0}, c2_?VectorQ] := {0}; mult[c1_?VectorQ, c2_?VectorQ] := ListConvolve[c1, c2, {1, -1}, 0]; diff[{_}] := ...


1

One way to debug what's going on is to limit how many times FixedPointList can iterate (which the OP shows in another form). FixedPointList[# /. {{s___List, w_String, x_String, r___} /; StringTake[w, 1] == StringTake[x, 1] :> {s, {w, x}, r}, {s___List, w_String, x_String, r___} :> {s, x, r}(*, {s___List}\[RuleDelayed]{s}*)} &, ...


4

Thanks for J.M.'s suggestion and happlyfish's hint:) coeff[u_, U_, i_, p_] := If[U[[i + p + 1]] != U[[i + 1]], (u - U[[i + 1]])/(U[[i + p + 1]] - U[[i + 1]]), 0] compiledNonzeroBasis= ReleaseHold[ Hold@Compile[{{p, _Integer}, {u, _Real, 1}, {u0, _Real}}, With[{i = searchSpan[{p, u}, u0]}, Module[ {lst = Table[0., {p + 2}, {p + 1}], cc = ...


3

If you want recursion, write recursively. dualF[Not[p_]] := Not[dualF[p]] dualF[And[p_, q_]] := Not[Or[Not[dualF[p]], Not[dualF[q]]]] dualF[Or[p_, q_]] := Not[And[Not[dualF[p]], Not[dualF[q]]]] dualF[p_Symbol] := p then dualF[p && (q || r)] ! (! p || (! q && ! r)) which has the truth table which is same as


1

Just for fun: fun[num_] := Module[{s}, s = Normal@Series[-(x/(-1 + x + x^2)), {x, 0, num}]; s /. {x :> Row[{Style[1, Red, Bold], x}], x^n_ :> Row[{Style[1, Red, Bold], x^n}], a_ x^n_?NumericQ :> Row[{Style[a, Red, Bold], x^n}]}] vis[n_] := Module[{ser = fun[n], tab}, tab = Table[{Text[ser[[j]], {j, Fibonacci[j] + 0.2 n}], ...


0

Manipulate[ListPlot[Fibonacci[Range[u]], Filling -> Axis], {u, 1, 20, 1}] or Manipulate[DiscretePlot[Fibonacci[t], {t, 1, u, 1}, Filling -> Axis], {u, 1, 20, 1}] or Manipulate[DiscretePlot[SeriesCoefficient[Series[x/(1 - x - x^2), {x, 0, u}], t], {t, 1, u, 1}, Filling -> Axis], {u, 1, 20, 1}] to get


2

This is a "computer assisted" solution rather than certified closed form but it may satisfy your needs. F1[n_, t_] := F1[n, t] = If[n >= 1, F1[n - 1, 2 t], t]; Table[F1[n, t], {n, 0, 10}] FindSequenceFunction[%] output : {t, 2 t, 4 t, 8 t, 16 t, 32 t, 64 t, 128 t, 256 t, 512 t, 1024 t} 2^(-1 + #1) t & and F2[n_, y_, t_] := F2[n, y, t] = If[n ...



Top 50 recent answers are included