After making a new type, it's desirable to install methods for displaying the instances of the new type in various formats.
i1 : Qu = new Type of List |
i2 : w = new Qu from {1,-2,0,4} |
For example, it's desirable to display the quaternion above so it looks like a quaternion. One way to achieve this is to install first a method for creating an Expression from a quaternion, since there are methods already installed for converting expressions to common forms of output, such as to nets, which are used most commonly.
i3 : expression Qu := z -> ( |
i4 : net Qu := z -> net expression z; |
i5 : toString Qu := z -> toString expression z; |
i6 : tex Qu := z -> tex expression z; |
i7 : html Qu := z -> html expression z; |
i8 : w |
i9 : toString w |
i10 : tex w |
i11 : html w |
Of course, now that we've decided that there should be certain quaternions called I, J, and K, perhaps we should install them, too.
i12 : I = new Qu from {0,1,0,0} |
i13 : J = new Qu from {0,0,1,0} |
i14 : K = new Qu from {0,0,0,1} |
i15 : 2*I + 5*J |
i16 : peek oo |