Console application
This console application illustrates features of the Jep Extensions package.
Field:
This example has been cross compiled to javascript using the GWTJep package.
Field selection
This console can perform calculations using various different fields including integers, fractions, decimals with a specific number of decimal places. Use
setfield doublefor standard floating point numberssetfield bigdec 30for big decimal numbers with 30 decimal placessetfield bigdec unlimitedfor big decimal numbers with unlimited sizesetfield integerall calculations in integersetfield exactintall calculations in integers throwing exceptions on overflowsetfield bigintall calculations using unlimited precision BigIntegerssetfield rationalfor fractions (rational numbers unlimited precision)setfield complexall calculations using complex numberssetfield simpleclosest match to standard jep operationsetfield mixed 30combines rational numbers and bigdecimal number with 30 dp
- Changing the field resets all variables.
- Different fields have different sets of functions and constants defiend
- The JavaScript versions may not always give the same results as the Java version as JavaScript has different ways of representing numbers.
Structured programming
The console allows simple structured programming constructs like loops and if statments. It supports
for(i=1;i<10;++i) { ... }
while(i<10) { ... } while loops
break; (inside a loop)
continue; (inside a loop)
if(i<10) { ... } else { ... }
statement; statement
{ statement; statement }
print(a,b,c)
println(a,b,c)
Examples
A simple loop can add the numbers from 1 to 10
sum=0; for(i=1; i<=10; ++i) { sum += i; }
Symbolic operations
diff(x^2,x)differentiate x^2 with respect to xrulesprints the set of differentiation rules usedclean(0+1*x)cleans a expressionsimplify(2x+3x)simplifies a expression using the polynomial simplification algorithmexpand((x+1)*(x-1))expands a polynomial'compare((x+1)^2, x^2+2x+1)compares without expansioncoeffs(x^2+2x+1,x)extract coefficients as an arraysubst(x*y*z,y=x+1,z=x-1)substitution rhs equations into the lhs expression
f := x^2set f to have and equation from the rhseqn(f)extract equation from a symbolic variableverbose on/verbose offswitch verbose mode on or off
Matrix operations
m = [[1,2],[3,4]]- creation of matrixu = [5,6]- creation of vectorm[1][2]- find the 2nd element in the 1st columndet(m)- the determinate of a matrixtrace(m)- the trace of a matrixtrans(m)- transpose of a matrixid(3)- creates a 3x3 identity matrixzeroMat(3,2)- creates a 3 by matrix of zeroszeroVec(3)- creates a vector of zeros length 3size(m)- finds the length of a vector or size of a matrixinv(m)- find the inverse of mv=solve(m,u)- find solution ofm * v = u
Statistical functions
count(v)- count the number of elementsmin(v)- finds the min value in a vector or matrixmax(v)- finds the max value in a vector or matrixsum(v)- finds the sum of the elementsproduct(v)- finds the product of the elementsmean(v)- finds the mean value in a vector or matrixvar(v)- finds the variance of the valuessd(v)- finds the standard deviation of the valuesmedian(v)- finds the mean value in a vector or matrixranks(d,data)- finds the rank of element d in data arrayranks(v)- finds the ranks all the elementsmode(v)- finds the mode of the values
Advanced Examples
Using the factorial(x) function to find number of digits of precision
Inputsetfield integer factorial(10) factorial(20) factorial(21) factorial(22) |
ResultSetting field INTEGER 3628800 2432902008176640000 51090942171709440000 1.1240007277776077e+21 |
Doubles work the same
setfield double factorial(21) factorial(22) |
Setting field DOUBLE 51090942171709440000 1.1240007277776077e+21 |
setfield bigint factorial(20) factorial(30) factorial(40) factorial(50) |
Setting field BIGINT 2432902008176640000 265252859812191058636308480000000 815915283247897734345611269596115894272000000000 30414093201713378043612608166064768844377641568960512000000000000 |
Calculations with fractions
setfield rational 1/6*2/5 1/6+1/2 |
Setting field RATIONAL 2/3 1/15 |
Calculation of pi using Ramanujan's formula
s=1103; a =1; c=1; d=1; \\
for(k=1;k<10;++k) {\\
a*=(4*k-3)*(4*k-2)*(4*k-1)*(4*k); \\
b =1103 + 26390*k; \\
c *= k*k*k*k; d *= 396^4; s+= a*b/(c*d); \\
v = 9801/(2*sqrt(2)*s); println(v); }
|
3.141592653589793877998905826306015 3.141592653589793238462649065702759 3.141592653589793238462643383279558 3.141592653589793238462643383279506 3.141592653589793238462643383279506 3.141592653589793238462643383279506 3.141592653589793238462643383279506 3.141592653589793238462643383279506 3.141592653589793238462643383279506 |
Calculation of e
s=1; f=1; for(k=1;k<30;++k) { f*=k; s+=1/f; println(s) }
|
2 2.5 2.666666666666666666666666666666667 2.708333333333333333333333333333334 2.716666666666666666666666666666667 2.718055555555555555555555555555556 2.718253968253968253968253968253969 ... 2.718281828459045235360287471352545 2.718281828459045235360287471352658 |
Continued fraction for pi
setfield double
a=zeroVec(20);
n=pi; for(i=1;i<=20;++i) { b=floor(n); n = 1/(n-b); a[i]=b }
a
|
Setting field DOUBLE [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] 4 [3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 3, 3, 23, 1, 1, 7, 4] |
a=[3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2]
for(i=1;i<=20;++i) { \\
s=a[i]; \\
for(j=i-1;j>0;--j) { \\
s = a[j]+1/s } \\
println(s) }
|
[3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2] 3 3.142857142857142857142857142857143 3.141509433962264150943396226415094 ... 3.141592653589793239014009759199591 3.141592653589793238386377506390380 3.141592653589793238493875058011561 |
f:= ...
f := x^2 - x - 1
g := diff(f,x)
x=1
for(i=0;i<10;++i) { x -= f/g; println(x,f); }
|
f:=x^2-x-1 g:=2*x-1 x=1 2, 1 1.666666666666666666666666666666667, 0.111111111111111111111111111111112 1.619047619047619047619047619047619, 0.002267573696145124716553287981859 1.618034447821681864235055724417427, 0.000001026515933067055100295739241 1.618033988749989097047296779290725, 2.10746819100131229750E-13 1.618033988749894848204586838338167, 8.882845E-27 1.618033988749894848204586834365638, 0E-33 1.618033988749894848204586834365638, 0E-33 1.618033988749894848204586834365638, 0E-33 1.618033988749894848204586834365638, 0E-33 |