|
(1) |
> |
test :=overload([
#1;
proc(p0::algebraic,$)
option overload;
[p0];
print("#1 single 1D input. No colour check required");
end,
#2;
proc(p0::algebraic,p1::algebraic,$)
option overload;
[p0,p1];
print("#2 pair of 1D inputs. No colour check required");
end,
#3;
proc(p0::{satisfies(s -> type(s, [algebraic $ 2])),'Vector[row]'(2, algebraic)},
clr::`string` := GCb,$)
option overload;
global GCb;
[p0,clr];
if clr="Blue" then
print("#3 input recognised 2D Point/Vector. Blue.") ;
elif clr= "Red" or clr="Green" then
print("#4 inputs recognised 2D Point/Vector. Red or Green");
end if;
end,
#4 If put before #3 causes false evaluation of #3 type input #4
# [p0,p1,clr] cures the problem because it itse the inputs ;
proc(p0::{satisfies(s -> type(s, [algebraic $ 2])),'Vector[row]'(2, algebraic)},
p1::{satisfies(s -> type(s, [algebraic $ 2])),'Vector[row]'(2, algebraic)},
clr::`string` := GCb,$)
option overload;
global GCb;
[p0,p1,clr];
if clr="Blue" then
print("#4 inputs recognised pair of 2D Points/Vectors.Valid for Blue.") ;
elif clr= "Red" or clr="Green" then
print("#4 inputs recognised pair of 2D Points/Vectors. Red or Green");
end if;
end,
#4X; If this is moved to before 4 causes false evaluation of #4 type input #4X
# [p0,p1,p2,clr] cures the problem because it itse the inputs;
proc(p0::{satisfies(s -> type(s, [algebraic $ 2])),'Vector[row]'(2, algebraic)},
p1::{satisfies(s -> type(s, [algebraic $ 2])),'Vector[row]'(2, algebraic)},
p2::{satisfies(s -> type(s, [algebraic $ 2])),'Vector[row]'(2, algebraic)},
clr::`string` := GCb,$)
option overload(callseq_only);
global GCb;
[p0,p1,p2,clr];
if clr="Blue" or clr="Red" or clr="Green" then
print("#4X inputs recognised Set of 3 2D Points/Vectors.Valid for Blue, Red & Green") ;
end if;
end,
#5;
proc(p0::{satisfies(s -> type(s, [algebraic $ 3])),'Vector[row]'(3, algebraic)},
clr::`string` := GCb,$)
option overload;
global GCb;
[p0,clr];
if clr="Blue" then
print("#5 inputs recognised single 3D Point/Vector");
else print("#5 error 3D Point/Vector only valid for Blue Geometry");
end if;
end,
#6;
proc(p0::{satisfies(s -> type(s, [algebraic $ 3])), 'Vector[row]'(3, algebraic)},
p1::{satisfies(s -> type(s, [algebraic $ 3])), 'Vector[row]'(3, algebraic)},
clr::`string` := GCb,$)
option overload;
global GCb;
[p0,p1,clr];
if clr="Blue" then
print("#6 inputs recognised pair of 3D Points/Vectors ") ;
else print("#6 3D points/vectors only valid for Blue Geometry");
end if;
end,
#7;
proc(p0::{satisfies(s -> type(s, [algebraic $ 2])),'Vector[row]'(2, algebraic)},
pl::{satisfies(s -> type(s, [algebraic $ 3])),'Vector[column]'(3, algebraic),`+`,procedure},var::satisfies(s -> type(s, [algebraic $ 2])):=[x,y],
clr::`string` := GCb,$)
option overload;
[p0,pl,clr];
print("#7 inputs recognised 2D Point and Line valid for Blue, Red & Green") ;
end,
#8;
proc(l1::satisfies(s -> type(s, [algebraic $ 3])),
l2::[{satisfies(s -> type(s, [algebraic $ 3])), 'Vector[row]'(3, algebraic)}, 'Vector[column]'(3, algebraic)],$)
option overload;
[l1,l2];
print("#8 inputs recognised 3D Point and 3D Line.No colour check Blue only");
end,
#9 if put before #5 it causes false evaluation of #5 type inputs as #9
# [p0,pl,vars] cure ;
proc(p0::{satisfies(s -> type(s, [algebraic $ 3])),'Vector[row]'(3, algebraic)},
pl::{'Vector[column]'(4, algebraic), `+`,procedure},var::satisfies(s -> type(s, [algebraic $ 3])):=[x,y,z],$)
option overload;
global gcb;
[p0,pl,vars];
print("#9 inputs recognised 3D Point and Plane.No colour check Blue only");
end,
#10;
proc(l1::[{satisfies(s -> type(s, [algebraic $ 3])), 'Vector[row]'(3, algebraic)}, 'Vector[column]'(3, algebraic)],
l2::[{satisfies(s -> type(s, [algebraic $ 3])), 'Vector[row]'(3, algebraic)}, 'Vector[column]'(3, algebraic)],$)
option overload;
[l1,l2];
print("#10 inputs recognised Skew lines 3D.No colour check Blue only") ;
end
]):
|
> |
# 3d lines a list or row vector for position point and column vector for direction
|
> |
l1:= [<1 | 5 | 7>, <3, 7, 9>]; #3D line
|
|
(2) |
> |
l2:=[<-4 | 2 | 1>, <3, 8, -9>]; #3D line
|
|
(3) |
> |
l3:= [[1 , 5 , 7], <3, 7, 9>]; #3D line
|
|
(4) |
> |
l4:=[[-4 , 2, 1 ], <3, 2, -9>]; #3D line
|
|
(5) |
|
(6) |
|
(7) |
> |
test([a,b],[e,t]);
test([a,b],[e,t],"Green");
test(<a|b>,<e|t>,"Red");
|
|
(8) |
> |
test([a,b],[a,c],[d,e])
|
|
(9) |
> |
test([a,b,c],"Blue");
test([a,b,c]);
test([a,b,c],"Red");
test(<a|b|c>);
|
|
(10) |
> |
test([a,b,c],[d,e,f]);
test([a,b,c],[d,e,f],"Red");
test(<a|b|c>,<d|e|f>);
|
|
(11) |
> |
test([a,b], <3, 2,d>,"Red");
|
> |
test([a,b], 3*x+ 2*y+d);
|
> |
test([a,b], 3*p+ 2*q+d,[p,q]);
f:=(p,q)-> 3*p+ 2*q+d;
test([a,b],f(p,q),[p,q])
|
|
(12) |
> |
test([a,b,c],l1);
test([a,b,c],l2);
test([a,b,c],l3);
test([a,b,c],l4);
|
|
(13) |
> |
test( [s,g,h],<1,2,3,4>);
test( [s,g,h],x+2*y+3*z+4);
test( [s,g,h],5*r-6*s+k*t+g,[r,s,t]);
h:=(r,s,t)-> 3*r+ 2*s-7*t+6 : # a plane
test( [s,g,h],h(r,s,t),[r,s,t])
|
|
(14) |
> |
test(l3,l4);
test(l1,l2);
test(l1,l3);
|
|
(15) |
> |
#false/incorrect type inputs working correctly as required
|
> |
test([a,b,d],[a,c,f],[d,e,n])
|
Error, invalid input: no implementation of test matches the arguments in call, 'test([a, b, d],[a, c, f],[d, e, n])'
|
|
> |
test([a,b], 3*p+ 2*q+d,[p,q],[e,t]);
|
> |
test( [s,g,h],h(r,s,t),[r,s,t],2)
|
Error, invalid input: no implementation of test matches the arguments in call, 'test([s, g, h],h(r,s,t),[r, s, t],2)'
|
|
> |
test( [s,g,h],5*r-6*s+k*t+g,[r,s,t],"Blue")
|
> |
test(5*r-6*s+k*t+g,[r,s,t],[s,g,h])
|
|
(16) |
> |
test1 :=overload([
#10;
proc(l1::[{satisfies(s -> type(s, [algebraic $ 3])), 'Vector[row]'(3, algebraic)}, 'Vector[column]'(3, algebraic)],
l2::[{satisfies(s -> type(s, [algebraic $ 3])), 'Vector[row]'(3, algebraic)}, 'Vector[column]'(3, algebraic)],$)
option overload;
[l1,l2];
print("#10 inputs recognised Skew lines 3D.No colour check Blue only") ;
end,
#9 if put before #5 it causes false evaluation of #5 type inputs as #9 Is there a way of checking p1 and triger overload or if not presest?
# [p0,pl,vars] cure ;
proc(p0::{satisfies(s -> type(s, [algebraic $ 3])),'Vector[row]'(3, algebraic)},
pl::{'Vector[column]'(4, algebraic), `+`,procedure},var::satisfies(s -> type(s, [algebraic $ 3])):=[x,y,z],$)
option overload;
global gcb;
[p0,pl,vars];
print("#9 inputs recognised 3D Point and Plane.No colour check Blue only");
end,
#8;
proc(l1::satisfies(s -> type(s, [algebraic $ 3])),
l2::[{satisfies(s -> type(s, [algebraic $ 3])), 'Vector[row]'(3, algebraic)}, 'Vector[column]'(3, algebraic)],$)
option overload;
[l1,l2];
print("#8 inputs recognised 3D Point and 3D Line.No colour check Blue only");
end,
#7;
proc(p0::{satisfies(s -> type(s, [algebraic $ 2])),'Vector[row]'(2, algebraic)},
pl::{satisfies(s -> type(s, [algebraic $ 3])),'Vector[column]'(3, algebraic),`+`,procedure},var::satisfies(s -> type(s, [algebraic $ 2])):=[x,y],
clr::`string` := GCb,$)
option overload;
[p0,pl,clr];
print("#7 inputs recognised 2D Point and Line valid for Blue, Red & Green") ;
end,
#6;
proc(p0::{satisfies(s -> type(s, [algebraic $ 3])), 'Vector[row]'(3, algebraic)},
p1::{satisfies(s -> type(s, [algebraic $ 3])), 'Vector[row]'(3, algebraic)},
clr::`string` := GCb,$)
option overload;
global GCb;
[p0,p1,clr];
if clr="Blue" then
print("#6 inputs recognised pair of 3D Points/Vectors ") ;
else print("#6 3D points/vectors only valid for Blue Geometry");
end if;
end,
#5;
proc(p0::{satisfies(s -> type(s, [algebraic $ 3])),'Vector[row]'(3, algebraic)},
clr::`string` := GCb,$)
option overload;
global GCb;
[p0,clr];
if clr="Blue" then
print("#5 inputs recognised single 3D Point/Vector");
else print("#5 error 3D Point/Vector only valid for Blue Geometry");
end if;
end,
#4X; If this is moved to before 4 causes false evaluation of #4 type input #4X
# [p0,p1,p2,clr] cures the problem because it itse the inputs;
proc(p0::{satisfies(s -> type(s, [algebraic $ 2])),'Vector[row]'(2, algebraic)},
p1::{satisfies(s -> type(s, [algebraic $ 2])),'Vector[row]'(2, algebraic)},
p2::{satisfies(s -> type(s, [algebraic $ 2])),'Vector[row]'(2, algebraic)},
clr::`string` := GCb,$)
option overload(callseq_only);
global GCb;
[p0,p1,p2,clr];
if clr="Blue" or clr="Red" or clr="Green" then
print("#4X inputs recognised Set of 3 2D Points/Vectors.Valid for Blue, Red & Green") ;
end if;
end,
#4 If put before #3 causes false evaluation of #3 type input #4
# [p0,p1,clr] cures the problem because it itse the inputs ;
proc(p0::{satisfies(s -> type(s, [algebraic $ 2])),'Vector[row]'(2, algebraic)},
p1::{satisfies(s -> type(s, [algebraic $ 2])),'Vector[row]'(2, algebraic)},
clr::`string` := GCb,$)
option overload;
global GCb;
[p0,p1,clr];
if clr="Blue" then
print("#4 inputs recognised pair of 2D Points/Vectors.Valid for Blue.") ;
elif clr= "Red" or clr="Green" then
print("#4 inputs recognised pair of 2D Points/Vectors. Red or Green");
end if;
end,
#3;
proc(p0::{satisfies(s -> type(s, [algebraic $ 2])),'Vector[row]'(2, algebraic)},
clr::`string` := GCb,$)
option overload;
global GCb;
[p0,clr];
if clr="Blue" then
print("#3 input recognised 2D Point/Vector. Blue.") ;
elif clr= "Red" or clr="Green" then
print("#4 inputs recognised 2D Point/Vector. Red or Green");
end if;
end,
#2;
proc(p0::algebraic,p1::algebraic,$)
option overload;
[p0,p1];
print("#2 pair of 1D inputs. No colour check required");
end,
#1;
proc(p0::algebraic,$)
option overload;
[p0];
if _params['p0']=NULL then `error nothing entered`
else print("#1 single 1D input. No colour check required");
end if;
end
]):
|
> |
# 3d lines a list or row vector for position point and column vector for direction
|
> |
l1:= [<1 | 5 | 7>, <3, 7, 9>]; #3D line
|
|
(17) |
> |
l2:=[<-4 | 2 | 1>, <3, 8, -9>]; #3D line
|
|
(18) |
> |
l3:= [[1 , 5 , 7], <3, 7, 9>]; #3D line
|
|
(19) |
> |
l4:=[[-4 , 2, 1 ], <3, 2, -9>]; #3D line
|
|
(20) |
|
(21) |
|
(22) |
> |
test1([a,b],[e,t]);
test1([a,b],[e,t],"Green");
test1(<a|b>,<e|t>,"Red");
|
|
(23) |
> |
test1([a,b],[a,c],[d,e])
|
|
(24) |
> |
test1([a,b,c],"Blue");
test1([a,b,c]);
test1([a,b,c],"Red");
test1(<a|b|c>);
|
|
(25) |
> |
test1([a,b,c],[d,e,f]);
test1([a,b,c],[d,e,f],"Red");
test1(<a|b|c>,<d|e|f>);
|
|
(26) |
> |
test1([a,b], <3, 2,d>,"Red");
|
> |
test1([a,b], 3*x+ 2*y+d);
|
> |
test1([a,b], 3*p+ 2*q+d,[p,q]);
f:=(p,q)-> 3*p+ 2*q+d;
test1([a,b],f(p,q),[p,q])
|
|
(27) |
> |
test1([a,b,c],l1);
test1([a,b,c],l2);
test1([a,b,c],l3);
test1([a,b,c],l4);
|
|
(28) |
> |
test1( [s,g,h],<1,2,3,4>);
test1( [s,g,h],x+2*y+3*z+4);
test1( [s,g,h],5*r-6*s+k*t+g,[r,s,t]);
h:=(r,s,t)-> 3*r+ 2*s-7*t+6 : # a plane
test1( [s,g,h],h(r,s,t),[r,s,t])
|
|
(29) |
> |
test1(l3,l4);
test1(l1,l2);
test1(l1,l3);
|
|
(30) |
> |
#false/incorrect type inputs working correctly as required
|
> |
test1([a,b,d],[a,c,f],[d,e,n])
|
Error, invalid input: no implementation of test1 matches the arguments in call, 'test1([a, b, d],[a, c, f],[d, e, n])'
|
|
|
(31) |
> |
test1([a,b], 3*p+ 2*q+d,[p,q],[e,t]);
|
> |
test1( [s,g,h],h(r,s,t),[r,s,t],2)
|
Error, invalid input: no implementation of test1 matches the arguments in call, 'test1([s, g, h],h(r,s,t),[r, s, t],2)'
|
|
> |
test1( [s,g,h],5*r-6*s+k*t+g,[r,s,t],"Blue")
|
> |
test1(5*r-6*s+k*t+g,[r,s,t],[s,g,h])
|
|