Are my computations sent to a server ?
No. All computations are made locally in your browser. Hence NumCalc preserves your privacy.
Is there a command line equivalent of numcalc.com ?
Yes, it is open source and you can download it with the
libbf library.
How can I reuse my previous inputs or results ?
With the {Up} and {Down} arrow keys you get your last inputs. With the _ symbol, you get the previous result.
Can I make symbolic calculus with NumCalc ?
NumCalc is not a generic symbolic calculator: it cannot simplify mathematical expressions. However, it does arbitrary precision computations involving integers, floating point numbers, fractions, complex numbers, polynomial and tensors, which are suffisent for many mathematical and engineering tasks.
How can I enter a polynomial ?
You must use the X variable. Try for example (1+X)^10 . Polynomials are stored internally as array of coefficients. The fact that they are displayed as conventional expressions is a cosmetic feature.
How can I convert between units ?
Use the convert function. Example: convert(32, "inches", "cm") .
How can I get the Taylor expansion of a function ?
O(x^n) indicates that you are manipulating Taylor series. Example: sin(X+O(X^10)) to get the Taylor expansion of sin(x) at order 9.
Can I get the derivative or integral of a function ?
NumCalc is not a symbolic calculator, so it cannot give you the result for arbitrary functions. However, as it manipulates polynomials, rational fonctions and power series, it can give the answer for them. Example: deriv((1+X^2)//(2+X)), integ(1+X^2)
NumCalc Tutorial
NumCalc is a lightweight and easy to use scientific calculator. It has
the following features:
- Arbitrary precision integers, decimal and binary floating point numbers, fractions
- Graphical plot of arbitrary functions
- Numerical equation solving
- Unit conversions
- Complex numbers including complex transcendental functions
- Polynomials, rational fonctions and Taylor series
- Linear algebra: matrix inversion, rank, eigen values and kernel extraction.
- Multi-dimensional array (tensor) support
NumCalc has a syntax close to Javascript with a type system
inspired from the Julia language. A command line version of
NumCalc (
bfcalc) is provided with
the
LibBF library.
Basic Use
You can type:
2*(1+3)
which yields:
8
_ is a variable containing the last result:
3*_
yields:
24
Fractions: NumCalc supports fraction with
the // operator:
1//3+1//2
which yields:
5//6
fractions and integers are not limited in size (except by the memory
and the time you want to spent waiting for the result !). For
example:
2^256
yields the exact value of 2 to the power of 256.
Floating point numbers: NumCalc supports decimal floating point numbers. They are entered with a decimal point. Integer division and negative integer power also yield floating point numbers:
1/3+1/7
yields:
0.4761904761904762
The number of digits can be modified with
the
setprec() function:
setprec(34)
1/7
0.1428571428571428571428571428571429
Built-in functions: all the usual mathematical functions are available such as: sqrt (square root), sin, cos, tab, log (logarithm in base e), exp, ...
Constants are referenced by upper case names, e.g. PI for the pi constant. Example:
sin(PI/8)
0.3826834323650897
Multiple expressions: You can type several expressions on the same line by separating them with a semicolon.
a=1+3;b=a^2+1
Variables: You can store your results in variables and reuse them in the following expressions:
a=sin(PI/8)
b=sqrt(a)
Functions: You can define single variable functions with the Javascript arrow function syntax:
f = x => 1/x^2
f(2)
0.25
Functions with more than one argument are only supported with the Javascript syntax:
function f(x, y) { return y/x^2 }
f(2,3)
0.75
Graphical plots: functions can easily be plotted:
plot(x => sin(x))
You can specify the x range with additional parameters:
plot(x => sin(x)/x,-2*PI,2*PI)
The y range is found automatically, but you can also specify it:
plot(x => sin(x)/x,-2*PI,2*PI,-1,1)
Equation solving: NumCalc can find a numerical solution for single variable equations. Let say you want to solve cos(x)=x. You can plot the function cos(x)-x to have an idea of the position of the solution:
plot(x => cos(x)-x)
Then you can feed the calculator with the initial guess (say 0.8) to have a more precise solution:
solve(x => cos(x)-x, 0.8)
0.7390851332151606
Unit convertion: the calculator can convert between most physical units. It also knows how to combine units and tell whether they measure the same quantity (i.e. it does dimensional analysis).
You can specify units either by typing their full name (e.g. kilometers or by using the standar abbreviation (e.g. km). Units can be combined with *, ^ and / (e.g. km*h^-1 or km/h are the same).
Example of unit conversions. Let's say you want to convert 10 meters per second to kilometers per hour:
convert(10, "m/s", "km/h")
36.0
All the understood units and prefixes can be viewed in the online help.
Binary arithmetic: Use the 0x prefix to enter
hexadecimal numbers (e.g. 0x1a). The 0b prefix is
used for binary numbers. The output radix can be changed with
the Decimal and Hexa radio buttons.
The calculator supports all the standard Javascript bitwise
logical and shift operators. The notable exception is
the exclusive or which is implemented with
the ^^ operator because the ^ binary
operator is reserved for the power operator.
All binary arithmetic functions assume that integers are
represented in two's complement notation. Hence a negative number can
be seen as having an infinite number of '1' to the left.
Advanced Use
You can stop reading this tutorial at this point if you don't intend to deal with more advanced mathematical objects.
Complex numbers: imaginary constants have a trailing 'i'. The I constant represents 1i:
(1+2i)*(2+3i)
Most predefined functions deal with complex numbers:
exp(-1i*PI)
Polynomials: use the X constant to enter polynomials. Polynomials are represented internally as an array of their coefficient, so the actual variable used to represent them does not matter. In the calculator, the X variable is used by convention.
(1+X)^3
X^3+3*X^2+3*X+1
You can evaluate a polynomial at one point by calling it as a function:
p=(1+X)^3;p(1/2)
It can also be useful to substitute the X variable with another polynomial.
A polynomial complex root finder based on the Laguerre's method is also included:
polroots(X^3-1)
Rational fonctions: if you make a fraction of two polynomials you get a rational fonction and they can be manipulated as objects too:
deriv(1//(1+X)+2//(2+X)+3//(3+X))
gets the derivative of the rational function. Note that integration of rational fonctions is not supported.
Taylor series: Taylor series are created with the O function. Taylor series can be seen as polynomials where all the terms of degrees >= O(X^n) are thrown away. To be more precise, the calculator handles Laurent series as well. It means that the exponents can be negative too.
Example of use:
(1+X+O(X^3))^(1/3)
1.0+0.3333333333333333*X-0.1111111111111111*X^2+O(X^3)
Computes the order 2 taylor expansion of (1+x)^(1/3). The calculator also knows the Taylor expansion of most usual functions:
sin(X+O(X^4))
1.0*X-0.1666666666666667*X^3+O(X^4)
You can get a rational result by forcing using a rational series:
sin(0//1+X+O(X^4))
1//1*X-1//6*X^3+O(X^4)
Linear algebra: Vectors, matrixes and more generally multi-dimensional arrays (tensors) are supported. All the elements of a tensor have the same type. Example:
Enter a 3x3 matrix as a two-dimensional tensor:
a=[[1,2,3],[2,3,4],[5,6,8]]
Compute its determinant:
det(a)
Inverse it:
inverse(a)
Sub matrixes can be extracted and assigned to (same idea as the Python language):
a[1:3,1:3]
[[3, 4],[6, 8]]
Extracts the 2x2 bottom left sub matrix of a.
The functions
rank,
ker,
charpoly and
eigenvals yield respectively the rank, kernel, characteric polynomial and eigen values of a matrix.
Vectors are also supported as one-dimensional tensor:
v=[1,2,3]
When dealing with matrix multiplication, they are considered as column vectors, e.g:
a*v
[14, 20, 41]
dp(x,y) does the dot product of vectors.
cp(x,y) does the 3 dimensional cross product of vectors. Most operations defined on numbers also work on vectors and matrixes component-wise. The special
.* binary operator does component-wise tensor multiplication.
Arrays: arrays are lists of elements of any type. They are created with Array(1,"a"). They are the equivalent of Javascript arrays or Python lists. len() return the number of elements of an array.
Primes: isprime(n) and nextprime(n) test if a number is prime using the Miller Rabin probabilistic test. factor(n) factorize a number using trial divisions.
Modulo arithmetic: invmod(a,m) returns the inverse
of a modulo m. pmod(a,b,m) compute a^b modulo m with less
computational resources than doing a^b%m. It also works with
polynomials.
Binary floating point numbers: Use a
trailing l to define binary floating point
literals: 2.125l or 0x1.0p1. They are
internally stored as arbitrary precision binary IEEE-754
floating numbers. Use setbprec() to set the number of
mantissa bits.
Javascript syntax: By enabling the Javascript syntax
(JS radio button), ^ becomes the xor operator
and [1,2] is equivalent to Array(1,
2). Tensors can be entered with Tensor([1,2]).
Type system: Numcalc is a strongly, dynamically typed language. The following numeric types are supported:
- Integer: arbitrarily large integers
- Fraction: rational number
- Decimal: decimal arbitrary precision floating point numbers with IEEE 754 semantics
- Float: binary arbitrary precision floating point numbers with IEEE 754 semantics
- Complex(T): complex number. T can be Integer, Fraction, Decimal or Float
The following other types are supported:
- Boolean: boolean (true and false values)
- Polynomial(T): polynomial of a numeric type T
- RationalFunction(T): rational function of numeric type T (fraction of polynomials)
- Series(T): series of a numeric type T
- Tensor(T): tensor of type T
- Array: array. Elements can have any type
- Function: function
- String: string of unicode characters
- Null: type of the null value
Credits
NumCalc borrows many ideas
from
PARI/GP,
calc and
Julia.
It uses the LibBF library.