2
$\begingroup$

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?

$\endgroup$
2
  • $\begingroup$ 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). $\endgroup$ Commented Oct 3, 2018 at 10:48
  • $\begingroup$ 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! $\endgroup$ Commented Oct 3, 2018 at 15:10

1 Answer 1

1
$\begingroup$

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

<< Quaternions` ListQuaternions = UnitQuaternions; ListQuad = Tuples[ListQuaternions, {4}]; prods = NonCommutativeMultiply @@@ ListQuad; sel = Pick[quads, Map[Norm, prods - Quaternion[1, 0, 0, 0]], 0]; {Length[ListQuad], Length[sel]} {331776, 13824} 

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.

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$ Commented Oct 3, 2018 at 15:11

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.