New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only invert an action if it's invertible #22573
Comments
Replying to @jdemeyer:
When I see this correctly, this is does not cause the problem. There is an action of an integer (from I am not sure what the correct solution would be. In some sense, the correct discovered action should be |
Author: Jeroen Demeyer |
comment:4
Replying to @dkrenn:
Yes, maybe you are right. The problem is that not all places calling |
New commits:
|
Commit: |
Reviewer: Julian Rüth |
comment:8
Looks good, assuming that the patchbots are happy. |
comment:9
Replying to @jdemeyer:
I think it is quite safe to replace the |
comment:10
Replying to @jdemeyer:
I am not convinced that this is a good solution. Overall, the coercion model correctly determines the way to deal with the situation in general, but in our particular example, there simply is no such action implemented. Deleting the code above prevents finding such an action at all, which is also not good. |
comment:11
Replying to @dkrenn:
Maybe something along the lines of
could do it, but I am not sure, if it is intended to call |
comment:12
Replying to @dkrenn:
I don't agree with this. The code is assuming that, if there is an action of ZZ on X, there is also an action of QQ on X. There is no reason at all in general why that should be the case. Instead, it should start from an action of QQ on X and then invert that (which is what the already-existing code in the coercion model does). |
comment:14
Replying to @jdemeyer:
This was formulated too unprecise of me, sorry. What I meant is, that the coercion model is at the moment able to discover an action, if it exists (but maybe discovers one that does not exist as no implentation or math-sense). By your changes, you eliminate the discovering of this situation at all (also if there would be an action of |
comment:15
Replying to @dkrenn:
Of course I do, because it is the right thing to do. If I want an action of QQ on X, there is no point in looking for an action of ZZ on X. Because even if an action of ZZ on X exists, it does not imply that there is an action of QQ on X. Note that the code in the coercion model already looks for an action from the fraction field: if op is div:
# Division on right is the same acting on right by inverse, if it is so defined.
right_mul = None
try:
right_mul = self.get_action(R, S, mul)
except NotImplementedError:
self._record_exception()
if right_mul is not None and not right_mul.is_left():
try:
action = ~right_mul
if action.right_domain() != S:
action = PrecomposedAction(action, None,
action.right_domain()._internal_coerce_map_from(S))
return action
except TypeError: # action may not be invertible
self._record_exception()
# It's possible an action is defined on the fraction field itself.
try:
K = S._pseudo_fraction_field()
except AttributeError:
pass
else:
if K is not S:
try:
right_mul = self.get_action(R, K, mul)
except NotImplementedError:
self._record_exception()
if right_mul is not None and not right_mul.is_left():
try:
return PrecomposedAction(~right_mul, None, K.coerce_map_from(S))
except TypeError: # action may not be invertible
self._record_exception() |
Changed reviewer from Julian Rüth to Julian Rüth, Daniel Krenn |
comment:16
Replying to @jdemeyer:
Ok, I see. Sorry for the noise. Patch is good then. (modulo patchbot; I'd be happy to put it (back) to positive review once the patchbot agrees). |
Changed keywords from none to days85 |
Changed branch from u/jdemeyer/_act_on____should_not_return_none_by_default to |
This should be an error:
I traced this to
which uses the default implementation of
_act_on_
fromsrc/sage/structure/element.pyx
:CC: @pelegm
Component: coercion
Keywords: days85
Author: Jeroen Demeyer
Branch/Commit:
e18c726
Reviewer: Julian Rüth, Daniel Krenn
Issue created by migration from https://trac.sagemath.org/ticket/22573
The text was updated successfully, but these errors were encountered: