Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
47
Task/Arithmetic-Complex/Ada/arithmetic-complex.adb
Normal file
47
Task/Arithmetic-Complex/Ada/arithmetic-complex.adb
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
with Ada.Numerics.Generic_Complex_Types;
|
||||
with Ada.Text_IO.Complex_IO;
|
||||
|
||||
procedure Complex_Operations is
|
||||
-- Ada provides a pre-defined generic package for complex types
|
||||
-- That package contains definitions for composition,
|
||||
-- negation, addition, subtraction, multiplication, division,
|
||||
-- conjugation, exponentiation, and absolute value, as well as
|
||||
-- basic comparison operations.
|
||||
-- Ada provides a second pre-defined package for sin, cos, tan, cot,
|
||||
-- arcsin, arccos, arctan, arccot, and the hyperbolic versions of
|
||||
-- those trigonometric functions.
|
||||
|
||||
-- The package Ada.Numerics.Generic_Complex_Types requires definition
|
||||
-- with the real type to be used in the complex type definition.
|
||||
|
||||
package Complex_Types is new Ada.Numerics.Generic_Complex_Types (Long_Float);
|
||||
use Complex_Types;
|
||||
package Complex_IO is new Ada.Text_IO.Complex_IO (Complex_Types);
|
||||
use Complex_IO;
|
||||
use Ada.Text_IO;
|
||||
|
||||
A : Complex := Compose_From_Cartesian (Re => 1.0, Im => 1.0);
|
||||
B : Complex := Compose_From_Polar (Modulus => 1.0, Argument => 3.14159);
|
||||
C : Complex;
|
||||
|
||||
begin
|
||||
-- Addition
|
||||
C := A + B;
|
||||
Put("A + B = "); Put(C);
|
||||
New_Line;
|
||||
-- Multiplication
|
||||
C := A * B;
|
||||
Put("A * B = "); Put(C);
|
||||
New_Line;
|
||||
-- Inversion
|
||||
C := 1.0 / A;
|
||||
Put("1.0 / A = "); Put(C);
|
||||
New_Line;
|
||||
-- Negation
|
||||
C := -A;
|
||||
Put("-A = "); Put(C);
|
||||
New_Line;
|
||||
-- Conjugation
|
||||
Put("Conjugate(-A) = ");
|
||||
C := Conjugate (C); Put(C);
|
||||
end Complex_Operations;
|
||||
14
Task/Arithmetic-Complex/COBOL/arithmetic-complex-1.cob
Normal file
14
Task/Arithmetic-Complex/COBOL/arithmetic-complex-1.cob
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
$SET SOURCEFORMAT "FREE"
|
||||
$SET ILUSING "System"
|
||||
$SET ILUSING "System.Numerics"
|
||||
class-id Prog.
|
||||
method-id. Main static.
|
||||
procedure division.
|
||||
declare num as type Complex = type Complex::ImaginaryOne()
|
||||
declare results as type Complex occurs any
|
||||
set content of results to ((num + num), (num * num), (- num), (1 / num), type Complex::Conjugate(num))
|
||||
perform varying result as type Complex thru results
|
||||
display result
|
||||
end-perform
|
||||
end method.
|
||||
end class.
|
||||
98
Task/Arithmetic-Complex/COBOL/arithmetic-complex-2.cob
Normal file
98
Task/Arithmetic-Complex/COBOL/arithmetic-complex-2.cob
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
$SET SOURCEFORMAT "FREE"
|
||||
class-id Prog.
|
||||
method-id. Main static.
|
||||
procedure division.
|
||||
declare a as type Complex = new Complex(1, 1)
|
||||
declare b as type Complex = new Complex(3.14159, 1.25)
|
||||
|
||||
display "a = " a
|
||||
display "b = " b
|
||||
display space
|
||||
|
||||
declare result as type Complex = a + b
|
||||
display "a + b = " result
|
||||
move (a - b) to result
|
||||
display "a - b = " result
|
||||
move (a * b) to result
|
||||
display "a * b = " result
|
||||
move (a / b) to result
|
||||
display "a / b = " result
|
||||
move (- b) to result
|
||||
display "-b = " result
|
||||
display space
|
||||
|
||||
display "Inverse of b: " type Complex::Inverse(b)
|
||||
display "Conjugate of b: " type Complex::Conjugate(b)
|
||||
end method.
|
||||
end class.
|
||||
|
||||
class-id Complex.
|
||||
|
||||
01 Real float-long property.
|
||||
01 Imag float-long property.
|
||||
|
||||
method-id new.
|
||||
set Real, Imag to 0
|
||||
end method.
|
||||
|
||||
method-id new.
|
||||
procedure division using value real-val as float-long, imag-val as float-long.
|
||||
set Real to real-val
|
||||
set Imag to imag-val
|
||||
end method.
|
||||
|
||||
method-id Norm static.
|
||||
procedure division using value a as type Complex returning ret as float-long.
|
||||
compute ret = a::Real ** 2 + a::Imag ** 2
|
||||
end method.
|
||||
|
||||
method-id Inverse static.
|
||||
procedure division using value a as type Complex returning ret as type Complex.
|
||||
declare norm as float-long = type Complex::Norm(a)
|
||||
set ret to new Complex(a::Real / norm, (0 - a::Imag) / norm)
|
||||
end method.
|
||||
|
||||
method-id Conjugate static.
|
||||
procedure division using value a as type Complex returning c as type Complex.
|
||||
set c to new Complex(a::Real, 0 - a::Imag)
|
||||
end method.
|
||||
|
||||
method-id ToString override.
|
||||
procedure division returning str as string.
|
||||
set str to type String::Format("{0}{1:+#0;-#}i", Real, Imag)
|
||||
end method.
|
||||
|
||||
operator-id + .
|
||||
procedure division using value a as type Complex, b as type Complex
|
||||
returning c as type Complex.
|
||||
set c to new Complex(a::Real + b::Real, a::Imag + b::Imag)
|
||||
end operator.
|
||||
|
||||
operator-id - .
|
||||
procedure division using value a as type Complex, b as type Complex
|
||||
returning c as type Complex.
|
||||
set c to new Complex(a::Real - b::Real, a::Imag - b::Imag)
|
||||
end operator.
|
||||
|
||||
operator-id * .
|
||||
procedure division using value a as type Complex, b as type Complex
|
||||
returning c as type Complex.
|
||||
set c to new Complex(a::Real * b::Real - a::Imag * b::Imag,
|
||||
a::Real * b::Imag + a::Imag * b::Real)
|
||||
end operator.
|
||||
|
||||
operator-id / .
|
||||
procedure division using value a as type Complex, b as type Complex
|
||||
returning c as type Complex.
|
||||
set c to new Complex()
|
||||
declare b-norm as float-long = type Complex::Norm(b)
|
||||
compute c::Real = (a::Real * b::Real + a::Imag * b::Imag) / b-norm
|
||||
compute c::Imag = (a::Imag * b::Real - a::Real * b::Imag) / b-norm
|
||||
end operator.
|
||||
|
||||
operator-id - .
|
||||
procedure division using value a as type Complex returning ret as type Complex.
|
||||
set ret to new Complex(- a::Real, 0 - a::Imag)
|
||||
end operator.
|
||||
|
||||
end class.
|
||||
58
Task/Arithmetic-Complex/Euphoria/arithmetic-complex.eu
Normal file
58
Task/Arithmetic-Complex/Euphoria/arithmetic-complex.eu
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
constant REAL = 1, IMAG = 2
|
||||
type complex(sequence s)
|
||||
return length(s) = 2 and atom(s[REAL]) and atom(s[IMAG])
|
||||
end type
|
||||
|
||||
function add(complex a, complex b)
|
||||
return a + b
|
||||
end function
|
||||
|
||||
function mult(complex a, complex b)
|
||||
return {a[REAL] * b[REAL] - a[IMAG] * b[IMAG],
|
||||
a[REAL] * b[IMAG] + a[IMAG] * b[REAL]}
|
||||
end function
|
||||
|
||||
function inv(complex a)
|
||||
atom denom
|
||||
denom = a[REAL] * a[REAL] + a[IMAG] * a[IMAG]
|
||||
return {a[REAL] / denom, -a[IMAG] / denom}
|
||||
end function
|
||||
|
||||
function neg(complex a)
|
||||
return -a
|
||||
end function
|
||||
|
||||
function scomplex(complex a)
|
||||
sequence s
|
||||
if a[REAL] != 0 then
|
||||
s = sprintf("%g",a)
|
||||
else
|
||||
s = {}
|
||||
end if
|
||||
|
||||
if a[IMAG] != 0 then
|
||||
if a[IMAG] = 1 then
|
||||
s &= "+i"
|
||||
elsif a[IMAG] = -1 then
|
||||
s &= "-i"
|
||||
else
|
||||
s &= sprintf("%+gi",a[IMAG])
|
||||
end if
|
||||
end if
|
||||
|
||||
if length(s) = 0 then
|
||||
return "0"
|
||||
else
|
||||
return s
|
||||
end if
|
||||
end function
|
||||
|
||||
complex a, b
|
||||
a = { 1.0, 1.0 }
|
||||
b = { 3.14159, 1.2 }
|
||||
printf(1,"a = %s\n",{scomplex(a)})
|
||||
printf(1,"b = %s\n",{scomplex(b)})
|
||||
printf(1,"a+b = %s\n",{scomplex(add(a,b))})
|
||||
printf(1,"a*b = %s\n",{scomplex(mult(a,b))})
|
||||
printf(1,"1/a = %s\n",{scomplex(inv(a))})
|
||||
printf(1,"-a = %s\n",{scomplex(neg(a))})
|
||||
19
Task/Arithmetic-Complex/Goboscript/arithmetic-complex.gobo
Normal file
19
Task/Arithmetic-Complex/Goboscript/arithmetic-complex.gobo
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
%include inflator/cmath
|
||||
|
||||
costumes "assets/blank.svg";
|
||||
|
||||
onflag {
|
||||
Complex z1 = Complex(1.5, 3);
|
||||
Complex z2 = Complex(1.5, 1.5);
|
||||
|
||||
log c_str(c_add(z1, z2));
|
||||
log c_str(c_sub(z1, z2));
|
||||
log c_str(c_mul(z1, z2));
|
||||
log c_str(c_div(z1, z2));
|
||||
log c_str(c_mul(z1, Complex(-1, 0)));
|
||||
log c_str(c_conj(z1));
|
||||
log c_abs(z1);
|
||||
log c_str(c_pow(z1, z2));
|
||||
log z1.r;
|
||||
log z1.i;
|
||||
}
|
||||
39
Task/Arithmetic-Complex/PowerShell/arithmetic-complex-1.ps1
Normal file
39
Task/Arithmetic-Complex/PowerShell/arithmetic-complex-1.ps1
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
class Complex {
|
||||
[Double]$x
|
||||
[Double]$y
|
||||
Complex() {
|
||||
$this.x = 0
|
||||
$this.y = 0
|
||||
}
|
||||
Complex([Double]$x, [Double]$y) {
|
||||
$this.x = $x
|
||||
$this.y = $y
|
||||
}
|
||||
[Double]abs2() {return $this.x*$this.x + $this.y*$this.y}
|
||||
[Double]abs() {return [math]::sqrt($this.abs2())}
|
||||
static [Complex]add([Complex]$m,[Complex]$n) {return [Complex]::new($m.x+$n.x, $m.y+$n.y)}
|
||||
static [Complex]mul([Complex]$m,[Complex]$n) {return [Complex]::new($m.x*$n.x - $m.y*$n.y, $m.x*$n.y + $n.x*$m.y)}
|
||||
[Complex]mul([Double]$k) {return [Complex]::new($k*$this.x, $k*$this.y)}
|
||||
[Complex]negate() {return $this.mul(-1)}
|
||||
[Complex]conjugate() {return [Complex]::new($this.x, -$this.y)}
|
||||
[Complex]inverse() {return $this.conjugate().mul(1/$this.abs2())}
|
||||
[String]show() {
|
||||
if(0 -ge $this.y) {
|
||||
return "$($this.x)+$($this.y)i"
|
||||
} else {
|
||||
return "$($this.x)$($this.y)i"
|
||||
}
|
||||
}
|
||||
static [String]show([Complex]$other) {
|
||||
return $other.show()
|
||||
}
|
||||
}
|
||||
$m = [complex]::new(3, 4)
|
||||
$n = [complex]::new(7, 6)
|
||||
"`$m: $($m.show())"
|
||||
"`$n: $($n.show())"
|
||||
"`$m + `$n: $([complex]::show([complex]::add($m,$n)))"
|
||||
"`$m * `$n: $([complex]::show([complex]::mul($m,$n)))"
|
||||
"negate `$m: $($m.negate().show())"
|
||||
"1/`$m: $([complex]::show($m.inverse()))"
|
||||
"conjugate `$m: $([complex]::show($m.conjugate()))"
|
||||
16
Task/Arithmetic-Complex/PowerShell/arithmetic-complex-2.ps1
Normal file
16
Task/Arithmetic-Complex/PowerShell/arithmetic-complex-2.ps1
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
function show([System.Numerics.Complex]$c) {
|
||||
if(0 -le $c.Imaginary) {
|
||||
return "$($c.Real)+$($c.Imaginary)i"
|
||||
} else {
|
||||
return "$($c.Real)$($c.Imaginary)i"
|
||||
}
|
||||
}
|
||||
$m = [System.Numerics.Complex]::new(3, 4)
|
||||
$n = [System.Numerics.Complex]::new(7, 6)
|
||||
"`$m: $(show $m)"
|
||||
"`$n: $(show $n)"
|
||||
"`$m + `$n: $(show ([System.Numerics.Complex]::Add($m,$n)))"
|
||||
"`$m * `$n: $(show ([System.Numerics.Complex]::Multiply($m,$n)))"
|
||||
"negate `$m: $(show ([System.Numerics.Complex]::Negate($m)))"
|
||||
"1/`$m: $(show ([System.Numerics.Complex]::Reciprocal($m)))"
|
||||
"conjugate `$m: $(show ([System.Numerics.Complex]::Conjugate($m)))"
|
||||
|
|
@ -1,49 +1,49 @@
|
|||
-- 23 Aug 2025
|
||||
-- 25 Apr 2026
|
||||
include Setting
|
||||
|
||||
say 'COMPLEX ARITHMETIC'
|
||||
say version
|
||||
say
|
||||
a = '1 2'; b = '3 4'; c = '5 6'; d = '7 8'; i = I()
|
||||
t = '1 2'; u = '3 4'; v = '5 6'; w = '7 8'; i = I()
|
||||
say 'VALUES'
|
||||
say 'a =' Rec2FormC(a)
|
||||
say 'b =' Rec2FormC(b)
|
||||
say 'c =' Rec2FormC(c)
|
||||
say 'd =' Rec2FormC(d)
|
||||
say 't =' Rec2FormC(t)
|
||||
say 'u =' Rec2FormC(u)
|
||||
say 'v =' Rec2FormC(v)
|
||||
say 'w =' Rec2FormC(w)
|
||||
say
|
||||
say 'BASICS'
|
||||
say 'i*i =' Rec2FormC(SquareC(i()))
|
||||
say 'a+b =' Rec2FormC(AddC(a,b))
|
||||
say 'a-b =' Rec2FormC(SubC(a,b))
|
||||
say 'a*b =' Rec2FormC(MulC(a,b))
|
||||
say 'a/b =' Rec2FormC(DivC(a,b))
|
||||
say 'a^2 =' Rec2FormC(SquareC(a,2))
|
||||
say 'a^5 =' Rec2FormC(PowC(a,5))
|
||||
say '-a =' Rec2FormC(NegC(a))
|
||||
say '1/a =' Rec2FormC(InvC(a))
|
||||
say 'a+b+c+d =' Rec2FormC(AddC(a,b,c,d))
|
||||
say 'a-b-c-d =' Rec2FormC(SubC(a,b,c,d))
|
||||
say 'a*b*c*d =' Rec2FormC(MulC(a,b,c,d))
|
||||
say 'a/b/c/d =' Rec2FormC(Normal(DivC(a,b,c,d)))
|
||||
say 'i*i =' Rec2FormC(SquareC(i))
|
||||
say 't+u =' Rec2FormC(AddC(t,u))
|
||||
say 't-u =' Rec2FormC(SubC(t,u))
|
||||
say 't*u =' Rec2FormC(MulC(t,u))
|
||||
say 't/u =' Rec2FormC(DivC(t,u))
|
||||
say 't^2 =' Rec2FormC(SquareC(t,2))
|
||||
say 't^5 =' Rec2FormC(PowC(t,5))
|
||||
say '-t =' Rec2FormC(NegC(t))
|
||||
say '1/t =' Rec2FormC(InvC(t))
|
||||
say
|
||||
say 'SUM AND PRODUCT OF A LIST'
|
||||
say 't+u+v+w =' Rec2FormC(AddCL(t';'u';'v';'w))
|
||||
say 't*u*v*w =' Rec2FormC(MulCL(t';'u';'v';'w))
|
||||
say
|
||||
say 'FORMULA'
|
||||
say 'a^2-2ab+3c-4ad^4+5 =' ,
|
||||
Rec2FormC(AddC(SquareC(a),MulC(-2,a,b),MulC(3,c),MulC(-4,a,PowerC(d,4)),5))
|
||||
say 't^2-2tu+3v-4tw^4+5 =' ,
|
||||
Rec2FormC(AddCL(SquareC(t)';'MulCL(-2';'t';'u)';'MulC(3,v)';'MulCL(-4';'t';'PowC(w,4))';'5))
|
||||
say
|
||||
say 'BONUS'
|
||||
say 'Argument(a) =' ArgC(a)+0
|
||||
say 'Conjugate(a) =' Rec2FormC(ConjC(a))
|
||||
say 'Imag(a) =' ImC(a)
|
||||
say 'Modulus(a) =' ModC(a)+0
|
||||
say 'Polar(a) =' Pol2FormC(Normal(Rec2PolC(a)))
|
||||
say 'Real(a) =' ReC(a)
|
||||
say 'Argument(t) =' ArgC(t)+0
|
||||
say 'Conjugate(t) =' Rec2FormC(ConjC(t))
|
||||
say 'Imag(t) =' ImC(t)
|
||||
say 'Modulus(t) =' ModC(t)+0
|
||||
say 'Polar(t) =' Pol2FormC(Normal(Rec2PolC(t)))
|
||||
say 'Real(t) =' ReC(t)
|
||||
say
|
||||
say 'MORE'
|
||||
say 'Arcsin(a) =' Rec2FormC(Normal(ArcSinC(a)))
|
||||
say 'Exp(a) =' Rec2FormC(Normal(ExpC(a)))
|
||||
say 'Ln(a) =' Rec2FormC(Normal(LnC(a)))
|
||||
say 'Sin(a) =' Rec2FormC(Normal(SinC(a)))
|
||||
say 'Sqrt(a) =' Rec2FormC(Normal(SqRtC(a)))
|
||||
say 'Arcsin(t) =' Rec2FormC(Normal(ArcSinC(t)))
|
||||
say 'Exp(t) =' Rec2FormC(Normal(ExpC(t)))
|
||||
say 'Ln(t) =' Rec2FormC(Normal(LnC(t)))
|
||||
say 'Sin(t) =' Rec2FormC(Normal(SinC(t)))
|
||||
say 'Sqrt(t) =' Rec2FormC(Normal(SqRtC(t)))
|
||||
say 'i^i =' Rec2FormC(Normal(PowerC(i,i)))
|
||||
exit
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue