Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,57 @@
PROGRAM VECTORPRODUCT
!$DOUBLE
TYPE TVECTOR=(X,Y,Z)
DIM A:TVECTOR,B:TVECTOR,C:TVECTOR
DIM AA:TVECTOR,BB:TVECTOR,CC:TVECTOR
DIM DD:TVECTOR,EE:TVECTOR,FF:TVECTOR
PROCEDURE DOTPRODUCT(DD.,EE.->DOTP)
DOTP=DD.X*EE.X+DD.Y*EE.Y+DD.Z*EE.Z
END PROCEDURE
PROCEDURE CROSSPRODUCT(DD.,EE.->FF.)
FF.X=DD.Y*EE.Z-DD.Z*EE.Y
FF.Y=DD.Z*EE.X-DD.X*EE.Z
FF.Z=DD.X*EE.Y-DD.Y*EE.X
END PROCEDURE
PROCEDURE SCALARTRIPLEPRODUCT(AA.,BB.,CC.->SCALARTP)
CROSSPRODUCT(BB.,CC.->FF.)
DOTPRODUCT(AA.,FF.->SCALARTP)
END PROCEDURE
PROCEDURE VECTORTRIPLEPRODUCT(AA.,BB.,CC.->FF.)
CROSSPRODUCT(BB.,CC.->FF.)
CROSSPRODUCT(AA.,FF.->FF.)
END PROCEDURE
PROCEDURE PRINTVECTOR(AA.)
PRINT("(";AA.X;",";AA.Y;",";AA.Z;")")
END PROCEDURE
BEGIN
A.X=3 A.Y=4 A.Z=5
B.X=4 B.Y=3 B.Z=5
C.X=-5 C.Y=-12 C.Z=-13
PRINT("A: ";) PRINTVECTOR(A.)
PRINT("B: ";) PRINTVECTOR(B.)
PRINT("C: ";) PRINTVECTOR(C.)
PRINT
DOTPRODUCT(A.,B.->DOTP)
PRINT("A.B =";DOTP)
CROSSPRODUCT(A.,B.->FF.)
PRINT("AxB =";) PRINTVECTOR(FF.)
SCALARTRIPLEPRODUCT(A.,B.,C.->SCALARTP)
PRINT("A.(BxC)=";SCALARTP)
VECTORTRIPLEPRODUCT(A.,B.,C.->FF.)
PRINT("Ax(BxC)=";) PRINTVECTOR(FF.)
END PROGRAM

View file

