Ticket #3952: trac_3952.patch

File trac_3952.patch, 13.6 kB (added by mhansen, 4 months ago)
  • a/sage/calculus/calculus.py

    old new  
    38883888 
    38893889    def _fast_float_(self, *vars): 
    38903890        """ 
     3891        Returns an object which provides fast floating point evaluation of  
     3892        self. 
     3893 
     3894        See sage.ext.fast_eval? for more information. 
     3895 
    38913896        EXAMPLES:  
    38923897            sage: x,y,z = var('x,y,z') 
    38933898            sage: f = 1 + sin(x)/x + sqrt(z^2+y^2)/cosh(x) 
     
    40604065                    return True 
    40614066 
    40624067    def _fast_float_(self, *vars): 
     4068        """ 
     4069        Returns an object which provides fast floating point evaluation of  
     4070        self. 
     4071 
     4072        See sage.ext.fast_eval? for more information. 
     4073 
     4074        EXAMPLES: 
     4075            sage: f = SR(2)._fast_float_() 
     4076            sage: f(3) 
     4077            2.0 
     4078        """ 
    40634079        return fast_float.fast_float_constant(float(self)) 
    40644080 
    40654081    def _recursive_sub(self, kwds): 
     
    46734689 
    46744690    def _fast_float_(self, *vars): 
    46754691        """ 
     4692        Returns an object which provides fast floating point evaluation of  
     4693        self. 
     4694 
     4695        See sage.ext.fast_eval? for more information. 
     4696 
    46764697        EXAMPLES:  
    46774698            sage: x,y = var('x,y') 
    46784699            sage: f = x*x-y 
    46794700            sage: ff = f._fast_float_('x','y') 
    46804701            sage: ff(2,3) 
    46814702            1.0 
    4682         """ 
     4703 
     4704            sage: a = x + 2*y 
     4705            sage: f = a._fast_float_() 
     4706            sage: f(1,0) 
     4707            1.0 
     4708            sage: f(0,1) 
     4709            2.0 
     4710        """ 
     4711        if vars == (): 
     4712            vars = self.arguments() 
    46834713        fops = [op._fast_float_(*vars) for op in self._operands] 
    46844714        return self._operator(*fops) 
    46854715 
     
    51915221            2.0 
    51925222            sage: sqrt(2)._fast_float_()(2) 
    51935223            1.4142135623730951 
    5194         """ 
     5224 
     5225            sage: f = x._fast_float_() 
     5226            sage: f(1.2) 
     5227            1.2 
     5228        """ 
     5229        #if no var 
     5230        if vars == (): 
     5231            return fast_float.fast_float_arg(0) 
     5232 
    51955233        if self._name in vars: 
    51965234            return fast_float.fast_float_arg(list(vars).index(self._name)) 
    51975235        svars = [repr(x) for x in vars] 
    51985236        if self._name in svars: 
    51995237            return fast_float.fast_float_arg(list(svars).index(self._name)) 
     5238 
    52005239        try: 
    52015240            return fast_float.fast_float_constant(float(self)) 
    52025241        except TypeError: 
     
    55915630        return self._expr._maxima_init_() 
    55925631         
    55935632    def _fast_float_(self, *vars): 
     5633        """ 
     5634        EXAMPLES: 
     5635            sage: a = var('a') 
     5636            sage: g(x) = sin(x) + 2 
     5637            sage: f = g._fast_float_() 
     5638            sage: f(0) 
     5639            2.0 
     5640        """ 
     5641        if vars == (): 
     5642            vars = self.arguments() 
    55945643        return self._expr._fast_float_(*vars) 
    55955644 
    55965645    def __float__(self): 
     
    60386087        return float(f._approx_(float(g))) 
    60396088 
    60406089    def _fast_float_(self, *vars): 
     6090        """ 
     6091        Returns an object which provides fast floating point evaluation of  
     6092        self. 
     6093 
     6094        See sage.ext.fast_eval? for more information. 
     6095 
     6096        EXAMPLES: 
     6097            sage: f = sqrt(x)._fast_float_('x') 
     6098            sage: f(2) 
     6099            1.41421356237309... 
     6100            sage: y = var('y') 
     6101            sage: f = sqrt(x+y)._fast_float_('x', 'y') 
     6102            sage: f(1,1) 
     6103            1.41421356237309... 
     6104 
     6105            sage: f = sqrt(x+2*y)._fast_float_() 
     6106            sage: f(2,0) 
     6107            1.41421356237309... 
     6108            sage: f(0,1) 
     6109            1.41421356237309... 
     6110   
     6111        """ 
     6112        if vars == (): 
     6113            vars = self.arguments() 
     6114 
    60416115        f = self._operands[0] 
    60426116        g = self._operands[1]._fast_float_(*vars) 
    60436117        try: 
     
    65686642                return math.sin(x) 
    65696643        return SymbolicComposition(self, SR(x)) 
    65706644 
    6571     def _fast_float_(self): 
     6645    def _fast_float_(self, *vars): 
     6646        """ 
     6647        Returns an object which provides fast floating point evaluation of  
     6648        self. 
     6649 
     6650        See sage.ext.fast_eval? for more information. 
     6651 
     6652        EXAMPLES: 
     6653            sage: from sage.ext.fast_eval import fast_float 
     6654            sage: fast_float(sin) 
     6655            <built-in function sin> 
     6656            sage: sin._fast_float_() 
     6657            <built-in function sin> 
     6658 
     6659        """ 
    65726660        return math.sin 
    65736661 
    65746662sin = Function_sin() 
     
    65946682                return math.cos(x) 
    65956683        return SymbolicComposition(self, SR(x)) 
    65966684 
    6597     def _fast_float_(self): 
     6685    def _fast_float_(self, *vars): 
     6686        """ 
     6687        Returns an object which provides fast floating point evaluation of  
     6688        self. 
     6689 
     6690        See sage.ext.fast_eval? for more information. 
     6691 
     6692        EXAMPLES: 
     6693            sage: from sage.ext.fast_eval import fast_float 
     6694            sage: fast_float(cos) 
     6695            <built-in function cos> 
     6696            sage: cos._fast_float_() 
     6697            <built-in function cos> 
     6698 
     6699        """ 
    65986700        return math.cos 
    65996701 
    66006702    
  • a/sage/plot/animate.py

    old new  
    6161 
    6262    TESTS: 
    6363    This illustrates ticket \#2066 is fixed (setting axes ranges when an endpoint is 0): 
    64         sage: animate(plot(sin, -1,1), xmin=0, ymin=0)._Animation__xmin 
     64        sage: animate([plot(sin, -1,1)], xmin=0, ymin=0)._Animation__xmin 
    6565        0     
    6666    """ 
    6767    def __init__(self, v,  
  • a/sage/plot/plot.py

    old new  
    116116    sage: g.show(dpi=200, axes=False) 
    117117 
    118118Another graph: 
    119     sage: P = plot(lambda x: sin(x)/x, -4,4, rgbcolor=(0,0,1)) + \ 
    120     ...    plot(lambda x: x*cos(x), -4,4, rgbcolor=(1,0,0)) + \ 
    121     ...    plot(lambda x: tan(x),-4,4,rgbcolor=(0,1,0)) 
     119    sage: x = var('x') 
     120    sage: P = plot(sin(x)/x, -4,4, rgbcolor=(0,0,1)) + \ 
     121    ...       plot(x*cos(x), -4,4, rgbcolor=(1,0,0)) + \ 
     122    ...       plot(tan(x),-4,4,rgbcolor=(0,1,0)) 
    122123    ... 
    123124    sage: P.show(ymin=-pi,ymax=pi) 
    124125 
     
    148149    sage: g1 + g2    # show their sum 
    149150 
    150151An illustration of integration: 
    151     sage: f = lambda x: (x-3)*(x-5)*(x-7)+40 
     152    sage: f = (x-3)*(x-5)*(x-7)+40 
    152153    sage: P = line([(2,0),(2,f(2))], rgbcolor=(0,0,0)) 
    153154    sage: P += line([(8,0),(8,f(8))], rgbcolor=(0,0,0)) 
    154155    sage: P += polygon([(2,0),(2,f(2))] + [(x, f(x)) for x in [2,2.1,..,8]] + [(8,0),(2,0)],  rgbcolor=(0.8,0.8,0.8)) 
     
    12991300            ...     gridlinesstyle=dict(color="blue", linestyle=":")) 
    13001301 
    13011302        Change the style of the horizontal or vertical grid lines separately. 
    1302             sage: p = polar_plot(lambda x:2 + 2*cos(x), 0, 2*pi, rgbcolor=hue(0.3)) 
     1303            sage: p = polar_plot(2 + 2*cos(x), 0, 2*pi, rgbcolor=hue(0.3)) 
    13031304            sage: p.show(gridlines=True, \ 
    13041305            ...     hgridlinesstyle=dict(color="orange", linewidth=1.0), \ 
    13051306            ...     vgridlinesstyle=dict(color="blue", linestyle=":")) 
     
    13221323            ...    gridlinesstyle=dict(marker='x',rgbcolor="black")) 
    13231324 
    13241325        Grid lines can be added to contour plots. 
    1325             sage: f = lambda x,y: sin(x^2 + y^2)*cos(x)*sin(y) 
     1326            sage: f = sin(x^2 + y^2)*cos(x)*sin(y) 
    13261327            sage: c = contour_plot(f, (-4, 4), (-4, 4), plot_points=100) 
    13271328            sage: c.show(gridlines=True, gridlinesstyle={'linestyle':':','linewidth':1, 'rgbcolor':'red'}) 
    13281329 
     
    28482849    EXAMPLES: 
    28492850 
    28502851    Here we plot a simple function of two variables: 
    2851         sage: f = lambda x,y: cos(x^2 + y^2
    2852         sage: contour_plot(f, (-4, 4), (-4, 4)) 
     2852        sage: x,y = var('x,y'
     2853        sage: contour_plot(cos(x^2+y^2), (-4, 4), (-4, 4)) 
    28532854          
    28542855         
    28552856    Here we change the ranges and add some options: 
    2856         sage: h = lambda x,y: (x^2)*cos(x*y) 
    2857         sage: contour_plot(h, (-10, 5), (-5, 5), fill=False, plot_points=100) 
     2857        sage: contour_plot((x^2)*cos(x*y), (-10, 5), (-5, 5), fill=False, plot_points=100) 
    28582858         
    28592859 
    28602860    An even more complicated plot. 
    2861         sage: f = lambda x,y: sin(x^2 + y^2)*cos(x)*sin(y) 
    2862         sage: contour_plot(f, (-4, 4), (-4, 4),plot_points=100) 
     2861        sage: contour_plot(sin(x^2 + y^2)*cos(x)*sin(y), (-4, 4), (-4, 4),plot_points=100) 
    28632862 
    28642863    Some elliptic curves, but with symbolic endpoints.  In the first 
    28652864    example, the plot is rotated 90 degrees because we switch the 
    28662865    variables x,y.  
    2867         sage: x, y = var('x,y') 
    28682866        sage: contour_plot(y^2 + 1 - x^3 - x, (y,-pi,pi), (x,-pi,pi)) 
    2869         sage: contour_plot(lambda x,y: y^2 + 1 - x^3 - x, (y,-pi,pi), (x,-pi,pi)) 
    28702867        sage: contour_plot(y^2 + 1 - x^3 - x, (-pi,pi), (-pi,pi)) 
    28712868 
    28722869 
    28732870    We can play with the contour levels. 
    2874         sage: f = lambda x,y: x^2 + y^2 
     2871        sage: f = x^2 + y^2 
    28752872        sage: contour_plot(f, (-2, 2), (-2, 2)) 
    28762873        sage: contour_plot(f, (-2, 2), (-2, 2), contours=2) 
    28772874        sage: contour_plot(f, (-2, 2), (-2, 2), contours=(0.1, 1.0, 1.2, 1.4), cmap='hsv') 
     
    31573154 
    31583155 
    31593156    TESTS: 
    3160         sage: p = plot_vector_field((lambda x,y: .01*x,x+y), (10,20), (10,20)) 
     3157        sage: p = plot_vector_field((.01*x,x+y), (10,20), (10,20)) 
    31613158        sage: p.xmin() 
    31623159        10.0 
    31633160        sage: p.ymin() 
     
    34353432    We plot with randomize=False, which makes the initial sample  
    34363433    points evenly spaced (hence always the same).  Adaptive plotting  
    34373434    might insert other points, however, unless plot_division=0.  
    3438         sage: p=plot(lambda x: 1, (x,0,3), plot_points=4, randomize=False, plot_division=0) 
     3435        sage: p=plot(1, (x,0,3), plot_points=4, randomize=False, plot_division=0) 
    34393436        sage: list(p[0]) 
    34403437        [(0.0, 1.0), (1.0, 1.0), (2.0, 1.0), (3.0, 1.0)] 
    34413438 
     
    35453542 
    35463543    options.update(kwds) 
    35473544 
     3545    if not is_fast_float(funcs): 
     3546        funcs =  fast_float(funcs) 
     3547 
    35483548    #parametric_plot will be a list or tuple of two functions (f,g) 
    35493549    #and will plotted as (f(x), g(x)) for all x in the given range 
    35503550    if parametric: 
    3551         if len(funcs) == 3: 
    3552             raise ValueError, "use parametric_plot3d for parametric plots in 3d dimensions." 
    3553         elif len(funcs) == 2: 
    3554             # 2d 
    3555             f,g = funcs 
    3556         else: 
    3557             raise ValueError, "parametric plots only implemented in 2 and 3 dimensions." 
    3558  
     3551        f, g = funcs 
    35593552    #or we have only a single function to be plotted: 
    35603553    else: 
    35613554        f = funcs 
     
    37023695        tmax -- end value of t 
    37033696        other options -- passed to plot. 
    37043697 
    3705     EXAMPLE
    3706     We draw a 2d parametric plot
     3698    EXAMPLES
     3699    We draw some 2d parametric plots
    37073700        sage: t = var('t') 
    37083701        sage: parametric_plot( (sin(t), sin(2*t)), 0, 2*pi, rgbcolor=hue(0.6) ) 
     3702        sage: parametric_plot((1, t), 0, 4) 
     3703        sage: parametric_plot((t, t^2), -4, 4) 
    37093704 
    37103705    We draw a 3d parametric plot: 
    37113706        sage: parametric_plot3d( (5*cos(x), 5*sin(x), x), (-12, 12), plot_points=150, color="red") 
    3712     """ 
     3707 
     3708    TESTS: 
     3709        sage: parametric_plot((x, t^2), -4, 4) 
     3710        Traceback (most recent call last): 
     3711        ... 
     3712        ValueError: there cannot be more than one free variable in funcs 
     3713 
     3714        sage: parametric_plot((1, x+t), -4, 4) 
     3715        Traceback (most recent call last): 
     3716        ... 
     3717        ValueError: there cannot be more than one free variable in funcs 
     3718 
     3719    """ 
     3720    if len(funcs) == 3: 
     3721        raise ValueError, "use parametric_plot3d for parametric plots in 3d dimensions." 
     3722    elif len(funcs) != 2: 
     3723        raise ValueError, "parametric plots only implemented in 2 and 3 dimensions." 
     3724    else: 
     3725        vars = [] 
     3726        f,g = funcs 
     3727        if hasattr(f, 'variables'): 
     3728            vars += list(f.variables()) 
     3729        if hasattr(g, 'variables'): 
     3730            vars += list(g.variables()) 
     3731        vars = [str(v) for v in vars] 
     3732         
     3733        from sage.misc.misc import uniq 
     3734        if len(uniq(vars)) > 1: 
     3735            raise ValueError, "there cannot be more than one free variable in funcs" 
     3736                          
    37133737    return plot(funcs, tmin, tmax, parametric=True, **kwargs)             
    37143738 
    37153739def polar_plot(funcs, xmin, xmax, **kwargs): 
     
    37193743 
    37203744    EXAMPLES: 
    37213745    Here is a blue 8-leaved petal: 
    3722         sage: polar_plot(lambda x:sin(5*x)^2, 0, 2*pi, rgbcolor=hue(0.6)) 
     3746        sage: polar_plot(sin(5*x)^2, 0, 2*pi, rgbcolor=hue(0.6)) 
    37233747 
    37243748    A red figure-8: 
    3725         sage: polar_plot(lambda x:abs(sqrt(1 - sin(x)^2)), 0, 2*pi, rgbcolor=hue(1.0)) 
     3749        sage: polar_plot(abs(sqrt(1 - sin(x)^2)), 0, 2*pi, rgbcolor=hue(1.0)) 
    37263750 
    37273751    A green limacon of Pascal: 
    3728         sage: polar_plot(lambda x:2 + 2*cos(x), 0, 2*pi, rgbcolor=hue(0.3)) 
     3752        sage: polar_plot(2 + 2*cos(x), 0, 2*pi, rgbcolor=hue(0.3)) 
    37293753         
    37303754    """ 
    37313755    return plot(funcs, xmin, xmax, polar=True, **kwargs) 
  • a/sage/structure/sage_object.pyx

    old new  
    9191        if hasattr(self, '_repr_'): 
    9292            return self._repr_() 
    9393        return str(type(self)) 
    94  
    95     def plot(self, *args, **kwds): 
    96         import sage.plot.plot 
    97         if len(args) == 0 and len(kwds) == 0: 
    98             return sage.plot.plot.text(repr(self), (0,0)) 
    99         else: 
    100             try: 
    101                 return sage.plot.plot.text(repr(self), *args, **kwds) 
    102             except TypeError: 
    103                 return sage.plot.plot.text(repr(self), (0,0))                 
    10494 
    10595    def __hash__(self): 
    10696        return hash(self.__repr__())