Discussion:
[Axiom-math] Very simple calculus on matrix and vector.
Francois Maltey
2006-02-24 20:19:19 UTC
Permalink
Hello,

Today I try to translate my first scholar work from mupad/maple to axiom.

With mupad/maple I have functions as :

kernel
find a basis (a list of vector) of the linear transform defined by a matrix
with axiom kernel is right.

basis
extract a basis from a family of vectors, the sub-family is linear free

sumBasis
compute a basis of a sum of space vectors defined by families of vectors
it isn't difficult to do when the basic function is defined.

intBasis
compute a basis of a intersect of space vectors.

linsolve
find a solution X of AX=B when A, B and X are matrix or vector.

Are theses functions present in axiom ?
I can't find it in the 30 years book.
Or must I play with kernel (horizConcat ...)

I can concat 2 vectors or 2 matrices with horizConcat.

U := vector [1,2,1]
V := vector [1,3,1]
W := vector [1,4,1]
M := horizConcat (U::Matrix Integer, V::Matrix Integer)

But can I concat 3 or 4 or more vectors with only ONE command ?

I don't know if I can define in axiom a function
with 1 or 2 or 3 or 4 ... arguments.
Sequences of maple or mupad allow this.
With axiom must I define a function with a list of arguments ?

Bill, Martin and others I don't forget to improve trigonometric expand.
But I prefer look an other aspect of axiom today.

Have a good day !

Francois
Ralf Hemmecke
2006-02-25 21:23:08 UTC
Permalink
Hello Francois
Post by Francois Maltey
But can I concat 3 or 4 or more vectors with only ONE command ?
I don't know if I can define in axiom a function
with 1 or 2 or 3 or 4 ... arguments.
Sequences of maple or mupad allow this.
With axiom must I define a function with a list of arguments ?
Well, I don't know whether I should call this a trick or not, but you
could achieve this easily in Aldor. There is something similar in Aldor.

In Aldor and Axiom you can write.

(4) -> (a, b) := (3, 5)

(4) 5
Type: PositiveInteger

Interestingly the type is shown as PositiveInteger.

In Aldor you would get

aldor -gloop
#include "aldor"
#include "aldorinterp"
import from Integer
(a, b) := (3, 5)
() @ AldorInteger, AldorInteger

which (interestingly) omits the parens around the type
AldorInteger, AldorInteger

(Note that in Aldor we have Integer==>AldorInteger.)

What you have seen is a "parallel assignment". And it also works in Axiom.

(5) -> a

(5) 3
Type: PositiveInteger
(6) -> b

(6) 5

It is interesting to analyse the type. It is something of the form
(X, X). That looks like a tuple. And in fact "Tuple" would be one
solution to your problem. Of course you can write a function that takes
a List as input as you suggested above.

However, if Axiom/Aldor sees an expression of the form

f x

it tries to find "f" and "x" with appropriate types. Now if x is of the
form (r,s,t) or (u,v) where all of the r,s,t,u,v are of the same type X.
Then the type for f must be "(X, X, X) -> Y" or "(X, X) -> Y".
But that is not all. What about "Tuple X -> Y"?
(r,s,t) and (u,v) are perfect elements of "Tuple X".

Basically, that says, instead of writing a function that takes arbitrary
elements, we are going to write a function that takes just one element.
However, the elements are (mathematically) elements of

\bigcup_{n\in N}X^n ((the union of any power of X))

Here is an example in Aldor... (compile it on the command line, no Axiom
is needed)
---- mysumaldor.as -------
-- aldor -grun -laldor mysumaldor.as
--empty sum = 0
--sum(2) = 2
--sum(2,3) = 5
--sum(2,3,5) = 10
#include "aldor"

macro {
Z == Integer;
P == PrimitiveArray Z;
}
MySum: with {
mysum: Tuple Z -> Z;
} == add {
mysum(t: Tuple Z): Z == {
import from MachineInteger;
local n: Z := 0;
for i in 1..(length t) repeat n := n + element(t, i);
n;
}
}

main(): () == {
import from MySum, Z, TextWriter, String, Character;
stdout << "empty sum = " << mysum() << newline;
stdout << "sum(2) = " << mysum(2) << newline;
stdout << "sum(2,3) = " << mysum(2,3) << newline;
stdout << "sum(2,3,5) = " << mysum(2,3,5) << newline;
}

main();
------ end mysumaldor.as


For Axiom the domain constructor "Tuple" has different exports. :-(
And there is a bug somewhere.

------ mysumaxiom.as
#include "axiom"

macro {
Z == Integer;
P == PrimitiveArray Z;
T == Tuple Z;
}
MySum: with {
mysum: T -> Z;
} == add {
mysum(t: T): Z == {
import from Z;
local n: Z := 0;
-- cannot use "select" because it is an Aldor keyword.
-- for i in 1..length t repeat n := n + select(t, n);
-- p: P := (coerce$T)(t)@P; -- strange that `t::P' does not work

-- Thirty trick due to a bug of Axiom/Aldor not finding "coerce".
-- Take representation of Tuple from src/algebra/array1.spad
R ==> Record(len: NonNegativeInteger, elts: P);
import from R;
p: P := (t pretend R).elts;
for i in 1..(length t)::Integer repeat n := n + p.i;
n;
}
}
----- end mysumaxiom.as

Well, it does not quite work in Axiom, but that seems only because I am
missing some "runtime.o". That is strange, because I have a runtime.lsp
in that directory and that should be enough for Axiom, shouldn't it?

Can someone explain the error message for mysumaxiom.as?

--(2) -> )co mysumaxiom.as
--(2) -> mysum()
--
-- >> System error:
-- Cannot open the file
-- /home/hemmecke/software/Axiom/mnt/linux/aldor/lib/runtime.o.
--
--(2) -> mysum(2)
--
-- >> System error:
-- Cannot open the file
-- /home/hemmecke/software/Axiom/mnt/linux/aldor/lib/runtime.o.

It is certainly easier if you write a function that works on List.
Anyway, if the compiler sees a "mysum(3,4,5)" in your code it will
internally create an array [3,4,5] and then hide this array by claiming
it to be a Tuple. But it means that the compiler has to use some extra
memory in order to store the tuple/array.

I hope, that helps. I'm sure you can translate the above code into
something that concatenates vectors.

Ralf
Francois Maltey
2006-02-26 19:21:25 UTC
Permalink
Thanks Ralf,
Post by Ralf Hemmecke
Post by Francois Maltey
But can I concat 3 or 4 or more vectors with only ONE command ?
I don't know if I can define in axiom a function with 1 or 2 or 3 or
4 ... arguments.
Sequences of maple or mupad allow this.
With axiom must I define a function with a list of arguments ?
I hope, that helps. I'm sure you can translate the above code into
something that concatenates vectors.
You don't loose your time, I discover Turple.

And it's also possible with reduce.

U1 := vector [1,2,3]
U2 := vector [2,2,3]
U3 := vector [3,2,3]
U4 := vector [4,2,3]
reduce ((u,v)+->horizConcat(u,v),
map (U +-> U::Matrix Integer, [U1,U2,U3,U4]))

Loading...