/
builtin_trig.go
69 lines (64 loc) · 1.83 KB
/
builtin_trig.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package expreduce
import (
"math"
"math/big"
"github.com/corywalker/expreduce/expreduce/atoms"
"github.com/corywalker/expreduce/pkg/expreduceapi"
)
func mathFnOneParam(fn func(float64) float64) func(expreduceapi.ExpressionInterface, expreduceapi.EvalStateInterface) expreduceapi.Ex {
return (func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.GetParts()) != 2 {
return this
}
flt, ok := this.GetParts()[1].(*atoms.Flt)
if ok {
flt64, acc := flt.Val.Float64()
if acc == big.Exact {
return atoms.NewReal(big.NewFloat(fn(flt64)))
}
}
return this
})
}
func getTrigDefinitions() (defs []Definition) {
defs = append(defs, Definition{
Name: "Sin",
legacyEvalFn: mathFnOneParam(math.Sin),
toString: simpleTeXToString("sin"),
})
defs = append(defs, Definition{
Name: "Cos",
legacyEvalFn: mathFnOneParam(math.Cos),
toString: simpleTeXToString("cos"),
})
defs = append(defs, Definition{
Name: "Tan",
legacyEvalFn: mathFnOneParam(math.Tan),
toString: simpleTeXToString("tan"),
})
defs = append(defs, Definition{
Name: "ArcTan",
legacyEvalFn: mathFnOneParam(math.Atan),
toString: simpleTeXToString("tan^{-1}"),
})
defs = append(defs, Definition{
Name: "Cot",
legacyEvalFn: mathFnOneParam(func(x float64) float64 { return 1 / math.Tan(x) }),
toString: simpleTeXToString("cot"),
})
defs = append(defs, Definition{
Name: "TrigExpand",
OmitDocumentation: true,
})
defs = append(defs, Definition{
Name: "TrigReduce",
OmitDocumentation: true,
})
defs = append(defs, Definition{
Name: "TrigToExp",
OmitDocumentation: true,
})
defs = append(defs, Definition{Name: "Degree"})
defs = append(defs, Definition{Name: "RotationMatrix"})
return
}