Skip to content

Commit

Permalink
Fix problems.
Browse files Browse the repository at this point in the history
Fixed problems with tests, FoldList, SameQ.
  • Loading branch information
Calle Ekdahl committed Sep 11, 2017
1 parent 82c0814 commit 3989b82
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions expreduce/builtin_functional.go
Expand Up @@ -64,12 +64,12 @@ func getFunctionalDefinitions() (defs []Definition) {
return this
}

toReturn := NewExpression([]Ex{values.Parts[0], first})

if len(values.Parts) < 2 {
return first
return toReturn
}

toReturn := NewExpression([]Ex{&Symbol{"System`List"}})

expr := NewExpression([]Ex{
f,
first,
Expand Down
6 changes: 1 addition & 5 deletions expreduce/resources/functional.m
Expand Up @@ -77,10 +77,8 @@
ESameTest[{1, f[1, 2], f[f[1, 2], 3]}, FoldList[f, 1, {2, 3}]],
ESameTest[{1, f[1, 2], f[f[1, 2], 3]}, FoldList[f, {1, 2, 3}]],
(* ESameTest[{1, f[1, 2], f[f[1, 2], 3]}, FoldList[f][{1, 2, 3}]], *)
ESameTest[{1, f[1, 2], f[f[1, 2], 3]}, FoldList[f][1, {2, 3}]],
ESameTest[h[e1, f[e1, e2], f[f[e1, e2], e3], f[f[f[e1, e2], e3], e4]], FoldList[f, e1, h[e2, e3, e4]]],
ESameTest[{h}, FoldList[f, h, {}]]
EComment["Known problem: FoldList[f, , {1}] ? this is because Null is not handled correctly. Try evaluating e.g. f[,]"]
]
}

Expand All @@ -94,10 +92,8 @@
ESameTest[f[f[1, 2], 3], Fold[f, 1, {2, 3}]],
ESameTest[f[f[1, 2], 3], Fold[f, {1, 2, 3}]],
(* ESameTest[f[f[1, 2], 3], Fold[f][{1, 2, 3}]], *)
ESameTest[f[f[1, 2], 3], Fold[f][1, {2, 3}]],
ESameTest[f[f[f[e1, e2], e3], e4], Fold[f, e1, h[e2, e3, e4]]],
ESameTest[h, Fold[f, h, {}]]
EComment["Known problem: Fold[f, , {1}] ? this is because Null is not handled correctly. Try evaluating e.g. f[,]"]
]
}

Expand Down Expand Up @@ -159,7 +155,7 @@
]
}

FixedPoint::usage = "`FixedPointList[f, expr]` applies `f` to `expr` until `UnsameQ` applied to the two most recent results
FixedPoint::usage = "`FixedPoint[f, expr]` applies `f` to `expr` until `UnsameQ` applied to the two most recent results
returns False."
FixedPoint[f_, expr_] := Last[NestWhileList[f, expr, UnsameQ, 2]]
Tests`FixedPoint = {
Expand Down
7 changes: 6 additions & 1 deletion expreduce/sameq.go
Expand Up @@ -23,7 +23,12 @@ func IsSameQ(a Ex, b Ex, cl *CASLogger) bool {
// https://stackoverflow.com/questions/46136886/comparing-floats-by-ignoring-last-bit-in-golang
aVal, _ := aFlt.Val.Float64()
bVal, _ := bFlt.Val.Float64()
return almostEqual(aVal, bVal)

if math.IsInf(aVal, 0) || math.IsInf(bVal, 0) {
return a.IsEqual(b, cl) == "EQUAL_TRUE"
} else {
return almostEqual(aVal, bVal)
}
} else {
return a.IsEqual(b, cl) == "EQUAL_TRUE"
}
Expand Down

0 comments on commit 3989b82

Please sign in to comment.