taschenrechner

Crates.iotaschenrechner
lib.rstaschenrechner
version0.2.5
sourcesrc
created_at2021-03-08 15:10:48.465989
updated_at2021-08-19 15:42:09.305641
descriptionComputer-Algebra-System including a REPL.
homepage
repository
max_upload_size
id365712
size86,105
Benedikt Schöps (m4dh0rs3)

documentation

README

TaschenrechnerComputer-Algebra-System :leftwards_arrow_with_hook:

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
Commit count: 0

cargo fmt