https://github.com/konstantin8105/sm
symbolic math on Go
https://github.com/konstantin8105/sm
ast go goast golang symbolic-math
Last synced: 7 months ago
JSON representation
symbolic math on Go
- Host: GitHub
- URL: https://github.com/konstantin8105/sm
- Owner: Konstantin8105
- License: mit
- Created: 2019-01-29T19:25:55.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-10-14T14:57:39.000Z (about 2 years ago)
- Last Synced: 2025-01-23T06:14:28.458Z (9 months ago)
- Topics: ast, go, goast, golang, symbolic-math
- Language: Go
- Size: 160 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sm
symbolic math on GoDocumentation:
```golang
// Sexpr - simplification of expression.
// Example:
//
// expr : "b*(2+3-1+8*a)",
// out : "4.000*b + 8.000*(a*b)",
//
// expr: "d(2*pow(x,a),x);constant(a);variable(x);",
// out: "2.000*(a*pow(x,a - 1.000))",
//
// Keywords:
//
// constant(a); for constants
// variables(a); for variables
// function(a,x,y,z,...); for function a(x,y,z)
//
func Sexpr(o io.Writer, expr string) (out string, err error) {
```Example:
```golang
func Example() {
eq, err := sm.Sexpr(os.Stdout, "-1+(-a)+(+5)+(+2+3+1)")
if err != nil {
panic(err)
}
fmt.Fprintf(os.Stdout, "%s", eq)
// Output:
// 5 + (-1 + (-a)) + (+2 + 3 + 1)
// 5.000 + (-1 + (-a)) + (+2 + 3 + 1)
// 5.000 + (-1 - a) + (+2 + 3 + 1)
// 5.000 + (-1.000 - a) + (+2 + 3 + 1)
// (5.000 + -1.000) - (a) + (+2 + 3 + 1)
// 4.000 - (a) + (+2 + 3 + 1)
// 4.000 - a + (+2 + 3 + 1)
// 4.000 - a + (1 + (+2 + 3))
// 4.000 - a + (1.000 + (+2 + 3))
// 4.000 - a + (1.000 + 5.000)
// 4.000 - a + 6.000
// (6.000 + 4.000) - (a)
// 10.000 - (a)
// 10.000 - a
// 10.000 - a
// 10.000 - a
}
```