Am 18.06.2020 um 19:47 schrieb Nils Bruin <nbr...@sfu.ca>: > > On Thursday, June 18, 2020 at 5:00:00 AM UTC-7, kcrisman wrote: > > I assume that would need a pretty major change in the preparser? Does other > mathematical software use this as a convention? (Just asking, no > presuppositions here.) > > No, not the preparser. It would affect the coercion framework quite a bit, > though. It would mean that __lshift__ and __rshift__ need to be hooked into > left actions and right actions. Using ">>" and "<<" for actions has the large > advantage that the methods are for the most part available. The coercion > framework can already discover left and right multiplicative actions (used > for scalar multiplication and matrix actions on modules), so I'd expect it > can be made to discover "shift" actions by specifying the relevant operator.
Indeed, this would not require changes to the preparser, as these are standard Python operators. I assume that we could implement the shift methods on SageObject (possibly with some special care for Integers that implement the bitwise shifts), which would then redirect to the appropriate discovery of the correct action that is already implemented. Cython actually helps us here because, instead of calling x.__lshift__(y), it automatically calls something like type(y).__lshift__(x, y) if __lshift__ is not implemented on x. This is useful if x is not a Sage type, but a Python type such as list or int, on which a permutation might act from the right. As for other mathematical software, I do not know any that uses >> and << for group actions. However, I think it is rather common to use operators that are the same but flipped for operations that have a right- and left-minded variant. In Python, only the shift operators can be used for that, unless we extend the preparser. The best example I can think of is that of the Monad bind operation >>= and Kleisli composition >=> in Haskell, which has also been adopted by several libraries in other languages. For a monad element m and Kleisli functions f and g, the following are the same (m >>= f) >>= g m >>= (f >=> g) so this can be thought of as a right action. Similarly, the flipped operators exist: f =<< (g =<< m) (f <=< g) =<< m Another common example of same-but-flipped operators is <<< and >>> for composition of arrows in a category/semigroupoid. Other examples include Matlab's / and \ operators for matrix division, and the / and \ operator in Macaulay2 for mapping a function over a list. For example, the following are the same in Macaulay2 (1,2,3) / sqrt / sin sin \ sqrt \ (1,2,3) sin @@ sqrt \ (1,2,3) so this is a left action. If one views permutations as bijective functions of {1,..,n}, the left action of permutations is a special case of this. Admittedly, these operators do not look like mathematical notation, but they can still be useful for programming. In all the associativity laws above, mathematically one does not care about the execution order, but for programming it is still often relevant. I do not expect Sage/Python to embrace unicode operators the way, for example, Agda does [1], so this limits the options quite a bit. [1] https://github.com/agda/agda-stdlib/blob/49fa0985b2e7ed8896174f4d7ecca92d4e8c847d/src/Algebra/Module/Bundles.agda#L145-L151 -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/59D0D81E-75CF-494A-BF50-1431DE13288E%40gmail.com.