Big Integer Expression Evaluator
By Yonghe Yan, November 2006
Expression:
Expression number base:
Result:
Result number base:
The Evaluator
The Big Integer Expression Evaluator is a Java Applet
that can evaluate an expression with arbitrary-precision
integers. The applet uses java.math.BigInteger
to represent values during the evaluation. Although
an expression with big integer values can be evaluated,
no decimal fraction can be entered or generated. For
example, the value of 3/4
is zero and
10/7 = 1
. To evaluate
an expression with decimal fractions, you may use
the DoubleExpression,
which uses double
to represent values.
Theoretically, this evaluator can evaluate any big
integer expressions. However, the computation may
take a very long time. For example, it may take years
for your computer to complete the computation
of 1234567890^1234567890.
The Expression
Any numbers and variables whose values have been saved
before can be used in the expression. The first character
of any number must be a digit or a zero.
The order of operations and available operators are
listed as follows:
|
Operator
|
Example
|
Assignment |
var = expression |
x=1+2*3 -> 7 , and the value is saved
in variable x. |
Parenthesis, negative, bitwise NOT |
(expression), -, ~ |
(1+2)*3 -> 9 |
Exponentiation,
Modular exponentiation |
^,
m^e%n |
10^2 -> 100 ,
65^5%119 -> 46 |
Multiplication, division, modulus |
*, /,
% |
2*3 -> 6 ,
11%4 -> 3 |
Addition, subtraction |
+, - |
1+2 -> 3 |
Bitwise AND |
& |
6&5 -> 4 |
Bitwise XOR |
# |
6#5 -> 3 |
Bitwise OR |
| |
6|5 -> 7 |
The Functions
Available functions are listed as follows:
abs(x) |
the absolute value of x. |
divideAndRemainder(x, y, varQ, varR) |
the value of (x / y). The value of (x / y) is saved
in the variable varQ, and the value of (x % y) in
varaible varR. The varQ and varR are any variable
identifers. |
gcd(x, y) |
a value that is the greatest common divisor of abs(x)
and abs(y). |
isProbablePrime(x, certainty) |
Returns 1 if x is probably prime, 0 if it's definitely
composite. The function returns 1 if the probability
that x is prime exceeds (1 - 1/2^certainty). |
max(x, y) |
the maximum of x and y. |
min(x, y) |
the minimum of x and y. |
modInverse(x, m) |
a value that is (x^-1 % m). |
nextProbablePrime(x) |
the first integer greater than x that is probably
prime. |
probablePrime(bitLength) |
a positive value that is probably prime, with the
specified bitLength. |
shiftLeft(x, n) |
the value of (x << n). |
shiftRight(x, n) |
the value of (x >> n). |
When it is possible, avoid converting a modular exponentiation
operation into an exponentiation operation followed
by a modulus operation, since modular exponentiation
operation is much faster than exponentiation operation.
For example, evaluating 12345^12345%54321, which is
a modular exponentiation operation, is much faster
than evaluating (12345^12345)%54321, which is an exponentiation
operation followed by a modulus operation.
Outputs
Result |
the value of the expression |
Computation Time |
the time to parse and evaluate the expression |
ToString Time |
the time to convert binary result to the output string |
Bit Length |
the binary bit length of the result |
Char Length |
the string length of the result |
Source Codes
The source codes can download here:
BigIntegerExpression.zip.
You can use it for any purpose without restriction.
I do not guarantee that it is correct, so use it at
your own risk.
Permission is granted to copy and distribute source
codes, provided that the following credit line is
included: "Big Integer Expression Evaluator, Yonghe
Yan 2006." Permission is granted to alter and distribute
source codes, provided that the following credit line
is included: "Adapted from Big Integer Expression
Evaluator, Yonghe Yan 2006."