Introduction
Installation
You can install mini-calc
via several methods
Cargo
cargo install mini-calc
Source
git clone https://github.com/vanilla-extracts/calc
cd calc
cargo build --release
./target/release/mini-calc
Nix
nix run github.com:vanilla-extracts/calc
Contributors
I am the main maintainer and developer of Calc.
Thanks to my friends, who helped me along the way
- Léana, for her help and code cleanup
- Sigmaficient, for his help to nixify the repo
Chapter I. Usage
Basic Operators
Calc supports basic arithmetic operators such as:
+
*
-
/
^
Variables
The calculators also implements a system of (for the moment all global) variables.
The syntax is simple, close to python. Its type-abilities are close to python too, you can re-assign a variable with another value of another type.
var = 5
Built-in variable
pi
is a double precision float representation of pie
is a double precision float representation of e
Chapter II. Functions
Built-in functions
The following functions are currently (as of 3.3.0
) built-in
- Trigonometry
sin
(vectorised)cos
(vectorised)tan
(vectorised)
- Hyperbolic trigonometry
sinh
(vectorised)cosh
(vectorised)tanh
(vectorised)
- Reverse trigonometry
asin
(vectorised)acos
(vectorised)atan
(vectorised)
- Exponentiation
exp
(vectorised)ln
(aliaslog
) (vectorised)
- Vectors
norm
- Matrices
det
invert
- Plot
plot
termplot
- Other
sqrt
(vectorised)factorial
(aliasfact
)abs
ceil
floor
round
Trigonometry
For trigonometry, the input is assumed to to in radians
, if it is in degrees
you need to add a second argument (can be anything, like true
) to the function
call.
Exp/ln
If you use the exp
function you can pass the base you want to work with
as a second argument. If nothing is supplied, we assume natural base.
Root
You can add a second argument to sqrt
for the nth
root instead
of the 2nd root.
User defined functions
You can define your own functions with the following syntax
(warning: it might change in 4.0.0
)
Partial functions
You can use a user-defined function to declare a partial function, to have a cos in degrees for example.
Chapter III. Configuration
The calculator is completely configurable, you can change the general color, the greeting message, the greeting color, the prompt and prompt color in a toml file found in your config folder.
$HOME/.config/mini-calc/mini-calc.toml
On most GNU+Linux distros.
Colors
You can use the following colors:
- blue
- black
- purple
- green
- cyan
- red
- yellow
- white
- an hexadecimal color (ex: #f7a8d8)
The default color (or if it can't be parsed) is cyan
.
Examples
A modified config might looks like this
And produce the following output
Command line interaction
You can interact in the REPL with the config the commands are:
config
: shows the config help.config reload
: reloads the configuration from the file.config reset
: resets the configuration to its default.config show
: shows the current configuration.config set <category> <value>
: modifies the configuration.
Categories are
greeting_message
: stringgreeting_color
: colorprompt_color
: colorprompt
: stringgeneral_color
: color
Chapter IV. Logic
Infix Operators
or
(alias||
)and
(alias&&
)geq
(alias>=
)leq
(alias<=
)gt
(alias>
)lt
(alias<
)
Chapter V. Plot
You can plot, provided you have gnuplot
installed,
which the backend relies on.
It works great on Linux and macOS, but it's not tested on Windows.
Help
As the plot
function is a little difficult you can call it without
parameters to show the help plot()
Section V.1. GUI
Default
To plot a function f
you just need to do plot(f)
Options
You can pass parameters to the function.
> plot(sin,-pi,pi,0.01,"sin","x(rad)","y","line")
Let's unpack, we have ploting the sin
function, from x=-pi
to x=pi
with a step of 0.01 rad
, the title of the graph is sin
, the x_axis
label is x(rad)
, the y_axis label is y
and we want a line.
User-defined functions
You can plot your own functions with the same call.
Here is the example for f(x) = x*x
Section V.2. Terminal
You can also plot right into the terminal, without need for the gnuplot
backend.
Default
The best example to show it to you (before the auto-scaling) is the square
function, from x=-5
to x=5
with a step of 0.1
.
Options
Like the GUI plotting, the terminal supports options
Auto scaling
Both the x
and y
axis supports auto-scaling
Chapter VI. Algebra
The calculator supports basic algebraic calculations, including
- Vectors
- Dot product (operator
*
- with another vector.) - Scalar product (operator
*
- with a scalar.) - Norm (function
norm
) - Addition (operator
+
)
- Dot product (operator
- Matrices
- Addition (operator
+
) - Multiplication (operator
*
- with another matrix.) - Scalar multiplication (operator
*
- with a scalar.) - Transposition (function
transpose
) - Determinant (via LUP-decomposition function
det
) - Inversion (via LUP-decomposition function
invert
)
- Addition (operator
The matrices (and vectors) are pretty printed (and aligned) (since v2.11.5
)
Section VI.1. Vectors
Basic vector calculation supports
- Addition (operator
+
) - Dot product (operator
*
- with another vector.) - Scalar product (operator
*
- with a scalar.) - Norm (function
norm
)
Section VI.2. Matrices
As of v2.7.0
matrix algebra supports
- Addition (operator
+
) - Multiplication (operator
*
- with another matrix.) - Scalar multiplication (operator
*
- with a scalar.) - Transposition (function
transpose
) - Determinant (via LUP-decomposition function
det
) - Inversion (via LUP-decomposition function
invert
)
Chapter VII. Exact math
Exact math has been added between version v2.11.0
to version v3.3.3
Section VII.1. Rational Reduction
As of version v2.11.0
rational exact math reduction was added, it supports.
- Rational operations
+
-
*
/
- Rational reductions
- Float rationalization (with 10 digits of precision)
Operations
In matrices
Section VII.2. Symbolic Reduction
As of v3.0.0
the support for symbolic reduction has been added to calc.
It supports multi-variables multi-operations reductions, you can reduce
expressions using it, fair warning, it uses a lot of parentheses
Section VII.3. Function differentiation
As of v3.2.0
, the calculator can differentiate both known functions (built-in)
and user-defined functions constructed using known functions and operations.
Warning
Beware, as of v3.3.3
there is some bugs to iron out. It doesn't
differentiate variables (for example x*x
works but not x²
).
And differentiation of function referencing each other
(for example v(x) = f(x) + x*x
) doesn't work either.
It's currently being fixed, and will be fixed before stable release v3.4.0
which is currently in alpha
development-testing (it will implements basic languages
features
such as flow control and condition.)
The release v3.3.4
, which correct those bugs is currently in beta
dev-testing
and will be released before v3.4.0
.
Examples
Built-in
User defined
Section VII.4. Float display
With v3.4.0
there is now a way to chose how you want your floats to be
displayed.
Modes
For example in normal
mode if you type
> 1.5
It outputs:
val: float = 1.5000000000
In exact
mode, that
> 1.5
Outputs:
val: rational = 3/2
And finally in science
mode, this
> 150.2
Outputs
val: float = 1.502*10²
Toggle float
There is a toggle_float
command in the REPL now.
Its usage is easy and it is auto-completed.
toggle_float <normal|science|exact>
It then displays a message telling you in which mode you toggled.
By default it is in exact
mode.