@@ -13529,38 +13529,62 @@ cdef class Expression(Expression_abc):
13529
13529
13530
13530
sage: f(x) = x+1
13531
13531
sage: f.compositional_inverse()
13532
+ x |--> x - 1
13532
13533
sage: var("y")
13534
+ y
13533
13535
sage: f(x) = x+y
13534
13536
sage: f.compositional_inverse()
13537
+ x |--> x - y
13535
13538
sage: f(x) = x^2
13536
13539
sage: f.compositional_inverse()
13540
+ x |--> -sqrt(x)
13537
13541
13538
13542
When ``allow_inverse_multivalued=False``, there is some additional checking::
13539
13543
13540
13544
sage: f(x) = x^2
13541
13545
sage: f.compositional_inverse(allow_inverse_multivalued=False)
13546
+ Traceback (most recent call last):
13547
+ ...
13548
+ ValueError: inverse is multivalued, pass allow_inverse_multivalued=True to bypass
13542
13549
13543
13550
Nonetheless, the checking is not always foolproof (``x |--> log(x) + 2*pi*I`` is another possibility)::
13544
13551
13545
13552
sage: f(x) = exp(x)
13546
13553
sage: f.compositional_inverse(allow_inverse_multivalued=False)
13554
+ x |--> log(x)
13547
13555
13548
13556
Sometimes passing ``kwargs`` is useful, for example ``algorithm`` can be used
13549
13557
when the default solver fails::
13550
13558
13551
13559
sage: f(x) = (2/3)^x
13552
13560
sage: f.compositional_inverse()
13553
- sage: f.compositional_inverse(algorithm="giac") # needs sage.libs.giac
13561
+ Traceback (most recent call last):
13562
+ ...
13563
+ KeyError: x
13564
+ sage: f.compositional_inverse(algorithm="giac") # needs sage.libs.giac
13565
+ x |--> -log(x)/(log(3) - log(2))
13554
13566
13555
13567
TESTS::
13556
13568
13557
13569
sage: f(x) = x+exp(x)
13558
13570
sage: f.compositional_inverse()
13571
+ Traceback (most recent call last):
13572
+ ...
13573
+ ValueError: cannot find an inverse
13559
13574
sage: f(x) = 0
13560
13575
sage: f.compositional_inverse()
13576
+ Traceback (most recent call last):
13577
+ ...
13578
+ ValueError: cannot find an inverse
13561
13579
sage: f(x, y) = (x, x)
13562
13580
sage: f.compositional_inverse()
13581
+ Traceback (most recent call last):
13582
+ ...
13583
+ ValueError: cannot find an inverse
13563
13584
sage: (x+1).compositional_inverse()
13585
+ Traceback (most recent call last):
13586
+ ...
13587
+ ValueError: base ring must be a symbolic expression ring
13564
13588
"""
13565
13589
from sage.modules.free_module_element import vector
13566
13590
return vector([self ]).compositional_inverse(allow_inverse_multivalued = allow_inverse_multivalued, ** kwargs)[0 ]
0 commit comments