Skip to content

A symbolic math module for the Go (Golang) Programming Language.

License

Notifications You must be signed in to change notification settings

MatProGo-dev/SymbolicMath.go

Folders and files

NameName
Last commit message
Last commit date
Aug 26, 2024
Feb 10, 2024
Feb 26, 2024
Apr 18, 2025
Apr 18, 2025
Apr 18, 2025
Dec 15, 2024
Nov 18, 2023
Jun 28, 2024
Dec 5, 2023
Nov 27, 2023

Repository files navigation

Go Reference codecov

SymbolicMath.go

A symbolic math module for the Go (Golang) Programming Language. It features a simple, composable API for performing math operations on symbolic expressions and is built to express everything from scalar constants to matrices of polynomials.

Some key features include:

  • Composable operations which allow complex mathematics to be expressed in as few lines as you wish (e.g., x.Transpose().Multiply(Q).Multiply(x))
  • Simple API for defining constants and variables (e.g., Q := getKMatrix.From([][]float64{{1, 0}, {0, 2.0}}))
  • Recognition of gonum matrices and vectors in most operations (e.g., vv1.Plus(mat.NewVecDense(N, []float64{1, 2, 3})))
  • Producing panics instead of errors (i.e., if something strange is written in symbolic math, like the multiplication of two mismatched matrices, then the program will panic instead of returning an error. This way, you can worry about the math and not the error handling.)

Some documentation can be found by clicking the "reference" badge above.

Installation

go get github.com/MatProGo-dev/SymbolicMath.go

Usage

package main

import (
    "fmt"
	getKMatrix "github.com/MatProGo-dev/SymbolicMath.go/get/KMatrix"
    "github.com/MatProGo-dev/SymbolicMath.go/symbolic"
)

func main() {
	// Constants
	N := 2
	x := symbolic.NewVariableVector(N)
	Q := getKMatrix.From(
		[][]float64{
			{1, 0},
			{0, 2.0},
		})
	
	// Create the quadratic polynomial
	quadPoly := x.Transpose().Multiply(Q).Multiply(x)

	// Print the polynomial
	fmt.Println(quadPoly.String())
	
	/* Other stuff... */
}

Further examples can be found in the examples directory.

Related Projects

This project was motivated by the need for a symbolic math package for defining optimization and control theory problems in Go, but symbolic mathematics is a topic that covers a wide range of applications. If this tool is not useful for your purpose, then you might find one of the following projects more helpful:

While other symbolic math libraries exist for Go, they typically focus on:

About

A symbolic math module for the Go (Golang) Programming Language.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages