algebra for Go

github.com/malcolmston/algebra

Symbolic mathematics — a tiny computer-algebra system.

 GitHubports sympy/sympy

A standard-library-only computer-algebra system, a spiritual port of a subset of Python's SymPy. Expressions are immutable trees over symbols, big.Int / big.Rat numbers, named constants and elementary functions — build, simplify, differentiate, integrate, expand, factor and solve, then print them back as readable infix.

Install

shell
$ go get github.com/malcolmston/algebra

Quick start

main.go
x := algebra.Sym("x")
f := algebra.MustParse("x^2 + 2*x + 1")

df := algebra.Diff(f, x)
fmt.Println(algebra.Simplify(df))   // 2*x + 2

Features

  • Immutable expression trees implementing an Expr interface
  • Exact arithmetic via math/big integers & rationals
  • Calculus: Diff and Integrate
  • Simplify, Expand, Factor, Collect, Subs
  • Equation solving: Solve (linear & quadratic)
  • Parse / MustParse infix input, canonical printing
algebra