Tag Info

New answers tagged

7

It seems, that findExponentialGeneratingFunction would be equivalent to FindGeneratingFunction of the sequence {a1/0!,a2/1!,a3/2!,...}. Therefore findExponentialGeneratingFunction = FindGeneratingFunction[#1/(Factorial /@ Range[0, Length@#1 - 1]), #2] & findExponentialGeneratingFunction[{1,1,1,1,1,1,1,1},x] (* Exp[x] *)


4

Select[Permutations[A, {3}], Greater @@ # &]


2

Expanding a little on the OP's problem, here is an alternative method based on pattern matching: SeedRandom[1] set = RandomInteger[100, 5] Cases[Permutations[set, {3}], {___, x_, ___, y_, ___, z_, ___} /; x > y > z] Here is the set: {80, 14, 0, 67, 3} And here are the desired permutations: { {80, 14, 0}, {80, 14, 3}, {80, 67, 14}, {80, ...


8

Subsets[Reverse@Range[5], {3}] (* {{5, 4, 3}, {5, 4, 2}, {5, 4, 1}, {5, 3, 2}, {5, 3, 1}, {5, 2, 1}, {4, 3, 2}, {4, 3, 1}, {4, 2, 1}, {3, 2, 1}} *) Reverse /@ Subsets[Range[5], {3}] (* {{3, 2, 1}, {4, 2, 1}, {5, 2, 1}, {4, 3, 1}, {5, 3, 1}, {5, 4, 1}, {4, 3, 2}, {5, 3, 2}, {5, 4, 2}, {5, 4, 3}} *)


2

For your second problem, use IntegerDigits, MemberQ and Select to find elements of the sequence that do not (!MemberQ[...,3]) have a 3 digit ... Select[RecurrenceTable[{a[n+1]==11*a[n],a[1]==7}, a[n], {n,1,11}],!MemberQ[IntegerDigits@#,3]&] (* results {7, 77, 847, 102487, 12400927, 1500512167, 181561972207} *)


2

For a reasonable number of items, make them all and delete the ones you don't want. A = {x, y, z, w, t}; DeleteCases[Permutations[A, {4}], {___, t, ___, z, ___}]


6

For n terms there are $2^{n-1}$ arrangements of signs of terms after first term. If the aim (for small n) is to display some examples of all sign arrangements for n-1 terms after first term then here is a way. There are doubtless much better ways. f[n_?Positive] := With[{t = Tuples[{-1, 1}, n - 1], s = Tuples[{"-", "+"}, n - 1], sq = HoldForm[#^2] ...


7

f[list_] := Join @@ (Tuples[ Transpose[{#, 1/#}] ] & /@ Subsets[list, {1, ∞}]) f[{2,3,4}] {{2}, {1/2}, {3}, {1/3}, {4}, {1/4}, {2, 3}, {2, 1/3}, {1/2, 3}, {1/2, 1/3}, {2, 4}, {2, 1/4}, {1/2, 4}, {1/2, 1/4}, {3, 4}, {3, 1/4}, {1/ 3, 4}, {1/3, 1/4}, {2, 3, 4}, {2, 3, 1/4}, {2, 1/3, 4}, {2, 1/3, 1/ 4}, {1/2, 3, 4}, {1/2, 3, 1/4}, {1/2, ...


5

A couple of ideas come to mind. Here's one approach - get all subsets of a list of equal length in symbolic form, then iterate each symbol over the member of the list and its inverse. list = {2, 3}; Flatten[ Table[ Evaluate@Subsets[Array[f, Length[list]], {1, Infinity}], Evaluate@ (Sequence @@ Array[{f[#], {list[[#]]^-1, list[[#]]}} &, ...


5

I propose: errorOps[n_, w_] := Module[{masks, tup}, masks = Permutations[Join @@ ConstantArray @@@ {{1, w}, {0, n - w}}]; tup = ArrayPad[{"X", "Y", "Z"} ~Tuples~ {w}, {0, {1, 0}}, "U"]; Join @@ Map[tup[[All, #]] &, 1 + masks (Accumulate /@ masks)] ] errorOps[10, 7] // Length // AbsoluteTiming {0.0406705, 262440} An alternate ...


4

Is this faster than the fastest of yours? xyz = {"X", "Y", "Z"}; ErrorOps[n_, w_] := Flatten[With[{tups = Tuples[xyz, w], R = Range[n]}, Table[R /. Join[Thread[Complement[R, i] -> j], Thread[i -> "U"]], {i, Subsets[R, {n - w}]}, {j, tups}]], 1]


1

In the spirit of the code review tag: This piece of code a = Table[1, {n, 1, k}]; nn = Length[a]; is better written as nn = 6; a = ConstantArray[1, nn]; because it makes the assignment of nn explicit. In your newer version of the code you could use k throughout, there is no reason to define nn. You're not often going to see experienced Mathematica ...


1

An alternative way to construct the matrix b: m = 6; aa = LowerTriangularize[ConstantArray[1, {m + 1, m}], -1]; bb = Join @@ Permutations /@ aa; bb == b (* True *)



Top 50 recent answers are included