# HG changeset patch
# User Nick Alexander <ncalexander@gmail.com>
# Date 1241902740 25200
# Branch symbolics_switch
# Node ID d4f2118fb20e3705214e799a35b9bb61799d4814
# Parent  2d4bc47a082f33c74612a0d9a0589901c78ae138
[mq]: elliptic_curves.patch

diff -r 2d4bc47a082f -r d4f2118fb20e sage/schemes/elliptic_curves/ell_generic.py
--- a/sage/schemes/elliptic_curves/ell_generic.py	Sat May 09 11:09:27 2009 -0700
+++ b/sage/schemes/elliptic_curves/ell_generic.py	Sat May 09 13:59:00 2009 -0700
@@ -359,9 +359,6 @@
         
             sage: eqn = symbolic_expression(E); eqn
             y^2 + y == x^3 - x^2 - 10*x - 20
-            sage: print eqn
-                                      2        3    2
-                                     y  + y == x  - x  - 10 x - 20
         
         We verify that the given point is on the curve::
         
@@ -372,58 +369,60 @@
         
         We create a single expression::
         
-            sage: F = eqn.lhs() - eqn.rhs(); print F
-                                      2        3    2
-                                     y  + y - x  + x  + 10 x + 20
+            sage: F = eqn.lhs() - eqn.rhs(); F
+            -x^3 + x^2 + y^2 + 10*x + y + 20
             sage: y = var('y')
-            sage: print F.solve(y)
-            [
-                                  3      2
-                        - sqrt(4 x  - 4 x  - 40 x - 79) - 1
-                    y == -----------------------------------
-                                         2,
-                                 3      2
-                         sqrt(4 x  - 4 x  - 40 x - 79) - 1
-                     y == ---------------------------------
-                                         2
-            ]
+            sage: F.solve(y)
+            [y == -1/2*sqrt(4*x^3 - 4*x^2 - 40*x - 79) - 1/2,
+             y == 1/2*sqrt(4*x^3 - 4*x^2 - 40*x - 79) - 1/2]
         
         You can also solve for x in terms of y, but the result is
         horrendous. Continuing with the above example, we can explicitly
         find points over random fields by substituting in values for x::
         
-            sage: v = F.solve(y)[0].rhs()   
-            sage: print v
-                                            3      2
-                                  - sqrt(4 x  - 4 x  - 40 x - 79) - 1
-                                  -----------------------------------
-                                                   2
+            sage: v = F.solve(y)[0].rhs(); v
+            -1/2*sqrt(4*x^3 - 4*x^2 - 40*x - 79) - 1/2
             sage: v = v.function(x)
             sage: v(3)
-            (-sqrt(127)*I - 1)/2
+            -1/2*sqrt(-127) - 1/2
             sage: v(7)
-            (-sqrt(817) - 1)/2
+            -1/2*sqrt(817) - 1/2
             sage: v(-7)
-            (-sqrt(1367)*I - 1)/2
+            -1/2*sqrt(-1367) - 1/2
             sage: v(sqrt(2))
-            (-sqrt(-32*sqrt(2) - 87) - 1)/2
+            -1/2*sqrt(-32*sqrt(2) - 87) - 1/2
         
         We can even do arithmetic with them, as follows::
         
             sage: E2 = E.change_ring(SR); E2
-            Elliptic Curve defined by y^2 + y = x^3 - x^2 - 10*x - 20 over Symbolic Ring
-            sage: P = E2.point((3, v(3), 1), check=False)
+            Elliptic Curve defined by y^2 + y = x^3 + (-1)*x^2 + (-10)*x + (-20) over Symbolic Ring
+            sage: P = E2.point((3, v(3), 1), check=False) # the check=False option doesn't verify that y^2 = f(x)
             sage: P
-            (3 : (-sqrt(127)*I - 1)/2 : 1)
+            (3 : -1/2*sqrt(-127) - 1/2 : 1)
             sage: P + P
-            (-756/127 : (sqrt(127)*I + 1)/2 + 12507*I/(127*sqrt(127)) - 1 : 1)
+            (-756/127 : 41143/32258*sqrt(-127) - 1/2 : 1)
         
         We can even throw in a transcendental::
         
             sage: w = E2.point((pi,v(pi),1), check=False); w
-            (pi : (-sqrt(4*pi^3 - 4*pi^2 - 40*pi - 79) - 1)/2 : 1)
+            (pi : -1/2*sqrt(-40*pi + 4*pi^3 - 4*pi^2 - 79) - 1/2 : 1)
+            sage: x, y, z = w; ((y^2 + y) - (x^3 - x^2 - 10*x - 20)).expand()
+            0
+
             sage: 2*w
