-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correctness of evaluateNode #148
Comments
I'm going to have to think about this. I'm wanting to setup a test which will validate correct/incorrect behavior. I will setup some tests tomorrow and see if we are getting the intended behavior. |
If I tweak the expression, maybe it will be easier to tell if this is the correct behavior or not. Multiply (2.0, AddFloat (2.0, Empty)) + AddFloat (-2.0, Empty) I negated the last float. Now the actual output from Now amplify this by replacing every occurrence of Should the output after summing be exactly |
I'm going to have this fixed today and put out a new release |
It is definitely wrong. This code: let d = Decision.createBoolean "d1"
let e = 2.0 * (1.0 * d) + 1.0 * d
let r = LinearExpression.Reduce e Produces
But should produce this
The reason that it is not causing a problem in our current code is that we don't have cases where we are multiplying I believe this is the correct implementation: | AddLinearExpression (lExpr, rExpr) ->
evaluateNode (multiplier, state) lExpr (fun (_, lState) -> evaluateNode (multiplier, lState) rExpr cont) The behavior would technically equivalent to what you proposed @TysonMN because the |
Yep, that implementation also works. I see the test you added in 90f4940. It looks great. |
I am suspicious of the correctness of
evaluateNode
. Unfortunately I still lack sufficient understanding to either convince myself that it is correct or be confident enough to know the correct behavior.flips/Flips/Types.fs
Lines 236 to 254 in 16a347c
I am surprised by the implementation of the
AddLinearExpression
case on line 251.flips/Flips/Types.fs
Lines 250 to 251 in 16a347c
The multiplier used in the continuation is the multiplier returned from recursing into the left expression. This could be different if that branch of the expression includes a
Multiply
case. Eventually theEmpty
case executes the continuation by passing in the multiplier it was given.To see what I mean, consider the
LinearExpression
The floats returned for it by
evaluateNode
are[ 4.0; 4.0 ]
, but I was expecting[ 4.0; 2.0 ]
because I didn't think theMultiply
on the left should change what the right returns (which would have been[ 2.0 ]
).The implementation I expected to see is
Is this a bug? If not, why is this the correct behavior?
The text was updated successfully, but these errors were encountered: