Here is a toy example to illustrate my problem. I have a list of 3-tuples and I want to delete elements from this list that satisfy a condition shown below.
tuples = Tuples[{-1, -2, 3}, {3}];
DeleteCases[tuples, _?((#[[1]] + 2 #[[2]] + #[[3]] == 0) &)]
This works perfectly. However, because each element of tuples
has this form {a,b,c}
and symbols a, b, c
have problem-specific meanings attached to them, the code would become more readable if written as follows:
tuples = Tuples[{-1, -2, 3}, {3}];
DeleteCases[tuples, _?((a + 2*b + c == 0) &)]
The motivation is that a + 2*b + c == 0
is easier for a human to read and understand than (#[[1]] + 2 #[[2]] + #[[3]] == 0
.
Question Is it possible to write this code using variables instead of slots?
Pick[tuples,Unitize@Total[Transpose[tuples]*{1, 2, 1}], 1]
$\endgroup$Unitize[tuples . {1, 2, 1}]
for the selection vector. $\endgroup$