Ticket #9652: smallfix1-arith_valuation.patch

File smallfix1-arith_valuation.patch, 1.4 KB (added by mderickx, 11 years ago)
  • sage/rings/arith.py

    # HG changeset patch
    # User Maarten Derickx <m.derickx.student@gmail.com>
    # Date 1280775385 -7200
    # Node ID b9a43c0caad2f17a3e47b6404eda1a9e4e5a182d
    # Parent  8dec8b43ccca5f104b1e280cb33c8f4c2c1b8f85
    This if statement will always return false since fraction fields have an atribute valuation. Might the statement magically return true cause of some buggy other code. Then this will return a buggy restult since the argument p is not passed to the numerator and denominator.
    
    diff -r 8dec8b43ccca -r b9a43c0caad2 sage/rings/arith.py
    a b  
    554554    """
    555555    return ZZ(n).is_prime_power(flag=flag)
    556556
    557 def valuation(m, p):
     557def valuation(m, p,*args1, **args2):
    558558    """
    559559    The exact power of p that divides m.
    560560   
     
    596596        sage: valuation(243*10007,10007)
    597597        1
    598598    """
    599     if hasattr(m, 'valuation'):
    600         return m.valuation(p)
    601     if m == 0:
    602         import sage.rings.all
    603         return sage.rings.all.infinity
    604     if is_FractionFieldElement(m):
    605         return valuation(m.numerator()) - valuation(m.denominator())
    606     r = 0
    607     power = p
    608     while not (m % power): # m % power == 0
    609         r += 1
    610         power *= p
    611     return r
     599    if isinstance(m,(int,long)):
     600        m=Integer(m)
     601    return m.valuation(p,*args1, **args2)
    612602
    613603def prime_powers(start, stop=None):
    614604    r"""