Question: Experimental format for projective vectors

I am experimenting using the this format of  Vector( [Vector] ) to make projective vectors a different data type to Vectors. I don't want to use 1 x 3 or 3 x 1 matrices. The format holds some promise.
I would like to be able to copy the Maple format of Vector or Vector[column]    and Vector[row] for my varaition. 

ProjVectoC and ProjVectorR    so ProjVector or ProjVector[column]   and ProjVector[row]
A secondary question  is on type checking (see previous question How to setup special type check in a procedure? - MaplePrimes  ). Would it be possible to have the type check return ProjVector[column] or ProjVector[row]?
The attached worksheet contains a procedure for factor reducing the vectors to to a minimal format of <x,y,z>. Also   Cross product and Dot product procedures to suit.

I am open to any efficiency improvements.

restart

interface(rtablesize=50)

[10, 10]

(1)

with(LinearAlgebra):

 

FactReduce:=overload([
     proc(v::{list,Vector})
          option overload;
          description " removes linear factor from",
                      " a list, vector, matrix or expression";
          uses LinearAlgebra;
          local i, num,tgdc,dnm, V1;
          num:=`ifelse`(type(v,Vector),numelems(v),nops(v));
          dnm:=frontend(lcm, [seq(denom(v[i]),i=1..num)]);
          V1:=radnormal(v*~dnm);
          tgdc:=V1[1];

          for i from 2 to num do
               tgdc:=frontend(gcd, [tgdc, V1[i]]);
          end do;

          return  simplify(V1/~tgdc);
     end proc,

     proc(M::{Matrix})
          option overload;
          uses LinearAlgebra;
          local i, num,r,c, tgdc,dnm, V1, Ml;
          r,c:=Dimension(M);
          num:=r*c;
          V1:=convert(M,list);
          dnm:=frontend(lcm, [seq(denom(V1[i]),i=1..num)]);
          Ml:=radnormal(dnm*~M);
          V1:=convert(Ml,list);#print((dnm,V1));
          tgdc:=V1[1];#print("xx")

          for i from 2 to num do
               tgdc:=frontend(gcd, [tgdc, V1[i]])
          end do;

          return  simplify(Ml/~tgdc);   
     end proc,

     proc(l::{`+`,`*`,`=`, `symbol`,procedure},  {vars::list:=[:-x,:-y]})
          option overload;
          uses LinearAlgebra;
          local i, num,f1,f1a,lv,lr, tgdc,dnm, V1,Vs;
          f1 := `if`(l::procedure, l(vars[]), l);
               f1a:=`if`(f1::`=`,lhs(f1)-rhs(f1),f1)  ; # Remequal(f1);
          lr:=primpart(f1a,vars);
          return lr
end proc

]):

ProjVectorC := proc(a, b, c)
local cfs, vectr;
description " A Projective Column (Line) Vector in Reduced format";
cfs := FactReduce([a, b, c]);
vectr := <[<cfs>]>;
end proc:

 

ProjVectorR := proc(a, b, c)
local cfs, vectr;
description " A Projective Row (Point) Vector";
cfs := sign(c)*FactReduce([a, b, c]);
vectr := <[<cfs>^%T]>^%T;
end proc:

 

`&otimes;` := proc(A, B)
local cp;
description "Cross Product of Projective Vectors in Reduced format";
cp :=sign(c)* FactReduce(LinearAlgebra:-`&x`(A[1], B[1]))^%T;
cp := ifelse(cp[3] <> 0, <[sign(cp[3]) *~ cp]>, cp); #makes sure format is [x,y,z] and not [x,y-z]
end proc:

 

`&odot;` := proc(A, B)
description "Dot Product of Projective Vectors";
(A[1]) . (B[1]);
end proc:

 

V := ProjVectorR(2, 4, -6); W := ProjVectorR(11, 7, 5); S := ProjVectorC(6, -18, 24)

Vector[column](%id = 36893490982610361748)

(2)

whattype(V); `~`[whattype](V)

Vector[row](%id = 36893490982610825812)

(3)

whattype(S); `~`[whattype](S)

Vector[column](%id = 36893490982626471436)

(4)

`~`[whattype](V[1])

Vector[row](%id = 36893490982558545668)

(5)

V[1] . V[1]

14

(6)

`&odot;`(V, V)

14

(7)

R := `&otimes;`(W, V)

Vector[column](%id = 36893490982630825980)

(8)

R := `&otimes;`(V, W)

Vector[column](%id = 36893490982630903548)

(9)

whattype(R)

Vector[column]

(10)

`~`[whattype](R)

Vector[column](%id = 36893490982598861396)

(11)

`~`[whattype](R[1])

Vector[column](%id = 36893490982598866092)

(12)

`&otimes;`(R, S)

Vector[column](%id = 36893490982624872076)

(13)

`&odot;`(R, S)

-85

(14)

`&odot;`(W, R)

0

(15)

`&odot;`(R, `<,>`([`<,>`(x, y, 1)]))

15-31*x+38*y

(16)
 

 

Download 2024-11-21_Q_Projective_Vector_Format.mw

Please Wait...