Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
22
Task/Arithmetic-Complex/Langur/arithmetic-complex.langur
Normal file
22
Task/Arithmetic-Complex/Langur/arithmetic-complex.langur
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
val conjugate = fn(c) {
|
||||
if c is not complex: throw "expected complex number"
|
||||
return complex(c[1], -c[2])
|
||||
}
|
||||
|
||||
val examples = {
|
||||
"-(1+1i)": -(1+1i),
|
||||
"abs(1+1i)": abs(1+1i),
|
||||
"(2+2i) + (5+13.2i)": (2+2i) + (5+13.2i),
|
||||
"5 + (2+2i)": 5 + (2+2i),
|
||||
"5i + (2+2i)": 5i + (2+2i),
|
||||
"5i - (2+2i)": 5i - (2+2i),
|
||||
"(1+1i) * (3.141592653589793+1.2i)": (1+1i) * (3.141592653589793+1.2i),
|
||||
"(5+3i) / (4-3i)": (5+3i) / (4-3i),
|
||||
"1 / (4-3i)": 1 / (4-3i),
|
||||
"(4-3i) ^ 3": (4-3i) ^ 3,
|
||||
"conjugate(7+21.0i)": conjugate(7+21.0i),
|
||||
}
|
||||
|
||||
for e of examples {
|
||||
writeln "{{e : 20}}: ", examples[e]
|
||||
}
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
Class Complex {
|
||||
private:
|
||||
double vr, vi
|
||||
public:
|
||||
property real {
|
||||
value {link parent vr to vr : value=vr}
|
||||
}
|
||||
property imaginary {
|
||||
value {link parent vi to vi : value=vi}
|
||||
}
|
||||
property toString {
|
||||
value {
|
||||
clear
|
||||
' so default variable VALUE deleted and again defined it as string
|
||||
link parent vr, vi to vr, vi
|
||||
if vi then
|
||||
if vr then
|
||||
if vi>0 then
|
||||
if vi==1 then
|
||||
value="("+vr+"+i)"
|
||||
else
|
||||
value="("+vr+"+"+vi+"i)"
|
||||
end if
|
||||
else
|
||||
if vi==-1 then
|
||||
value="("+vr+"-i)"
|
||||
else
|
||||
value="("+vr+""+vi+"i)"
|
||||
end if
|
||||
end if
|
||||
else
|
||||
if vi=1 then
|
||||
value="(i)"
|
||||
else.if vi=-1 then
|
||||
value="(-i)"
|
||||
else
|
||||
value="("+vi+"i)"
|
||||
end if
|
||||
end if
|
||||
else
|
||||
value="("+vr+")"
|
||||
end if
|
||||
}
|
||||
}
|
||||
function final Arg {
|
||||
declare m math
|
||||
Method m, "Atan2", .vi, .vr as ret
|
||||
=ret
|
||||
}
|
||||
function final exp(rr=10) {
|
||||
double exp = 2.71828182845905^.vr
|
||||
c=this
|
||||
th=.vi/1.74532925199433E-02
|
||||
c.vr<=round(exp * cos(th), rr)
|
||||
c.vi<=round(exp * sin(th),rr)
|
||||
=c
|
||||
}
|
||||
function final cabs {
|
||||
if abs(.vr)=infinity or abs(.vi)=infinity then
|
||||
=1.7976931348623157E+308 : break
|
||||
end if
|
||||
double c=abs(.vr), d=abs(.vi)
|
||||
if c>d then
|
||||
r=d/c : =c*sqrt(1+r*r)
|
||||
else.if d==0 then
|
||||
=c
|
||||
else
|
||||
r=c/d : =d*sqrt(1+r*r)
|
||||
end if
|
||||
}
|
||||
function final clog {
|
||||
c=this
|
||||
c.vr<=ln(.cabs())
|
||||
c.vi<=.Arg()
|
||||
=c
|
||||
}
|
||||
function final pow {
|
||||
if match("G") then
|
||||
read p as Complex
|
||||
else
|
||||
read p1 as double
|
||||
p=this:p.vr=p1:p.vi=0
|
||||
end if
|
||||
Read ? rr=10
|
||||
exp=.clog()*p
|
||||
c=exp.exp(rr)
|
||||
c.vr=round(c.vr, rr)
|
||||
c.vi=round(c.vi, rr)
|
||||
=c
|
||||
}
|
||||
function final inv {
|
||||
if .vr==0 and .vi==0 then error "zero complex num"
|
||||
acb=this.conj()
|
||||
c=this*acb
|
||||
c.vi <= acb.vi/c.vr
|
||||
c.vr <= acb.vr/c.vr
|
||||
=c
|
||||
}
|
||||
function final conj {
|
||||
c=this : c.vi-! : =c
|
||||
}
|
||||
function final absc {
|
||||
c=this*.conj() : =sqrt(c.vr)
|
||||
}
|
||||
operator final "+" {
|
||||
read k as Complex : .vr+= k.vr : .vi+= k.vi
|
||||
}
|
||||
operator final "-" {
|
||||
read k as Complex : .vr-= k.vr : .vi-= k.vi
|
||||
}
|
||||
operator final high "*" {
|
||||
read k as Complex
|
||||
double ivr = .vr*k.vr-.vi*k.vi
|
||||
.vi <= .vi*k.vr+.vr*k.vi
|
||||
.vr <= ivr
|
||||
}
|
||||
operator final high "/" {
|
||||
read k as Complex
|
||||
k1=k*k.conj()
|
||||
acb = this*k.conj()
|
||||
.vr <= acb.vr/k1.vr
|
||||
.vi <= acb.vi/k1.vr
|
||||
}
|
||||
operator final unary {
|
||||
.vr-!
|
||||
.vi-!
|
||||
}
|
||||
|
||||
class:
|
||||
module Complex (.vr, .vi) {}
|
||||
}
|
||||
Module Check (filename as string="") {
|
||||
def f(x)=x.toString
|
||||
a=Complex(8,-3)
|
||||
b=a.inv()
|
||||
open filename for wide output as #f
|
||||
Print #f, "A="+a.toString
|
||||
Print #f, " r=";a.cabs();" θ=";a.Arg();" rad"
|
||||
Print #f, "B="+b.toString+" as 1/A"
|
||||
Print #f, " r=";b.cabs();" θ=";b.Arg();" rad"
|
||||
Print #f, a.toString+"*"+b.toString+"="+f(a*b)
|
||||
Print #f, Complex(1).toString+"/"+b.toString+"="+f(Complex(1)/b)
|
||||
Print #f, a.toString+"/"+a.toString+"="+f(a/a)
|
||||
Print #f, a.toString+"+"+a.toString+"="+f(a+a)
|
||||
Print #f, a.toString+"-"+a.toString+"="+f(a-a)
|
||||
Print #f, "-"+a.toString+"="+f(-a)
|
||||
Print #f, "e^(πi)+1="+f(Complex(2.71828182845905).pow(Complex(0,pi))+Complex(1))
|
||||
close #f
|
||||
if filename<>"" then if exist(filename) then win "notepad", dir$+filename
|
||||
}
|
||||
Check "out.txt"
|
||||
Check ' just show here
|
||||
|
|
@ -1,23 +1,38 @@
|
|||
/*REXX program demonstrates how to support some math functions for complex numbers. */
|
||||
x = '(5,3i)' /*define X ─── can use I i J or j */
|
||||
y = "( .5, 6j)" /*define Y " " " " " " " */
|
||||
include Settings
|
||||
|
||||
say ' addition: ' x " + " y ' = ' Cadd(x, y)
|
||||
say ' subtraction: ' x " - " y ' = ' Csub(x, y)
|
||||
say 'multiplication: ' x " * " y ' = ' Cmul(x, y)
|
||||
say ' division: ' x " ÷ " y ' = ' Cdiv(x, y)
|
||||
say ' inverse: ' x " = " Cinv(x, y)
|
||||
say ' conjugate of: ' x " = " Conj(x, y)
|
||||
say ' negation of: ' x " = " Cneg(x, y)
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
Conj: procedure; parse arg a ',' b,c ',' d; call C#; return C$( a , -b )
|
||||
Cadd: procedure; parse arg a ',' b,c ',' d; call C#; return C$( a+c , b+d )
|
||||
Csub: procedure; parse arg a ',' b,c ',' d; call C#; return C$( a-c , b-d )
|
||||
Cmul: procedure; parse arg a ',' b,c ',' d; call C#; return C$( ac-bd , bc+ad)
|
||||
Cdiv: procedure; parse arg a ',' b,c ',' d; call C#; return C$((ac+bd)/s, (bc-ad)/s)
|
||||
Cinv: return Cdiv(1, arg(1))
|
||||
Cneg: return Cmul(arg(1), -1)
|
||||
C_: return word(translate(arg(1), , '{[(JjIi)]}') 0, 1) /*get # or 0*/
|
||||
C#: a=C_(a); b=C_(b); c=C_(c); d=C_(d); ac=a*c; ad=a*d; bc=b*c; bd=b*d;s=c*c+d*d; return
|
||||
C$: parse arg r,c; _='['r; if c\=0 then _=_","c'j'; return _"]" /*uses j */
|
||||
say version; say 'Arithmetic numbers'; say
|
||||
numeric digits 9
|
||||
divi. = 0; a = 0; c = 0
|
||||
do i = 1
|
||||
/* Is the number arithmetic? */
|
||||
if Arithmetic(i) then do
|
||||
a = a+1
|
||||
/* Is the number composite? */
|
||||
if divi.0 > 2 then
|
||||
c = c+1
|
||||
/* Output control */
|
||||
if a <= 100 then do
|
||||
if a = 1 then
|
||||
say 'First 100 arithmetic numbers are'
|
||||
call Charout ,Right(i,4)
|
||||
if a//10 = 0 then
|
||||
say
|
||||
if a = 100 then
|
||||
say
|
||||
end
|
||||
if a = 100 | a = 1000 | a = 10000 | a = 100000 | a = 1000000 then do
|
||||
say 'The' a'th arithmetic number is' i
|
||||
say 'Of the first' a 'numbers' c 'are composite'
|
||||
say
|
||||
end
|
||||
/* Max 1m, higher takes too long */
|
||||
if a = 1000000 then
|
||||
leave
|
||||
end
|
||||
end
|
||||
say Format(Time('e'),,3) 'seconds'
|
||||
exit
|
||||
|
||||
include Numbers
|
||||
include Functions
|
||||
include Abend
|
||||
|
|
|
|||
11
Task/Arithmetic-Complex/Uiua/arithmetic-complex.uiua
Normal file
11
Task/Arithmetic-Complex/Uiua/arithmetic-complex.uiua
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
Za ← ℂ 3 1.5 # 1.5+3i
|
||||
Zb ← ℂ 1.5 1.5 # 1.5+1.5i
|
||||
+ Zb Za
|
||||
- Zb Za
|
||||
× Zb Za
|
||||
÷ Zb Za
|
||||
¯Za
|
||||
ℂ¯ °ℂ Za
|
||||
⌵ Za
|
||||
ⁿ Zb Za
|
||||
°ℂZa
|
||||
Loading…
Add table
Add a link
Reference in a new issue