kalker/kalk
bakk 0dc2e0572f Fixed "dx" in integrals, and created calculus.rs
Previously, eg. "dx" would not be parsed as "dx" after a function, since
the parser did not keep track of whether or not it was currently inside
an integral or not, properly. This commit fixes that, and also makes it
possible to use any variable after the "d", eg. "dy". The integration
function was also put in its own file: calculus.rs.
2021-05-17 16:51:16 +02:00
..
src Fixed "dx" in integrals, and created calculus.rs 2021-05-17 16:51:16 +02:00
Cargo.toml kalk_web: Updated kalk and fixed audit problems 2021-05-15 17:22:18 +02:00
LICENSE WebAssembly foundation 2020-12-30 22:50:39 +01:00
README.md Updated kalk library README to include a JavaScript example, disabled wasm optimization, and created wasm build script 2020-12-31 01:47:09 +01:00
wasm-build.sh Updated the kalk version in web related things 2021-03-31 22:10:05 +02:00

kalk

Kalk is a math parser library that supports user-defined variables and functions. An example of what it can parse:

f(x, y) = sum(1, 3, (2sin4/x!)^y) + cos(n deg)
a = 3
f(a, 2)

>> 1.1899401098014355

Features

  • Operators: +, -, *, /, !
  • Groups: (), ⌈⌉, ⌋⌊
  • Pre-defined functions and constants
  • User-defined functions and variables. f(x, y) = xy, x = 5
  • Understands fairly ambiguous syntax. Eg. 2sin50 + 2xy
  • Syntax highlighting
  • Special-symbol completion on tab. Eg. write sqrt and press tab. It will be turned into .

Rust Usage

use kalk::parser;
let mut parser_context = parser::Context::new();
let precision = 53;
let result = parser::eval(&mut parser_context, "5*3", precision).unwrap().unwrap();
assert_eq!(result.to_f64(), 15f64);

Using f64 instead of rug::Float

The cargo feature rug enables rug, and is used by default. If you disalbe this, kalk will use f64 instead, making it more portable.

Compiling

Make sure you have diffutils gcc make and m4 installed.

JavaScript Usage

const kalk = await import("@paddim8/kalk");
const context = new kalk.Context();
console.log(context.evaluate("2pi + 3").toScientificNotation().toString());