Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,47 +0,0 @@
|
|||
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;
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
$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.
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
$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.
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
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))})
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
val conjugate = fn(c) {
|
||||
if c is not complex: throw "expected complex number"
|
||||
val conjugate = fn(c complex) {
|
||||
return complex(c[1], -c[2])
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,19 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #000080;font-style:italic;">-- demo\rosetta\ArithComplex.exw</span>
|
||||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
|
||||
<span style="color: #008080;">include</span> <span style="color: #004080;">complex</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
|
||||
<span style="color: #004080;">complex</span> <span style="color: #000000;">a</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">complex_new</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">),</span> <span style="color: #000080;font-style:italic;">-- (or just {1,1})</span>
|
||||
<span style="color: #000000;">b</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">complex_new</span><span style="color: #0000FF;">(</span><span style="color: #000000;">3.14159</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1.25</span><span style="color: #0000FF;">),</span>
|
||||
<span style="color: #000000;">c</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">complex_new</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">),</span>
|
||||
<span style="color: #000000;">d</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">complex_new</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"a = %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">complex_sprint</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">)})</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"b = %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">complex_sprint</span><span style="color: #0000FF;">(</span><span style="color: #000000;">b</span><span style="color: #0000FF;">)})</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"c = %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">complex_sprint</span><span style="color: #0000FF;">(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">)})</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"d = %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">complex_sprint</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">)})</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"a+b = %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">complex_sprint</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">complex_add</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">,</span><span style="color: #000000;">b</span><span style="color: #0000FF;">))})</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"a*b = %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">complex_sprint</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">complex_mul</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">,</span><span style="color: #000000;">b</span><span style="color: #0000FF;">))})</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"1/a = %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">complex_sprint</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">complex_inv</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">))})</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"c/a = %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">complex_sprint</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">complex_div</span><span style="color: #0000FF;">(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">,</span><span style="color: #000000;">a</span><span style="color: #0000FF;">))})</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"c-a = %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">complex_sprint</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">complex_sub</span><span style="color: #0000FF;">(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">,</span><span style="color: #000000;">a</span><span style="color: #0000FF;">))})</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"d-a = %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">complex_sprint</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">complex_sub</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">,</span><span style="color: #000000;">a</span><span style="color: #0000FF;">))})</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"-a = %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">complex_sprint</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">complex_neg</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">))})</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"conj a = %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">complex_sprint</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">complex_conjugate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">))})</span>
|
||||
<!--
|
||||
-- demo\rosetta\ArithComplex.exw
|
||||
with javascript_semantics
|
||||
include complex.e
|
||||
complex a = complex_new(1,1), -- (or just {1,1})
|
||||
b = complex_new(3.14159,1.25),
|
||||
c = complex_new(1,0),
|
||||
d = complex_new(0,1)
|
||||
printf(1,"a = %s\n",{complex_sprint(a)})
|
||||
printf(1,"b = %s\n",{complex_sprint(b)})
|
||||
printf(1,"c = %s\n",{complex_sprint(c)})
|
||||
printf(1,"d = %s\n",{complex_sprint(d)})
|
||||
printf(1,"a+b = %s\n",{complex_sprint(complex_add(a,b))})
|
||||
printf(1,"a*b = %s\n",{complex_sprint(complex_mul(a,b))})
|
||||
printf(1,"1/a = %s\n",{complex_sprint(complex_inv(a))})
|
||||
printf(1,"c/a = %s\n",{complex_sprint(complex_div(c,a))})
|
||||
printf(1,"c-a = %s\n",{complex_sprint(complex_sub(c,a))})
|
||||
printf(1,"d-a = %s\n",{complex_sprint(complex_sub(d,a))})
|
||||
printf(1,"-a = %s\n",{complex_sprint(complex_neg(a))})
|
||||
printf(1,"conj a = %s\n",{complex_sprint(complex_conjugate(a))})
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
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()))"
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
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,5 +1,5 @@
|
|||
-- 7 Aug 2025
|
||||
include Settings
|
||||
-- 23 Aug 2025
|
||||
include Setting
|
||||
|
||||
say 'COMPLEX ARITHMETIC'
|
||||
say version
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue