Changeset 7706:63bdacc97605
- Timestamp:
- 12/06/07 02:53:18 (5 years ago)
- Branch:
- default
- File:
-
- 1 edited
-
sage/calculus/calculus.py (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/calculus/calculus.py
r7670 r7706 1122 1122 return ans 1123 1123 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 1124 1136 def _has_op(self, operator): 1125 1137 """ … … 1188 1200 sage: f(x=3,y=4) 1189 1201 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 1190 1209 """ 1191 1210 if len(args) == 0: … … 3017 3036 return sys_init(self._obj, system) 3018 3037 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 3019 3050 def maxima_init(x): 3020 3051 try: … … 3268 3299 return SymbolicArithmetic([self, right], operator.pow) 3269 3300 3301 3270 3302 class SymbolicPolynomial(Symbolic_object): 3271 3303 """ … … 3350 3382 return tuple(variables) 3351 3383 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 3352 3399 def polynomial(self, base_ring): 3353 3400 """ … … 3415 3462 self.__variables = vars 3416 3463 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) ) 3417 3499 3418 3500 def var_cmp(x,y): … … 3526 3608 variables = list( self.variables() ) 3527 3609 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() 3530 3612 3531 3613 new_ops = [] … … 4054 4136 return (self, ) 4055 4137 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 4056 4149 def __cmp__(self, right): 4057 4150 if isinstance(right, SymbolicVariable): … … 4280 4373 def arguments(self): 4281 4374 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()) 4282 4390 4283 4391 def _maxima_init_(self): … … 4856 4964 return complex(eval(a)) 4857 4965 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 4858 4977 4859 4978 _syms = {} … … 5959 6078 self.__variables = vars 5960 6079 return vars 6080 5961 6081 5962 6082 class SymbolicFunctionEvaluation_delayed(SymbolicFunctionEvaluation):
Note: See TracChangeset
for help on using the changeset viewer.
