Ticket #7828: trac_7828-sign.patch

File trac_7828-sign.patch, 2.0 KB (added by kcrisman, 12 years ago)

Based on 4.4.2

  • sage/functions/all.py

    # HG changeset patch
    # User Karl-Dieter Crisman <kcrisman@gmail.com>
    # Date 1274901979 14400
    # Node ID b64640bfe4a0b07c17ab28c45d24ec4eb7ec55e1
    # Parent  27c18494b6cb25ffdad2749fbea6a09efc363916
    Trac 7828 - Make top-level sign function (which is same as sgn function)
    
    diff -r 27c18494b6cb -r b64640bfe4a0 sage/functions/all.py
    a b  
    6060from wigner import (wigner_3j, clebsch_gordan, racah, wigner_6j,
    6161                    wigner_9j, gaunt)
    6262
    63 from generalized import (dirac_delta, heaviside, unit_step, sgn,
     63from generalized import (dirac_delta, heaviside, unit_step, sgn, sign,
    6464                         kronecker_delta)
    6565
    6666from min_max import max_symbolic, min_symbolic
  • sage/functions/generalized.py

    diff -r 27c18494b6cb -r b64640bfe4a0 sage/functions/generalized.py
    a b  
    402402        sage: sgn(x)
    403403        sgn(x)
    404404
     405    We can also use ``sign``::
     406
     407        sage: sign(1)
     408        1
     409        sage: sign(0)
     410        0
     411        sage: a = AA(-5).nth_root(7)
     412        sage: sign(a)
     413        -1
     414
    405415    REFERENCES:
    406416 
    407417    -  http://en.wikipedia.org/wiki/Sign_function
     
    449459            0
    450460            sage: sgn(x).subs(x=-1)
    451461            -1
     462
     463        More tests::
     464
     465            sage: sign(RR(2))
     466            1
     467            sage: sign(RDF(2))
     468            1
     469            sage: sign(AA(-2))
     470            -1
     471            sage: sign(AA(0))
     472            0
    452473        """
     474        if hasattr(x,'sign'): # First check if x has a sign method
     475            return x.sign()
    453476        try:
    454477            approx_x = ComplexIntervalField()(x)
    455478            if bool(approx_x.imag() == 0):      # x is real
     
    477500        return 2*dirac_delta(x)
    478501
    479502sgn = FunctionSignum()
     503sign = sgn
    480504
    481505class FunctionKroneckerDelta(BuiltinFunction):
    482506    r"""