Skip to content

Commit 7a1e709

Browse files
committed
Add test output
1 parent 2248ae9 commit 7a1e709

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/sage/modules/free_module_element.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4285,11 +4285,16 @@ cdef class FreeModuleElement(Vector): # abstract base class
42854285

42864286
sage: f(x, y, z) = (y, z, x)
42874287
sage: f.compositional_inverse()
4288+
(x, y, z) |--> (z, x, y)
42884289

42894290
TESTS::
42904291

42914292
sage: f.change_ring(SR)
4293+
(y, z, x)
42924294
sage: f.change_ring(SR).compositional_inverse()
4295+
Traceback (most recent call last):
4296+
...
4297+
ValueError: base ring must be a symbolic expression ring
42934298
"""
42944299
from sage.rings.abc import CallableSymbolicExpressionRing
42954300
if not isinstance(self.base_ring(), CallableSymbolicExpressionRing):

src/sage/symbolic/expression.pyx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13529,38 +13529,62 @@ cdef class Expression(Expression_abc):
1352913529
1353013530
sage: f(x) = x+1
1353113531
sage: f.compositional_inverse()
13532+
x |--> x - 1
1353213533
sage: var("y")
13534+
y
1353313535
sage: f(x) = x+y
1353413536
sage: f.compositional_inverse()
13537+
x |--> x - y
1353513538
sage: f(x) = x^2
1353613539
sage: f.compositional_inverse()
13540+
x |--> -sqrt(x)
1353713541
1353813542
When ``allow_inverse_multivalued=False``, there is some additional checking::
1353913543
1354013544
sage: f(x) = x^2
1354113545
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
1354213549
1354313550
Nonetheless, the checking is not always foolproof (``x |--> log(x) + 2*pi*I`` is another possibility)::
1354413551
1354513552
sage: f(x) = exp(x)
1354613553
sage: f.compositional_inverse(allow_inverse_multivalued=False)
13554+
x |--> log(x)
1354713555
1354813556
Sometimes passing ``kwargs`` is useful, for example ``algorithm`` can be used
1354913557
when the default solver fails::
1355013558
1355113559
sage: f(x) = (2/3)^x
1355213560
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))
1355413566
1355513567
TESTS::
1355613568
1355713569
sage: f(x) = x+exp(x)
1355813570
sage: f.compositional_inverse()
13571+
Traceback (most recent call last):
13572+
...
13573+
ValueError: cannot find an inverse
1355913574
sage: f(x) = 0
1356013575
sage: f.compositional_inverse()
13576+
Traceback (most recent call last):
13577+
...
13578+
ValueError: cannot find an inverse
1356113579
sage: f(x, y) = (x, x)
1356213580
sage: f.compositional_inverse()
13581+
Traceback (most recent call last):
13582+
...
13583+
ValueError: cannot find an inverse
1356313584
sage: (x+1).compositional_inverse()
13585+
Traceback (most recent call last):
13586+
...
13587+
ValueError: base ring must be a symbolic expression ring
1356413588
"""
1356513589
from sage.modules.free_module_element import vector
1356613590
return vector([self]).compositional_inverse(allow_inverse_multivalued=allow_inverse_multivalued, **kwargs)[0]

0 commit comments

Comments
 (0)