@@ -13441,77 +13441,6 @@ cdef class Expression(Expression_abc):
13441
13441
raise TypeError (" this expression must be a relation" )
13442
13442
return self / x
13443
13443
13444
- def implicit_derivative (self , Y , X , n = 1 ):
13445
- """
13446
- Return the `n`-th derivative of `Y` with respect to `X` given
13447
- implicitly by this expression.
13448
-
13449
- INPUT:
13450
-
13451
- - ``Y`` -- the dependent variable of the implicit expression
13452
-
13453
- - ``X`` -- the independent variable with respect to which the
13454
- derivative is taken
13455
-
13456
- - ``n`` -- (default: 1) the order of the derivative
13457
-
13458
- EXAMPLES::
13459
-
13460
- sage: var('x, y')
13461
- (x, y)
13462
- sage: f = cos(x)*sin(y)
13463
- sage: f.implicit_derivative(y, x)
13464
- sin(x)*sin(y)/(cos(x)*cos(y))
13465
- sage: g = x*y^2
13466
- sage: g.implicit_derivative(y, x, 3)
13467
- -1/4*(y + 2*y/x)/x^2 + 1/4*(2*y^2/x - y^2/x^2)/(x*y) - 3/4*y/x^3
13468
-
13469
- It is an error to not include an independent variable term
13470
- in the expression::
13471
-
13472
- sage: (cos(x)*sin(x)).implicit_derivative(y, x)
13473
- Traceback (most recent call last):
13474
- ...
13475
- ValueError: Expression cos(x)*sin(x) contains no y terms
13476
-
13477
-
13478
- TESTS:
13479
-
13480
- Check that the symbols registry is not polluted::
13481
-
13482
- sage: var('x,y')
13483
- (x, y)
13484
- sage: psr = copy(SR.symbols)
13485
- sage: (x^6*y^5).implicit_derivative(y, x, 3)
13486
- -792/125*y/x^3 + 12/25*(15*x^4*y^5 + 28*x^3*y^5)/(x^6*y^4) - 36/125*(20*x^5*y^4 + 43*x^4*y^4)/(x^7*y^3)
13487
- sage: psr == SR.symbols
13488
- True
13489
- """
13490
- from sage.symbolic.ring import SR
13491
- from sage.symbolic.function import SymbolicFunction
13492
-
13493
- if not self .has(Y):
13494
- raise ValueError (" Expression {} contains no {} terms" .format(self , Y))
13495
- with SR.temp_var() as x:
13496
- with SR.temp_var() as yy:
13497
- y = SymbolicFunction(' y' , 1 )(x)
13498
- f = SymbolicFunction(' f' , 2 )(x, yy)
13499
- Fx = f.diff(x)
13500
- Fy = f.diff(yy)
13501
- G = - (Fx/ Fy)
13502
- G = G.subs({yy: y})
13503
- di = {y.diff(x): - self .diff(X)/ self .diff(Y)}
13504
- R = G
13505
- S = G.diff(x, n - 1 )
13506
- for i in range (n + 1 ):
13507
- di[y.diff(x, i + 1 ).subs({x: x})] = R
13508
- S = S.subs(di)
13509
- R = G.diff(x, i)
13510
- for j in range (n + 1 - i):
13511
- di[f.diff(x, i, yy, j).subs({x: x, yy: y})] = self .diff(X, i, Y, j)
13512
- S = S.subs(di)
13513
- return S
13514
-
13515
13444
def compositional_inverse (self , allow_inverse_multivalued = True , **kwargs ):
13516
13445
"""
13517
13446
Find the compositional inverse of this symbolic function.
@@ -13589,6 +13518,77 @@ cdef class Expression(Expression_abc):
13589
13518
from sage.modules.free_module_element import vector
13590
13519
return vector([self ]).compositional_inverse(allow_inverse_multivalued = allow_inverse_multivalued, ** kwargs)[0 ]
13591
13520
13521
+ def implicit_derivative (self , Y , X , n = 1 ):
13522
+ """
13523
+ Return the `n`-th derivative of `Y` with respect to `X` given
13524
+ implicitly by this expression.
13525
+
13526
+ INPUT:
13527
+
13528
+ - ``Y`` -- the dependent variable of the implicit expression
13529
+
13530
+ - ``X`` -- the independent variable with respect to which the
13531
+ derivative is taken
13532
+
13533
+ - ``n`` -- (default: 1) the order of the derivative
13534
+
13535
+ EXAMPLES::
13536
+
13537
+ sage: var('x, y')
13538
+ (x, y)
13539
+ sage: f = cos(x)*sin(y)
13540
+ sage: f.implicit_derivative(y, x)
13541
+ sin(x)*sin(y)/(cos(x)*cos(y))
13542
+ sage: g = x*y^2
13543
+ sage: g.implicit_derivative(y, x, 3)
13544
+ -1/4*(y + 2*y/x)/x^2 + 1/4*(2*y^2/x - y^2/x^2)/(x*y) - 3/4*y/x^3
13545
+
13546
+ It is an error to not include an independent variable term
13547
+ in the expression::
13548
+
13549
+ sage: (cos(x)*sin(x)).implicit_derivative(y, x)
13550
+ Traceback (most recent call last):
13551
+ ...
13552
+ ValueError: Expression cos(x)*sin(x) contains no y terms
13553
+
13554
+
13555
+ TESTS:
13556
+
13557
+ Check that the symbols registry is not polluted::
13558
+
13559
+ sage: var('x,y')
13560
+ (x, y)
13561
+ sage: psr = copy(SR.symbols)
13562
+ sage: (x^6*y^5).implicit_derivative(y, x, 3)
13563
+ -792/125*y/x^3 + 12/25*(15*x^4*y^5 + 28*x^3*y^5)/(x^6*y^4) - 36/125*(20*x^5*y^4 + 43*x^4*y^4)/(x^7*y^3)
13564
+ sage: psr == SR.symbols
13565
+ True
13566
+ """
13567
+ from sage.symbolic.ring import SR
13568
+ from sage.symbolic.function import SymbolicFunction
13569
+
13570
+ if not self .has(Y):
13571
+ raise ValueError (" Expression {} contains no {} terms" .format(self , Y))
13572
+ with SR.temp_var() as x:
13573
+ with SR.temp_var() as yy:
13574
+ y = SymbolicFunction(' y' , 1 )(x)
13575
+ f = SymbolicFunction(' f' , 2 )(x, yy)
13576
+ Fx = f.diff(x)
13577
+ Fy = f.diff(yy)
13578
+ G = - (Fx/ Fy)
13579
+ G = G.subs({yy: y})
13580
+ di = {y.diff(x): - self .diff(X)/ self .diff(Y)}
13581
+ R = G
13582
+ S = G.diff(x, n - 1 )
13583
+ for i in range (n + 1 ):
13584
+ di[y.diff(x, i + 1 ).subs({x: x})] = R
13585
+ S = S.subs(di)
13586
+ R = G.diff(x, i)
13587
+ for j in range (n + 1 - i):
13588
+ di[f.diff(x, i, yy, j).subs({x: x, yy: y})] = self .diff(X, i, Y, j)
13589
+ S = S.subs(di)
13590
+ return S
13591
+
13592
13592
13593
13593
cpdef _repr_Expression(x):
13594
13594
r """
0 commit comments