Ticket #10246: trac_10246-callable-x.patch

File trac_10246-callable-x.patch, 2.0 KB (added by kcrisman, 11 years ago)

Based on 4.7.alpha1

  • sage/plot/plot.py

    # HG changeset patch
    # User Karl-Dieter Crisman <kcrisman@gmail.com>
    # Date 1300245098 14400
    # Node ID 8a1c0b64001620f77918b39fbc5792524c087bfa
    # Parent  66048f26316334c2e7199124a56092785ce87da0
    Trac 10246 - allow f(x)=x to plot.
    
    The callable symbolic expression x |-> x was a symbol, but did not work with fast_float because its repr was not just the variable.  This is now fixed.
    
    diff -r 66048f263163 -r 8a1c0b640016 sage/plot/plot.py
    a b  
    30113011        Traceback (most recent call last):
    30123012        ...
    30133013        RuntimeError: Error in line(): option 'foo' not valid.
     3014
     3015    We test that we can plot `f(x)=x` (see Trac 10246)::
     3016
     3017        sage: f(x)=x; f
     3018        x |--> x
     3019        sage: plot(f,(x,-1,1))
    30143020    """
    30153021    G_kwds = Graphics._extract_kwds_for_show(kwds, ignore=['xmin', 'xmax'])
    30163022
  • sage/symbolic/expression_conversions.py

    diff -r 66048f263163 -r 8a1c0b640016 sage/symbolic/expression_conversions.py
    a b  
    10521052            sage: f(1.2)
    10531053            1.2
    10541054
     1055        Using _fast_float_ on a function which is the identity is
     1056        now supported (see Trac 10246)::
     1057       
     1058            sage: f = symbolic_expression(x).function(x)
     1059            sage: f._fast_float_(x)
     1060            <sage.ext.fast_eval.FastDoubleFunc object at ...>
     1061            sage: f(22)
     1062            22
    10551063        """
    10561064        self.ex = ex
    10571065
     
    11261134        if name in svars:
    11271135            return self.ff.fast_float_arg(svars.index(name))
    11281136
     1137        if ex._is_symbol(): # case of callable function which is the variable, like f(x)=x
     1138            name = repr(SR(ex)) # this gets back just the 'output' of the function
     1139            if name in svars:
     1140                return self.ff.fast_float_arg(svars.index(name))
     1141
    11291142        try:
    11301143            return self.ff.fast_float_constant(float(ex))
    11311144        except TypeError: