Changeset 7706:63bdacc97605


Ignore:
Timestamp:
12/06/07 02:53:18 (5 years ago)
Author:
Mike Hansen <mhansen@…>
Branch:
default
Message:

Fixed #533.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sage/calculus/calculus.py

    r7670 r7706  
    11221122        return ans 
    11231123 
     1124    def number_of_arguments(self): 
     1125        """ 
     1126        Returns the number of arguments the object can take. 
     1127 
     1128        EXAMPLES: 
     1129            sage: a,b,c = var('a,b,c') 
     1130            sage: foo = function('foo', a,b,c) 
     1131            sage: foo.number_of_arguments() 
     1132            3 
     1133        """ 
     1134        return len(self.variables()) 
     1135 
    11241136    def _has_op(self, operator): 
    11251137        """ 
     
    11881200            sage: f(x=3,y=4) 
    11891201            7 
     1202 
     1203            sage: a = (2^(8/9)) 
     1204            sage: a(4) 
     1205            Traceback (most recent call last): 
     1206            ... 
     1207            ValueError: the number of arguments must be less than or equal to 0 
     1208 
    11901209        """ 
    11911210        if len(args) == 0: 
     
    30173036        return sys_init(self._obj, system) 
    30183037 
     3038    def number_of_arguments(self): 
     3039        """ 
     3040        Returns the number of arguments this object can take. 
     3041 
     3042        EXAMPLES: 
     3043            sage: SR = SymbolicExpressionRing() 
     3044            sage: a = SR(e) 
     3045            sage: a.number_of_arguments() 
     3046            0 
     3047        """ 
     3048        return 0 
     3049 
    30193050def maxima_init(x): 
    30203051    try: 
     
    32683299        return SymbolicArithmetic([self, right], operator.pow) 
    32693300 
     3301 
    32703302class SymbolicPolynomial(Symbolic_object): 
    32713303    """ 
     
    33503382        return tuple(variables) 
    33513383 
     3384    def number_of_arguments(self): 
     3385        """ 
     3386        Returns the number of arguments this object can take.  For 
     3387        SymbolicPolynomials, this is just the number of variables 
     3388        of the polynomial. 
     3389         
     3390        EXAMPLES: 
     3391            sage: R.<x> = QQ[]; S.<y> = R[] 
     3392            sage: f = x+y*x+y^2 
     3393            sage: g = SR(f) 
     3394            sage: g.number_of_arguments() 
     3395            2 
     3396        """ 
     3397        return len(self.variables()) 
     3398 
    33523399    def polynomial(self, base_ring): 
    33533400        """ 
     
    34153462        self.__variables = vars 
    34163463        return vars 
     3464 
     3465    def number_of_arguments(self): 
     3466        """ 
     3467        Returns the number of arguements this object can take. 
     3468 
     3469        EXAMPLES: 
     3470            sage: x,y,z = var('x,y,z') 
     3471            sage: (x+y).number_of_arguments() 
     3472            2 
     3473            sage: (x+1).number_of_arguments() 
     3474            1 
     3475            sage: (sin+1).number_of_arguments() 
     3476            1 
     3477            sage: (sin+x).number_of_arguments() 
     3478            1 
     3479            sage: (sin+x+y).number_of_arguments() 
     3480            2 
     3481            sage: (sin(z)+x+y).number_of_arguments() 
     3482            3 
     3483            sage: (sin+cos).number_of_arguments() 
     3484            1 
     3485            sage: (sin(x+y)).number_of_arguments() 
     3486            2 
     3487             
     3488            sage: ( 2^(8/9) - 2^(1/9) )(x-1) 
     3489            Traceback (most recent call last): 
     3490            ... 
     3491            ValueError: the number of arguments must be less than or equal to 0 
     3492 
     3493        """ 
     3494        variables = self.variables() 
     3495 
     3496        #We need to do this maximum to correctly handle the case where 
     3497        #self is something like (sin+1) 
     3498        return max( max(map(lambda i: i.number_of_arguments(), self._operands)+[0]), len(variables) ) 
    34173499 
    34183500def var_cmp(x,y): 
     
    35263608            variables = list( self.variables() ) 
    35273609 
    3528             if len(args) > len(variables) and len(args) > 1: 
    3529                 raise ValueError, "the number of arguments must be less than or equal to %s"%len(variables) 
     3610            if len(args) > self.number_of_arguments(): 
     3611                raise ValueError, "the number of arguments must be less than or equal to %s"%self.number_of_arguments() 
    35303612             
    35313613            new_ops = [] 
     
    40544136        return (self, ) 
    40554137 
     4138    def number_of_arguments(self): 
     4139        """ 
     4140        Returns the number of arguments of self. 
     4141 
     4142        EXAMPLES: 
     4143            sage: x = var('x') 
     4144            sage: x.number_of_arguments() 
     4145            1 
     4146        """ 
     4147        return 1 
     4148 
    40564149    def __cmp__(self, right): 
    40574150        if isinstance(right, SymbolicVariable): 
     
    42804373    def arguments(self): 
    42814374        return self.args() 
     4375 
     4376    def number_of_arguments(self): 
     4377        """ 
     4378        Returns the number of arguments of self. 
     4379 
     4380        EXAMPLES: 
     4381            sage: a = var('a') 
     4382            sage: g(x) = sin(x) + a 
     4383            sage: g.number_of_arguments() 
     4384            1 
     4385            sage: g(x,y,z) = sin(x) - a + a 
     4386            sage: g.number_of_arguments() 
     4387            3 
     4388        """ 
     4389        return len(self.args()) 
    42824390 
    42834391    def _maxima_init_(self): 
     
    48564964        return complex(eval(a)) 
    48574965         
     4966    def number_of_arguments(self): 
     4967        """ 
     4968        Returns the number of arguments of self. 
     4969         
     4970        EXAMPLES: 
     4971            sage: sin.variables() 
     4972            () 
     4973            sage: sin.number_of_arguments() 
     4974            1 
     4975        """ 
     4976        return 1 
    48584977 
    48594978_syms = {} 
     
    59596078        self.__variables = vars 
    59606079        return vars 
     6080 
    59616081 
    59626082class SymbolicFunctionEvaluation_delayed(SymbolicFunctionEvaluation): 
Note: See TracChangeset for help on using the changeset viewer.