Skip to content
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

Wrong result #10

Open
newmen opened this issue Feb 25, 2012 · 5 comments
Open

Wrong result #10

newmen opened this issue Feb 25, 2012 · 5 comments

Comments

@newmen
Copy link

newmen commented Feb 25, 2012

Hello,

When I tried to use your beauty gem, I wrote this code:
x = var :name => 'x'
y = var :name => 'y'
puts x - (y + x) / 5

And I got the next result:
x-0.2*y+x

but its wrong :(

Best wishes, Gleb

@brainopia
Copy link
Owner

Indeed, I can confirm your findings. I will investigate it later, hope to get back at you soon.

Thanks for report.

@eregon eregon closed this as completed in ea1cce5 Feb 26, 2012
@eregon eregon reopened this Feb 26, 2012
@eregon
Copy link
Collaborator

eregon commented Feb 26, 2012

The bug was only in the representation (#to_s), so the internal expression is correct, although not totally optimized. You can try the latest symbolic with Bundler, fetching directly from the master, or wait the next release.

@newmen
Copy link
Author

newmen commented Feb 26, 2012

integration_spec.rb says that failures still occur

Failures:

  1) Symbolic optimization: x-0.2*(y+x)
     Failure/Error: non_optimized.should == optimized
       expected: Symbolic(0.8*x-0.2*y)
            got: Symbolic(x-0.2*(y+x)) (using ==)
       Diff:
       @@ -1,2 +1,2 @@
       -Symbolic(0.8*x-0.2*y)
       +Symbolic(x-0.2*(y+x))
     # ./integration_spec.rb:96:in `block (4 levels) in <top (required)>'

  2) Symbolic to_s: -x**y+7
     Failure/Error: expr.to_s.should == str
       expected: "-x**y+7"
            got: "-(x**y)+7" (using ==)
     # ./integration_spec.rb:166:in `block (4 levels) in <top (required)>'

Finished in 0.01495 seconds
81 examples, 2 failures

Thus, I'm still not getting the correct result when using the expression x-(y + x)/5, i.e. is not 0.8*x-0.2*y.

@eregon
Copy link
Collaborator

eregon commented Feb 26, 2012

Indeed, this expression is "not totally optimized", but both expressions are mathematically equal.
So we need to work on this, but at least it's coherent now (the representation).

Do you need such simplification?

@newmen
Copy link
Author

newmen commented Feb 27, 2012

Your gem is perfect, because ultimately you can get an expression that contains only one time mention of a particular variable. In the case of incomplete simplify the expression - it does not. At the same time, the expression x-0.2*(y+x) can be simplified by symbolic to the correct expression. In this case you must call symbolic again, but its better not to do so. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants