Documentation
¶
Overview ¶
Package nerdamer provides a small and light-weight symbolic math expression evaluator.
The back end used is Nerdamer-prime.
Example (Diff) ¶
Evaluating diff via nerdamer(string).
n, _ := New()
defer n.Close()
fmt.Println(n.Eval("nerdamer('diff(sin(x)/x, x)').toString()"))
Output: -sin(x)*x^(-2)+cos(x)*x^(-1) <nil>
Example (Diff2) ¶
Evaluating diff via the property of the nerdamer object.
n, _ := New()
defer n.Close()
fmt.Println(n.Eval("nerdamer.diff('sin(x)/x', 'x').toString()"))
Output: -sin(x)*x^(-2)+cos(x)*x^(-1) <nil>
Example (Expand) ¶
Evaluating expand as a string.
n, _ := New()
defer n.Close()
fmt.Println(n.Eval("nerdamer('expand((x+1)^2)').toString()"))
Output: 1+2*x+x^2 <nil>
Example (Expand2) ¶
Evaluating expand as JSON for machine processing.
n, _ := New()
defer n.Close()
fmt.Println(n.Eval("nerdamer('expand((x+1)^2)')"))
Output: {"symbol":{"group":8,"value":"1+2*x+x^2","multiplier":{"num":"1","den":"1"},"power":{"num":"1","den":"1"},"symbols":{"x":{"group":6,"value":"x","multiplier":{"num":"1","den":"1"},"power":{"num":"1","den":"1"},"symbols":{"1":{"group":3,"value":"x","multiplier":{"num":"2","den":"1"},"power":{"num":"1","den":"1"},"imaginary":false,"isInfinity":false},"2":{"group":3,"value":"x","multiplier":{"num":"1","den":"1"},"power":{"num":"2","den":"1"},"imaginary":false,"isInfinity":false}},"length":2,"imaginary":false,"isInfinity":false},"#":{"group":1,"value":"#","multiplier":{"num":"1","den":"1"},"power":{"num":"1","den":"1"}}},"length":2,"imaginary":false,"isInfinity":false}} <nil>
Example (Expand3) ¶
Evaluating expand as formatted JSON for a human reader.
n, _ := New()
defer n.Close()
fmt.Println(n.Eval("JSON.stringify(nerdamer('expand((x+1)^2)'), null, 2)"))
Output: { "symbol": { "group": 8, "value": "1+2*x+x^2", "multiplier": { "num": "1", "den": "1" }, "power": { "num": "1", "den": "1" }, "symbols": { "x": { "group": 6, "value": "x", "multiplier": { "num": "1", "den": "1" }, "power": { "num": "1", "den": "1" }, "symbols": { "1": { "group": 3, "value": "x", "multiplier": { "num": "2", "den": "1" }, "power": { "num": "1", "den": "1" }, "imaginary": false, "isInfinity": false }, "2": { "group": 3, "value": "x", "multiplier": { "num": "1", "den": "1" }, "power": { "num": "2", "den": "1" }, "imaginary": false, "isInfinity": false } }, "length": 2, "imaginary": false, "isInfinity": false }, "#": { "group": 1, "value": "#", "multiplier": { "num": "1", "den": "1" }, "power": { "num": "1", "den": "1" } } }, "length": 2, "imaginary": false, "isInfinity": false } } <nil>
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Nerdamer ¶
type Nerdamer struct {
// contains filtered or unexported fields
}
Nerdamer is the evaluator instance.
func New ¶
New returns a newly created Nerdamer. The instance must be eventually properly Nerdamer.Close-ed to prevent resource leaks.
func (*Nerdamer) Eval ¶
Eval returns the result of evaluating 'js'.
Additional info migth be available at nerdamer and/or nerdamer-prime.
