I want to do the following:
f[x_] := If[OddQ[x[[1]]], Nothing, x/2 // Simplify]
A = Table[2 (n + k), {k, 0, 4}]/2
n = 2 n1;
f /@ A
n = 2 n1 + 1;
f /@ A
This outputs the following:
{n, 1 + n, 2 + n, 3 + n, 4 + n}
{n1, 1 + n1, 2 + n1}
{1 + n1, 2 + n1}
That is: It takes the list A, makes a substitution, sieves out whatever has an odd constant. Now I want to do apply the same process to the second and third list, and then to the second and third list of the previous ones, etc. This will yield a binary tree structure but I have no idea how to do that in Mathematica. Can you help me? I'm not sure if the tagging is correct, tho.
EDIT: I'll write a simpler example that If solved, I could use it to my original problem. Suppose I want to program the following:
That is: It starts with $a$, if it moves to the left, it concatenates $a$ on the left and we get $aa$, if it moves to the left, it concatenates $b$ to the left so we get $ab$ and then, we proceed this way and build the tree. Now, I want to store every level of the tree so that I can show it in a graph such as the one in here. I've been thinking and I guess I could make some elementary program to do this but it is possible that Mathematica already has some neat stuff for this?
n1
then does this get removed, or does it get changed ton1/2
? $\endgroup$Select
to "sieve out by retention" (that is, keeping only the ones you want). (2) You can useFixedPoint
to stop the sieving once the set stabilizes. (3) It is not really safe to assume the constant (which might be zero) is found asx[[1]]
. I recommend instead finding the variable(s) in the list, call themvars
, and determining whether constant term is odd using e.g.OddQ[x/.Thread[vars->0]]
. $\endgroup$