@@ -61,11 +61,14 @@ def __new__(cls):
61
61
###############################################################################
62
62
63
63
64
- def sqrt (arg ):
64
+ def sqrt (arg , evaluate = None ):
65
65
"""The square root function
66
66
67
67
sqrt(x) -> Returns the principal square root of x.
68
68
69
+ The parameter evaluate determines if the expression should be evaluated.
70
+ If None, its value is taken from global_evaluate
71
+
69
72
Examples
70
73
========
71
74
@@ -126,13 +129,16 @@ def sqrt(arg):
126
129
.. [2] http://en.wikipedia.org/wiki/Principal_value
127
130
"""
128
131
# arg = sympify(arg) is handled by Pow
129
- return Pow (arg , S .Half )
132
+ return Pow (arg , S .Half , evaluate = evaluate )
130
133
131
134
132
- def cbrt (arg ):
135
+ def cbrt (arg , evaluate = None ):
133
136
"""This function computes the principal cube root of `arg`, so
134
137
it's just a shortcut for `arg**Rational(1, 3)`.
135
138
139
+ The parameter evaluate determines if the expression should be evaluated.
140
+ If None, its value is taken from global_evaluate.
141
+
136
142
Examples
137
143
========
138
144
@@ -176,13 +182,15 @@ def cbrt(arg):
176
182
* http://en.wikipedia.org/wiki/Principal_value
177
183
178
184
"""
179
- return Pow (arg , Rational (1 , 3 ))
185
+ return Pow (arg , Rational (1 , 3 ), evaluate = evaluate )
180
186
181
187
182
- def root (arg , n , k = 0 ):
188
+ def root (arg , n , k = 0 , evaluate = None ):
183
189
"""root(x, n, k) -> Returns the k-th n-th root of x, defaulting to the
184
190
principal root (k=0).
185
191
192
+ The parameter evaluate determines if the expression should be evaluated.
193
+ If None, its value is taken from global_evaluate.
186
194
187
195
Examples
188
196
========
@@ -265,16 +273,19 @@ def root(arg, n, k=0):
265
273
"""
266
274
n = sympify (n )
267
275
if k :
268
- return Pow (arg , S .One / n ) * S .NegativeOne ** (2 * k / n )
269
- return Pow (arg , 1 / n )
276
+ return Mul ( Pow (arg , S .One / n , evaluate = evaluate ), S .NegativeOne ** (2 * k / n ), evaluate = evaluate )
277
+ return Pow (arg , 1 / n , evaluate = evaluate )
270
278
271
279
272
- def real_root (arg , n = None ):
280
+ def real_root (arg , n = None , evaluate = None ):
273
281
"""Return the real nth-root of arg if possible. If n is omitted then
274
282
all instances of (-n)**(1/odd) will be changed to -n**(1/odd); this
275
283
will only create a real root of a principal root -- the presence of
276
284
other factors may cause the result to not be real.
277
285
286
+ The parameter evaluate determines if the expression should be evaluated.
287
+ If None, its value is taken from global_evaluate.
288
+
278
289
Examples
279
290
========
280
291
@@ -308,10 +319,10 @@ def real_root(arg, n=None):
308
319
from sympy .functions .elementary .piecewise import Piecewise
309
320
if n is not None :
310
321
return Piecewise (
311
- (root (arg , n ), Or (Eq (n , S .One ), Eq (n , S .NegativeOne ))),
312
- (sign (arg )* root (Abs (arg ), n ), And ( Eq ( im ( arg ), S . Zero ),
313
- Eq (Mod (n , 2 ), S .One ))),
314
- (root (arg , n ), True ))
322
+ (root (arg , n , evaluate = evaluate ), Or (Eq (n , S .One ), Eq (n , S .NegativeOne ))),
323
+ (Mul ( sign (arg ), root (Abs (arg ), n , evaluate = evaluate ), evaluate = evaluate ),
324
+ And ( Eq ( im ( arg ), S . Zero ), Eq (Mod (n , 2 ), S .One ))),
325
+ (root (arg , n , evaluate = evaluate ), True ))
315
326
rv = sympify (arg )
316
327
n1pow = Transform (lambda x : - (- x .base )** x .exp ,
317
328
lambda x :
0 commit comments