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

Addition commutativity violated with 'times' method #3

Closed
GoogleCodeExporter opened this issue Aug 4, 2015 · 2 comments
Closed

Addition commutativity violated with 'times' method #3

GoogleCodeExporter opened this issue Aug 4, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

Consider the following Lea session:
{{{
>>> (die1.times(2)) + die1
 3 :  1/216
 4 :  3/216
 5 :  6/216
 6 : 10/216
 7 : 15/216
 8 : 21/216
 9 : 25/216
10 : 27/216
11 : 27/216
12 : 25/216
13 : 21/216
14 : 15/216
15 : 10/216
16 :  6/216
17 :  3/216
18 :  1/216
>>> die1 + (die1.times(2))
 3 : 1/6
 6 : 1/6
 9 : 1/6
12 : 1/6
15 : 1/6
18 : 1/6
}}}
Both results should be the same! The second result can be explained by the 
binding mechanism.
A workaround is to clone _die1_ before doing the _times(2)_:
{{{
>>> die1 + (die1.clone().times(2))
 3 :  1/216
 4 :  3/216
 5 :  6/216
 6 : 10/216
 7 : 15/216
 8 : 21/216
 9 : 25/216
10 : 27/216
11 : 27/216
12 : 25/216
}}}

Resolution: change the _times_ method to perform a clone of self.

Original issue reported on code.google.com by pde@n-side.com on 14 Oct 2014 at 8:47

@GoogleCodeExporter
Copy link
Author

Original comment by pde@n-side.com on 13 Nov 2014 at 9:28

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

Fixed in Lea 2

Original comment by pde@n-side.com on 25 Dec 2014 at 11:07

  • Changed state: Verified

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

No branches or pull requests

1 participant