LijiH

90 Reputation

7 Badges

13 years, 40 days

MaplePrimes Activity


These are replies submitted by LijiH

first of all, thank you for your help.

yes what I am doing is trying to write my own quaternion package.

the one written by Michael Carter from Purdue University uses the following:

proc () [`*` = Quaternions:-`*`] end proc

#so * points to Quaternions:-`*`, so let's see what Quaternions:-`*` is.

readlib(Quaternions:-`*`)

proc (qx::quaternion, qy::quaternion)
    options overload;
    if type(qx, complex) and type(qy, complex) then
        return qx*qy
    end if;
    try
    return `Quaternions:-Qmult`(qx, qy)
    catch:
    return qx*qy
    end try
end proc

#so we need to know what Quaternions:-Qmult is:

readlib(Qmult);
proc (qx::quaternion, qy::quaternion)
    local q, q1, q2;
    q1 := Qeval(qx);
    q2 := Qeval(qy);
    if is(q1, real) or is(q2, real) then
        return Qeval(q1*q2)
    end if;
    try q := Qeval(linalg[multiply](q1, q2)) catch:
        return q1*q2
    end try;
    if not is(q, quaternion) then
        Qeval(evalf(q))
    else
        return q
    end if
end proc

#so all of this depend on Qeval:

readlib(Qeval);
proc(q1)
    local q:=q1;
    try
        if type(evalm(q),'matrix'(square)) then
            return sort(collect(expand(linalg[trace](linalg[submatrix](q,1..1,1..1))+linalg[trace](linalg[submatrix](q,1..1,2..2))*'i'+linalg[trace](linalg[submatrix](q,3..3,2..2))*'j'+linalg[trace](linalg[submatrix](q,3..3,1..1))*'k'),{i,j,k}),[k,j,i],ascending)
        else
            return sort(expand(q),[k,j,i],ascending)
        end if
    catch:
        return eval(q1)
    end try
end proc

 

Now, on the other hand, my approach is somewhat completely different.

I want to define the quaternion multiplication rules first, so

define(M, 'flat', 'multilinear', 'identity' = 1,
M(I,I)=-1, M(J,J)=-1, M(K,K)=-1, M(I,J)=K, M(J,I)=-K, M(J,K)=I, M(K,J)=-I, M(I,K)=-J, M(K,I)=J);

and then somehow extend '*' so that it does what M does when it sees I/J/K.

thanks again acer.

thanks again acer.

@acer 

thanks acer.

@acer 

thanks acer.

thanks!

is there anyway to add more things to my Helloworld module? for example, i want to squeeze in all of the following into my Helloworld module...

restart;interface(imaginaryunit=ii):
with(PolynomialTools):with(RandomTools):
protect('I');protect('J');protect('K');
define(M, 'flat', 'multilinear', 'identity' = 1,
M(I,I)=-1, M(J,J)=-1, M(K,K)=-1, M(I,J)=K, M(J,I)=-K, M(J,K)=I, M(K,J)=-I, M(I,K)=-J, M(K,I)=J);

basically this is what i want Maple to do when people type with(Helloworld),
1, it will restart the workspace.
2, it will use packages PolynomialTools and RandomTools.
3, it will protect the letters I, J and K.
4, define M, which is not a proc but will be used in some proc that Helloworld offers.

thanks!

is there anyway to add more things to my Helloworld module? for example, i want to squeeze in all of the following into my Helloworld module...

restart;interface(imaginaryunit=ii):
with(PolynomialTools):with(RandomTools):
protect('I');protect('J');protect('K');
define(M, 'flat', 'multilinear', 'identity' = 1,
M(I,I)=-1, M(J,J)=-1, M(K,K)=-1, M(I,J)=K, M(J,I)=-K, M(J,K)=I, M(K,J)=-I, M(I,K)=-J, M(K,I)=J);

basically this is what i want Maple to do when people type with(Helloworld),
1, it will restart the workspace.
2, it will use packages PolynomialTools and RandomTools.
3, it will protect the letters I, J and K.
4, define M, which is not a proc but will be used in some proc that Helloworld offers.

@Alec Mihailovs 

 

ok thanks!

@Alec Mihailovs 

 

ok thanks!

I appreciate the sense of humor.

are you saying that builtin functions like `*` are written in C and therefore are fundamentally different from user-defined "proc"?

I appreciate the sense of humor.

are you saying that builtin functions like `*` are written in C and therefore are fundamentally different from user-defined "proc"?

1 2 3 4 5 Page 5 of 5