I have this code to replace the data of each row in a specific function and display a new column showing the values of the function
RS = 1 - (1 - Subscript[x, 1] Subscript[x, 2]) (1 -
Subscript[x, 1] Subscript[x, 3]);
(data = Tuples[{0, 1}, 3]) // MatrixForm; LLR = {Block[{Subscript},
Do[Subscript[x, j] = Transpose[data][[j]], {j, 3}]; RS]};
(table = Prepend[
Transpose@Join[{Range@Length@data}, Transpose@data, LLR],
Flatten[{"order", Subscript["x", #] & /@ Range[3], "H"}]]) //
Grid[#, Frame -> All] &
I am looking for taking the complement of each column separately ($1-x_1$,$1-x_2$,$1-x_3$) and substituting the complement with the rest of the columns and displaying the result of the function in another columns ($H1,H2,H3$).
In other words, the complement of the first column ($1-x_1$) with the second ($x_2$ and third ($x_3$) columns gives $H1$, ($1-x_2$) with ($x_1$ and ($x_3$) gives $H2$, ($1-x_3$) with ($x_1$ and ($x_2$) gives $H3$
My attempts gave accurate results but the code seems to be useless in more general cases. When the number of variables increases.
RS = 1 - (1 - Subscript[x, 1] Subscript[x, 2]) (1 -
Subscript[x, 1] Subscript[x, 3]);
RS1 = 1 - (1 - Subscript[x, 1] Subscript[x, 2]) (1 -
Subscript[x, 1] Subscript[x, 3]) /.
Subscript[x, 1] -> (1 - Subscript[x, 1]) ;
RS2 = 1 - (1 - Subscript[x, 1] Subscript[x, 2]) (1 -
Subscript[x, 1] Subscript[x, 3]) /.
Subscript[x, 2] -> (1 - Subscript[x, 2]) ;
RS3 = 1 - (1 - Subscript[x, 1] Subscript[x, 2]) (1 -
Subscript[x, 1] Subscript[x, 3]) /.
Subscript[x, 3] -> (1 - Subscript[x, 3]) ;
(data = Tuples[{0, 1}, 3]) // MatrixForm; LLR = {Block[{Subscript},
Do[Subscript[x, j] = Transpose[data][[j]], {j, 3}]; RS]};
LLR1 = {Block[{Subscript},
Do[Subscript[x, j] = Transpose[data][[j]], {j, 3}]; RS1]};
LLR2 = {Block[{Subscript},
Do[Subscript[x, j] = Transpose[data][[j]], {j, 3}]; RS2]};
LLR3 = {Block[{Subscript},
Do[Subscript[x, j] = Transpose[data][[j]], {j, 3}]; RS3]};
(table = Prepend[
Transpose@
Join[{Range@Length@data}, Transpose@data, LLR, LLR1, LLR2, LLR3],
Flatten[{"order", Subscript["x", #] & /@ Range[3], "H", "H1",
"H2", "H3"}]]) // Grid[#, Frame -> All] &
I have put a condition on the function and duplicated the code... but this seems to be useless in general.
I am looking for better dynamics for the code in more general cases.
Thanks a lot for the help
x4
(and thenx5
, etc)? So your core data structure would beTuples[{0, 1}, n]
where you started with n = 3 and you want to expand to n > 3, is that right? $\endgroup$Tuples[{0, 1}, 10]
and the variables are $x_1,x_2,...,x_{10}$ $\endgroup$RS
should be generated. For the n = 3 case, we took all pairs that includedx1
(so we excluded the term that would have usedx2 x3
). So, for n = 4 will we take the terms built fromx1 x2
,x1 x3
, andx1 x4
? That's half of the possible 6 ways to pair up the terms. Or is it a more complicated rule? $\endgroup$RS=1-(1-x1 x2)(1-x3 x4)
and for n=5,RS=1-(1-x1)(1-x2)(1-x4)(1-x3 x5)
. Can the function be considered an input and may change? $\endgroup$