§ Weird canonical example of monic and epic: left/right shift
- Consider the function
right
over an infinite sequence a_n
which is defined as right(a[:])[i] = 0 if i == 0 else a[i-1]
. That is, it shifts a sequence to the right. - See that this is injective, and not surjective: for example, there is no pre-image to any sequence that starts with a non-zero value, such as
1, 0, 0, ...
. - Its dual,
left(a[:])[i] = a[i+1]
is surjective, but not injective. - This makes it ideal as an "extreme case" to test the monic/epic conditions as left/right cancellable.
§ Monic
- We know that
right
is monic. Is it cancellable if we run it before or after? - We should run it after --- that way, if
right(f(a[:]))
equals right(g(a[:]))
for all a[:]
, we know that the sequences are (0, f1, f2, ...)
which equals (0, g1, g2, ...)
which implies (f1, f2, ...)
equals (g1, g2, ...)
. So we can conclude that f = g
from right . f = right . g
. - On the other hand, if we consider
f(right(a[:]))
and g(right([a:])
, we will only test the equality of f
and g
at sequences of the form (0, a1, a2, ...)
which is insufficient, this we cannot conclude f = g
. So we cannot conclude f = g
from f . right = g . right
.
§ Epic
- We know that
left
is epic. Is it cancellable if we run it before or after? - Suppose
f . left = g . left
. Since left
is epic, this tests f
and g
on every possible input. Thus f = g
. - On the other hand, suppose
left . f = left . g
. This is insufficient, since we will only test the equality of (f2, f3, ...)
with (g2, g3, ...)
leaving f1 =? g1
untested. Thus, we cannot conclude f = g
from left . f = left . g
.