Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
61
Task/Arithmetic-Rational/Elisa/arithmetic-rational-1.elisa
Normal file
61
Task/Arithmetic-Rational/Elisa/arithmetic-rational-1.elisa
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
component RationalNumbers;
|
||||
type Rational;
|
||||
Rational(Numerator = integer, Denominater = integer) -> Rational;
|
||||
|
||||
Rational + Rational -> Rational;
|
||||
Rational - Rational -> Rational;
|
||||
Rational * Rational -> Rational;
|
||||
Rational / Rational -> Rational;
|
||||
|
||||
Rational == Rational -> boolean;
|
||||
Rational <> Rational -> boolean;
|
||||
Rational >= Rational -> boolean;
|
||||
Rational <= Rational -> boolean;
|
||||
Rational > Rational -> boolean;
|
||||
Rational < Rational -> boolean;
|
||||
|
||||
+ Rational -> Rational;
|
||||
- Rational -> Rational;
|
||||
abs(Rational) -> Rational;
|
||||
|
||||
Rational(integer) -> Rational;
|
||||
Numerator(Rational) -> integer;
|
||||
Denominator(Rational) -> integer;
|
||||
begin
|
||||
Rational(A,B) = Rational:[A;B];
|
||||
|
||||
R1 + R2 = Normalize( R1.A * R2.B + R1.B * R2.A, R1.B * R2.B);
|
||||
R1 - R2 = Normalize( R1.A * R2.B - R1.B * R2.A, R1.B * R2.B);
|
||||
R1 * R2 = Normalize( R1.A * R2.A, R1.B * R2.B);
|
||||
R1 / R2 = Normalize( R1.A * R2.B, R1.B * R2.A);
|
||||
|
||||
R1 == R2 = [ R = (R1 - R2); R.A == 0];
|
||||
R1 <> R2 = [ R = (R1 - R2); R.A <> 0];
|
||||
R1 >= R2 = [ R = (R1 - R2); R.A >= 0];
|
||||
R1 <= R2 = [ R = (R1 - R2); R.A <= 0];
|
||||
R1 > R2 = [ R = (R1 - R2); R.A > 0];
|
||||
R1 < R2 = [ R = (R1 - R2); R.A < 0];
|
||||
|
||||
+ R = R;
|
||||
- R = Rational(-R.A, R.B);
|
||||
|
||||
abs(R) = Rational(abs(R.A), abs(R.B));
|
||||
Rational(I) = Rational (I, 1);
|
||||
Numerator(R) = R.A;
|
||||
Denominator(R) = R.B;
|
||||
|
||||
<< internal definitions >>
|
||||
|
||||
Normalize (A = integer, B = integer) -> Rational;
|
||||
Normalize (A, B) = [ exception( B == 0, "Illegal Rational Number");
|
||||
Common = GCD(abs(A), abs(B));
|
||||
if B < 0 then Rational(-A / Common, -B / Common)
|
||||
else Rational( A / Common, B / Common) ];
|
||||
|
||||
GCD (A = integer, B = integer) -> integer;
|
||||
GCD (A, B) = [ if A == 0 then return(B);
|
||||
if B == 0 then return(A);
|
||||
if A > B then GCD (B, mod(A,B))
|
||||
else GCD (A, mod(B,A)) ];
|
||||
|
||||
end component RationalNumbers;
|
||||
14
Task/Arithmetic-Rational/Elisa/arithmetic-rational-2.elisa
Normal file
14
Task/Arithmetic-Rational/Elisa/arithmetic-rational-2.elisa
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
use RationalNumbers;
|
||||
|
||||
PerfectNumbers( Limit = integer) -> multi(integer);
|
||||
PerfectNumbers( Limit) =
|
||||
[ Candidate = 2 .. Limit;
|
||||
Sum:= Rational(1,Candidate);
|
||||
[ Divisor = 2 .. integer(sqrt(real(Candidate)));
|
||||
if mod(Candidate, Divisor) == 0 then
|
||||
Sum := Sum + Rational(1, Divisor) + Rational(Divisor, Candidate);
|
||||
];
|
||||
if Sum == Rational(1,1) then Candidate
|
||||
];
|
||||
|
||||
PerfectNumbers(10000)?
|
||||
Loading…
Add table
Add a link
Reference in a new issue