I want to input: Quaternion[1, 2, 3, 4] to get a list: {1,2,3,4}.

  • 2
    $\begingroup$ You could always just List @@ q (see Apply). But then you can do almost anything with q = Quaternion[1,2,3,4] that you can do with {1,2,3,4}. For example, you can extract the 2nd part as q[[2]], etc. I am a bit tempted to vote to close as simple mistake. If you disagree, can you elaborate? $\endgroup$
    – Szabolcs
    Commented Feb 4, 2016 at 10:49
  • $\begingroup$ @Szabolics Thank you. I was not aware that q[[2]] would extract the 2nd part. Now I am even more embarrassed to ask this question: I have: 7 + 5 Sqrt[2] but I want the list: {7,5}. $\endgroup$ Commented Feb 6, 2016 at 13:36
  • 1
    $\begingroup$ This second question is not a simple one. The difficulty is deciding (i..e precisely defining) why the second term should be 5 and not 5 Sqrt[2] or something else. If we treat Sqrt[2] as special, we can use CoefficientList[7 + 5 Sqrt[2], Sqrt[2]]. $\endgroup$
    – Szabolcs
    Commented Feb 8, 2016 at 10:35
  • $\begingroup$ Thank you very much Szabolics. I use CoefficientList quite often. I don't know why I did not think to try it here. $\endgroup$ Commented Feb 8, 2016 at 10:52


Browse other questions tagged or ask your own question.