Ticket #11751: 11751_free_module_generic_pid-fix.patch

File 11751_free_module_generic_pid-fix.patch, 3.0 KB (added by mderickx, 10 years ago)
  • sage/modules/free_module.py

    # HG changeset patch
    # User Maarten Derickx <m.derickx.student@gmail.com>
    # Date 1314392754 25200
    # Node ID dbd551af997fabb9a4f13efd29449bd23b81bc7f
    # Parent  d860cb782750ede05ba7cf036809e4de0973a023
    11751 make free_module_generic_pid also work for pid's other then integers
    
    diff --git a/sage/modules/free_module.py b/sage/modules/free_module.py
    a b  
    829829        if isinstance(x, (int, long, sage.rings.integer.Integer)) and x==0:
    830830            return self.zero_vector()
    831831        elif isinstance(x, free_module_element.FreeModuleElement):
    832             if x.parent() is self:
     832            if x.parent() == self:
    833833                if copy:
    834834                    return x.__copy__()
    835835                else:
     
    24972497            Traceback (most recent call last):
    24982498            ...
    24992499            ArithmeticError: Argument gens (= [(0, 1, 0)]) does not generate a submodule of self.
     2500            sage: V.span([[1,0,0],[1/5,4,0],[6,3/4,0]])
     2501            Free module of degree 3 and rank 2 over Integer Ring
     2502            Echelon basis matrix:
     2503            [1/5   0   0]
     2504            [  0 1/4   0]
     2505       
     2506
     2507        Show that it also works with other things than integers
     2508
     2509        ::
     2510
     2511            sage: R.<x>=QQ[]
     2512            sage: L=R^1
     2513            sage: a=L.span([(1/x,)])
     2514            sage: a
     2515            Free module of degree 1 and rank 1 over Univariate Polynomial Ring in x over Rational Field
     2516            Echelon basis matrix:
     2517            [1/x]
     2518            sage: b=L.span([(1/x,)])
     2519            sage: a(b.gens()[0])
     2520            (1/x)
     2521            sage: L2 = R^2
     2522            sage: L2.span([[(x^2+x)/(x^2-3*x+2),1/5],[(x^2+2*x)/(x^2-4*x+3),x]])
     2523            Free module of degree 2 and rank 2 over Univariate Polynomial Ring in x over Rational Field
     2524            Echelon basis matrix:
     2525            [x/(x^3 - 6*x^2 + 11*x - 6)  2/15*x^2 - 17/75*x - 1/75]
     2526            [                         0 x^3 - 11/5*x^2 - 3*x + 4/5]
     2527       
     2528        Note that the base_ring can make a huge difference. If we just want the answer to be the
     2529        sub vectorspace over the fraction field of R everything becomes a lot easier.
     2530       
     2531        ::
     2532
     2533            sage: L2.span([[(x^2+x)/(x^2-3*x+2),1/5],[(x^2+2*x)/(x^2-4*x+3),x]],base_ring=R.fraction_field())
     2534            Vector space of degree 2 and dimension 2 over Fraction Field of Univariate Polynomial Ring in x over Rational Field
     2535            Basis matrix:
     2536            [1 0]
     2537            [0 1]
     2538       
     2539
    25002540        """
    25012541        if is_FreeModule(gens):
    25022542            gens = gens.gens()
     
    50755115        """
    50765116        if len(B) == 0:
    50775117            return 1
    5078         d = sage.rings.integer.Integer((hasattr(B[0],'denominator') and B[0].denominator()) or 1)
     5118        d = B[0].denominator()
    50795119        for x in B[1:]:
    5080             d = d.lcm((hasattr(x,'denominator') and x.denominator()) or 1)
     5120            d = d.lcm(x.denominator())
    50815121        return d
    50825122   
    50835123    def _repr_(self):