Ticket #7492: trac_7492_review.patch

File trac_7492_review.patch, 3.0 KB (added by davidloeffler, 11 years ago)

apply over previous patch

  • sage/combinat/permutation.py

    # HG changeset patch
    # User David Loeffler <d.loeffler.01@cantab.net>
    # Date 1274190776 -3600
    # Node ID e6f6fcb4f0acd42adcd2590484fa177dce3e70b2
    # Parent  221804dc9284b171fcdfb1b1ee03a860772dfe8c
    [mq]: trac_7492_review.patch
    
    diff -r 221804dc9284 -r e6f6fcb4f0ac sage/combinat/permutation.py
    a b  
    35633563    Returns the positive sum of permutations corresponding to
    35643564    the bistochastic matrix.
    35653565
    3566     A stochastic matrix is a matrix such that the sum of the elements
    3567     of any row is equal to 1. A bistochastic matrix is a stochastic matrix
    3568     whose transpose matrix is also stochastic ( there are conditions
    3569     both on the rows and on the columns ).
     3566    A stochastic matrix is a matrix with nonnegative real entries such that the
     3567    sum of the elements of any row is equal to 1. A bistochastic matrix is a
     3568    stochastic matrix whose transpose matrix is also stochastic ( there are
     3569    conditions both on the rows and on the columns ).
    35703570
    35713571    According to the Birkhoff-von Neumann Theorem, any bistochastic matrix
    35723572    can be written as a positive sum of permutation matrices, which also
     
    35823582
    35833583    - ``M`` -- A bistochastic matrix
    35843584
    3585     - ``check`` (boolean) -- set to ``True`` (default) to checl
     3585    - ``check`` (boolean) -- set to ``True`` (default) to check
    35863586      that the matrix is indeed bistochastic
    35873587
    35883588    OUTPUT:
     
    36283628        sage: print decomp
    36293629        2*B[[1, 4, 2, 3, 5]] + 3*B[[3, 1, 4, 2, 5]] + 9*B[[4, 1, 3, 5, 2]] + 6*B[[5, 3, 4, 1, 2]]
    36303630
    3631     An exception is raised when the matrix is not bistochastic::
     3631    An exception is raised when the matrix is not positive and bistochastic::
    36323632
    36333633        sage: M = Matrix([[2,3],[2,2]])
    36343634        sage: decomp = bistochastic_as_sum_of_permutations(M)
    36353635        Traceback (most recent call last):
    36363636        ...
    36373637        ValueError: The matrix is not bistochastic
     3638
     3639        sage: bistochastic_as_sum_of_permutations(Matrix(GF(7), 2, [2,1,1,2]))
     3640        Traceback (most recent call last):
     3641        ...
     3642        ValueError: The base ring of the matrix must have a coercion map to RR
     3643
     3644        sage: bistochastic_as_sum_of_permutations(Matrix(ZZ, 2, [2,-1,-1,2]))
     3645        Traceback (most recent call last):
     3646        ...
     3647        ValueError: The matrix should have nonnegative entries
    36383648    """
    36393649
    36403650    from sage.graphs.bipartite_graph import BipartiteGraph
    36413651    from sage.combinat.free_module import CombinatorialFreeModule
    3642     from sage.rings.real_mpfr import RR
     3652    from sage.rings.all import RR
    36433653
    36443654    n=M.nrows()
    36453655
     
    36523662    if not RR.has_coerce_map_from(M.base_ring()):
    36533663        raise ValueError("The base ring of the matrix must have a coercion map to RR")
    36543664
     3665    if not all([x >= 0 for x in M.list()]):
     3666        raise ValueError, "The matrix should have nonnegative entries"
     3667
    36553668    CFM=CombinatorialFreeModule(M.base_ring(),Permutations(n))
    36563669    value=0
    36573670