Volker,
I am writing somewhat hesitatently, since it's not my intent to talk anybody
out of writing something useful. So, I ask for your forgiveness if I am just
missing something obvious, but it seems to me that much of the functionality
you propose already exists.
For instance, while there are differences in detail, I get much the same
functionality that you propose if I just do this:
vector([elements]):=transpose(matrix(elements));
which lets me define a vector as a column matrix. Some of the code from your
example then would look like this:
(%i1) vector([elements]):=transpose(matrix(elements));
(%o1) vector([elements]) := transpose(matrix(elements))
(%i2) v:vector(a,b);
[ a ]
(%o2) [ ]
[ b ]
(%i3) w:vector(c,d);
[ c ]
(%o3) [ ]
[ d ]
(%i4) m:matrix([i,j],[p,q]);
[ i j ]
(%o4) [ ]
[ p q ]
(%i5) declare(x,nonscalar);
(%o5) done
(%i6) v+v;
[ 2 a ]
(%o6) [ ]
[ 2 b ]
(%i7) v+w;
[ c + a ]
(%o7) [ ]
[ d + b ]
(%i8) v.w;
(%o8) b d + a c
(%i9) x*v;
[ a ]
(%o9) x [ ]
[ b ]
(%i10) s*v;
[ a s ]
(%o10) [ ]
[ b s ]
(%i11) alias(vec,vector);
(%o11) [vec]
(%i12) plane1:vec(1,2,3)+p*vec(4,5,6)+q*vec(7,8,9);
[ 7 q + 4 p + 1 ]
[ ]
(%o12) [ 8 q + 5 p + 2 ]
[ ]
[ 9 q + 6 p + 3 ]
(%i13) plane2:s*vec(9,8,7)+r*vec(6,5,4)+vec(3,2,1);
[ 9 s + 6 r + 3 ]
[ ]
(%o13) [ 8 s + 5 r + 2 ]
[ ]
[ 7 s + 4 r + 1 ]
(%i14) map("=",transpose(plane1)[1],transpose(plane2)[1]);
(%o14) [7 q + 4 p + 1 = 9 s + 6 r + 3, 8 q + 5 p + 2 = 8 s + 5 r + 2,
9 q + 6 p + 3 = 7 s + 4 r +
1]
(%i15) algsys(%,[p,q,r,s]);
16 %r2 + 13 %r1 + 16
(%o15) [[p = %r1, q = %r2, r = - --------------------,
3
13 %r2 + 10 %r1 +
10
s =
--------------------]]
3
There are, of course, some differences. You propose not to simplify
automatically expressions such as v.w; perhaps that is a good thing, but one
can already achieve that by quoting:
(%i16) 'v.'w;
(%o16) v . w
(%i17) %,eval;
(%o17) b d + a c
Another distinction is that your scheme doesn't differentiate row and column
matrices, whereas in my example, we get an error:
(%i18) v.m;
incompatible dimensions - cannot multiply
-- an error. To debug this try debugmode(true);
Personally, I don't see this is a problem though, on the contrary: often, it
is important to treat row and column vectors as distinct types of entities,
both for pedagogical reasons and also in practical situations when the
underlying coordinate system is not rectilinear. In any case, when we wish
to multiply a row vector with a matrix on the right, we can always write
(%i19) transpose(v).m;
(%o19) [ b p + a i b q + a j ]
What do you think?
Viktor
-----Original Message-----
From: maxima-bounces at math.utexas.edu [mailto:maxima-bounces at math.utexas.edu]
On Behalf Of van Nek
Sent: Monday, November 17, 2008 5:07 PM
To: Maxima at math.utexas.edu
Subject: proposal about vectors
According to the recent discussion I propose the following
basic conception for vectors:
(%i1) load("vectors.lisp")$
(%i2) v: vector(a,b)$
(%i3) w: vector(c,d)$
(%i4) m: matrix([i,j],[p,q])$
(%i5) declare(s, scalar)$
(%i6) display2d: false$
(%i7) stardisp: true$
Implicit simplification:
(%i8) v+v;
(%o8) 2*vector(a,b)
(%i9) v+w;
(%o9) vector(c,d)+vector(a,b)
(%i10) v-v;
(%o10) vector(0,0)
(%i11) 0*v;
(%o11) vector(0,0)
(%i12) v*x;
(%o12) x*vector(a,b)
commutative, non-vector x is displayed left
(%i13) s*v;
(%o13) s*vector(a,b)
(%i14) v.w;
(%o14) vector(a,b) . vector(c,d)
(%i15) m.v;
(%o15) matrix([i,j],[p,q]) . vector(a,b)
Explicit simplification:
(%i16) v+w, vector_simp;
(%o16) vector(c+a,d+b)
(%i17) x*v, vector_simp;
(%o17) x*vector(a,b)
(%i18) s*v, vector_simp;
(%o18) vector(s*a,s*b)
(%i19) v.w, vector_simp;
(%o19) b . d+a . c
(%i20) w.v, vector_simp;
(%o20) d . b+c . a
(%i21) m.v, vector_simp;
(%o21) vector(j . b+i . a,q . b+p . a)
(%i22) v.m, vector_simp;
(%o22) vector(a,b) . matrix([i,j],[p,q])
(%i23) x.v, vector_simp;
(%o23) x . vector(a,b)
(%i24) v.x, vector_simp;
(%o24) vector(a,b) . x
(%i25) declare(a,scalar)$
(%i26) v.w, vector_simp;
(%o26) b . d+a . c
(%i27) dotscrules:true$
(%i28) v.w, vector_simp;
(%o28) a*c+b . d
Reconstruction of multiplicative and additive expressions:
(%i29) vector_rebuild( vector(s*a+c,s*b+d), [s] );
(%o29) vector(c,d)+s*vector(a,b)
This conception uses as few as possible implicit simplification
and allows to reconstruct results of multiplicative-additive
computations in a readable form. E.g. a working example:
(%i1) load("vectors.lisp")$
(%i2) alias(vec, vector)$
(%i3) display2d:false$
(%i4) declare([p,q,r,s,u,v],scalar)$
(%i5) plane1: vec(1,2,3)+p*vec(4,5,6)+q*vec(7,8,9);
(%o5) q*vec(7,8,9)+p*vec(4,5,6)+vec(1,2,3)
(%i6) plane2: vec(3,2,1)+r*vec(6,5,4)+s*vec(9,8,7)$
(%i7) veq: rhs(plane1) = rhs(plane2);
(%o7) q*vec(7,8,9)+p*vec(4,5,6)+vec(1,2,3) =
s*vec(9,8,7)+r*vec(6,5,4)+vec(3,2,1)
(%i8) map(disp, sys: extract_equations(veq))$
7*q+4*p+1 = 9*s+6*r+3
8*q+5*p+2 = 8*s+5*r+2
9*q+6*p+3 = 7*s+4*r+1
(%i9) params: algsys(sys,[p,q,r,s]);
(%o9) [[p = %r1,q = %r2,r = -1/3*(16*%r2+13*%r1+16),s =
1/3*(13*%r2+10*%r1+10)]]
(%i10) params: params, %r1=u, %r2=v$
(%i11) plane1, params;
(%o11) v*vec(7,8,9)+u*vec(4,5,6)+vec(1,2,3)
(%i12) plane2, params;
(%o12)
1/3*(13*v+10*u+10)*vec(9,8,7)-1/3*(16*v+13*u+16)*vec(6,5,4)+vec(3,2,1)
(%i13) vector_rebuild(plane2,[v,u]), params;
(%o13) v*vec(7,8,9)+u*vec(4,5,6)+vec(1,2,3)
Display properties:
(%i1) load("vectors.lisp")$
(%i2) alias(vec,vector)$
(%i3) v: vec(1,2);
[ 1 ]
(%o3) [ ]
[ 2 ]
(%i4) [vectorp(v), matrixp(v), listp(v)];
(%o4) [true, false, false]
(%i5) vector_display2d:false$
(%i6) w: apply(vec,[3,4]);
(%o6) [3, 4]
(%i7) [vectorp(w), matrixp(w), listp(w)];
(%o7) [true, false, false]
alternatively
vector_display2d: col, row or text
with mode col and row like above and text like
(%i3) v: vec(1,2);
(%o3) vector(1,2)
Volker van Nek