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

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 

Example

Built-in variable

  • pi is a double precision float representation of pi
  • e 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 (alias log) (vectorised)
  • Vectors
    • norm
  • Matrices
    • det
    • invert
  • Plot
    • plot
    • termplot
  • Other
    • sqrt (vectorised)
    • factorial (alias fact)
    • 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.

example

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.

example

Root

You can add a second argument to sqrt for the nth root instead of the 2nd root.

example

User defined functions

You can define your own functions with the following syntax (warning: it might change in 4.0.0)

example

Partial functions

You can use a user-defined function to declare a partial function, to have a cos in degrees for example.

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.

config

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

mod_config

And produce the following output

mod_config_look

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: string
  • greeting_color: color
  • prompt_color: color
  • prompt: string
  • general_color: color

conf_inter

Chapter IV. Logic

Infix Operators

  • or (alias ||)
  • and (alias &&)
  • geq (alias >=)
  • leq (alias <=)
  • gt (alias >)
  • lt (alias <)

example

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()

plot_help

Section V.1. GUI

Default

To plot a function f you just need to do plot(f)

plot_default

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.

plot_custom

User-defined functions

You can plot your own functions with the same call. Here is the example for f(x) = x*x

plot_f

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.

plot_term

Options

Like the GUI plotting, the terminal supports options

plot_term_option

Auto scaling

Both the x and y axis supports auto-scaling

plot_term_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 +)
  • 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)

The matrices (and vectors) are pretty printed (and aligned) (since v2.11.5)

matrix_pretty_printed

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)

vector_calc

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)

matrix

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

operations

In matrices

matrix

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

symbolic reduction

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 ). 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

diff_bi

User defined

ud

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.

Example

float_mode