6
6
7
7
def add_vararg (first , * rest ):
8
8
r"""
9
- Addition of a variable number of arguments.
9
+ Return the sum of all the arguments.
10
10
11
11
INPUT:
12
12
13
- - ``first``, ``rest`` -- arguments to add
13
+ - ``first``, ``* rest`` -- arguments to add
14
14
15
- OUTPUT: sum of arguments
15
+ OUTPUT: sum of the arguments
16
16
17
17
EXAMPLES::
18
18
19
19
sage: from sage.symbolic.operators import add_vararg
20
- sage: add_vararg(1,2,3,4,5,6, 7)
20
+ sage: add_vararg(1, 2, 3, 4, 5, 6, 7)
21
21
28
22
- sage: F = (1+x+x^2)
23
- sage: bool(F.operator()(*F.operands()) == F)
22
+ sage: x = SR.var('x')
23
+ sage: s = 1 + x + x^2 # symbolic sum
24
+ sage: bool(s.operator()(*s.operands()) == s)
24
25
True
25
26
"""
26
27
for r in rest :
@@ -30,21 +31,22 @@ def add_vararg(first, *rest):
30
31
31
32
def mul_vararg (first , * rest ):
32
33
r"""
33
- Multiplication of a variable number of arguments.
34
+ Return the product of all the arguments.
34
35
35
36
INPUT:
36
37
37
- - ``args `` -- arguments to multiply
38
+ - ``first``, ``*rest `` -- arguments to multiply
38
39
39
- OUTPUT: product of arguments
40
+ OUTPUT: product of the arguments
40
41
41
42
EXAMPLES::
42
43
43
44
sage: from sage.symbolic.operators import mul_vararg
44
- sage: mul_vararg(9,8,7,6,5, 4)
45
+ sage: mul_vararg(9, 8, 7, 6, 5, 4)
45
46
60480
46
- sage: G = x*cos(x)*sin(x)
47
- sage: bool(G.operator()(*G.operands())==G)
47
+ sage: x = SR.var('x')
48
+ sage: p = x * cos(x) * sin(x) # symbolic product
49
+ sage: bool(p.operator()(*p.operands()) == p)
48
50
True
49
51
"""
50
52
for r in rest :
@@ -69,30 +71,44 @@ def mul_vararg(first, *rest):
69
71
operator .ge :'>=' }
70
72
71
73
class FDerivativeOperator ():
74
+ r"""
75
+ Function derivative operators.
76
+
77
+ A function derivative operator represents a partial derivative
78
+ of a function with respect to some variables.
79
+
80
+ The underlying data are the function, and the parameter set,
81
+ a list recording the indices of the variables with respect
82
+ to which the partial derivative is taken.
83
+ """
72
84
def __init__ (self , function , parameter_set ):
73
- """
85
+ r"""
86
+ Initialize this function derivative operator.
87
+
74
88
EXAMPLES::
75
89
76
90
sage: from sage.symbolic.operators import FDerivativeOperator
77
91
sage: f = function('foo')
78
- sage: op = FDerivativeOperator(f, [0,1])
92
+ sage: op = FDerivativeOperator(f, [0, 1])
79
93
sage: loads(dumps(op))
80
94
D[0, 1](foo)
81
95
"""
82
96
self ._f = function
83
97
self ._parameter_set = [int (_ ) for _ in parameter_set ]
84
98
85
99
def __call__ (self , * args ):
86
- """
100
+ r"""
101
+ Call this function derivative operator on these arguments.
102
+
87
103
EXAMPLES::
88
104
89
105
sage: from sage.symbolic.operators import FDerivativeOperator
90
- sage: x,y = var('x,y')
106
+ sage: x, y = SR. var('x, y')
91
107
sage: f = function('foo')
92
- sage: op = FDerivativeOperator(f, [0,1])
93
- sage: op(x,y)
108
+ sage: op = FDerivativeOperator(f, [0, 1])
109
+ sage: op(x, y)
94
110
diff(foo(x, y), x, y)
95
- sage: op(x,x^2)
111
+ sage: op(x, x^2)
96
112
D[0, 1](foo)(x, x^2)
97
113
98
114
TESTS:
@@ -115,56 +131,65 @@ def __call__(self, *args):
115
131
# temporary variable e.g. `t0` and then evaluate the
116
132
# derivative f'(t0) symbolically at t0=1. See trac
117
133
# #12796.
118
- temp_args = SR .temp_var (n = len (args ))
119
- vars = [temp_args [i ] for i in self ._parameter_set ]
134
+ temp_args = SR .temp_var (n = len (args ))
135
+ vars = [temp_args [i ] for i in self ._parameter_set ]
120
136
return self ._f (* temp_args ).diff (* vars ).function (* temp_args )(* args )
121
137
vars = [args [i ] for i in self ._parameter_set ]
122
138
return self ._f (* args ).diff (* vars )
123
139
124
140
def __repr__ (self ):
125
- """
141
+ r"""
142
+ Return the string representation of this function derivative operator.
143
+
126
144
EXAMPLES::
127
145
128
146
sage: from sage.symbolic.operators import FDerivativeOperator
129
147
sage: f = function('foo')
130
- sage: op = FDerivativeOperator(f, [0,1]); op
148
+ sage: op = FDerivativeOperator(f, [0, 1]); op
131
149
D[0, 1](foo)
132
150
"""
133
- return "D[%s](%s)" % (", " .join (map (repr , self ._parameter_set )), self ._f )
151
+ return "D[%s](%s)" % (", " .join (map (repr , self ._parameter_set )), self ._f )
134
152
135
153
def function (self ):
136
- """
154
+ r"""
155
+ Return the function associated to this function derivative operator.
156
+
137
157
EXAMPLES::
138
158
139
159
sage: from sage.symbolic.operators import FDerivativeOperator
140
160
sage: f = function('foo')
141
- sage: op = FDerivativeOperator(f, [0,1])
161
+ sage: op = FDerivativeOperator(f, [0, 1])
142
162
sage: op.function()
143
163
foo
144
164
"""
145
165
return self ._f
146
166
147
167
def change_function (self , new ):
148
- """
149
- Returns a new FDerivativeOperator with the same parameter set
150
- for a new function.
168
+ r """
169
+ Return a new function derivative operator with the same
170
+ parameter set but for a new function.
151
171
152
172
sage: from sage.symbolic.operators import FDerivativeOperator
153
173
sage: f = function('foo')
154
174
sage: b = function('bar')
155
- sage: op = FDerivativeOperator(f, [0,1])
175
+ sage: op = FDerivativeOperator(f, [0, 1])
156
176
sage: op.change_function(bar)
157
177
D[0, 1](bar)
158
178
"""
159
179
return FDerivativeOperator (new , self ._parameter_set )
160
180
161
181
def parameter_set (self ):
162
- """
182
+ r"""
183
+ Return the parameter set of this function derivative operator.
184
+
185
+ This is the list of indices of variables with respect to which
186
+ the derivative is taken.
187
+
163
188
EXAMPLES::
164
189
165
190
sage: from sage.symbolic.operators import FDerivativeOperator
166
191
sage: f = function('foo')
167
- sage: op = FDerivativeOperator(f, [0,1])
192
+ sage: op = FDerivativeOperator(f, [0, 1])
168
193
sage: op.parameter_set()
169
194
[0, 1]
170
195
"""
0 commit comments