mini-calc 3.4.2

A Fully-Featured Configurable (mini) Rust Calculator
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
# Calc

<div align="center">

**Calc: A fully-featured minimalistic configurable rust calculator**

[![Rust Test](https://github.com/coco33920/calc/actions/workflows/rust-test.yml/badge.svg)](https://github.com/coco33920/calc/actions/workflows/rust-test.yml)
[![Release](https://img.shields.io/github/v/release/coco33920/calc.svg?include_prereleases=&sort=semver&color=f7a8d8)](https://github.com/coco33920/calc/releases/latest)
[![](https://img.shields.io/crates/v/mini-calc?link=https%3A%2F%2Fcrates.io%2Fcrates%2Fmini-calc)](https://crates.io/crates/mini-calc)
![](https://img.shields.io/crates/l/mini-calc?link=https%3A%2F%2Fgithub.com%2coco33920%2Fcalc%2Fblob%2Fmaster%2FLICENCE)
[![](https://img.shields.io/crates/d/mini-calc)](https://crates.io/crates/mini-calc)

</div>

## Install

### Source 

You can install the latest version from source

```bash
git clone https://github.com/vanilla-extracts/calc
cd calc
cargo build --release
./target/release/mini-calc
```

### Cargo
```bash
cargo install mini-calc
```

### using Nix

Alternatively, you can use [nix](https://nixos.org) to build or run this project.

Running directly:
```sh
nix run github:vanilla-extracts/calc
```
> You may need to enable nix experimental features. In that case, execute the following command: `mkdir -p ~/.config/nix && echo "experimental-features = nix-command flakes" | tee ~/.config/nix/nix.conf`

### From packaged version
Both `.deb` and `.rpm` packages are availables in the download page

## Website
The website (powered by oranda) is available for more informations [the website](https://calc.charlotte-thomas.me) for more informations.

## Manual

If you prefer a PDF, there is a [manual](manual.pdf)

## Contributors

|                                                                                                                                               | Name    | Role                     | Website                                     |
|-------------------------------------------------------------------------------------------------------------------------------------------------|:--------|:-------------------------|:--------------------------------------------|
| [<img src="https://avatars.githubusercontent.com/u/17108449?v=4" style="border-radius: 50%;height:90pt;width:auto">]https://github.com/vanilla-extracts        |Charlotte THOMAS          | Main developer/Maintener | [Main page]https://www.charlotte-thomas.me         | 
| [<img src="https://avatars.githubusercontent.com/u/87855546?v=4" style="border-radius: 50%;height:90pt;width:auto">]https://github.com/leana8959        |Léana 江                  | Help, cleanup            | [Website/Blog]https://earth2077.fr        |
| [<img src="https://avatars.githubusercontent.com/u/53050011?v=4" style="border-radius:50%;height:90pt;width:auto">]https://github.com/Sigmaficient      |Sigmaficient              | Nixify                   | [Website]https://sigmanificient.github.io/|

## TODO List

The TODO list is completed so I collapsed it
<details> 
<summary>TODO List</summary>

- [X] Lexing of basic operations
    - [X] Lexing operators
    - [X] Lexing lpar,rpar,quote
    - [X] Lexing int
    - [X] Lexing floats
    - [X] Lexing identifiers
- [X] Parsing of basic operations
    - [X] Parsing int,floats,identifiers
    - [X] sum operation
    - [X] minus operation
    - [X] multiplication operation
    - [X] division operation
- [X] Parsing advanced operations
    - [X] Parsing lpar,rpar
    - [X] mathematical priority
        - [X] Left priority
        - [X] Right priority
    - [X] parenthesis support
    - [X] Assignment
    - [X] associativity support
        - [X] Left associativity
        - [X] Right associativity
- [X] Application REPL
    - [X] Add the REPL
        - [X] basic REPL
        - [X] colour message
        - [X] colourised prompt
    - [X] Add colour
- [X] Interpreter
    - [X] Basic operation interpreter
    - [X] Advanced operation interpreter
    - [X] Identifiers (variable) interpreter
- [X] Built-in
    - [X] pi
    - [X] e
- [X] Config
    - [X] Config colours
    - [X] Config prompt
- [X] Add more operations
    - [X] exponent
- [X] Add support for functions
    - [X] exp
    - [X] ln
    - [X] log base a
    - [X] cos/sin/tan
    - [X] cosh/sinh/tanh
    - [X] atan/acos/asin
- [X] Add logic
    - [X] Add basic true/false
    - [X] Add binary operator
        - [X] or (&&)
        - [X] and (||)
        - [X] `>=`
        - [X] `>`
        - [X] `<=`
        - [X] `<`
        - [X] `==`
    - [X] Add unary operator
        - [X] not (!)
- [X] Vector calculation
    - [X] Add vectors to the datatypes
    - [X] Lex vectors
    - [X] Parse vectors
    - [X] Add vector operations
      - [X] Dot product
      - [X] Vector norm
      - [X] Vector addition
- [X] Matrix calculation
    - [X] Add matrix to the datatypes
    - [X] Lex matrices
    - [X] Parse matrices
    - [X] Add matrices operation
      - [X] Matrix addition
      - [X] Matrix multiplication
      - [X] Calculate the matrix determinant
      - [X] Calculate the reverse matrix
- [X] Interact with the configuration
    - [X] Print current config
    - [X] Reset config to default
    - [X] Set config
      - [X] Set main color
      - [X] Set prompt color
      - [X] Set prompt 
      - [X] Set greeting message
      - [X] Set greeting color 
    - [X] Reload config
</details>

## Evolution

Everything is advanced so I'll put a big details here

<details>
<summary>Finished Evolution</summary>

### Ploting

Plot functions (both stdlib, and runtime) would be useful and appreciated.
Plotting is powered by gnuplot, it will works on Unix-like (MacOS, Linux) but I don't have any idea about Windows

- [X] Plot stdlib functions
- [X] Plot runtime functions
- [X] Save plot to png/svg/pdf

- [X] Add terminal ploting
    - [X] Calculate ploting height and width
    - [X] Computes individual points
    - [X] Generate each line
    - [X] Prints each line

- [X] Auto level x axis in termplot
- [X] Auto level y axis in termplot

#### Example of plotting

You can plot function defined in the standard library of calc or user defined functions, to display the help just type `plot()`

![](docs/assets/plot_help.png)

You can then plot for example

Plotting cos with the default values (from 0 to 3pi, with a step of 0.01pi)

![](docs/assets/plot_cos_default.png)

Plotting sin with custom values (from -pi to pi, with a step of 0.01rad, with line, title, x label, y label)

![](docs/assets/plot_sin_custom.png)

Defining f(x) = x² and plotting it with custom values (from -10 to 10, with a step of 0.1, with linespoint)

![](docs/assets/plot_f.png)

#### Example of terminal plotting

You can plot in the terminal, for example 

![](docs/assets/plot_term_x_squared.png)

And it supports the labels too

![](docs/assets/plot_term_x_squared_labels.png)

And now it auto scales on y!

![](docs/assets/termplot_cos.png)

</details>

### Exact math calculator

As this project provides a frontend with a parser we could plug an exact math engine in the backend to transform `calc` into a 
real exact math calculator.
TODO List for the Exact Math Engine

- [X] Rational calculation
  - [X] Implement rational numbers operations 
  - [X] Rational reduction
- [X] Literal calculation
  - [X] Computes literal expression with uninitialized operators
  - [X] Literal reduction
- [ ] Irrational calculation 
  - [ ] Implement irrational numbers operations
  - [ ] Irrational reduction

#### Example of rational computations

As of 2.11.0 the support for rational exact math has been implemented

![](docs/assets/exact_rationals.png)

As of 2.11.1 it works in matrices!

![](docs/assets/exact_inverse.png)

As of 2.11.4 floats are automatically rationalized (with 10 decimal points of precision)

![](docs/assets/rationalize.png)

### CAS

If we ever go to this step, yes, I will remove the "minimalistic" from the description
- [ ] It's hard.


## Examples

This is big, so details once again. The README is not up to date please read the
manual for more up to date informations

<details>
<summary>Examples</summary>

### REPL with only Lexing (verbose mode: on by default)

![](docs/assets/test_lexing.png)

### REPL with lexing and basic operation parsing (verbose mode: on by default)

![](docs/assets/test_parsing_basic_operations.png)

### REPL and functionning interpreter (verbose mode: off by default)

![](docs/assets/test_interpreter.png)

## Configuration

You can configure the general color, greeting message, greeting color, prompt and prompt color from the file for example
in (for linux)

```
~/.config/mini-calc/mini-calc.toml
```

Or situated in your operating system config folder.


You can interact with the configuration with the command line, more info in [the web page](https://calc.nwa2coco.fr/config.html)


### What the configuration looks like

The default configuration looks like this

![img.png](docs/assets/img.png)

### Colors

Available colors are

- purple
- cyan
- blue
- black
- red
- yellow
- green
- white
- an hexadecimal colour (ex: "#f7a8d8")

Default colour (if the configuration fail to load) is Cyan.

### Example of a modified configuration

Configuration:

![img.png](docs/assets/config_modified.png)

It looks like:

![img.png](docs/assets/config_looks.png)

## Functions

The following functions are available

- sin
- cos
- tan
- sinh
- cosh
- tanh
- asin
- acos
- atan
- exp
- ln (alias: log)
- sqrt
- factorial (alias: fact)
- abs
- ceil
- floor
- round

### Trigonometry

For trigonometry, the input are assumed to be in radian, if not, you have to put "false" or "true" as second argument,
example shown bellow

![img.png](docs/assets/trigo.png)

### Exp/ln

If you use the exp function you can pass a second argument for the base you are using, if no second arguments are passed
this is assumed to be in natural base

![img.png](docs/assets/expln.png)

### Root

You can take the nth root with the sqrt function, by default it takes the second root.

![img.png](docs/assets/nth_root.png)

### Round

You can round to the nth decimal with the round function, by default it round to the integer (floor)

![img.png](docs/assets/round.png)

### Vectorization 

Function are now vectorized! Just pass a vector as an argument!

![](docs/assets/sqrt_vectorized.png)

## Logic

You can now use logic! I implemented the following functions:

- or (alias : ||)
- and (alias : &&)
- geq (alias : `>=`)
- gt (alias : `>`)
- leq (alias : `<=`)
- lt (alias :`<`)
- eq (alias : `==`)

Example:

![img.png](docs/assets/logic.png)

## User defined functions!

You can define your own functions!

![img.png](docs/assets/user_defined.png)

## Vector calculation !

You can use vectors! 

- add vector to each others
- added the `norm` function to compute the norm
- dot product between two vectors ( * operator)

Functions added: 
- norm

![](docs/assets/vector.png)

## Matrices !

As of 2.7.0 matrix algebra is implemented (using lup reduction)

- you can add matrices 
- multiply compatible matrices

functions added
- transpose
- invert
- det 

![](docs/assets/matrix.png)

As of 2.11.3 matrices are pretty printed !

![](docs/assets/matrix_pretty_printed.png)

## Non interactive use
As of 2.12.0 non interactive use was added

![](docs/assets/non_interactive_use.png)

</details>