@@ -533,7 +533,11 @@ def scale_by(self, t):
533533
534534 def normalize_coordinates (self ):
535535 """
536- Removes the gcd from the coordinates of this point (including `-1`).
536+ Removes the gcd from the coordinates of this point (including `-1`)
537+ and rescales everything so that the last nonzero entry is as "simple"
538+ as possible. The notion of "simple" here depends on the base ring;
539+ concretely, the last nonzero coordinate will be `1` in a field and
540+ positive over an ordered ring.
537541
538542 .. WARNING:: The gcd will depend on the base ring.
539543
@@ -552,7 +556,7 @@ def normalize_coordinates(self):
552556 sage: P = ProjectiveSpace(Zp(7), 2, 'x')
553557 sage: p = P([-5, -15, -2])
554558 sage: p.normalize_coordinates(); p
555- (5 + O(7^20) : 1 + 2*7 + O(7^20) : 2 + O(7^20))
559+ (6 + 3*7 + 3*7^2 + 3*7^3 + 3*7^4 + 3*7^ 5 + 3*7^6 + 3*7^7 + 3*7^8 + 3*7^9 + 3*7^10 + 3*7^11 + 3*7^12 + 3*7^13 + 3*7^14 + 3*7^15 + 3*7^16 + 3*7^17 + 3*7^18 + 3*7^19 + O(7^20) : 4 + 4*7 + 3*7^2 + 3*7^3 + 3*7^4 + 3*7^5 + 3*7^6 + 3*7^7 + 3*7^8 + 3*7^9 + 3*7^10 + 3*7^11 + 3*7^12 + 3*7^13 + 3*7^14 + 3*7^15 + 3*7^16 + 3*7^17 + 3*7^18 + 3*7^19 + O(7^20) : 1 + O(7^20))
556560
557561 ::
558562
@@ -576,8 +580,8 @@ def normalize_coordinates(self):
576580 sage: R.<c> = PolynomialRing(QQ)
577581 sage: P = ProjectiveSpace(R, 1)
578582 sage: Q = P(2*c, 4*c)
579- sage: Q.normalize_coordinates();Q
580- (2 : 4 )
583+ sage: Q.normalize_coordinates(); Q
584+ (1/ 2 : 1 )
581585
582586 A polynomial ring over a ring gives the more intuitive result. ::
583587
@@ -614,15 +618,19 @@ def normalize_coordinates(self):
614618 else :
615619 GCD = R (gcd (self ._coords [0 ], self ._coords [1 ]))
616620 index = 2
617- neg = self ._coords [0 ] <= 0 and self ._coords [1 ] <= 0
618- while not GCD .is_one () and index < len (self ._coords ):
619- neg = self ._coords [index ] <= 0
621+ while not GCD .is_unit () and index < len (self ._coords ):
620622 GCD = R (gcd (GCD , self ._coords [index ]))
621623 index += 1
622- if not GCD .is_one ():
624+ if not GCD .is_unit ():
623625 self .scale_by (~ GCD )
624- if neg :
625- self .scale_by (- ZZ .one ())
626+ index = len (self ._coords ) - 1
627+ while not self ._coords [index ]:
628+ index -= 1
629+ if self ._coords [index ].is_unit ():
630+ if not self ._coords [index ].is_one ():
631+ self .scale_by (~ self ._coords [index ])
632+ elif self ._coords [index ] < 0 :
633+ self .scale_by (- R .one ())
626634 self ._normalized = True
627635
628636 def dehomogenize (self , n ):
0 commit comments