Options

Lecture 11 - Bartosz Milewski

YouTube link.

Comments

  • 1.

    How do we know that Fix is an initial algebra? As I understand, Lambek's lemma tells us that if it's an initial algebra, then it will be a fixed point (because F(X) is isomorphic to X). But how do we know that the converse is true? Just because something is a fixed point, does that also mean it will be an initial algebra?

    Comment Source:How do we know that Fix is an initial algebra? As I understand, Lambek's lemma tells us that if it's an initial algebra, then it will be a fixed point (because F(X) is isomorphic to X). But how do we know that the converse is true? Just because something is a fixed point, does that also mean it will be an initial algebra?
  • 2.
    edited February 2

    @EricRogstad Recall that a morphism in the category of F-algebras is a function m :: a -> b mapping f :: f a -> a to g :: f b -> b by obeying the law:

     m . f = g . fmap m
    

    In order to show that Fix :: f (Fix f) -> Fix f is initial, we need to find for every other algebra h :: f c -> c some m :: Fix f -> c where the rule above is obeyed...

    [EDIT: Formatting, fixing F-algebra morphism law]

    Comment Source:@EricRogstad Recall that a morphism in the category of F-algebras is a function `m :: a -> b` mapping `f :: f a -> a` to `g :: f b -> b` by obeying the law: m . f = g . fmap m In order to show that `Fix :: f (Fix f) -> Fix f` is initial, we need to find for every other algebra `h :: f c -> c` some `m :: Fix f -> c` where the rule above is obeyed... [EDIT: Formatting, fixing F-algebra morphism law]
  • 3.

    The answer is that, in general, we don't know. If there is a unique fixed point then it must be both the initial algebra and the terminal coalgebra. Infinite streams are an example of a terminal coalgebra for the product functor Pair a x, but an initial algebra for it is Void.

    Comment Source:The answer is that, in general, we don't know. If there is a unique fixed point then it must be both the initial algebra and the terminal coalgebra. Infinite streams are an example of a terminal coalgebra for the product functor `Pair a x`, but an initial algebra for it is `Void`.
  • 4.
    edited February 2

    @EricRogstad - I want to follow up and ellaborate on your question (and clear things up, mostly for my own edification).

    How do we know that Fix is an initial algebra?

    Bartosz just pointed out that we don't always know if Fix :: f (Fix f) -> Fix f is initial, because we don't always know if the type Fix f is inhabited. For example if we define the type

      data Pair a b = Pair a b
    

    ...then neither Fix (Pair a) nor Pair a (Fix (Pair a) are inhabited by a terminating program. So you couldn't do anything meaningful with one in PureScript, and we have to leverage lazy evaluation in Haskell to make use of it.

    The restriction that we only consider terminating programs comes from page 33 of the companion notes, as mentioned elsewhere on this forum.

    Since Fix (Pair a) has no inhabitants, it's like Void. Void is the empty datatype defined like this:

    data Void
    

    But how do we know that the converse is true? Just because something is a fixed point, does that also mean it will be an initial algebra?

    I started answering this yesterday but I'll finish today, starting from the top. Define:

    data Fix f = Fix { unfix :: f (Fix f) }
    

    And let's suppose that f is a functor and the type Fix f is inhabited. We want to show that the F-algebra

    Fix :: f (Fix f) -> Fix f
    

    is initial.

    Proof. In order to show it's initial, then for each F-algebra g :: f a -> a we must find a function m :: Fix f -> a such that m . Fix = g . fmap m

    Here's how we do it. First define cata as follows (I'm stealing this from Bartosz's writings on www.schoolofhaskell.com):

      cata :: Functor f => (f a -> a) -> Fix f -> a
      cata alg = alg . fmap (cata alg) . unFix
    

    This is exactly what we need!

    Let m be cata g :: Fix f -> a. We need to show that cata g . Fix = g . fmap (cata g), which is pretty straight-forward:

      cata g . Fix
        = g . fmap (cata g) . unFix . Fix
        = g . fmap (cata g)
    

    ...since unFix . Fix = id. So there we go, we have a constructive proof that Fix :: f (Fix f) -> Fix f is initial. \(\Box\)

    [EDIT: typos]

    Comment Source:@EricRogstad - I want to follow up and ellaborate on your question (and clear things up, mostly for my own edification). > How do we know that Fix is an initial algebra? Bartosz just pointed out that we _don't always know_ if `Fix :: f (Fix f) -> Fix f` is initial, because we don't always know if the type `Fix f` is inhabited. For example if we define the type data Pair a b = Pair a b ...then neither `Fix (Pair a)` nor `Pair a (Fix (Pair a)` are inhabited by a terminating program. So you couldn't do anything meaningful with one in PureScript, and we have to leverage lazy evaluation in Haskell to make use of it. The restriction that we only consider terminating programs comes from page 33 of [the companion notes](http://brendanfong.com/programmingcats_files/cats4progs-DRAFT.pdf), as mentioned elsewhere on this forum. Since `Fix (Pair a)` has no inhabitants, it's like `Void`. `Void` is the empty datatype defined like this: data Void ---------------------------------------- > But how do we know that the converse is true? Just because something is a fixed point, does that also mean it will be an initial algebra? I started answering this yesterday but I'll finish today, starting from the top. Define: data Fix f = Fix { unfix :: f (Fix f) } And let's suppose that `f` is a functor and the type `Fix f` is inhabited. We want to show that the F-algebra Fix :: f (Fix f) -> Fix f is initial. **Proof.** In order to show it's initial, then for each F-algebra `g :: f a -> a` we must find a function `m :: Fix f -> a` such that `m . Fix = g . fmap m` Here's how we do it. First define `cata` as follows (I'm stealing this from Bartosz's writings on [www.schoolofhaskell.com](https://www.schoolofhaskell.com/user/bartosz/understanding-algebras#catamorphisms)): cata :: Functor f => (f a -> a) -> Fix f -> a cata alg = alg . fmap (cata alg) . unFix _**This is exactly what we need!**_ Let `m` be `cata g :: Fix f -> a`. We need to show that `cata g . Fix = g . fmap (cata g)`, which is pretty straight-forward: cata g . Fix = g . fmap (cata g) . unFix . Fix = g . fmap (cata g) ...since `unFix . Fix = id`. So there we go, we have a constructive proof that `Fix :: f (Fix f) -> Fix f` is initial. \\(\Box\\) [EDIT: typos]
  • 5.

    Thanks!

    Comment Source:Thanks!
  • 6.

    @MatthewDotty : Strictly speaking, you'd also have to prove that the catamorphism is unique.

    Comment Source:@MatthewDotty : Strictly speaking, you'd also have to prove that the catamorphism is unique.
  • 7.

    @Bartosz - You are absolutely right!

    But I can't really think of sufficient conditions for f which let us get that cata g is unique...

    Comment Source:@Bartosz - You are absolutely right! But I can't really think of sufficient conditions for `f` which let us get that `cata g` is unique...
  • 8.

    Is this question even for this lecture (I wonder :) ) First let me say hi from Amsterdam, and complement all of you on this magnificent project. Things are slowly clicking in my mind, but now I am pondering this question (after watching this lecture hence) if I have carrier i and structure map F i -> i as my initial algebra and another algebra F a -> a and they commute (as they would) does a needs to be of the same type as i? Or could it be completely different. Thanks in advance for any answer. Regards Laurens

    Comment Source:Is this question even for this lecture (I wonder :) ) First let me say hi from Amsterdam, and complement all of you on this magnificent project. Things are slowly clicking in my mind, but now I am pondering this question (after watching this lecture hence) if I have carrier i and structure map F i -> i as my initial algebra and another algebra F a -> a and they commute (as they would) does a needs to be of the same type as i? Or could it be completely different. Thanks in advance for any answer. Regards Laurens
  • 9.

    The answer is I guess that the structure map is not a ploymorphic function and thus i and a in the above question are of the same type.

    Comment Source:The answer is I guess that the structure map is not a ploymorphic function and thus i and a in the above question are of the same type.
Sign In or Register to comment.