general elimination and catamorphisms
play

General elimination and catamorphisms David Ripley Monash - PowerPoint PPT Presentation

General elimination and catamorphisms David Ripley Monash University http://davewripley.rocks The question The question Gentzen Gentzen 1934: The introductions represent, as it were, the definitions of the symbols concerned, and


  1. General elimination and catamorphisms David Ripley Monash University http://davewripley.rocks

  2. The question

  3. The question Gentzen Gentzen 1934: “The introductions represent, as it were, the ‘definitions’ of the symbols concerned, and the eliminations are no more… than the consequences of these definitions.… By making these ideas more precise it should be possible to display the E-inferences as unique functions of their corresponding I-inferences”

  4. The question Dummett “Such [introduction] laws will be ‘self-justifying’: we are entitled simply to stipulate [them], because by so doing we fix…the meanings of the logical constants that they govern”

  5. The question Dummett “Plainly, the elimination rules are not consequences of the introduction rules in the straightfoward sense of being derivable from them; Gentzen must therefore have had in mind some more powerful means of drawing consequences”

  6. The question Dummett “Plainly, the elimination rules are not consequences of the introduction rules in the straightfoward sense of being derivable from them; Gentzen must therefore have had in consequences” mind some more powerful means of drawing

  7. The question What is this “more powerful means”? Given introduction rules for a connective, how to determine its elimination rules?

  8. Examples

  9. Examples Propositions as types, proofs as programs, etc A proposition is either: are propositions, or are propositions, or … • basic Int , Char , Double , …, or • Pair a b , where a and b are types, or • Either a b , where a and b are types, or … A type is either: • atomic p , q , r , . . . , or • A ∧ B , where A and B • A ∨ B , where A and B

  10. Examples Disjunction (sum) (a -> c) -> (b -> c) either :: C C . . . C . . . Left a | Right b data Either a b = B A -> Either a b -> c ∨ I l : ∨ I r : A ∨ B A ∨ B ( A ) ( B ) A ∨ B ∨ E:

  11. Examples Disjunction (sum) (a -> c) -> (b -> c) either :: C C . . . C . . . Left a | Right b data Either a b = B A ∨ I l : ∨ I r : A ∨ B A ∨ B ( A ) ( B ) A ∨ B ∨ E: -> Either a b -> c

  12. Examples Disjunction (sum) (a -> c) -> (b -> c) either :: C C . . . C . . . Left a | Right b data Either a b = B A -> Either a b -> c ∨ I l : ∨ I r : A ∨ B A ∨ B ( A ) ( B ) A ∨ B ∨ E:

  13. Examples Disjunction (sum) either f _ ( Left x) -> Either a b -> c (a -> c) -> (b -> c) either :: C f A x C C . . . C f A x = f x ( B ) ( A ) ∨ I l : A ∨ B ∨ E: ⇝

  14. Examples . either f _ ( Left x) (a -> c) -> (b -> c) either :: C f A x C Disjunction (sum) C . . C f A x = f x ( B ) ( A ) ∨ I l : A ∨ B ∨ E: -> Either a b -> c ⇝

  15. Examples Achievement unlocked: reading the title bar (25 pts) = f x either f _ ( Left x) -> Either a b -> c (a -> c) -> (b -> c) either :: C g B y C C g C . . . B y either _ g ( Right y) = g y ( A ) ( B ) ∨ I r : A ∨ B ∨ E: ⇝

  16. Examples Two lenses compound formula compound type I rule type constructor E rule type signature for elimination function reduction step definition of elimination function

  17. Examples Conjunction (product) uncurry :: C C . . . (a -> b -> c) -> Pair a b -> c B data Pair a b = Pr a b A ∧ I: A ∧ B ( A ) , ( B ) � �� � A ∧ B ∧ GE:

  18. Examples Conjunction (product) (a -> b -> c) -> Pair a b -> c uncurry :: C f B y A x C uncurry f (Pr x y) = f x y C f B y A x ( A ) , ( B ) � �� � ∧ I: A ∧ B ∧ GE: ⇝ � �� �

  19. Method 1: general elimination

  20. Method 1: general elimination Negri “[W]hatever follows from the sufficient grounds for deriv- ing a formula must follow from that formula… [W]hatever follows from a for- mula must follow from the sufficient grounds for deriv- ing the formula”

  21. Method 1: general elimination Read “The introduction-rule not only shows what is [sufficient for] the conclusion but also [what is] necessary”

  22. Method 1: general elimination Moriconi & Tesconi Moriconi & Tesconi: “[I]t is quite natural to ask what consequences can be drawn from A , given that A can be produced only by [certain] rules. The answer is: we can draw all the consequences that we can draw from the premisses of those rules”

  23. Method 1: general elimination C C . . . C . . . B Revisiting the examples A C C A . . B . ( A ) , ( B ) � �� � A ∧ B ∧ I: ∧ GE: A ∧ B ( A ) ( B ) A ∨ B ∨ I l : ∨ I r : ∨ E: A ∨ B A ∨ B

  24. Method 2: Catamorphisms

  25. Method 2: catamorphisms Background Catamorphisms give a different way to generate either , uncurry , and the like The first step into so-called ‘recursion schemes’

  26. Method 2: catamorphisms Lists Nil: A Cons: data [a] = [] | a : [a] In Dummett’s terminology, Cons is: pure, simple, direct, not sheer, not single-ended, violates the complexity condition [ A ] [ A ] [ A ]

  27. Method 2: catamorphisms Lists Nil: A Cons: data [a] = [] | a : [a] In Dummett’s terminology, Cons is: pure, simple, direct, not sheer, not single-ended, violates the complexity condition [ A ] [ A ] [ A ]

  28. Method 2: catamorphisms A foldr :: (a -> b -> b) -> B foldr: B . . . B B Lists A data [a] = [] | a : [a] Cons: A Nil: b -> [a] -> b [ A ] [ A ] [ A ]

  29. Method 2: catamorphisms Lists foldr :: (a -> b -> b) -> B foldr: B . . . B data [a] = [] | a : [a] Cons: A Nil: b -> [a] -> b [ A ] [ A ] [ A ] ( A ) , ( B ) � �� � [ A ]

  30. Method 2: catamorphisms Lists foldr :: (a -> b -> b) -> B foldr: B . . . B data [a] = [] | a : [a] Cons: A Nil: [ A ] [ A ] [ A ] ( A ) , ( B ) � �� � [ A ] b -> [a] -> b

  31. Method 2: catamorphisms Lists foldr :: (a -> b -> b) -> B foldr: B . . . B Cons: A Nil: b -> [a] -> b [ A ] [ A ] [ A ] data [a] = [] | a : [a] ( A ) , ( B ) � �� � [ A ]

  32. Method 2: catamorphisms Lists b -> [a] -> b foldr :: (a -> b -> b) -> B z B foldr: B . . . B z Nil: foldr _ z [] = z ( A ) , ( B ) � �� � [ A ] ⇝

  33. Method 2: catamorphisms x foldr f z (x : xs) = foldr _ z [] = z b -> [a] -> b foldr :: (a -> b -> b) -> B f B foldr: B f B z Lists A xs f x ( foldr f z xs) B x A xs Cons: B z B f foldr: ( A ) , ( B ) � �� � [ A ] [ A ] ⇝ ( A ) , ( B ) � �� � [ A ] � �� �

  34. Method 2: catamorphisms Motivation: generality Meijer, Fokkinga, Paterson: “Countless list processing functions are readily recognizable as catamorphisms”

  35. Method 2: catamorphisms Motivation: generality ns = 1 : (3 : (5 : (7 : []))) foldr (*) 1 ns = 1 * (3 * (5 * (7 * 1 ))) = product ns foldr (+) 0 ns = 1 + (3 + (5 + (7 + 0 ))) = sum ns

  36. Method 2: catamorphisms Motivation: generality append :: [a] -> [a] -> [a] append xs ys = foldr (:) ys xs concat :: [[a]] -> [a] concat xss = foldr append [] xss

  37. Method 2: catamorphisms Motivation: generality Nil: . . . B Cons: foldr: ( A ) ([ B ]) [ A ] [ B ] [ B ] [ B ]

  38. Method 2: catamorphisms . Nil: foldr: Cons: B Motivation: generality . . Nil: Nil: ( A ) ([ B ]) [ A ] [ B ] [ B ] [ B ] ⇝ [ B ]

  39. Method 2: catamorphisms B Cons: foldr: Nil: Cons: xs B f A x Motivation: generality foldr: Cons: B f Nil: Cons: xs A x f ( A ) [ A ] ([ B ]) [ A ] [ B ] [ B ] [ B ] ⇝ ( A ) ([ B ]) [ A ] [ B ] [ B ] [ B ] [ B ]

  40. Method 2: catamorphisms Intuition: translation Nil: A Cons: We can translate this language into a language for proofs of B if we can translate each rule [ A ] [ A ] [ A ] This is a language for building proofs of [ A ]

  41. Method 2: catamorphisms Disjunction (sum) A B provide proofs f from A to C and g from B to C either :: (a -> c) -> (b -> c) -> Either a b -> c either f _ ( Left x) = f x either _ g ( Right y) = g y ∨ I l : ∨ I r : A ∨ B A ∨ B To get a catamorphism from A ∨ B to C , Replace ∨ I l with f and ∨ I r with g

  42. Method 2: catamorphisms Conjunction (product) A B provide a proof f from A and B to C uncurry :: (a -> b -> c) -> Pair a b -> c uncurry f (Pr x y) = f x y ∧ I: A ∧ B To get a catamorphism from A ∧ B to C , Replace ∧ I with f

  43. Differences

  44. Differences Disjunction and conjunction General elimination and catamorphisms have a lot in common! Catamorphisms for disjunction give us the usual (general) elimination rule And catamorphisms for conjunction give us the general elimination rule

  45. Differences B foldr: B . . . B B GE for lists B . . . B ( A ) , ([ A ]) ( A ) , ( B ) � �� � � �� � [ A ] [ A ] [ ] GE:

  46. Differences B z B foldr: B . . . B z Nil: B GE for lists z B B B . . Nil: . z ( A ) , ([ A ]) ( A ) , ( B ) � �� � � �� � [ A ] [ A ] [ ] GE: ⇝ ⇝

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend