# Select elements in a list of tuples of quaternions that satisfy a condition

I defined 24 quaternions using the Quaternions package and i create the list of all possible 4-tuples using

ListQuad = Tuples[ListQuaternions, 4]


where ListQuaternions is the list of the 24 elements I defined. Now I would like to select all the 4-tuples such that the product of the four quaternions is equal to Quaternion[1, 0, 0, 0].

I tried to use this:

Select[ListQuad,{x_, y_, z_, w_} /; x ** y ** z ** w == Quaternion[1, 0, 0, 0] &]


but this gives me an empty list, which I'm sure it can't be true because I know that some 4-tuples satisfy that condition.

I don't understand what I'm doing wrong. Probably the condition I put in the Select command?

• You might want to use Select[ListQuad, (x ** y ** z ** w == Quaternion[1, 0, 0, 0]) &] instead. In general, you have to decide whether to use Select (function based selection) or Cases (pattern based selection). – Henrik Schumacher Oct 3 '18 at 10:48
• I tried also the solution you wrote me but it still gives me an empty list. probably there is something wrong in the definition of the list. Thank you so much! – B.manca Oct 3 '18 at 15:10

Henrik has already mentioned Select[] and Cases[]. For this answer, I'll show how to use Pick[]:

<< Quaternions

ListQuaternions = UnitQuaternions;

The slightly complicated condition in Pick[] is necessitated by the fact that Equal (==) cannot handle quaternions; e.g. Quaternion[1, 0, 0, 0] == Quaternion[-1, 0, 0, 0] remains unevaluated.
• Thank you so much! I didn't know the Pick[] command, also the lengths of ListQuad and sel` coincide with the numbers I know I should get. – B.manca Oct 3 '18 at 15:11