diff --git a/expreduce/allocations.go b/expreduce/allocations.go index b163bf9..2d3adb0 100644 --- a/expreduce/allocations.go +++ b/expreduce/allocations.go @@ -1,7 +1,7 @@ package expreduce type allocIterState struct { - currForm int + currForm int remaining int currFormI int } @@ -29,7 +29,7 @@ func (ai *allocIter) next() bool { if p.currForm+1 >= len(ai.forms) { if (ai.forms[p.currForm].startI <= p.remaining) && (p.remaining <= ai.forms[p.currForm].endI) { ai.stack = append(ai.stack, allocIterState{ - p.currForm+1, 0, p.remaining}) + p.currForm + 1, 0, p.remaining}) } } else { // Optional forms fill eagerly instead of lazily. @@ -39,14 +39,14 @@ func (ai *allocIter) next() bool { for i := ai.forms[p.currForm].startI; i <= Min(ai.forms[p.currForm].endI, p.remaining); i++ { if p.remaining-i >= 0 { ai.stack = append(ai.stack, allocIterState{ - p.currForm+1, p.remaining-i, i}) + p.currForm + 1, p.remaining - i, i}) } } } else { for i := Min(ai.forms[p.currForm].endI, p.remaining); i >= ai.forms[p.currForm].startI; i-- { if p.remaining-i >= 0 { ai.stack = append(ai.stack, allocIterState{ - p.currForm+1, p.remaining-i, i}) + p.currForm + 1, p.remaining - i, i}) } } } @@ -71,22 +71,22 @@ type assnIterState struct { // to do all asignments of it to two BlankNullSequences, we have an // underlying data structure called assnData which could contain {0, 1} or // {1, 0} in the case where the assignment was {{1}, {0}}. - assnDataI int + assnDataI int crossedBoundary bool - toFree int + toFree int } type assnIter struct { - forms []parsedForm - assnData []int - assnIndices []int - assns [][]int - formMatches [][]bool - orderless bool - taken []bool - stack []assnIterState + forms []parsedForm + assnData []int + assnIndices []int + assns [][]int + formMatches [][]bool + orderless bool + taken []bool + stack []assnIterState iteratingOrderless bool - ai allocIter + ai allocIter } func (asi *assnIter) nextOrderless() bool { @@ -118,7 +118,7 @@ func (asi *assnIter) nextOrderless() bool { willCrossBoundary = formI != asi.assnIndices[p.assnDataI+1] } - startI := p.lastTaken+1 + startI := p.lastTaken + 1 if p.crossedBoundary { startI = 0 } @@ -127,10 +127,10 @@ func (asi *assnIter) nextOrderless() bool { -1, 0, true, p.lastTaken, }) } - for i := len(asi.taken)-1; i >= startI; i-- { + for i := len(asi.taken) - 1; i >= startI; i-- { if !asi.taken[i] && asi.formMatches[formI][i] { asi.stack = append(asi.stack, assnIterState{ - i, p.assnDataI+1, willCrossBoundary, -1, + i, p.assnDataI + 1, willCrossBoundary, -1, }) } } @@ -149,7 +149,7 @@ func (asi *assnIter) next() bool { // ReplaceList[ExpreduceFlatFn[a,b,c],ExpreduceFlatFn[x___//pm,b//pm,y___//pm]->{{x},{y}}] lasti := 0 for i := range asi.assns { - asi.assns[i] = asi.assnData[lasti:lasti+asi.ai.alloc[i]] + asi.assns[i] = asi.assnData[lasti : lasti+asi.ai.alloc[i]] for j := lasti; j < lasti+asi.ai.alloc[i]; j++ { asi.assnIndices[j] = i } diff --git a/expreduce/allocations_test.go b/expreduce/allocations_test.go index a9ef763..126affb 100644 --- a/expreduce/allocations_test.go +++ b/expreduce/allocations_test.go @@ -14,14 +14,14 @@ func newPf(startI int, endI int) parsedForm { } } -// sequenceAssignments[len_Integer, forms_List, orderless_?BooleanQ] := +// sequenceAssignments[len_Integer, forms_List, orderless_?BooleanQ] := // ReplaceList[ -// fn @@ Range[0, len - 1] /. -// fn -> If[orderless, ExpreduceOrderlessFn, foo], +// fn @@ Range[0, len - 1] /. +// fn -> If[orderless, ExpreduceOrderlessFn, foo], // fn @@ Table[ -// Pattern[Alphabet[][[i]] // ToExpression // Evaluate, -// Repeated[_, forms[[i]]]], {i, Length[forms]}] -> -// Table[{Alphabet[][[i]] // ToExpression}, {i, Length[forms]}] /. +// Pattern[Alphabet[][[i]] // ToExpression // Evaluate, +// Repeated[_, forms[[i]]]], {i, Length[forms]}] -> +// Table[{Alphabet[][[i]] // ToExpression}, {i, Length[forms]}] /. // fn -> If[orderless, ExpreduceOrderlessFn, foo]] func TestAllocations(t *testing.T) { @@ -138,7 +138,8 @@ func TestAllocations(t *testing.T) { } ai = NewAllocIter(800000, forms) num := 0 - for num = 0; ai.next(); num++ {} + for num = 0; ai.next(); num++ { + } assert.Equal(t, 800000, num) // should be 1/2 n (1+n)/.n->(ncomps-1) @@ -150,7 +151,8 @@ func TestAllocations(t *testing.T) { newPf(0, 999999), } ai = NewAllocIter(1400, forms) - for num = 0; ai.next(); num++ {} + for num = 0; ai.next(); num++ { + } assert.Equal(t, 979300, num) } @@ -246,11 +248,13 @@ func TestAssignments(t *testing.T) { nComps = 1400 ai = NewAssnIter(nComps, forms, allMatch(nComps, len(forms)), false) num := 0 - for num = 0; ai.next(); num++ {} + for num = 0; ai.next(); num++ { + } assert.Equal(t, 979300, num) nComps = 8 ai = NewAssnIter(nComps, forms, allMatch(nComps, len(forms)), true) - for num = 0; ai.next(); num++ {} + for num = 0; ai.next(); num++ { + } assert.Equal(t, 40824, num) } diff --git a/expreduce/builtin.go b/expreduce/builtin.go index 3891fdd..9a2b219 100644 --- a/expreduce/builtin.go +++ b/expreduce/builtin.go @@ -32,7 +32,7 @@ type Definition struct { toString ToStringFnType Attributes []string - Default string + Default string } func ToTestInstructions(tc *Expression) []TestInstruction { @@ -110,23 +110,23 @@ func (def *Definition) AnnotateWithDynamicTests(es *EvalState) { if !headIsSym { continue } - if (headSym.Name == "System`ESimpleExamples") { + if headSym.Name == "System`ESimpleExamples" { def.SimpleExamples = append( def.SimpleExamples, ToTestInstructions(testColExpr)...) - } else if (headSym.Name == "System`EFurtherExamples") { + } else if headSym.Name == "System`EFurtherExamples" { def.FurtherExamples = append( def.FurtherExamples, ToTestInstructions(testColExpr)...) - } else if (headSym.Name == "System`ETests") { + } else if headSym.Name == "System`ETests" { def.Tests = append( def.Tests, ToTestInstructions(testColExpr)...) - } else if (headSym.Name == "System`EKnownFailures") { + } else if headSym.Name == "System`EKnownFailures" { def.KnownFailures = append( def.KnownFailures, ToTestInstructions(testColExpr)...) - } else if (headSym.Name == "System`EKnownDangerous") { + } else if headSym.Name == "System`EKnownDangerous" { def.KnownDangerous = append( def.KnownDangerous, ToTestInstructions(testColExpr)...) diff --git a/expreduce/builtin_arithmetic.go b/expreduce/builtin_arithmetic.go index 11fffb4..643c1cd 100644 --- a/expreduce/builtin_arithmetic.go +++ b/expreduce/builtin_arithmetic.go @@ -220,8 +220,8 @@ func collectTerms(e *Expression) *Expression { func getArithmeticDefinitions() (defs []Definition) { defs = append(defs, Definition{ - Name: "Plus", - Default: "0", + Name: "Plus", + Default: "0", toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) { return ToStringInfix(this.Parts[1:], " + ", form, context, contextPath) }, @@ -265,8 +265,8 @@ func getArithmeticDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Times", - Default: "1", + Name: "Times", + Default: "1", toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) { return ToStringInfix(this.Parts[1:], " * ", form, context, contextPath) }, diff --git a/expreduce/builtin_atoms.go b/expreduce/builtin_atoms.go index cd15871..db0b415 100644 --- a/expreduce/builtin_atoms.go +++ b/expreduce/builtin_atoms.go @@ -2,7 +2,7 @@ package expreduce func getAtomsDefinitions() (defs []Definition) { defs = append(defs, Definition{ - Name: "Rational", + Name: "Rational", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 3 { return this @@ -15,8 +15,8 @@ func getAtomsDefinitions() (defs []Definition) { 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: "String"}) + defs = append(defs, Definition{Name: "Real"}) + defs = append(defs, Definition{Name: "Integer"}) return } diff --git a/expreduce/builtin_boolean.go b/expreduce/builtin_boolean.go index ce92cfd..8c9ce30 100644 --- a/expreduce/builtin_boolean.go +++ b/expreduce/builtin_boolean.go @@ -2,7 +2,7 @@ package expreduce func GetBooleanDefinitions() (defs []Definition) { defs = append(defs, Definition{ - Name: "And", + Name: "And", toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) { return ToStringInfix(this.Parts[1:], " && ", form, context, contextPath) }, @@ -11,7 +11,7 @@ func GetBooleanDefinitions() (defs []Definition) { for i := 1; i < len(this.Parts); i++ { this.Parts[i] = this.Parts[i].Eval(es) if booleanQ(this.Parts[i], &es.CASLogger) { - if falseQ(this.Parts[i], &es.CASLogger) { + if falseQ(this.Parts[i], &es.CASLogger) { return &Symbol{"System`False"} } } else { @@ -28,7 +28,7 @@ func GetBooleanDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Or", + Name: "Or", toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) { return ToStringInfix(this.Parts[1:], " || ", form, context, contextPath) }, @@ -37,7 +37,7 @@ func GetBooleanDefinitions() (defs []Definition) { for i := 1; i < len(this.Parts); i++ { this.Parts[i] = this.Parts[i].Eval(es) if booleanQ(this.Parts[i], &es.CASLogger) { - if trueQ(this.Parts[i], &es.CASLogger) { + if trueQ(this.Parts[i], &es.CASLogger) { return &Symbol{"System`True"} } } else { @@ -54,7 +54,7 @@ func GetBooleanDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Not", + Name: "Not", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this @@ -69,11 +69,11 @@ func GetBooleanDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "TrueQ", + Name: "TrueQ", legacyEvalFn: singleParamQLogEval(trueQ), }) defs = append(defs, Definition{ - Name: "BooleanQ", + Name: "BooleanQ", legacyEvalFn: singleParamQLogEval(booleanQ), }) defs = append(defs, Definition{Name: "AllTrue"}) diff --git a/expreduce/builtin_combinatorics.go b/expreduce/builtin_combinatorics.go index cd13ff2..de60fc4 100644 --- a/expreduce/builtin_combinatorics.go +++ b/expreduce/builtin_combinatorics.go @@ -132,7 +132,7 @@ func getCombinatoricsDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Permutations", + Name: "Permutations", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this @@ -158,10 +158,10 @@ func getCombinatoricsDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Multinomial", + Name: "Multinomial", }) defs = append(defs, Definition{ - Name: "Factorial", + Name: "Factorial", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this diff --git a/expreduce/builtin_comparison.go b/expreduce/builtin_comparison.go index 68398fb..cdcab56 100644 --- a/expreduce/builtin_comparison.go +++ b/expreduce/builtin_comparison.go @@ -5,7 +5,7 @@ import "sort" func getComparisonDefinitions() (defs []Definition) { defs = append(defs, Definition{ - Name: "Equal", + Name: "Equal", toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) { return ToStringInfixAdvanced(this.Parts[1:], " == ", true, "", "", form, context, contextPath) }, @@ -32,7 +32,7 @@ func getComparisonDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Unequal", + Name: "Unequal", toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) { return ToStringInfixAdvanced(this.Parts[1:], " != ", true, "", "", form, context, contextPath) }, @@ -54,7 +54,7 @@ func getComparisonDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "SameQ", + Name: "SameQ", toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) { return ToStringInfixAdvanced(this.Parts[1:], " === ", true, "", "", form, context, contextPath) }, @@ -75,7 +75,7 @@ func getComparisonDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "UnsameQ", + Name: "UnsameQ", toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) { return ToStringInfixAdvanced(this.Parts[1:], " =!= ", true, "", "", form, context, contextPath) }, @@ -85,7 +85,7 @@ func getComparisonDefinitions() (defs []Definition) { } for i := 1; i < len(this.Parts); i++ { - for j := i+1; j < len(this.Parts); j++ { + for j := i + 1; j < len(this.Parts); j++ { if IsSameQ(this.Parts[i], this.Parts[j], &es.CASLogger) { return &Symbol{"System`False"} } @@ -95,7 +95,7 @@ func getComparisonDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "AtomQ", + Name: "AtomQ", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this @@ -113,10 +113,10 @@ func getComparisonDefinitions() (defs []Definition) { legacyEvalFn: singleParamQEval(numberQ), }) defs = append(defs, Definition{ - Name: "NumericQ", + Name: "NumericQ", }) defs = append(defs, Definition{ - Name: "Less", + Name: "Less", toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) { return ToStringInfixAdvanced(this.Parts[1:], " < ", true, "", "", form, context, contextPath) }, @@ -135,7 +135,7 @@ func getComparisonDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Greater", + Name: "Greater", toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) { return ToStringInfixAdvanced(this.Parts[1:], " > ", true, "", "", form, context, contextPath) }, @@ -154,7 +154,7 @@ func getComparisonDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "LessEqual", + Name: "LessEqual", toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) { return ToStringInfixAdvanced(this.Parts[1:], " <= ", true, "", "", form, context, contextPath) }, @@ -177,7 +177,7 @@ func getComparisonDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "GreaterEqual", + Name: "GreaterEqual", toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) { return ToStringInfixAdvanced(this.Parts[1:], " >= ", true, "", "", form, context, contextPath) }, @@ -200,13 +200,13 @@ func getComparisonDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Positive", + Name: "Positive", }) defs = append(defs, Definition{ - Name: "Negative", + Name: "Negative", }) defs = append(defs, Definition{ - Name: "Max", + Name: "Max", legacyEvalFn: func(this *Expression, es *EvalState) Ex { // Flatten nested lists into arguments. origHead := this.Parts[0] diff --git a/expreduce/builtin_expression.go b/expreduce/builtin_expression.go index 616ead4..c04c3d2 100644 --- a/expreduce/builtin_expression.go +++ b/expreduce/builtin_expression.go @@ -31,7 +31,7 @@ func flattenExpr(src *Expression, dst *Expression, level int64, cl *CASLogger) { func GetExpressionDefinitions() (defs []Definition) { defs = append(defs, Definition{ - Name: "Head", + Name: "Head", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this @@ -65,7 +65,7 @@ func GetExpressionDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Depth", + Name: "Depth", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this @@ -74,7 +74,7 @@ func GetExpressionDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Length", + Name: "Length", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this @@ -88,16 +88,16 @@ func GetExpressionDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Sequence", + Name: "Sequence", }) defs = append(defs, Definition{ - Name: "Evaluate", + Name: "Evaluate", }) defs = append(defs, Definition{ - Name: "Hold", + Name: "Hold", }) defs = append(defs, Definition{ - Name: "HoldForm", + Name: "HoldForm", toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) { if len(this.Parts) != 2 { return false, "" @@ -109,7 +109,7 @@ func GetExpressionDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Flatten", + Name: "Flatten", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) < 2 { return this @@ -132,15 +132,15 @@ func GetExpressionDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Flat", + Name: "Flat", OmitDocumentation: true, }) defs = append(defs, Definition{ - Name: "Orderless", + Name: "Orderless", OmitDocumentation: true, }) defs = append(defs, Definition{ - Name: "OneIdentity", + Name: "OneIdentity", OmitDocumentation: true, }) return diff --git a/expreduce/builtin_flowcontrol.go b/expreduce/builtin_flowcontrol.go index d0a81ef..8946af9 100644 --- a/expreduce/builtin_flowcontrol.go +++ b/expreduce/builtin_flowcontrol.go @@ -2,7 +2,7 @@ package expreduce func GetFlowControlDefinitions() (defs []Definition) { defs = append(defs, Definition{ - Name: "If", + Name: "If", // WARNING: Watch out for putting rules here. It can interfere with how // Return works. legacyEvalFn: func(this *Expression, es *EvalState) Ex { @@ -27,7 +27,7 @@ func GetFlowControlDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "While", + Name: "While", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 3 { return this @@ -56,7 +56,7 @@ func GetFlowControlDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "CompoundExpression", + Name: "CompoundExpression", legacyEvalFn: func(this *Expression, es *EvalState) Ex { var toReturn Ex for i := 1; i < len(this.Parts); i++ { @@ -70,7 +70,7 @@ func GetFlowControlDefinitions() (defs []Definition) { }) // https://mathematica.stackexchange.com/questions/29353/how-does-return-work defs = append(defs, Definition{ - Name: "Return", + Name: "Return", }) return } diff --git a/expreduce/builtin_functional.go b/expreduce/builtin_functional.go index 9d4c643..5d3dce7 100644 --- a/expreduce/builtin_functional.go +++ b/expreduce/builtin_functional.go @@ -10,7 +10,7 @@ func getFunctionalDefinitions() (defs []Definition) { Name: "Slot", }) defs = append(defs, Definition{ - Name: "Apply", + Name: "Apply", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 3 { return this @@ -27,7 +27,7 @@ func getFunctionalDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Map", + Name: "Map", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 3 { return this @@ -48,7 +48,7 @@ func getFunctionalDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Array", + Name: "Array", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 3 { return this @@ -70,7 +70,7 @@ func getFunctionalDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Identity", + Name: "Identity", }) return } diff --git a/expreduce/builtin_list.go b/expreduce/builtin_list.go index 7c53364..d464635 100644 --- a/expreduce/builtin_list.go +++ b/expreduce/builtin_list.go @@ -79,7 +79,7 @@ func ThreadExpr(expr *Expression) (*Expression, bool) { for i := 1; i < len(expr.Parts); i++ { list, isList := HeadAssertion(expr.Parts[i], "System`List") if isList { - lengths = append(lengths, len(list.Parts) - 1) + lengths = append(lengths, len(list.Parts)-1) } } if len(lengths) == 0 { @@ -111,14 +111,14 @@ func ThreadExpr(expr *Expression) (*Expression, bool) { func GetListDefinitions() (defs []Definition) { defs = append(defs, Definition{ - Name: "List", - toString: (*Expression).ToStringList, + Name: "List", + toString: (*Expression).ToStringList, }) defs = append(defs, Definition{ - Name: "Total", + Name: "Total", }) defs = append(defs, Definition{ - Name: "Mean", + Name: "Mean", }) defs = append(defs, Definition{ Name: "Table", @@ -145,7 +145,7 @@ func GetListDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "MemberQ", + Name: "MemberQ", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 3 { return this @@ -160,7 +160,7 @@ func GetListDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Cases", + Name: "Cases", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 3 { return this @@ -194,7 +194,7 @@ func GetListDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "DeleteCases", + Name: "DeleteCases", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 3 { return this @@ -217,7 +217,7 @@ func GetListDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Union", + Name: "Union", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) == 1 { return NewExpression([]Ex{&Symbol{"System`List"}}) @@ -307,7 +307,7 @@ func GetListDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Part", + Name: "Part", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) == 1 { return this @@ -330,10 +330,10 @@ func GetListDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "All", + Name: "All", }) defs = append(defs, Definition{ - Name: "Thread", + Name: "Thread", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this @@ -347,7 +347,7 @@ func GetListDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Append", + Name: "Append", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 3 { return this @@ -362,10 +362,10 @@ func GetListDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "AppendTo", + Name: "AppendTo", }) defs = append(defs, Definition{ - Name: "Prepend", + Name: "Prepend", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 3 { return this @@ -381,10 +381,10 @@ func GetListDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "PrependTo", + Name: "PrependTo", }) defs = append(defs, Definition{ - Name: "DeleteDuplicates", + Name: "DeleteDuplicates", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this @@ -408,7 +408,7 @@ func GetListDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Last", + Name: "Last", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this @@ -416,7 +416,7 @@ func GetListDefinitions() (defs []Definition) { expr, isExpr := this.Parts[1].(*Expression) if isExpr { - if len(expr.Parts) < 2{ + if len(expr.Parts) < 2 { return this } return expr.Parts[len(expr.Parts)-1] @@ -425,7 +425,7 @@ func GetListDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Select", + Name: "Select", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 3 { return this diff --git a/expreduce/builtin_manip.go b/expreduce/builtin_manip.go index 54da6f8..58717ec 100644 --- a/expreduce/builtin_manip.go +++ b/expreduce/builtin_manip.go @@ -14,7 +14,7 @@ func distribute(e *Expression, built *Expression, res *Expression) { } } if shouldDistribute { - for _, dPart := range(partAsExpr.Parts[1:]) { + for _, dPart := range partAsExpr.Parts[1:] { builtCopy := built.ShallowCopy() builtCopy.appendEx(dPart) distribute(e, builtCopy, res) @@ -29,7 +29,7 @@ func distribute(e *Expression, built *Expression, res *Expression) { func GetManipDefinitions() (defs []Definition) { defs = append(defs, Definition{Name: "Together"}) defs = append(defs, Definition{ - Name: "Distribute", + Name: "Distribute", Rules: []Rule{ {"Distribute[e_]", "Distribute[e, Plus]"}, }, diff --git a/expreduce/builtin_matrix.go b/expreduce/builtin_matrix.go index f0a4998..f9e2294 100644 --- a/expreduce/builtin_matrix.go +++ b/expreduce/builtin_matrix.go @@ -62,7 +62,7 @@ func GetMatrixDefinitions() (defs []Definition) { Details: "The row-reduce method has not been added yet, but the shortcuts to finding the inverses of matrices up to 3x3 have been added.", }) defs = append(defs, Definition{ - Name: "Dimensions", + Name: "Dimensions", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this @@ -83,7 +83,7 @@ func GetMatrixDefinitions() (defs []Definition) { legacyEvalFn: singleParamQLogEval(matrixQ), }) defs = append(defs, Definition{ - Name: "Dot", + Name: "Dot", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) == 2 { return this.Parts[1] @@ -140,7 +140,7 @@ func GetMatrixDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Transpose", + Name: "Transpose", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this diff --git a/expreduce/builtin_numbertheory.go b/expreduce/builtin_numbertheory.go index cb4b1a1..75dc9ea 100644 --- a/expreduce/builtin_numbertheory.go +++ b/expreduce/builtin_numbertheory.go @@ -4,7 +4,7 @@ import "math/big" func GetNumberTheoryDefinitions() (defs []Definition) { defs = append(defs, Definition{ - Name: "PrimeQ", + Name: "PrimeQ", legacyEvalFn: singleParamQEval(primeQ), }) defs = append(defs, Definition{ diff --git a/expreduce/builtin_pattern.go b/expreduce/builtin_pattern.go index a0deaa6..a7407b5 100644 --- a/expreduce/builtin_pattern.go +++ b/expreduce/builtin_pattern.go @@ -19,7 +19,7 @@ func ToStringBlankType(repr string, parts []Ex, form string, context *String, co func GetPatternDefinitions() (defs []Definition) { defs = append(defs, Definition{ - Name: "MatchQ", + Name: "MatchQ", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 3 { return this @@ -80,19 +80,19 @@ func GetPatternDefinitions() (defs []Definition) { Name: "Except", }) defs = append(defs, Definition{ - Name: "PatternTest", + Name: "PatternTest", }) defs = append(defs, Definition{ - Name: "Condition", + Name: "Condition", }) defs = append(defs, Definition{ - Name: "Alternatives", + Name: "Alternatives", }) defs = append(defs, Definition{ - Name: "FreeQ", + Name: "FreeQ", }) defs = append(defs, Definition{ - Name: "ReplaceList", + Name: "ReplaceList", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 3 { return this @@ -115,13 +115,13 @@ func GetPatternDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Repeated", + Name: "Repeated", }) defs = append(defs, Definition{ - Name: "Optional", + Name: "Optional", }) defs = append(defs, Definition{ - Name: "Verbatim", + Name: "Verbatim", // Not fully supported. Don't document OmitDocumentation: true, }) diff --git a/expreduce/builtin_power.go b/expreduce/builtin_power.go index 5421e15..668388f 100644 --- a/expreduce/builtin_power.go +++ b/expreduce/builtin_power.go @@ -7,8 +7,8 @@ import ( func GetPowerDefinitions() (defs []Definition) { defs = append(defs, Definition{ - Name: "Power", - Default: "1", + Name: "Power", + Default: "1", toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) { return ToStringInfixAdvanced(this.Parts[1:], "^", false, "", "", form, context, contextPath) }, @@ -126,19 +126,19 @@ func GetPowerDefinitions() (defs []Definition) { {"PowerExpand[exp_]", "exp //. {Log[x_ y_]:>Log[x]+Log[y],Log[x_^k_]:>k Log[x]}"}, }, }) - defs = append(defs, Definition{Name: "Expand"}) - defs = append(defs, Definition{Name: "PolynomialQ"}) - defs = append(defs, Definition{Name: "Exponent"}) - defs = append(defs, Definition{Name: "Coefficient"}) - defs = append(defs, Definition{Name: "PolynomialQuotientRemainder"}) - defs = append(defs, Definition{Name: "PolynomialQuotient"}) - defs = append(defs, Definition{Name: "PolynomialRemainder"}) - defs = append(defs, Definition{Name: "FactorTermsList"}) - defs = append(defs, Definition{Name: "Variables"}) - defs = append(defs, Definition{Name: "PolynomialGCD"}) + defs = append(defs, Definition{Name: "Expand"}) + defs = append(defs, Definition{Name: "PolynomialQ"}) + defs = append(defs, Definition{Name: "Exponent"}) + defs = append(defs, Definition{Name: "Coefficient"}) + defs = append(defs, Definition{Name: "PolynomialQuotientRemainder"}) + defs = append(defs, Definition{Name: "PolynomialQuotient"}) + defs = append(defs, Definition{Name: "PolynomialRemainder"}) + defs = append(defs, Definition{Name: "FactorTermsList"}) + defs = append(defs, Definition{Name: "Variables"}) + defs = append(defs, Definition{Name: "PolynomialGCD"}) defs = append(defs, Definition{Name: "SquareFreeQ"}) defs = append(defs, Definition{ - Name: "PSimplify", + Name: "PSimplify", OmitDocumentation: true, ExpreduceSpecific: true, }) diff --git a/expreduce/builtin_random.go b/expreduce/builtin_random.go index e06f2b0..903ac73 100644 --- a/expreduce/builtin_random.go +++ b/expreduce/builtin_random.go @@ -18,7 +18,7 @@ func GetRandomDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "SeedRandom", + Name: "SeedRandom", Details: "`SeedRandom[UnixTime[]]` is called automatically upon " + "initialization of Expreduce, so random number sequences will not " + "repeat over subsequent sessions.", diff --git a/expreduce/builtin_replacement.go b/expreduce/builtin_replacement.go index d94b406..3902e6d 100644 --- a/expreduce/builtin_replacement.go +++ b/expreduce/builtin_replacement.go @@ -103,7 +103,7 @@ func getReplacementDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Rule", + Name: "Rule", toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) { if len(this.Parts) != 3 { return false, "" @@ -112,7 +112,7 @@ func getReplacementDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "RuleDelayed", + Name: "RuleDelayed", toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) { if len(this.Parts) != 3 { return false, "" diff --git a/expreduce/builtin_sort.go b/expreduce/builtin_sort.go index 4458fb9..e55e050 100644 --- a/expreduce/builtin_sort.go +++ b/expreduce/builtin_sort.go @@ -7,7 +7,7 @@ import ( func GetSortDefinitions() (defs []Definition) { defs = append(defs, Definition{ - Name: "Sort", + Name: "Sort", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this @@ -25,7 +25,7 @@ func GetSortDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Order", + Name: "Order", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 3 { return this diff --git a/expreduce/builtin_string.go b/expreduce/builtin_string.go index a581fc8..4e42f56 100644 --- a/expreduce/builtin_string.go +++ b/expreduce/builtin_string.go @@ -2,7 +2,7 @@ package expreduce func GetStringDefinitions() (defs []Definition) { defs = append(defs, Definition{ - Name: "ToString", + Name: "ToString", // For some reason this is fast for StringJoin[Table["x", {k,2000}]/.List->Sequence] legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 3 { @@ -24,7 +24,7 @@ func GetStringDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "StringJoin", + Name: "StringJoin", toString: func(this *Expression, form string, context *String, contextPath *Expression) (bool, string) { return ToStringInfix(this.Parts[1:], " <> ", form, context, contextPath) }, diff --git a/expreduce/builtin_system.go b/expreduce/builtin_system.go index a79291c..fc4f816 100644 --- a/expreduce/builtin_system.go +++ b/expreduce/builtin_system.go @@ -65,9 +65,9 @@ func GetSystemDefinitions() (defs []Definition) { sym, ok := this.Parts[1].(*Symbol) if ok { if sym.Name == "System`True" { - levelSym, lsOk := this.Parts[2].(*Symbol) + levelSym, lsOk := this.Parts[2].(*Symbol) if !lsOk { - return NewExpression([]Ex{&Symbol{"System`Error"}, &String{"Invalid level."}}) + return NewExpression([]Ex{&Symbol{"System`Error"}, &String{"Invalid level."}}) } if levelSym.Name == "System`Debug" { es.DebugOn(logging.DEBUG) @@ -76,7 +76,7 @@ func GetSystemDefinitions() (defs []Definition) { } else if levelSym.Name == "System`Notice" { es.DebugOn(logging.NOTICE) } else { - return NewExpression([]Ex{&Symbol{"System`Error"}, &String{"Invalid level."}}) + return NewExpression([]Ex{&Symbol{"System`Error"}, &String{"Invalid level."}}) } return &Symbol{"System`Null"} } else if sym.Name == "System`False" { @@ -105,7 +105,7 @@ func GetSystemDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Attributes", + Name: "Attributes", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this @@ -127,7 +127,7 @@ func GetSystemDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Default", + Name: "Default", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this @@ -146,7 +146,7 @@ func GetSystemDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Clear", + Name: "Clear", legacyEvalFn: func(this *Expression, es *EvalState) Ex { for _, arg := range this.Parts[1:] { es.Debugf("arg: %v", arg) @@ -303,7 +303,7 @@ func GetSystemDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Timing", + Name: "Timing", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this @@ -316,8 +316,8 @@ func GetSystemDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Print", - Usage: "`Print[expr1, expr2, ...]` prints the string representation of the expressions to the console and returns `Null`.", + Name: "Print", + Usage: "`Print[expr1, expr2, ...]` prints the string representation of the expressions to the console and returns `Null`.", Bootstrap: true, legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) < 2 { @@ -332,10 +332,10 @@ func GetSystemDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "MessageName", + Name: "MessageName", }) defs = append(defs, Definition{ - Name: "Trace", + Name: "Trace", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this @@ -359,7 +359,7 @@ func GetSystemDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "N", + Name: "N", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this @@ -368,59 +368,59 @@ func GetSystemDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Listable", + Name: "Listable", }) defs = append(defs, Definition{ - Name: "ExpreduceFlatFn", + Name: "ExpreduceFlatFn", OmitDocumentation: true, ExpreduceSpecific: true, - Attributes: []string{"Flat"}, + Attributes: []string{"Flat"}, }) defs = append(defs, Definition{ - Name: "ExpreduceOrderlessFn", + Name: "ExpreduceOrderlessFn", OmitDocumentation: true, ExpreduceSpecific: true, - Attributes: []string{"Orderless"}, + Attributes: []string{"Orderless"}, }) defs = append(defs, Definition{ - Name: "ExpreduceOneIdentityFn", + Name: "ExpreduceOneIdentityFn", OmitDocumentation: true, ExpreduceSpecific: true, - Attributes: []string{"OneIdentity"}, + Attributes: []string{"OneIdentity"}, }) defs = append(defs, Definition{ - Name: "ExpreduceFlatFn2", + Name: "ExpreduceFlatFn2", OmitDocumentation: true, ExpreduceSpecific: true, - Attributes: []string{"Flat"}, + Attributes: []string{"Flat"}, }) defs = append(defs, Definition{ - Name: "ExpreduceFlOrFn", + Name: "ExpreduceFlOrFn", OmitDocumentation: true, ExpreduceSpecific: true, - Attributes: []string{"Flat", "Orderless"}, + Attributes: []string{"Flat", "Orderless"}, }) defs = append(defs, Definition{ - Name: "ExpreduceFlOiFn", + Name: "ExpreduceFlOiFn", OmitDocumentation: true, ExpreduceSpecific: true, - Attributes: []string{"Flat", "OneIdentity"}, + Attributes: []string{"Flat", "OneIdentity"}, }) defs = append(defs, Definition{ - Name: "ExpreduceFlOrOiFn", + Name: "ExpreduceFlOrOiFn", OmitDocumentation: true, ExpreduceSpecific: true, - Attributes: []string{"Flat", "Orderless", "OneIdentity"}, + Attributes: []string{"Flat", "Orderless", "OneIdentity"}, }) defs = append(defs, Definition{ - Name: "ExpreduceLikePlus", - Default: "0", + Name: "ExpreduceLikePlus", + Default: "0", OmitDocumentation: true, ExpreduceSpecific: true, - Attributes: []string{"Flat", "Listable", "NumericFunction", "OneIdentity", "Orderless"}, + Attributes: []string{"Flat", "Listable", "NumericFunction", "OneIdentity", "Orderless"}, }) defs = append(defs, Definition{ - Name: "Get", + Name: "Get", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this @@ -458,7 +458,7 @@ func GetSystemDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "Module", + Name: "Module", legacyEvalFn: func(this *Expression, es *EvalState) Ex { // Coarse parsing of arguments. if len(this.Parts) != 3 { @@ -480,10 +480,10 @@ func GetSystemDefinitions() (defs []Definition) { // Parse locals into a struct type parsedLocal struct { - sym *Symbol - uniqueName string - setValue Ex - isSet bool + sym *Symbol + uniqueName string + setValue Ex + isSet bool isSetDelayed bool } var parsedLocals []parsedLocal @@ -523,7 +523,7 @@ func GetSystemDefinitions() (defs []Definition) { } } } - es.Define(&Symbol{"System`$ModuleNumber"}, &Integer{big.NewInt(mn+1)}) + es.Define(&Symbol{"System`$ModuleNumber"}, &Integer{big.NewInt(mn + 1)}) toReturn := this.Parts[2] pm := EmptyPD() for _, pl := range parsedLocals { @@ -545,14 +545,14 @@ func GetSystemDefinitions() (defs []Definition) { }, }) defs = append(defs, Definition{ - Name: "ESameTest", + Name: "ESameTest", OmitDocumentation: true, ExpreduceSpecific: true, - Bootstrap: true, - Attributes: []string{"HoldAll", "SequenceHold"}, + Bootstrap: true, + Attributes: []string{"HoldAll", "SequenceHold"}, }) defs = append(defs, Definition{ - Name: "Hash", + Name: "Hash", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 2 { return this diff --git a/expreduce/builtin_time.go b/expreduce/builtin_time.go index c47d529..38c6e01 100644 --- a/expreduce/builtin_time.go +++ b/expreduce/builtin_time.go @@ -5,7 +5,7 @@ import "time" func GetTimeDefinitions() (defs []Definition) { defs = append(defs, Definition{ - Name: "UnixTime", + Name: "UnixTime", legacyEvalFn: func(this *Expression, es *EvalState) Ex { if len(this.Parts) != 1 { return this diff --git a/expreduce/cas_test.go b/expreduce/cas_test.go index 291e603..3730f27 100644 --- a/expreduce/cas_test.go +++ b/expreduce/cas_test.go @@ -5,8 +5,8 @@ import ( "fmt" "github.com/stretchr/testify/assert" "math/big" - "testing" "regexp" + "testing" ) var testmodules = flag.String("testmodules", "", diff --git a/expreduce/caslogger.go b/expreduce/caslogger.go index 23cdf61..aab985d 100644 --- a/expreduce/caslogger.go +++ b/expreduce/caslogger.go @@ -13,9 +13,9 @@ var format = logging.MustStringFormatter( ) type CASLogger struct { - _log *logging.Logger - leveled logging.LeveledBackend - debugState bool + _log *logging.Logger + leveled logging.LeveledBackend + debugState bool isProfiling bool } diff --git a/expreduce/definition.go b/expreduce/definition.go index 5129058..e4eab45 100644 --- a/expreduce/definition.go +++ b/expreduce/definition.go @@ -3,8 +3,8 @@ package expreduce import "bytes" type Def struct { - downvalues []Expression - attributes Attributes + downvalues []Expression + attributes Attributes defaultExpr Ex // A function defined here will override downvalues. diff --git a/expreduce/evalstate.go b/expreduce/evalstate.go index 2a0e82a..efcd2b5 100644 --- a/expreduce/evalstate.go +++ b/expreduce/evalstate.go @@ -2,11 +2,11 @@ package expreduce import ( "bytes" + "fmt" "log" "sort" "strings" "time" - "fmt" ) type DefMap map[string]Def @@ -15,11 +15,11 @@ type EvalState struct { // Embedded type for logging CASLogger - defined DefMap - trace *Expression - NoInit bool + defined DefMap + trace *Expression + NoInit bool timeCounter TimeCounterGroup - freeze bool + freeze bool } func (this *EvalState) Load(def Definition) { @@ -74,7 +74,7 @@ func (this *EvalState) Load(def Definition) { func (es *EvalState) Init(loadAllDefs bool) { es.defined = make(map[string]Def) - // These are fundamental symbols that affect even the parsing of + // These are fundamental symbols that affect even the parsing of // expressions. We must define them before even the bootstrap definitions. es.Define(&Symbol{"System`$Context"}, &String{"System`"}) es.Define(&Symbol{"System`$ContextPath"}, NewExpression([]Ex{ @@ -197,7 +197,7 @@ func (this *EvalState) GetDef(name string, lhs Ex) (Ex, bool, *Expression) { } this.Debugf("Inside GetDef(\"%s\",%s)", name, lhs) for i := range this.defined[name].downvalues { - def := this.defined[name].downvalues[i] + def := this.defined[name].downvalues[i] defStr, lhsDefStr := "", "" started := int64(0) @@ -210,7 +210,7 @@ func (this *EvalState) GetDef(name string, lhs Ex) (Ex, bool, *Expression) { res, replaced := Replace(lhs, &def, this) if this.isProfiling { - elapsed := float64(time.Now().UnixNano() - started) / 1000000000 + elapsed := float64(time.Now().UnixNano()-started) / 1000000000 this.timeCounter.AddTime(CounterGroupDefTime, defStr, elapsed) this.timeCounter.AddTime(CounterGroupLhsDefTime, lhsDefStr, elapsed) } diff --git a/expreduce/ex_expression.go b/expreduce/ex_expression.go index 1797f92..64eb06d 100644 --- a/expreduce/ex_expression.go +++ b/expreduce/ex_expression.go @@ -13,11 +13,11 @@ var printevals = flag.Bool("printevals", false, "") var checkhashes = flag.Bool("checkhashes", false, "") type Expression struct { - Parts []Ex - needsEval bool + Parts []Ex + needsEval bool correctlyInstantiated bool - evaledHash uint64 - cachedHash uint64 + evaledHash uint64 + cachedHash uint64 } // Deprecated in favor of headExAssertion @@ -80,7 +80,7 @@ func (this *Expression) mergeSequences(es *EvalState, headStr string, shouldEval // accept level depths. It is a specific case of Flatten. res := NewEmptyExpression() encounteredSeq := false - for _, e := range(this.Parts) { + for _, e := range this.Parts { seq, isseq := HeadAssertion(e, headStr) if isseq { encounteredSeq = true @@ -278,7 +278,7 @@ func (this *Expression) Eval(es *EvalState) Ex { // Handle end of profiling if es.isProfiling { - elapsed := float64(time.Now().UnixNano() - started) / 1000000000 + elapsed := float64(time.Now().UnixNano()-started) / 1000000000 es.timeCounter.AddTime(CounterGroupEvalTime, currStr, elapsed) es.timeCounter.AddTime(CounterGroupHeadEvalTime, currHeadStr, elapsed) } @@ -482,15 +482,15 @@ func (this *Expression) Hash() uint64 { func NewExpression(parts []Ex) *Expression { return &Expression{ - Parts: parts, - needsEval: true, + Parts: parts, + needsEval: true, correctlyInstantiated: true, } } func NewEmptyExpression() *Expression { return &Expression{ - needsEval: true, + needsEval: true, correctlyInstantiated: true, } } diff --git a/expreduce/ex_rational.go b/expreduce/ex_rational.go index bde1421..345a359 100644 --- a/expreduce/ex_rational.go +++ b/expreduce/ex_rational.go @@ -5,8 +5,8 @@ import "math/big" import "hash/fnv" type Rational struct { - Num *big.Int - Den *big.Int + Num *big.Int + Den *big.Int needsEval bool } diff --git a/expreduce/matchq.go b/expreduce/matchq.go index dfe126d..3c51493 100644 --- a/expreduce/matchq.go +++ b/expreduce/matchq.go @@ -9,9 +9,9 @@ type matchIter interface { } type dummyMatchIter struct { - isMatchQ bool - pm *PDManager - isDone bool + isMatchQ bool + pm *PDManager + isDone bool } func (this *dummyMatchIter) next() (bool, *PDManager, bool) { @@ -263,19 +263,19 @@ func isMatchQRational(a *Rational, b *Expression, pm *PDManager, es *EvalState) type assignedIterState struct { formI int assnI int - pm *PDManager + pm *PDManager } type assignedMatchIter struct { - assn [][]int + assn [][]int // Inherited from sequenceMatchIter - components []Ex - lhs_components []parsedForm - pm *PDManager - sequenceHead string - es *EvalState - stack []assignedIterState + components []Ex + lhs_components []parsedForm + pm *PDManager + sequenceHead string + es *EvalState + stack []assignedIterState } func NewAssignedMatchIter(assn [][]int, smi *sequenceMatchIter) assignedMatchIter { @@ -314,7 +314,7 @@ func (ami *assignedMatchIter) next() bool { patOk := DefineSequence(lhs, seq, p.pm, ami.sequenceHead, ami.es) if patOk { ami.stack = append(ami.stack, assignedIterState{ - p.formI+1, 0, p.pm, + p.formI + 1, 0, p.pm, }) } continue @@ -334,7 +334,7 @@ func (ami *assignedMatchIter) next() bool { toAddReversed = append(toAddReversed, submatches) } } - for i := len(toAddReversed)-1; i >= 0; i-- { + for i := len(toAddReversed) - 1; i >= 0; i-- { updatedPm := p.pm if toAddReversed[i].Len() > 0 { if len(toAddReversed) > 1 { @@ -343,7 +343,7 @@ func (ami *assignedMatchIter) next() bool { updatedPm.Update(toAddReversed[i]) } ami.stack = append(ami.stack, assignedIterState{ - p.formI, p.assnI+1, updatedPm, + p.formI, p.assnI + 1, updatedPm, }) } } @@ -351,14 +351,14 @@ func (ami *assignedMatchIter) next() bool { } type sequenceMatchIter struct { - components []Ex - lhs_components []parsedForm - pm *PDManager - sequenceHead string - es *EvalState - ai assnIter - iteratingAmi bool - ami assignedMatchIter + components []Ex + lhs_components []parsedForm + pm *PDManager + sequenceHead string + es *EvalState + ai assnIter + iteratingAmi bool + ami assignedMatchIter } func NewSequenceMatchIter(components []Ex, lhs_components []Ex, isOrderless bool, isFlat bool, sequenceHead string, pm *PDManager, es *EvalState) (matchIter, bool) { diff --git a/expreduce/order.go b/expreduce/order.go index c5fea2e..d3e91a6 100644 --- a/expreduce/order.go +++ b/expreduce/order.go @@ -106,8 +106,8 @@ func ExOrder(a Ex, b Ex) int64 { } } if timesMode { - ai := len(aAsExp.Parts)-1 - bi := len(bAsExp.Parts)-1 + ai := len(aAsExp.Parts) - 1 + bi := len(bAsExp.Parts) - 1 for ai >= 0 && bi >= 0 { aPart, bPart := aAsExp.Parts[ai], bAsExp.Parts[bi] ai, bi = ai-1, bi-1 diff --git a/expreduce/parse_form.go b/expreduce/parse_form.go index b632b34..70a2fd1 100644 --- a/expreduce/parse_form.go +++ b/expreduce/parse_form.go @@ -1,16 +1,16 @@ package expreduce type parsedForm struct { - startI int - endI int - form Ex - origForm Ex - isBlank bool - isImpliedBs bool - isOptional bool - defaultExpr Ex - hasPat bool - patSym *Symbol + startI int + endI int + form Ex + origForm Ex + isBlank bool + isImpliedBs bool + isOptional bool + defaultExpr Ex + hasPat bool + patSym *Symbol } func ParseRepeated(e *Expression) (Ex, int, int, bool) { @@ -115,7 +115,7 @@ func ParseForm(lhs_component Ex, isFlat bool, sequenceHead string, headDefault E form = blank } else if isRepeated { repPat, repMin, repMax, repOk := ParseRepeated(repeated) - if (repOk) { + if repOk { if repMin != -1 { startI = repMin } diff --git a/expreduce/permutations.go b/expreduce/permutations.go index 50e57ab..4d11686 100644 --- a/expreduce/permutations.go +++ b/expreduce/permutations.go @@ -15,7 +15,7 @@ func reverse(ar []int) { } func nextKPermutation(ar []int, n int, k int) int { - if (k <= 0) { + if k <= 0 { return 0 } diff --git a/expreduce/replace.go b/expreduce/replace.go index 089074f..4a86156 100644 --- a/expreduce/replace.go +++ b/expreduce/replace.go @@ -83,7 +83,7 @@ func ReplacePD(this Ex, es *EvalState, pm *PDManager) Ex { // the RHS. We will merely make sure that the named patterns are added to pm. // Final named pattern substitution will occur at the last possible time. func ReplaceAll(this Ex, r *Expression, es *EvalState, pm *PDManager, - stopAtHead string) Ex { + stopAtHead string) Ex { asExpression, isExpression := this.(*Expression) if isExpression { diff --git a/expreduce/time_counter.go b/expreduce/time_counter.go index 251bcbe..b630c1a 100644 --- a/expreduce/time_counter.go +++ b/expreduce/time_counter.go @@ -66,9 +66,9 @@ const ( ) type TimeCounterGroup struct { - defTimeCounter TimeCounter - lhsDefTimeCounter TimeCounter - evalTimeCounter TimeCounter + defTimeCounter TimeCounter + lhsDefTimeCounter TimeCounter + evalTimeCounter TimeCounter headEvalTimeCounter TimeCounter }