Ticket #12336: trac_12336_symbolic_data.patch

File trac_12336_symbolic_data.patch, 8.5 KB (added by malb, 10 years ago)
  • doc/en/reference/databases.rst

    # HG changeset patch
    # User Martin Albrecht <martinralbrecht@googlemail.com>
    # Date 1328444479 0
    # Node ID 664b72dcc7f05310e6e95491f2153c3631a50d00
    # Parent  18620dc67e5765b0f9c259f8011cd1277ca8d247
    #12336 fix optional keywords of symbolic_data tests, reformat docs, add to reference manual
    
    diff --git a/doc/en/reference/databases.rst b/doc/en/reference/databases.rst
    a b  
    5959   sage/databases/sloane
    6060   sage/databases/conway
    6161   sage/databases/odlyzko
     62   sage/databases/symbolic_data
  • sage/databases/symbolic_data.py

    diff --git a/sage/databases/symbolic_data.py b/sage/databases/symbolic_data.py
    a b  
    1 r"""
    2 Thin wrapper for the optional SymbolicData set of ideals as published
    3 on \url{http://www.symbolicdata.org} . From that website:
     1"""
     2Ideals from the Symbolic Data project
     3
     4This file implements a thin wrapper for the optional symbolic data set
     5of ideals as published on http://www.symbolicdata.org . From the
     6project website:
    47
    58    For different purposes algorithms and implementations are tested
    69    on certified and reliable data. The development of tools and data
     
    2932    certified data that could be addressed and extended during further
    3033    development.
    3134
    32 EXAMPLE:
    33     sage: sd = SymbolicData(); sd # optional requires database_symbolic_data
     35EXAMPLES::
     36
     37    sage: sd = SymbolicData(); sd # optional - database_symbolic_data
    3438    SymbolicData with 372 ideals
    3539
    36     sage: sd.ZeroDim__example_1 # optional requires database_symbolic_data
     40    sage: sd.ZeroDim__example_1 # optional - database_symbolic_data
    3741    Ideal (x1^2 + x2^2 - 10, x1^2 + x1*x2 + 2*x2^2 - 16) of Multivariate Polynomial Ring in x1, x2 over Rational Field
    3842
    39     sage: sd.Katsura_3 # optional requires database_symbolic_data
    40     Ideal (u0 + 2*u1 + 2*u2 + 2*u3 - 1, 
    41            u1^2 + 2*u0*u2 + 2*u1*u3 - u2, 
    42            2*u0*u1 + 2*u1*u2 + 2*u2*u3 - u1, 
     43    sage: sd.Katsura_3 # optional - database_symbolic_data
     44    Ideal (u0 + 2*u1 + 2*u2 + 2*u3 - 1,
     45           u1^2 + 2*u0*u2 + 2*u1*u3 - u2,
     46           2*u0*u1 + 2*u1*u2 + 2*u2*u3 - u1,
    4347           u0^2 + 2*u1^2 + 2*u2^2 + 2*u3^2 - u0) of Multivariate Polynomial Ring in u0, u1, u2, u3 over Rational Field
    4448
    45     sage: sd.get_ideal('Katsura_3',GF(127),'degrevlex') # optional requires database_symbolic_data
    46     Ideal (u0 + 2*u1 + 2*u2 + 2*u3 - 1, 
     49    sage: sd.get_ideal('Katsura_3',GF(127),'degrevlex') # optional - database_symbolic_data
     50    Ideal (u0 + 2*u1 + 2*u2 + 2*u3 - 1,
    4751           u1^2 + 2*u0*u2 + 2*u1*u3 - u2,
    48            2*u0*u1 + 2*u1*u2 + 2*u2*u3 - u1, 
     52           2*u0*u1 + 2*u1*u2 + 2*u2*u3 - u1,
    4953           u0^2 + 2*u1^2 + 2*u2^2 + 2*u3^2 - u0) of Multivariate Polynomial Ring in u0, u1, u2, u3 over Finite Field of size 127
    5054
    51 AUTHOR: Martin Albrecht <malb@informatik.uni-bremen.de>   
     55AUTHORS:
     56
     57- Martin Albrecht <martinralbrecht@googlemail.com>
    5258"""
    5359import os
    5460from xml.dom.minidom import parse
     
    5763
    5864class SymbolicData:
    5965    """
    60     Access to the benchmark and test ideals of the SymbolicData
    61     suite. This class needs the optional database-symbolicdata package
    62     to be installed.
     66    Database of ideals as distributed by the The SymbolicData Project
     67    (http://symbolicdata.org).
     68
     69    This class needs the optional ``database_symbolic_data`` package to be
     70    installed.
    6371    """
    6472    def __init__(self):
    6573        """
    66         EXAMPLE:
    67             sage: sd = SymbolicData(); sd # optional requires database_symbolic_data
     74        EXAMPLES:
     75            sage: sd = SymbolicData(); sd # optional - database_symbolic_data
    6876            SymbolicData with 372 ideals
    6977        """
    7078        path=os.environ["SAGE_ROOT"]+"/data/symbolic_data"
    7179        self.__intpath = path + "/Data/XMLResources/INTPS/"
    7280        self.__genpath = path + "/Data/XMLResources/GenPS/"
    73        
     81
    7482    def get_ideal(self, name, base_ring=QQ, term_order="degrevlex"):
    7583        """
    7684        Returns the ideal given by 'name' over the base ring given by
     
    7886        'term_order'.
    7987
    8088        INPUT:
    81             name -- name as in the SymbolicData package
    82             base_ring -- base ring for the polynomial ring (default: QQ)
    83             term_order -- term order for the polynomial ring (default: degrevlex)
     89
     90        - ``name`` - name as on the symbolic data website
     91        - ``base_ring`` - base ring for the polynomial ring (default: ``QQ``)
     92        - ``term_order`` - term order for the polynomial ring (default: ``degrevlex``)
    8493
    8594        OUTPUT:
    86             ideal as given by name in PolynomialRing(base_ring,vars,term_order)
    87        
    88         EXAMPLE:
    89             sage: sd = SymbolicData() # optional requires database_symbolic_data
    90             sage: sd.get_ideal('Katsura_3',GF(127),'degrevlex') # optional requires database_symbolic_data
    91             Ideal (u0 + 2*u1 + 2*u2 + 2*u3 - 1,
    92                    u1^2 + 2*u0*u2 + 2*u1*u3 - u2,
    93                    2*u0*u1 + 2*u1*u2 + 2*u2*u3 - u1,
     95
     96            ideal as given by ``name`` in ``PolynomialRing(base_ring,vars,term_order)``
     97
     98        EXAMPLES::
     99
     100            sage: sd = SymbolicData() # optional - database_symbolic_data
     101            sage: sd.get_ideal('Katsura_3',GF(127),'degrevlex') # optional - database_symbolic_data
     102            Ideal (u0 + 2*u1 + 2*u2 + 2*u3 - 1,
     103                   u1^2 + 2*u0*u2 + 2*u1*u3 - u2,
     104                   2*u0*u1 + 2*u1*u2 + 2*u2*u3 - u1,
    94105                   u0^2 + 2*u1^2 + 2*u2^2 + 2*u3^2 - u0) of Multivariate Polynomial Ring in u0, u1, u2, u3 over Finite Field of size 127
    95106        """
    96107
     
    116127
    117128            return l
    118129
     130        orig_name = name
    119131        name = name.replace('__','.')
    120132
    121133        try:
     
    126138                name = self.__genpath + name + ".xml"
    127139                open(name)
    128140            except IOError:
    129                 raise AttributeError, "Ideal not found on disk"
    130        
     141                raise AttributeError("No ideal matching '%s' found in database."%orig_name)
    131142
    132143        dom = parse(name)
    133144        res = _dom2ideal(dom)
    134         vars,polys = res[0].replace("_",""),[p.replace("_","") for p in res[1:]]
     145        variables, polys = res[0].replace("_",""), [p.replace("_","") for p in res[1:]]
    135146
    136         return PolynomialRing(base_ring, len(vars.split(",")), vars).ideal(polys)
    137    
     147        P = PolynomialRing(base_ring, len(variables.split(",")), variables)
     148        I = P.ideal([P(f) for f in polys])
     149        return I
     150
    138151
    139152    def __repr__(self):
    140153        """
    141         EXAMPLE:
    142             sage: sd = SymbolicData(); sd # optional requires database_symbolic_data
     154        EXAMPLES::
     155
     156            sage: sd = SymbolicData(); sd # optional - database_symbolic_data
    143157            SymbolicData with 372 ideals
    144158        """
    145159        try:
     
    150164
    151165    def __getattr__(self, name):
    152166        """
    153         EXAMPLE:
    154            sage: sd = SymbolicData() # optional requires database_symbolic_data
    155            sage: sd.Cyclic5 # optional requires database_symbolic_data
     167        EXAMPLES::
     168
     169           sage: sd = SymbolicData() # optional - database_symbolic_data
     170           sage: sd.Cyclic5 # optional - database_symbolic_data
    156171           Traceback (most recent call last):
    157172           ...
    158            AttributeError: Ideal not found on disk
     173           AttributeError: No ideal matching 'Cyclic5' found in database.
    159174
    160            sage: sd.Cyclic_5 # optional requires database_symbolic_data
    161            Ideal (v + w + x + y + z, 
    162                   v*w + w*x + x*y + v*z + y*z, 
    163                   v*w*x + w*x*y + v*w*z + v*y*z + x*y*z, 
    164                   v*w*x*y + v*w*x*z + v*w*y*z + v*x*y*z + w*x*y*z, 
     175           sage: sd.Cyclic_5 # optional - database_symbolic_data
     176           Ideal (v + w + x + y + z,
     177                  v*w + w*x + x*y + v*z + y*z,
     178                  v*w*x + w*x*y + v*w*z + v*y*z + x*y*z,
     179                  v*w*x*y + v*w*x*z + v*w*y*z + v*x*y*z + w*x*y*z,
    165180                  v*w*x*y*z - 1) of Multivariate Polynomial Ring in v, w, x, y, z over Rational Field
    166181        """
    167182        return self.get_ideal(name)
    168183
    169184    def trait_names(self):
    170185        """
    171         EXAMPLE:
    172             sage: sd = SymbolicData() # optional requires database_symbolic_data
    173             sage: sorted(sd.trait_names())[:10]# optional requires database_symbolic_data
     186        EXAMPLES::
     187
     188            sage: sd = SymbolicData() # optional - database_symbolic_data
     189            sage: sorted(sd.trait_names())[:10] # optional - database_symbolic_data
    174190            ['Bjoerk_8',
    175191             'Bronstein-86',
    176192             'Buchberger-87',