Changeset 7837:c10ef4622faf
- Timestamp:
- 12/22/07 08:45:22 (5 years ago)
- Branch:
- default
- File:
-
- 1 edited
-
sage/calculus/calculus.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/calculus/calculus.py
r7832 r7837 3553 3553 def number_of_arguments(self): 3554 3554 """ 3555 Returns the number of argu ements this object can take.3555 Returns the number of arguments this object can take. 3556 3556 3557 3557 EXAMPLES: … … 4849 4849 """ 4850 4850 SymbolicOperation.__init__(self, [f,g]) 4851 4852 def _polynomial_(self, R): 4853 """ 4854 Symbolic compositions cannot be converted to polynomials unless 4855 they are constants. 4856 4857 EXAMPLES: 4858 sage: sqrt(2).polynomial(RR) 4859 1.41421356237310 4860 4861 sage: sqrt(2).polynomial(CC) 4862 1.41421356237310 4863 4864 sage: cos(x).polynomial(QQ) 4865 Traceback (most recent call last): 4866 .... 4867 TypeError: cannot convert self (= cos(x)) to a polynomial 4868 4869 sage: sqrt(x).polynomial(QQ) 4870 Traceback (most recent call last): 4871 .... 4872 TypeError: cannot convert self (= sqrt(x)) to a polynomial 4873 4874 sage: K3.<a> = NumberField(sqrt(x)) 4875 Traceback (most recent call last): 4876 .... 4877 TypeError: polynomial (=sqrt(x)) must be a polynomial. 4878 """ 4879 if self.number_of_arguments() == 0: 4880 #Convert self into R's base ring and then into R since 4881 #self must be a constant. 4882 return R( R.base_ring()(self) ) 4883 else: 4884 raise TypeError, "cannot convert self (= %s) to a polynomial"%str(self).strip() 4885 4886 4887 def number_of_arguments(self): 4888 """ 4889 Returns the number of arguments that self can take. 4890 4891 EXAMPLES: 4892 sage: sqrt(x).number_of_arguments() 4893 1 4894 sage: sqrt(2).number_of_arguments() 4895 0 4896 """ 4897 try: 4898 return self.__number_of_args 4899 except AttributeError: 4900 pass 4901 variables = self.variables() 4902 if not self.is_simplified(): 4903 n = self.simplify().number_of_arguments() 4904 else: 4905 # Note that we use self._operands[1:] so we don't include the 4906 # number of arguments that the function takes since it is 4907 # already being "called" 4908 n = max( max(map(lambda i: i.number_of_arguments(), self._operands[1:])+[0]), len(variables) ) 4909 self.__number_of_args = n 4910 return n 4851 4911 4852 4912 def _recursive_sub(self, kwds):
Note: See TracChangeset
for help on using the changeset viewer.
