[package] [Java implementation] [Execution output]


BigIntegers


import java.math.BigInteger;

import church.lang.Array;

// bigInteger(String: s) = BigInteger.new(s);
bigInteger(long: i) = BigInteger.valueOf(i);

// Arithmetic identities / implementation

                                 stream << (BigInteger: a) = stream << a.toString();

// Equality

                        (BigInteger: a) == (BigInteger: b) = a.equals(b);

// Ring

                                         additive_identity = BigInteger.ZERO;

                         (BigInteger: a) + (BigInteger: b) = a.add(b);

                                          -(BigInteger: a) = a.negate();

                                   multiplicative_identity = BigInteger.ONE;

                         (BigInteger: a) * (BigInteger: b) = a.multiply(b);

                                (BigInteger: a) ^ (int: n) = a.pow(n);

// Euclidean

                   divide(BigInteger: a, BigInteger: b, f) = {qNr = a.divideAndRemainder(b); f(qNr[0], qNr[1])};

                    quotient(BigInteger: a, BigInteger: b) = a.divide(b);

                         (BigInteger: a) % (BigInteger: b) = a.remainder(b);

// Ordering

                     compare(BigInteger: a, BigInteger: b) = {
                                                                 c = a.compareTo(b);
                                                                 if c < 0 then Ordering.LT else
                                                                 if c > 0 then Ordering.GT else
                                                                               Ordering.EQ;
                                                             };