/
builtin_atoms.go
62 lines (60 loc) · 1.68 KB
/
builtin_atoms.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
package expreduce
import (
"github.com/corywalker/expreduce/expreduce/atoms"
"github.com/corywalker/expreduce/pkg/expreduceapi"
)
func getAtomsDefinitions() (defs []Definition) {
defs = append(defs, Definition{
Name: "Rational",
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.GetParts()) != 3 {
return this
}
nAsInt, nIsInt := this.GetParts()[1].(*atoms.Integer)
dAsInt, dIsInt := this.GetParts()[2].(*atoms.Integer)
if nIsInt && dIsInt {
return es.Eval(atoms.NewRational(nAsInt.Val, dAsInt.Val))
}
return this
},
})
defs = append(defs, Definition{
Name: "Complex",
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.GetParts()) != 3 {
return this
}
validComplexType := func(e expreduceapi.Ex) bool {
switch e.(type) {
case *atoms.Integer:
return true
case *atoms.Flt:
return true
case *atoms.Rational:
return true
default:
return false
}
}
if validComplexType(this.GetParts()[1]) &&
validComplexType(this.GetParts()[2]) {
return es.Eval(
atoms.NewComplex(this.GetParts()[1], this.GetParts()[2]),
)
}
return this
},
})
defs = append(defs, Definition{Name: "String"})
defs = append(defs, Definition{Name: "Real"})
defs = append(defs, Definition{Name: "Integer"})
defs = append(defs, Definition{Name: "IntegerQ"})
defs = append(defs, Definition{Name: "Im"})
defs = append(defs, Definition{Name: "Re"})
defs = append(defs, Definition{
Name: "ReIm",
OmitDocumentation: true,
expreduceSpecific: true,
})
return
}