On Tuesday, June 23, 2015 at 1:04:58 AM UTC-7, John Cremona wrote: > > Here's an example: > > sage: E = EllipticCurve(GF(101),[0,1,1,1,0]) > sage: P = E.random_point() > sage: P.order() > 8 > sage: P+=P > sage: P.order() > 4 > > Now, after calling P.order(), P caches its order. Luckily the += > function discards that so that the new P does not have the wrong order > stored. >
That's not quite what happens; see https://docs.python.org/2/reference/simple_stmts.html#augmented-assignment-statements The operation "+=" *may* be inplace, but it doesn't need to be. In particular, for points on elliptic curves I think is executed as "P = P+P". So no order gets erased. After the assignment, P is just bound to a different object, not a mutated one: sage: id(P) 140298093730624 sage: P+=P sage: id(P) 140298093731184 It's true that P.__iadd__ is the inherited sage.structure.element.ModuleElement.__iadd__ that does try to P._iadd_ if a reference threshold is met, but that's just sage.structure.element.ModuleElement._iadd_, which dispatches to the not in-place P._add_. Indeed, it seems a+=b is more or less equivalent to a = a.__iadd__(b), so it's up to the implementation whether it's really inplace or not. Furthermore, some objects such as python integers don't have an __iadd__ and the "+=" notation still works, so "+=" still has a fallback to use plain addition if the "__iadd__" slot isn't filled. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.