@ -0,0 +1,20 @@
(lib 'math)
(define (scalar-triple-product a b c)
(dot-product a (cross-product b c)))
(define (vector-triple-product a b c)
(cross-product a (cross-product b c)))
(define a #(3 4 5))
(define b #(4 3 5))
(define c #(-5 -12 -13))
(cross-product a b)
→ #( 5 5 -7)
(dot-product a b)
→ 49
(scalar-triple-product a b c)
→ 6
(vector-triple-product a b c)
→ #( -267 204 -3)

View file

@ -0,0 +1,32 @@
'Construct only required operators for this.
Type V3
As double x,y,z
declare operator cast() as string
End Type
#define dot *
#define cross ^
#define Show(t1,t) ? #t1;tab(22);t
operator V3.cast() as string
return "("+str(x)+","+str(y)+","+str(z)+")"
end operator
Operator dot(v1 As v3,v2 As v3) As double
Return v1.x*v2.x+v1.y*v2.y+v1.z*v2.z
End Operator
Operator cross(v1 As v3,v2 As v3) As v3
Return type<v3>(v1.y*v2.z-v2.y*v1.z,-(v1.x*v2.z-v2.x*v1.z),v1.x*v2.y-v2.x*v1.y)
End Operator
dim as V3 a = (3, 4, 5), b = (4, 3, 5), c = (-5, -12, -13)
Show(a,a)
Show(b,b)
Show(c,c)
?
Show(a . b,a dot b)
Show(a X b,a cross b)
Show(a . b X c,a dot b cross c)
Show(a X (b X c),a cross (b cross c))
sleep

View file

@ -0,0 +1,13 @@
A = (3, 4, 5)
B = (4, 3, 5)
C = (-5, -12, -13)
def dot( u, v ) = sum( u(i)v(i) | i <- 0:u.>length() )
def cross( u, v ) = (u(1)v(2) - u(2)v(1), u(2)v(0) - u(0)v(2), u(0)v(1) - u(1)v(0) )
def scalarTriple( u, v, w ) = dot( u, cross(v, w) )
def vectorTriple( u, v, w ) = cross( u, cross(v, w) )
println( "A\u00b7B = ${dot(A, B)}" )
println( "A\u00d7B = ${cross(A, B)}" )
println( "A\u00b7(B\u00d7C) = ${scalarTriple(A, B, C)}" )
println( "A\u00d7(B\u00d7C) = ${vectorTriple(A, B, C)}" )

View file

@ -0,0 +1,11 @@
a = vector(1,2,3)
b = vector(4,5,6)
put a * b
-- 32.0000
put a.dot(b)
-- 32.0000
put a.cross(b)
-- vector( -3.0000, 6.0000, -3.0000 )

View file

@ -0,0 +1,33 @@
import strutils
type Vector3 = array[1..3, float]
proc `$`(a: Vector3): string =
result = "["
for i, x in a:
if i > a.low:
result.add ", "
result.add formatFloat(x, precision = 0)
result.add "]"
proc `~`(a, b: Vector3): Vector3 =
result = [a[2]*b[3] - a[3]*b[2], a[3]*b[1] - a[1]*b[3], a[1]*b[2] - a[2]*b[1]]
proc `~•`[T](a, b: T): float =
for i in a.low..a.high:
result += a[i] * b[i]
proc scalartrip(a, b, c: Vector3): float = a ~• (b ~ c)
proc vectortrip(a, b, c: Vector3): Vector3 = a ~ (b ~ c)
let
a = [3.0, 4.0, 5.0]
b = [4.0, 3.0, 5.0]
c = [-5.0, -12.0, -13.0]
echo "a b = ", a ~ b
echo "a • b = ", (a ~• b).formatFloat(precision = 0)
echo "a . (b c) = ", (scalartrip(a, b, c)).formatFloat(precision = 0)
echo "a (b c) = ", vectortrip(a, b, c)

View file

@ -0,0 +1,23 @@
function dot_product(sequence a, b)
return sum(sq_mul(a,b))
end function
function cross_product(sequence a, b)
integer {a1,a2,a3} = a, {b1,b2,b3} = b
return {a2*b3-a3*b2, a3*b1-a1*b3, a1*b2-a2*b1}
end function
function scalar_triple_product(sequence a, b, c)
return dot_product(a,cross_product(b,c))
end function
function vector_triple_product(sequence a, b, c)
return cross_product(a,cross_product(b,c))
end function
constant a = {3, 4, 5}, b = {4, 3, 5}, c = {-5, -12, -13}
puts(1," a . b = ") ?dot_product(a,b)
puts(1," a x b = ") ?cross_product(a,b)
puts(1,"a . (b x c) = ") ?scalar_triple_product(a,b,c)
puts(1,"a x (b x c) = ") ?vector_triple_product(a,b,c)

View file

@ -0,0 +1,25 @@
class Vector(x, y, z) {
method ∙(vec) {
[self{:x,:y,:z}] »*« [vec{:x,:y,:z}] «+»;
}
method ⨉(vec) {
Vector(self.y*vec.z - self.z*vec.y,
self.z*vec.x - self.x*vec.z,
self.x*vec.y - self.y*vec.x);
}
method to_s {
"(#{x}, #{y}, #{z})";
}
}
var a = Vector(3, 4, 5);
var b = Vector(4, 3, 5);
var c = Vector(-5, -12, -13);
say "a=#{a}; b=#{b}; c=#{c};";
say "a ∙ b = #{a ∙ b}";
say "a ⨉ b = #{a ⨉ b}";
say "a ∙ (b ⨉ c) = #{a ∙ (b ⨉ c)}";
say "a ⨉ (b ⨉ c) = #{a ⨉ (b ⨉ c)}";

View file

@ -0,0 +1,21 @@
@let {
dot &[a b] @sum @mapm ^* [a b]
cross &[a b] [[
-*a.1 b.2 *a.2 b.1
-*a.2 b.0 *a.0 b.2
-*a.0 b.1 *a.1 b.0
]]
scalarTripleProduct &[a b c] !!dot a !!cross b c
vectorTripleProduct &[a b c] !!cross a !!cross b c
a [3 4 5]
b [4 3 5]
c [5N 12N 13N]
[[
!!dot a b
!!cross a b
@!scalarTripleProduct [a b c]
@!vectorTripleProduct [a b c]
]]
}

View file

@ -0,0 +1,21 @@
def dot_product(a; b):
reduce range(0;a|length) as $i (0; . + (a[$i] * b[$i]) );
# for 3d vectors
def cross_product(a;b):
[ a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1]-a[1]*b[0] ];
def scalar_triple_product(a;b;c):
dot_product(a; cross_product(b; c));
def vector_triple_product(a;b;c):
cross_product(a; cross_product(b; c));
def main:
[3, 4, 5] as $a
| [4, 3, 5] as $b
| [-5, -12, -13] as $c
| "a . b = \(dot_product($a; $b))",
"a x b = [\( cross_product($a; $b) | map(tostring) | join (", ") )]" ,
"a . (b x c) = \( scalar_triple_product ($a; $b; $c)) )",
"a x (b x c) = [\( vector_triple_product($a; $b; $c)|map(tostring)|join (", ") )]" ;

View file

@ -0,0 +1,4 @@
"a . b = 49"
"a x b = [5, 5, -7]"
"a . (b x c) = 6 )"
"a x (b x c) = [-267, 204, -3]"