Ticket #727: trac_727_more_conic_files7.patch

File trac_727_more_conic_files7.patch, 15.2 KB (added by Marco Streng, 12 years ago)

apply the 1-6 patch on sage 4.5.1, then apply this one

  • doc/en/reference/quadratic_forms.rst

    # HG changeset patch
    # User Marco Streng <marco.streng@gmail.com>
    # Date 1279625403 -7200
    # Node ID 4c87bd2ae96911b58dffe93aeefda6cf498072b5
    # Parent  d8f792fb37aa5db2c4b0d7023dc775da4684dfdc
    Trac 727: Corrected indentation of documentation. Correctec qfsolve for non-ternary forms
    
    diff -r d8f792fb37aa -r 4c87bd2ae969 doc/en/reference/quadratic_forms.rst
    a b  
    1 .. _ch:schemes:
     1.. _ch:quadratic-forms:
    22
    33Quadratic Forms
    44===============
     
    66.. toctree::
    77   :maxdepth: 2
    88
    9     sage/quadratic_forms/fsolve.py
     9    sage/quadratic_forms/qfsolve
    1010
  • sage/quadratic_forms/qfsolve.py

    diff -r d8f792fb37aa -r 4c87bd2ae969 sage/quadratic_forms/qfsolve.py
    a b  
    33
    44Interface to the GP quadratic forms code of Denis Simon.
    55
    6 AUTHOR:
    7     Denis Simon (GP code)
    8     Nick Alexander (Sage interface)
     6AUTHORS:
     7
     8 * Denis Simon (GP code)
     9
     10 * Nick Alexander (Sage interface)
    911"""
    1012
    1113#*****************************************************************************
    12 #       Copyright (C) 2008 William Stein <wstein@gmail.com>
     14#       Copyright (C) 2008 Nick Alexander
    1315#
    1416#  Distributed under the terms of the GNU General Public License (GPL)
    1517#
     
    5759# \\ quadratique ternaire G, en utilisant la solution particuliere sol.
    5860# \\ si fl>0, la 'fl'eme forme quadratique est reduite.
    5961
    60 def Qfsolve(G, factD=None):
    61     r"""Find a solution to (x,y,z)^t*G*(x,y,z) = 0.
     62def qfsolve(G, factD=None):
     63    r"""
     64    Find a solution `x = (x_0,...,x_n)` to `x G x^t = 0` for an
     65    `n \times n`-matrix ``G`` over `\QQ`.
    6266
    63     If successful, returns a triple of rational numbers (x0, y0, z0).
    64     If unsuccessful, returns -1 if no solutions exists over the reals and a
    65     prime p if no solution exists over the p-adic field Q_p.
     67    If a solution exists, returns a tuple of rational numbers `x`.
     68    Otherwise, returns `-1` if no solutions exists over the reals and a
     69    prime `p` if no solution exists over the `p`-adic field `\QQ_p`.
    6670
    67     EXAMPLES:
    68         sage: from sage.quadratic_forms.qfsolve import Qfsolve
     71    EXAMPLES::
     72
     73        sage: from sage.quadratic_forms.qfsolve import qfsolve
    6974        sage: M = Matrix(QQ, [[0, 0, -12], [0, -12, 0], [-12, 0, -1]]); M
    7075        [  0   0 -12]
    7176        [  0 -12   0]
    7277        [-12   0  -1]
    73         sage: sol = Qfsolve(M); sol
     78        sage: sol = qfsolve(M); sol
    7479        (1, 0, 0)
    7580        sage: sol[0].parent() is QQ
    7681        True
    7782       
    7883        sage: M = Matrix(QQ, [[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    79         sage: ret = Qfsolve(M); ret
     84        sage: ret = qfsolve(M); ret
    8085        -1
    8186        sage: ret.parent() is ZZ
    8287        True
    8388
    8489        sage: M = Matrix(QQ, [[1, 0, 0], [0, 1, 0], [0, 0, -7]])
    85         sage: Qfsolve(M)
     90        sage: qfsolve(M)
    8691        7
     92
     93        sage: M = Matrix(QQ, [[3, 0, 0, 0], [0, 5, 0, 0], [0, 0, -7, 0], [0, 0, 0, -11]])
     94        sage: qfsolve(M)
     95        (-3, 4, 3, 2)
    8796    """
    8897    gp = _gp_for_simon()
    8998    if factD is not None:
    90         raise NotImplementedError
     99        raise NotImplementedError, "qfsolve not implemented with parameter factD"
    91100    ret = pari(gp('Qfsolve(%s)' % G._pari_()))
    92101    if ret.type() == 't_COL':
    93         return (QQ(ret[0]), QQ(ret[1]), QQ(ret[2]))
     102        return tuple([QQ(r) for r in ret])
    94103    return ZZ(ret)
    95104
    96 def Qfparam(G, sol):
     105def qfparam(G, sol):
    97106    r"""
     107    Parametrizes the conic defined by the matrix ``G``.
    98108
    99     EXAMPLES:
    100         sage: from sage.quadratic_forms.qfsolve import Qfsolve, Qfparam
     109    INPUT:
     110
     111     - ``G`` -- a `3 \times 3`-matrix over `\QQ`.
     112
     113     - ``sol`` -- a triple of rational numbers providing a solution
     114       to sol*G*sol^t = 0.
     115
     116    OUTPUT:
     117
     118    A triple of polynomials that parametrizes all solutions of
     119    x*G*x^t = 0 up to scaling.
     120
     121    ALGORITHM:
     122
     123    Uses Denis Simon's pari script Qfparam.
     124
     125    EXAMPLES::
     126
     127        sage: from sage.quadratic_forms.qfsolve import qfsolve, qfparam
    101128        sage: M = Matrix(QQ, [[0, 0, -12], [0, -12, 0], [-12, 0, -1]]); M
    102129        [  0   0 -12]
    103130        [  0 -12   0]
    104131        [-12   0  -1]
    105         sage: sol = Qfsolve(M);
    106         sage: ret = Qfparam(M, sol); ret
     132        sage: sol = qfsolve(M);
     133        sage: ret = qfparam(M, sol); ret
    107134        (-t^2 - 12, 24*t, 24*t^2)
    108135        sage: ret[0].parent() is QQ['t']
    109136        True
    110137    """
    111138    gp = _gp_for_simon()
    112139    R = QQ['t']
    113     str = 'Qfparam(%s, (%s)~)*[t^2,t,1]~' % (G._pari_(), pari(gp(sol))._pari_())
    114     ret = pari(gp(str))
    115     return (R(ret[0]), R(ret[1]), R(ret[2]))
     140    t = R.gen()
     141    s = 'Qfparam(%s, (%s)~)*[t^2,t,1]~' % (G._pari_(), pari(gp(sol))._pari_())
     142    ret = pari(gp(s))
     143    return tuple([R(r) for r in ret])
    116144
    117 qfsolve = Qfsolve
    118 qfparam = Qfparam
  • sage/schemes/plane_conics/con_field.py

    diff -r d8f792fb37aa -r 4c87bd2ae969 sage/schemes/plane_conics/con_field.py
    a b  
    519519            sage: c.hom(Matrix([[0, 0, 1/2], [0, 1, 0], [1, 0, 0]]), d)
    520520            Scheme morphism:
    521521              From: Projective Conic Curve over Rational Field defined by -x^2 + y^2 + z^2
    522                 To:   Projective Conic Curve over Rational Field defined by 4*x^2 + y^2 - z^2
    523                   Defn: Defined on coordinates by sending (x : y : z) to
    524                           (1/2*z : y : x)
     522              To:   Projective Conic Curve over Rational Field defined by 4*x^2 + y^2 - z^2
     523              Defn: Defined on coordinates by sending (x : y : z) to
     524                    (1/2*z : y : x)
    525525
    526526        ``ValueError`` is raised if the wrong codomain ``Y`` is specified:
    527527
     
    970970        return self.defining_polynomial().parent().variable_names()
    971971   
    972972       
    973        
    974 
    975  
  • sage/schemes/plane_conics/con_number_field.py

    diff -r d8f792fb37aa -r 4c87bd2ae969 sage/schemes/plane_conics/con_number_field.py
    a b  
    7171        Returns ``True`` if and only if ``self`` has a point
    7272        defined over its base field `B`.
    7373
    74         If ``point`` or ``obstruction`` is True, then returns
    75         a second output ``S``:
    76         - if ``point`` is True and ``self`` has a rational point,
    77           then ``S`` is a rational point;
    78         - if ``obstruction`` is True, ``self`` has no rational point,
    79           then ``S`` is a prime or infinite place of `B` such that no
    80           rational point exists over the completion at ``S``.
    81        
     74        If ``point`` and ``obstruction`` are both False (default),
     75        then the output is boolean ``out`` saying whether ``self``
     76        has a rational point.
     77
     78        If ``point`` or ``obstruction`` is True, then the output is
     79        a pair ``(out, S)``, where ``out`` is as above and:
     80
     81         - if ``point`` is True and ``self`` has a rational point,
     82           then ``S`` is a rational point,
     83
     84         - if ``obstruction`` is True, ``self`` has no rational point,
     85           then ``S`` is a prime or infinite place of `B` such that no
     86           rational point exists over the completion at ``S``.
     87
    8288        Points and obstructions are cached whenever they are found.
    8389        Cached information is used for the output if available, but only
    8490        if ``read_cache`` is True.
    8591       
    8692        ALGORITHM:
    8793           
    88             The parameter ``algorithm``
    89             specifies the algorithm to be used:
     94        The parameter ``algorithm``
     95        specifies the algorithm to be used:
    9096           
    91                 ``'rnfisnorm'`` - Use PARI's rnfisnorm (cannot be combined with
    92                                   ``obstruction = True``)
    93                 ``'local'``     - Check if a local solution exists for all primes
    94                                   and infinite places of `B` (cannot be combined with
    95                                   ``point = True``)
    96                 ``'default'``   - Use ``algorithm = 'local'`` first. If a rational
    97                                   point exists, then use ``algorithm = 'rnfisnorm'``
    98                                   to find one.
     97         - ``'rnfisnorm'`` -- Use PARI's rnfisnorm
     98           (cannot be combined with ``obstruction = True``)
     99
     100         - ``'local'`` -- Check if a local solution exists for all primes
     101           and infinite places of `B` and apply the Hasse principle
     102           (cannot be combined with ``point = True``)
     103         
     104         - ``'default'`` -- Use ``'local'`` first.
     105           If a rational point exists, then use ``'rnfisnorm'``
     106           to find one.
    99107           
    100108        NOTE:
    101109       
    102             Algorithms for local solubility of conics over number fields
    103             of degree `> 1` have not been implemented yet, so
    104             'rnfisnorm' is the only working algorithm.
     110        Algorithms for local solubility of conics over number fields
     111        of degree `> 1` have not been implemented yet, so
     112        'rnfisnorm' is the only working algorithm.
     113       
     114        To implement algorithms for local solubility, use Hilbert symbols
     115        from Trac #9334.
    105116           
    106             To implement algorithms for local solubility, use Hilbert symbols
    107             from Trac #9334.
    108            
    109             The algorithm 'rnfisnorm' only works for small examples and
    110             gives the error
    111             ``GP/PARI ERROR: *** rnfisnorm: precision too low in isunit.``
    112             if the examples become to large.
    113             Instead of improving rnfisnorm.py, replace it by Trac #2329
    114             as soon as that ticket is finished.
     117        The algorithm 'rnfisnorm' only works for small examples and
     118        gives the error
     119        ``GP/PARI ERROR: *** rnfisnorm: precision too low in isunit.``
     120        if the examples become to large.
     121        Instead of improving rnfisnorm.py, replace it by Trac #2329
     122        as soon as that ticket is finished.
    115123           
    116124        EXAMPLES:
    117125       
     
    165173            sage: d = [C.has_rational_point(algorithm = 'rnfisnorm', point = True) for C in c] # long time: 15 seconds
    166174            sage: assert all([c[k].defining_polynomial()(Sequence(d[k][1])) == 0 for k in range(len(c)) if d[k][0]])
    167175
    168         Create a bunch of conics that are known to have rational points already over `\QQ`
    169         and check if points are found by ``has_rational_point``.
     176        Create a bunch of conics that are known to have rational points
     177        already over `\QQ` and check if points are found by
     178        ``has_rational_point``. ::
    170179
    171180            sage: l = Sequence(cartesian_product_iterator([[-1, 0, 1] for i in range(3)]))
    172181            sage: K.<a> = QuadraticField(-23)
  • sage/schemes/plane_conics/con_rational_field.py

    diff -r d8f792fb37aa -r 4c87bd2ae969 sage/schemes/plane_conics/con_rational_field.py
    a b  
    3030from sage.schemes.generic.projective_space import ProjectiveSpace
    3131from sage.matrix.constructor import Matrix
    3232
    33 from sage.quadratic_forms.qfsolve import Qfsolve, Qfparam
     33from sage.quadratic_forms.qfsolve import qfsolve, qfparam
    3434
    3535from con_number_field import ProjectiveConic_number_field
    3636
     
    7070        r"""
    7171        Returns True if and only if ``self`` has a point defined over `\QQ`.
    7272
    73         If ``point`` or ``obstruction`` is True, then returns
    74         a second output ``S``:
    75         - if ``point`` is True and ``self`` has a rational point,
    76           then ``S`` is a rational point;
    77         - if ``obstruction`` is True and ``self`` has no rational point,
    78           then ``S`` is a prime such that no rational point exists
    79           over the completion at ``S`` or `-1` if no point exists over `\RR`.
     73        If ``point`` and ``obstruction`` are both False, then the output
     74        is a boolean ``out`` saying whether ``self`` has a rational point.
     75
     76        If ``point`` or ``obstruction`` is True, then the output is
     77        a pair ``(out, S)``, where ``out`` is as above and the following
     78        holds:
     79       
     80         - if ``point`` is True and ``self`` has a rational point,
     81           then ``S`` is a rational point,
     82
     83         - if ``obstruction`` is True and ``self`` has no rational point,
     84           then ``S`` is a prime such that no rational point exists
     85           over the completion at ``S`` or `-1` if no point exists over `\RR`.
    8086       
    8187        Points and obstructions are cached, whenever they are found.
    8288        Cached information is used if and only if ``read_cache`` is True.
     
    8692        The parameter ``algorithm``
    8793        specifies the algorithm to be used:
    8894           
    89         - ``'qfsolve'``   - Use Denis Simon's Qfsolve (only over `\QQ`)
    90         - ``'rnfisnorm'`` - Use PARI's rnfisnorm (cannot be combined with
    91                             ``obstruction = True``)
    92         - ``'local'``     - Check if a local solution exists for all primes
    93                             and infinite places of `\QQ` (cannot be combined with
    94                             point = True)
    95         - ``'default'``   - Use ``'qfsolve'`` over `\QQ`. Use ``'local'`` over
    96                             other number fields. If self has a rational point
    97                             and ``point`` is True, then use ``'rnfisnorm'`` to find
    98                             the point.
     95         - ``'qfsolve'`` -- Use Denis Simon's pari script Qfsolve
     96           (see ``sage.quadratic_forms.qfsolve.qfsolve``)
     97
     98         - ``'rnfisnorm'`` -- Use PARI's function rnfisnorm
     99           (cannot be combined with ``obstruction = True``)
     100
     101         - ``'local'`` -- Check if a local solution exists for all primes
     102           and infinite places of `\QQ` and apply the Hasse principle
     103           (cannot be combined with ``point = True``)
     104
     105         - ``'default'`` -- Use ``'qfsolve'``
    99106           
    100107        EXAMPLES::
    101108
     
    154161            if obstruction:
    155162                return True, None
    156163            return True
    157         if algorithm == 'default':
    158             algorithm = 'qfsolve'
    159         if algorithm == 'qfsolve':                       
     164        if algorithm == 'default' or algorithm == 'qfsolve':
    160165            M = self.symmetric_matrix()
    161166            M *= lcm([ t.denominator() for t in M.list() ])
    162             pt = Qfsolve(M)
     167            pt = qfsolve(M)
    163168            if pt in ZZ:
    164169                if self._local_obstruction == None:
    165170                    self._local_obstruction = pt
     
    296301       
    297302        ALGORITHM:
    298303       
    299             Uses Denis Simon's Qfparam.
     304        Uses Denis Simon's pari script Qfparam.
     305        See ``sage.quadratic_forms.qfsolve.qfparam``.
    300306       
    301307        EXAMPLES ::
    302308
     
    353359            gens = self.ambient_space().gens()
    354360            M = self.symmetric_matrix()
    355361            M *= lcm([ t.denominator() for t in M.list() ])
    356             par1 = Qfparam(M, point)
     362            par1 = qfparam(M, point)
    357363            B = Matrix([[par1[i][j] for j in range(3)] for i in range(3)])
    358364            # self is in the image of B and does not lie on a line,
    359365            # hence B is invertible