-            ((3*pi^2 - 2*pi - 10)^2/(4*pi^3 - 4*pi^2 - 40*pi - 79) - 2*pi + 1 : (sqrt(4*pi^3 - 4*pi^2 - 40*pi - 79) + 1)/2 - (3*pi^2 - 2*pi - 10)*(-(3*pi^2 - 2*pi - 10)^2/(4*pi^3 - 4*pi^2 - 40*pi - 79) + 3*pi - 1)/sqrt(4*pi^3 - 4*pi^2 - 40*pi - 79) - 1 : 1)
+            (-2*pi + (2*pi - 3*pi^2 + 10)^2/(-40*pi + 4*pi^3 - 4*pi^2 - 79) + 1 : (2*pi - 3*pi^2 + 10)*(3*pi - (2*pi - 3*pi^2 + 10)^2/(-40*pi + 4*pi^3 - 4*pi^2 - 79) - 1)/sqrt(-40*pi + 4*pi^3 - 4*pi^2 - 79) + 1/2*sqrt(-40*pi + 4*pi^3 - 4*pi^2 - 79) - 1/2 : 1)
+            
+            sage: x, y, z = 2*w; temp = ((y^2 + y) - (x^3 - x^2 - 10*x - 20)).expand()
+
+        This is not simplified to zero correctly:
+
+            sage: temp
+            0
+
+        But in fact it is zero, as this suggests:
+
+            sage: RDF(temp).abs() < 1e-10
+            True
         """
         a = [SR(x) for x in self.a_invariants()]
         x, y = SR.var('x, y')
diff -r 2d4bc47a082f -r d4f2118fb20e sage/symbolic/expression.pyx
--- a/sage/symbolic/expression.pyx	Sat May 09 11:09:27 2009 -0700
+++ b/sage/symbolic/expression.pyx	Sat May 09 13:59:00 2009 -0700
@@ -3154,7 +3154,7 @@
                 return R({tuple([0]*R.ngens()):self})
             else:
                 return R([self])
-        return self.polynomial(ring=R)
+        return self.polynomial(None, ring=R)
     
     def power_series(self, base_ring):
         """
diff -r 2d4bc47a082f -r d4f2118fb20e sage/symbolic/expression_conversions.py
--- a/sage/symbolic/expression_conversions.py	Sat May 09 11:09:27 2009 -0700
+++ b/sage/symbolic/expression_conversions.py	Sat May 09 13:59:00 2009 -0700
@@ -207,10 +207,10 @@
         """        
         raise NotImplementedError
 
-    def relation(self, ex):
+    def relation(self, ex, operator):
         """
         The input to this method is a symbolic expression which
-        corresponds to a relation.
+        corresponds to a relation with specified operator.
         
         TESTS::
 
@@ -220,6 +220,10 @@
             Traceback (most recent call last):
             ...
             NotImplementedError
+            sage: Converter().relation(x==3, operator.lt)
+            Traceback (most recent call last):
+            ...
+            NotImplementedError
         """        
         raise NotImplementedError
 
@@ -318,6 +322,8 @@
             sage: m = InterfaceInit(maxima)
             sage: m.relation(x==3, operator.eq)
             'x = 3'
+            sage: m.relation(x==3, operator.lt)
+            'x < 3'
         """
         return "%s %s %s"%(self(ex.lhs()), self.relation_symbols[operator],
                            self(ex.rhs()))
@@ -642,6 +648,33 @@
         """
         return self.base_ring(ex)
 
+    def relation(self, ex, op):
+        """
+        EXAMPLES::
+
+            sage: import operator
+            sage: from sage.symbolic.expression_conversions import PolynomialConverter
+
+            sage: x, y = var('x, y')
+            sage: p = PolynomialConverter(x, base_ring=RR)
+
+            sage: p.relation(x==3, operator.eq)
+            1.00000000000000*x - 3.00000000000000
+            sage: p.relation(x==3, operator.lt)
+            Traceback (most recent call last):
+            ...
+            ValueError: Unable to represent as a polynomial
+
+            sage: p = PolynomialConverter(x - y, base_ring=QQ)
+            sage: p.relation(x^2 - y^3 + 1 == x^3, operator.eq)
+            -x^3 - y^3 + x^2 + 1
+        """
+        import operator
+        if op == operator.eq:
+            return self(ex.lhs()) - self(ex.rhs())
+        else:
+            raise ValueError, "Unable to represent as a polynomial"
+
     def arithmetic(self, ex, operator):
         if len(ex.variables()) == 0:
             return self.base_ring(ex)
@@ -674,6 +707,12 @@
          sage: _.parent()
          Multivariate Polynomial Ring in x, y over Rational Field
 
+         sage: x, y = var('x, y')
+         sage: polynomial(x + y^2, ring=QQ['x,y'])
+         y^2 + x
+         sage: _.parent()
+         Multivariate Polynomial Ring in x, y over Rational Field
+
     The polynomials can have arbitrary (constant) coefficients so long as
     they coerce into the base ring::
 
