Go Mathematical Expression Toolkit

Go Doc Reference Build Status Go Report Card

The Go Expression Toolkit (Go-ExprTk) is a wrapper library based on C++ Mathematical Expression Toolkit Library (ExprTk).

It is a simple to use, easy to integrate and extremely efficient run-time mathematical expression parser and evaluation engine.

Go-ExprTk supports numerous forms of functional, logical and vector processing semantics and is very easily extendible.


go get github.com/Pramod-Devireddy/go-exprtk


package main

import (


func main() {
    exprtkObj := exprtk.NewExprtk()
    defer exprtkObj.Delete()

    exprtkObj.SetExpression("(x + 2)*(y-2)")


    err := exprtkObj.CompileExpression()
    if err != nil {

    exprtkObj.SetDoubleVariableValue("x", 18)
    exprtkObj.SetDoubleVariableValue("y", 32)


Check out more Examples

āš” Features

The Go-ExprTk library has the following capabilities:

  • Mathematical operators (+, -, *, /, %, ^)

  • Functions (min, max, avg, sum, abs, ceil, floor, round, roundn, exp, log, log10, logn, pow, root, sqrt, clamp, inrange, swap)

  • Trigonometry (sin, cos, tan, acos, asin, atan, atan2, cosh, cot, csc, sec, sinh, tanh, d2r, r2d, d2g, g2d, hyp)

  • Equalities & Inequalities (=, ==, <>, !=, <, <=, >, >=)

  • Assignment (:=, +=, -=, *=, /=, %=)

  • Logical operators (and, nand, nor, not, or, xor, xnor, mand, mor)

  • Control structures (if-then-else, ternary conditional, switch case, return-statement)

  • Loop structures (while loop, for loop, repeat until loop, break, continue)

  • Optimization of expressions (constant folding, strength reduction, operator coupling, special functions and dead code elimination)

  • String operations (equalities, inequalities, logical operators, concatenation and sub-ranges)

  • Expression local variables, vectors and strings

  • User defined variables, vectors, strings, constants and function support

  • Multivariate function composition

  • Multiple sequence point and sub expression support

  • Numeric integration and differentiation

  • Vector Processing: BLAS-L1 (axpy, axpby, axpb), all/any-true/false, count, rotate-left/right, shift-left/right, sort, nth_element, iota, sum, kahan-sum, dot-product, copy

ā¤ļø Credits

This module could not be possible without the ExprTk library by Arash Partow and the idea of creating the wrapper module by Narayana Rao G S

Published under MIT License

Go Exprtk

Go Mathematical Expression Toolkit. Run-time mathematical expression parser and evaluation engine.

Go Exprtk Info

ā­ Stars 13
šŸ”— Homepage pkg.go.dev
šŸ”— Source Code github.com
šŸ•’ Last Update 5 months ago
šŸ•’ Created a year ago
šŸž Open Issues 2
āž— Star-Issue Ratio 7
šŸ˜Ž Author Pramod-Devireddy