4 releases
0.2.5 | Aug 19, 2021 |
---|---|
0.2.4 | Aug 19, 2021 |
0.2.3 | Aug 19, 2021 |
0.2.2 | Mar 8, 2021 |
#10 in #infix
49KB
1K
SLoC
Taschenrechner
– Computer-Algebra-System ↩️
A
CAS
is an advanced symbolic calculator. It can evaluate, simplify, differentiate, integrate and solve algebraic expressions. This is a crate written in Rust.
Features
Warning: This is not yet feature-complete. See libqalculate for a better alternative.
- REPL interface
- Lex operators, functions, symbols, deciaml numbers
- Parse expressions of infix notation into a expressions tree
- Define variables and functions
- Simplify expressions
- Evaluate expressions to single numbers
- Comprehensive notation-error messages
- Arbitrary-precision arithmetic
- Integrate, differentiate expressions
- Solve single- and multi-variable equations / inequalities
TODO
Eval
The current eval is not very sophisticated. It is functional, but can't simplify any expressions, if a subexpression remains unresolved.
REPL
This crate comes with an interactive comand-line-interface: Read-Eval-Print-Loop.
use cas::prelude::*;
fn main() {
REPL::start();
}
Built-in functions and constants
(for a full complete list see default_env.txt
)
π
(pi),τ
(tau),e
(eurler's number),inf
(infinity),nan
(not a number)- trigonometric functions:
sin
,cos
,tan
, their inverse and hyperbole abs
,ceil
,floor
,trunc
,fract
How to build see Cargo for Rust
Technical
Also see my blog post!
Algebraic expressions
4.3 - π^2 = sin y
is an algebraic expression. It consists of atoms (4.3, π, 2, y
) and operators (-, ^, =, sin
). Operators manipulate atoms. We normally write such expressions in infix-notaion, where one has to know the precedence and associativity of an operator. The exponent (^
) must be evaluated before the the substraction (-
), evon though it appears later. To evaluate the expression linearly, it has to be converted into polish noation, which is basicly a single function call of function calls (= - 4.3 ^ π 2 sin y
).
Lexer and parser
To evaluate the string of an expression, it undergoes 3 steps:
- Lexer the string is split up into tokens (
4.3, -, π, ^, 2, =, sin, y
) - Parser the stream of tokens will be ordered into polish notation
- Eval the expression tree can now be evaluated recursively