aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 0fd44fba7c8e21bddf7dbb7508ba39200bca86ff (plain)
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
# computorv2

Calculator REPL

## Types

| Name     | Letter | Example              |
|----------|--------|----------------------|
| Rational | Q      | `1.5`                |
| Complex  | C      | `1.5i + 1.5`         |
| Matrix   | M      | `[ [1, 2]; [3, 4] ]` |

Imaginary number are converted to Complex.

## Operations

* `+` Addition
* `-` Substraction
* `*` Multiplication
* `/` Division
* `%` Modulo
* `^` Exponent
* `**` Matrix multiplication

|   | Q                            | C                       | M                   |
|---|------------------------------|-------------------------|---------------------|
| Q | `+`, `-`, `*`, `/`, `^`, `%` | `+`, `-`, `*`, `/`, `^` | `*`                 |
| C |                              | `+`, `-`, `*`, `/`, `^` | `*`                 |
| M |                              |                         | `**`, `+`, `-`, `*` |

## Expressions

* Declaration
    * Variable
    * Function (with one parameter)
* Evaluation

### Examples

```
> a = 1 + 3
4
> f(x) = x * 2
x * 2
> a = ?
4
> f(4) = ?
16
> f(4) + a + 5 = ?
25
```

Uses eager evaluation, variable value is known after assignment, function value is reduced to the maximum (except for parameter).

```
> a = 3
3
> b = a + 3
6
> f(x) = 2 * 3 * 4 * x
24 * x
```

## TODO

- [ ] Reduce functions expression
- [ ] `i` is not a valid label name
- [ ] Check if matrix are rectangular
- [ ] Polynomial detection and resolution
- [ ] More operators

- Bonus
    - [ ] Better error message
    - [ ] Builtin functions (sin, cos, ...)
    - [ ] Add realline library
    - [ ] Command to print environment