Skip to content

Commit

Permalink
Fix some lint issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
corywalker committed Oct 22, 2018
1 parent 945a91e commit eef18a3
Show file tree
Hide file tree
Showing 12 changed files with 266 additions and 263 deletions.
2 changes: 2 additions & 0 deletions expreduce/atoms/calculator.go
Expand Up @@ -5,7 +5,9 @@ import "github.com/corywalker/expreduce/pkg/expreduceapi"
type foldFn int

const (
// FoldFnAdd designates that values should be added.
FoldFnAdd foldFn = iota
// FoldFnMul designates that values should be multiplied.
FoldFnMul
)

Expand Down
112 changes: 56 additions & 56 deletions expreduce/atoms/ex_complex.go
Expand Up @@ -14,120 +14,120 @@ type Complex struct {
needsEval bool
}

func (this *Complex) StringForm(p expreduceapi.ToStringParams) string {
func (cmplx *Complex) StringForm(p expreduceapi.ToStringParams) string {
if p.Form == "FullForm" {
return fmt.Sprintf("Complex[%v, %v]", this.Re, this.Im)
return fmt.Sprintf("Complex[%v, %v]", cmplx.Re, cmplx.Im)
}
p.PreviousHead = "System`Plus"
return fmt.Sprintf("(%v + %v*I)", this.Re.StringForm(p), this.Im.StringForm(p))
return fmt.Sprintf("(%v + %v*I)", cmplx.Re.StringForm(p), cmplx.Im.StringForm(p))
}

func (this *Complex) String(esi expreduceapi.EvalStateInterface) string {
func (cmplx *Complex) String(esi expreduceapi.EvalStateInterface) string {
context, contextPath := defaultStringFormArgs()
return this.StringForm(expreduceapi.ToStringParams{
return cmplx.StringForm(expreduceapi.ToStringParams{
Form: "InputForm", Context: context, ContextPath: contextPath, Esi: esi})
}

func (this *Complex) IsEqual(other expreduceapi.Ex) string {
func (cmplx *Complex) IsEqual(other expreduceapi.Ex) string {
otherConv, otherIsComplex := other.(*Complex)
if !otherIsComplex {
return "EQUAL_FALSE"
}
if (this.Re.IsEqual(otherConv.Re) != "EQUAL_TRUE") || (this.Im.IsEqual(otherConv.Im) != "EQUAL_TRUE") {
if (cmplx.Re.IsEqual(otherConv.Re) != "EQUAL_TRUE") || (cmplx.Im.IsEqual(otherConv.Im) != "EQUAL_TRUE") {
return "EQUAL_FALSE"
}
return "EQUAL_TRUE"
}

func (this *Complex) DeepCopy() expreduceapi.Ex {
return &Complex{this.Re.DeepCopy(), this.Im.DeepCopy(), this.needsEval}
func (cmplx *Complex) DeepCopy() expreduceapi.Ex {
return &Complex{cmplx.Re.DeepCopy(), cmplx.Im.DeepCopy(), cmplx.needsEval}
}

func (this *Complex) Copy() expreduceapi.Ex {
return this.DeepCopy()
func (cmplx *Complex) Copy() expreduceapi.Ex {
return cmplx.DeepCopy()
}

func (this *Complex) NeedsEval() bool {
return this.needsEval
func (cmplx *Complex) NeedsEval() bool {
return cmplx.needsEval
}

func NewComplex(r expreduceapi.Ex, i expreduceapi.Ex) *Complex {
return &Complex{r, i, true}
}

func (this *Complex) Hash() uint64 {
func (cmplx *Complex) Hash() uint64 {
h := fnv.New64a()
h.Write([]byte{82, 226, 223, 39, 113, 26, 149, 249})
b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, this.Re.Hash())
binary.LittleEndian.PutUint64(b, cmplx.Re.Hash())
h.Write(b)
binary.LittleEndian.PutUint64(b, this.Im.Hash())
binary.LittleEndian.PutUint64(b, cmplx.Im.Hash())
h.Write(b)
return h.Sum64()
}

func (this *Complex) addReal(e expreduceapi.Ex) {
a, _ := ComputeNumericPart(FoldFnAdd, E(S("Dummy"), this.Re, e))
this.Re = a
this.needsEval = true
func (cmplx *Complex) addReal(e expreduceapi.Ex) {
a, _ := ComputeNumericPart(FoldFnAdd, E(S("Dummy"), cmplx.Re, e))
cmplx.Re = a
cmplx.needsEval = true
}

func (this *Complex) addI(i *Integer) {
this.addReal(i)
func (cmplx *Complex) addI(i *Integer) {
cmplx.addReal(i)
}

func (this *Complex) addF(f *Flt) {
this.addReal(f)
func (cmplx *Complex) addF(f *Flt) {
cmplx.addReal(f)
}

func (this *Complex) addR(r *Rational) {
this.addReal(r)
func (cmplx *Complex) addR(r *Rational) {
cmplx.addReal(r)
}

func (this *Complex) addC(c *Complex) {
a, _ := ComputeNumericPart(FoldFnAdd, E(S("Dummy"), this.Re, c.Re))
b, _ := ComputeNumericPart(FoldFnAdd, E(S("Dummy"), this.Im, c.Im))
this.Re = a
this.Im = b
this.needsEval = true
func (cmplx *Complex) addC(c *Complex) {
a, _ := ComputeNumericPart(FoldFnAdd, E(S("Dummy"), cmplx.Re, c.Re))
b, _ := ComputeNumericPart(FoldFnAdd, E(S("Dummy"), cmplx.Im, c.Im))
cmplx.Re = a
cmplx.Im = b
cmplx.needsEval = true
}

func (this *Complex) mulReal(e expreduceapi.Ex) {
a, _ := ComputeNumericPart(FoldFnMul, E(S("Dummy"), this.Re, e))
b, _ := ComputeNumericPart(FoldFnMul, E(S("Dummy"), this.Im, e))
this.Re = a
this.Im = b
this.needsEval = true
func (cmplx *Complex) mulReal(e expreduceapi.Ex) {
a, _ := ComputeNumericPart(FoldFnMul, E(S("Dummy"), cmplx.Re, e))
b, _ := ComputeNumericPart(FoldFnMul, E(S("Dummy"), cmplx.Im, e))
cmplx.Re = a
cmplx.Im = b
cmplx.needsEval = true
}

func (this *Complex) mulI(i *Integer) {
this.mulReal(i)
func (cmplx *Complex) mulI(i *Integer) {
cmplx.mulReal(i)
}

func (this *Complex) mulF(f *Flt) {
this.mulReal(f)
func (cmplx *Complex) mulF(f *Flt) {
cmplx.mulReal(f)
}

func (this *Complex) mulR(r *Rational) {
this.mulReal(r)
func (cmplx *Complex) mulR(r *Rational) {
cmplx.mulReal(r)
}

func (this *Complex) mulC(c *Complex) {
func (cmplx *Complex) mulC(c *Complex) {
// HoldPattern[Complex[x_, y_]*Complex[u_, v_]*rest___] -> Complex[x*u + (y*v)*(-1), x*v + y*u]*rest)
// This is ugly. Need to refactor.
// cmplx is ugly. Need to refactor.
// Perhaps create "Calculator" utility??
// TODO(corywalker) Remove the definition that this implements in code.
a, _ := ComputeNumericPart(FoldFnMul, E(S("Dummy"), this.Re, c.Re))
b, _ := ComputeNumericPart(FoldFnMul, E(S("Dummy"), NewInt(-1), this.Im, c.Im))
cc, _ := ComputeNumericPart(FoldFnMul, E(S("Dummy"), this.Re, c.Im))
d, _ := ComputeNumericPart(FoldFnMul, E(S("Dummy"), this.Im, c.Re))
// TODO(corywalker) Remove the definition that cmplx implements in code.
a, _ := ComputeNumericPart(FoldFnMul, E(S("Dummy"), cmplx.Re, c.Re))
b, _ := ComputeNumericPart(FoldFnMul, E(S("Dummy"), NewInt(-1), cmplx.Im, c.Im))
cc, _ := ComputeNumericPart(FoldFnMul, E(S("Dummy"), cmplx.Re, c.Im))
d, _ := ComputeNumericPart(FoldFnMul, E(S("Dummy"), cmplx.Im, c.Re))
e, _ := ComputeNumericPart(FoldFnAdd, E(S("Dummy"), a, b))
f, _ := ComputeNumericPart(FoldFnAdd, E(S("Dummy"), cc, d))
this.Re = e
this.Im = f
this.needsEval = true
cmplx.Re = e
cmplx.Im = f
cmplx.needsEval = true
}

func (this *Complex) SetNeedsEval(newVal bool) {
this.needsEval = newVal
func (cmplx *Complex) SetNeedsEval(newVal bool) {
cmplx.needsEval = newVal
}
52 changes: 26 additions & 26 deletions expreduce/atoms/ex_integer.go
Expand Up @@ -31,41 +31,41 @@ func (i *Integer) StringForm(params expreduceapi.ToStringParams) string {
return fmt.Sprintf("%d", i.Val)
}

func (this *Integer) String(esi expreduceapi.EvalStateInterface) string {
func (thisInt *Integer) String(esi expreduceapi.EvalStateInterface) string {
context, contextPath := defaultStringFormArgs()
return this.StringForm(expreduceapi.ToStringParams{Form: "InputForm", Context: context, ContextPath: contextPath, Esi: esi})
return thisInt.StringForm(expreduceapi.ToStringParams{Form: "InputForm", Context: context, ContextPath: contextPath, Esi: esi})
}

func (this *Integer) IsEqual(other expreduceapi.Ex) string {
func (thisInt *Integer) IsEqual(other expreduceapi.Ex) string {
otherConv, ok := other.(*Integer)
if !ok {
otherFlt, ok := other.(*Flt)
if ok {
thisAsFlt := big.NewFloat(0)
thisAsFlt.SetInt(this.Val)
if thisAsFlt.Cmp(otherFlt.Val) == 0 {
thisIntAsFlt := big.NewFloat(0)
thisIntAsFlt.SetInt(thisInt.Val)
if thisIntAsFlt.Cmp(otherFlt.Val) == 0 {
return "EQUAL_TRUE"
}
}
return "EQUAL_UNK"
}
if this.Val.Cmp(otherConv.Val) != 0 {
if thisInt.Val.Cmp(otherConv.Val) != 0 {
return "EQUAL_FALSE"
}
return "EQUAL_TRUE"
}

func (this *Integer) DeepCopy() expreduceapi.Ex {
func (thisInt *Integer) DeepCopy() expreduceapi.Ex {
tmp := big.NewInt(0)
tmp.Set(this.Val)
return &Integer{Val: tmp, cachedHash: this.cachedHash}
tmp.Set(thisInt.Val)
return &Integer{Val: tmp, cachedHash: thisInt.cachedHash}
}

func (this *Integer) Copy() expreduceapi.Ex {
return this
func (thisInt *Integer) Copy() expreduceapi.Ex {
return thisInt
}

func (this *Integer) NeedsEval() bool {
func (thisInt *Integer) NeedsEval() bool {
return false
}

Expand All @@ -77,30 +77,30 @@ func NewInt(i int64) *Integer {
return NewInteger(big.NewInt(i))
}

func (this *Integer) Hash() uint64 {
if this.cachedHash > 0 {
return this.cachedHash
func (thisInt *Integer) Hash() uint64 {
if thisInt.cachedHash > 0 {
return thisInt.cachedHash
}
h := fnv.New64a()
h.Write([]byte{242, 99, 84, 113, 102, 46, 118, 94})
bytes, _ := this.Val.MarshalText()
bytes, _ := thisInt.Val.MarshalText()
h.Write(bytes)
this.cachedHash = h.Sum64()
thisInt.cachedHash = h.Sum64()
return h.Sum64()
}

func (this *Integer) asBigFloat() *big.Float {
func (thisInt *Integer) asBigFloat() *big.Float {
newfloat := big.NewFloat(0)
newfloat.SetInt(this.Val)
newfloat.SetInt(thisInt.Val)
return newfloat
}

func (this *Integer) addI(i *Integer) {
this.Val.Add(this.Val, i.Val)
this.cachedHash = 0
func (thisInt *Integer) addI(i *Integer) {
thisInt.Val.Add(thisInt.Val, i.Val)
thisInt.cachedHash = 0
}

func (this *Integer) mulI(i *Integer) {
this.Val.Mul(this.Val, i.Val)
this.cachedHash = 0
func (thisInt *Integer) mulI(i *Integer) {
thisInt.Val.Mul(thisInt.Val, i.Val)
thisInt.cachedHash = 0
}

0 comments on commit eef18a3

Please sign in to comment.