Skip to content

Commit

Permalink
Just need to add interface functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
corywalker committed Oct 17, 2018
1 parent d8bc8b4 commit ead23b0
Show file tree
Hide file tree
Showing 41 changed files with 318 additions and 318 deletions.
4 changes: 2 additions & 2 deletions expreduce/builtin.go
Expand Up @@ -24,7 +24,7 @@ type Definition struct {
Details string

// Map symbol to Eval() function
legacyEvalFn (func(*expreduceapi.ExpressionInterface, *expreduceapi.EvalStateInterface) expreduceapi.Ex)
legacyEvalFn (func(expreduceapi.ExpressionInterface, expreduceapi.EvalStateInterface) expreduceapi.Ex)
SimpleExamples []TestInstruction
FurtherExamples []TestInstruction
Tests []TestInstruction
Expand Down Expand Up @@ -160,7 +160,7 @@ func (def *Definition) AnnotateWithDynamicUsage(es expreduceapi.EvalStateInterfa
}
}

func (def *Definition) AnnotateWithDynamic(es *expreduceapi.EvalStateInterface) {
func (def *Definition) AnnotateWithDynamic(es expreduceapi.EvalStateInterface) {
def.AnnotateWithDynamicTests(es)
def.AnnotateWithDynamicUsage(es)
}
Expand Down
16 changes: 8 additions & 8 deletions expreduce/builtin_arithmetic.go
Expand Up @@ -203,7 +203,7 @@ func splitTerm(e expreduceapi.Ex) (expreduceapi.Ex, expreduceapi.Ex, bool) {
return NewInteger(big.NewInt(1)), NewExpression(append([]expreduceapi.Ex{NewSymbol("System`Times")}, asTimes.Parts[1:]...)), true
}
}
asExpr, isExpr := e.(*expreduceapi.ExpressionInterface)
asExpr, isExpr := e.(expreduceapi.ExpressionInterface)
if isExpr {
return NewInteger(big.NewInt(1)), NewExpression([]expreduceapi.Ex{
NewSymbol("System`Times"),
Expand Down Expand Up @@ -239,7 +239,7 @@ func collectedToTerm(coeffs []expreduceapi.Ex, vars expreduceapi.Ex, fullPart ex
return toAdd
}

func collectTerms(e *expreduceapi.ExpressionInterface) *expreduceapi.ExpressionInterface {
func collectTerms(e expreduceapi.ExpressionInterface) expreduceapi.ExpressionInterface {
collected := NewExpression([]expreduceapi.Ex{NewSymbol("System`Plus")})
var lastVars expreduceapi.Ex
var lastFullPart expreduceapi.Ex
Expand Down Expand Up @@ -276,10 +276,10 @@ func getArithmeticDefinitions() (defs []Definition) {
defs = append(defs, Definition{
Name: "Plus",
Default: "0",
toString: func(this *expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
toString: func(this expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
return ToStringInfix(this.Parts[1:], " + ", "System`Plus", params)
},
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
// Calls without argument receive identity values
if len(this.Parts) == 1 {
return NewInteger(big.NewInt(0))
Expand Down Expand Up @@ -318,14 +318,14 @@ func getArithmeticDefinitions() (defs []Definition) {
})
defs = append(defs, Definition{
Name: "Sum",
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
return this.evalIterationFunc(es, NewInteger(big.NewInt(0)), "System`Plus")
},
})
defs = append(defs, Definition{
Name: "Times",
Default: "1",
toString: func(this *expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
toString: func(this expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
delim := "*"
if params.form == "TeXForm" {
delim = " "
Expand All @@ -336,7 +336,7 @@ func getArithmeticDefinitions() (defs []Definition) {
}
return ok, res
},
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
// Calls without argument receive identity values
if len(this.Parts) == 1 {
return NewInteger(big.NewInt(1))
Expand Down Expand Up @@ -405,7 +405,7 @@ func getArithmeticDefinitions() (defs []Definition) {
})
defs = append(defs, Definition{
Name: "Product",
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
return this.evalIterationFunc(es, NewInteger(big.NewInt(1)), "System`Times")
},
})
Expand Down
4 changes: 2 additions & 2 deletions expreduce/builtin_atoms.go
Expand Up @@ -5,7 +5,7 @@ import "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 {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.Parts) != 3 {
return this
}
Expand All @@ -19,7 +19,7 @@ func getAtomsDefinitions() (defs []Definition) {
})
defs = append(defs, Definition{
Name: "Complex",
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.Parts) != 3 {
return this
}
Expand Down
10 changes: 5 additions & 5 deletions expreduce/builtin_boolean.go
Expand Up @@ -5,10 +5,10 @@ import "github.com/corywalker/expreduce/pkg/expreduceapi"
func GetBooleanDefinitions() (defs []Definition) {
defs = append(defs, Definition{
Name: "And",
toString: func(this *expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
toString: func(this expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
return ToStringInfix(this.Parts[1:], " && ", "", params)
},
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
res := NewExpression([]expreduceapi.Ex{NewSymbol("System`And")})
for i := 1; i < len(this.Parts); i++ {
this.Parts[i] = this.Parts[i].Eval(es)
Expand All @@ -31,10 +31,10 @@ func GetBooleanDefinitions() (defs []Definition) {
})
defs = append(defs, Definition{
Name: "Or",
toString: func(this *expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
toString: func(this expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
return ToStringInfix(this.Parts[1:], " || ", "", params)
},
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
res := NewExpression([]expreduceapi.Ex{NewSymbol("System`Or")})
for i := 1; i < len(this.Parts); i++ {
this.Parts[i] = this.Parts[i].Eval(es)
Expand All @@ -57,7 +57,7 @@ func GetBooleanDefinitions() (defs []Definition) {
})
defs = append(defs, Definition{
Name: "Not",
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.Parts) != 2 {
return this
}
Expand Down
8 changes: 4 additions & 4 deletions expreduce/builtin_combinatorics.go
Expand Up @@ -92,7 +92,7 @@ func factorial(n *big.Int) (result *big.Int) {
func getCombinatoricsDefinitions() (defs []Definition) {
defs = append(defs, Definition{
Name: "IntegerPartitions",
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.Parts) != 2 && len(this.Parts) != 3 {
return this
}
Expand Down Expand Up @@ -136,12 +136,12 @@ func getCombinatoricsDefinitions() (defs []Definition) {
})
defs = append(defs, Definition{
Name: "Permutations",
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.Parts) != 2 {
return this
}

list, listIsExpr := this.Parts[1].(*expreduceapi.ExpressionInterface)
list, listIsExpr := this.Parts[1].(expreduceapi.ExpressionInterface)
if !listIsExpr {
return this
}
Expand All @@ -165,7 +165,7 @@ func getCombinatoricsDefinitions() (defs []Definition) {
})
defs = append(defs, Definition{
Name: "Factorial",
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.Parts) != 2 {
return this
}
Expand Down
44 changes: 22 additions & 22 deletions expreduce/builtin_comparison.go
Expand Up @@ -13,7 +13,7 @@ const (
MinFn
)

func extremaFunction(this *expreduceapi.ExpressionInterface, fnType extremaFnType, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
func extremaFunction(this expreduceapi.ExpressionInterface, fnType extremaFnType, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
// Flatten nested lists into arguments.
origHead := this.Parts[0]
this.Parts[0] = S("List")
Expand Down Expand Up @@ -77,10 +77,10 @@ func getCompSign(e expreduceapi.Ex) int {
func getComparisonDefinitions() (defs []Definition) {
defs = append(defs, Definition{
Name: "Equal",
toString: func(this *expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
toString: func(this expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
return ToStringInfixAdvanced(this.Parts[1:], " == ", "System`Equal", false, "", "", params)
},
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.Parts) < 1 {
return this
}
Expand All @@ -101,10 +101,10 @@ func getComparisonDefinitions() (defs []Definition) {
})
defs = append(defs, Definition{
Name: "Unequal",
toString: func(this *expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
toString: func(this expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
return ToStringInfixAdvanced(this.Parts[1:], " != ", "System`Unequal", false, "", "", params)
},
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.Parts) != 3 {
return this
}
Expand All @@ -123,10 +123,10 @@ func getComparisonDefinitions() (defs []Definition) {
})
defs = append(defs, Definition{
Name: "SameQ",
toString: func(this *expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
toString: func(this expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
return ToStringInfixAdvanced(this.Parts[1:], " === ", "System`SameQ", false, "", "", params)
},
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.Parts) < 1 {
return this
}
Expand All @@ -144,10 +144,10 @@ func getComparisonDefinitions() (defs []Definition) {
})
defs = append(defs, Definition{
Name: "UnsameQ",
toString: func(this *expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
toString: func(this expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
return ToStringInfixAdvanced(this.Parts[1:], " =!= ", "System`UnsameQ", false, "", "", params)
},
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.Parts) < 1 {
return this
}
Expand All @@ -164,12 +164,12 @@ func getComparisonDefinitions() (defs []Definition) {
})
defs = append(defs, Definition{
Name: "AtomQ",
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.Parts) != 2 {
return this
}

_, IsExpr := this.Parts[1].(*expreduceapi.ExpressionInterface)
_, IsExpr := this.Parts[1].(expreduceapi.ExpressionInterface)
if IsExpr {
return NewSymbol("System`False")
}
Expand All @@ -185,10 +185,10 @@ func getComparisonDefinitions() (defs []Definition) {
})
defs = append(defs, Definition{
Name: "Less",
toString: func(this *expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
toString: func(this expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
return ToStringInfixAdvanced(this.Parts[1:], " < ", "", true, "", "", params)
},
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.Parts) != 3 {
return this
}
Expand All @@ -209,10 +209,10 @@ func getComparisonDefinitions() (defs []Definition) {
})
defs = append(defs, Definition{
Name: "Greater",
toString: func(this *expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
toString: func(this expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
return ToStringInfixAdvanced(this.Parts[1:], " > ", "", true, "", "", params)
},
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.Parts) != 3 {
return this
}
Expand All @@ -232,10 +232,10 @@ func getComparisonDefinitions() (defs []Definition) {
})
defs = append(defs, Definition{
Name: "LessEqual",
toString: func(this *expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
toString: func(this expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
return ToStringInfixAdvanced(this.Parts[1:], " <= ", "", true, "", "", params)
},
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.Parts) != 3 {
return this
}
Expand All @@ -259,10 +259,10 @@ func getComparisonDefinitions() (defs []Definition) {
})
defs = append(defs, Definition{
Name: "GreaterEqual",
toString: func(this *expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
toString: func(this expreduceapi.ExpressionInterface, params expreduceapi.ToStringParams) (bool, string) {
return ToStringInfixAdvanced(this.Parts[1:], " >= ", "", true, "", "", params)
},
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.Parts) != 3 {
return this
}
Expand Down Expand Up @@ -292,13 +292,13 @@ func getComparisonDefinitions() (defs []Definition) {
})
defs = append(defs, Definition{
Name: "Max",
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
return extremaFunction(this, MaxFn, es)
},
})
defs = append(defs, Definition{
Name: "Min",
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
return extremaFunction(this, MinFn, es)
},
})
Expand All @@ -307,7 +307,7 @@ func getComparisonDefinitions() (defs []Definition) {
defs = append(defs, Definition{Name: "Element"})
defs = append(defs, Definition{
Name: "Inequality",
legacyEvalFn: func(this *expreduceapi.ExpressionInterface, es *expreduceapi.EvalStateInterface) expreduceapi.Ex {
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.Parts) == 1 {
return this
}
Expand Down

0 comments on commit ead23b0

Please sign in to comment.