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 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”
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”
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”
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
The question What is this “more powerful means”? Given introduction rules for a connective, how to determine its elimination rules?
Examples
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
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:
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
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:
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: ⇝
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 ⇝
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: ⇝
Examples Two lenses compound formula compound type I rule type constructor E rule type signature for elimination function reduction step definition of elimination function
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:
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: ⇝ � �� �
Method 1: general elimination
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”
Method 1: general elimination Read “The introduction-rule not only shows what is [sufficient for] the conclusion but also [what is] necessary”
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”
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
Method 2: Catamorphisms
Method 2: catamorphisms Background Catamorphisms give a different way to generate either , uncurry , and the like The first step into so-called ‘recursion schemes’
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 ]
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 ]
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 ]
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 ]
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
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 ]
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 ] ⇝
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 ] � �� �
Method 2: catamorphisms Motivation: generality Meijer, Fokkinga, Paterson: “Countless list processing functions are readily recognizable as catamorphisms”
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
Method 2: catamorphisms Motivation: generality append :: [a] -> [a] -> [a] append xs ys = foldr (:) ys xs concat :: [[a]] -> [a] concat xss = foldr append [] xss
Method 2: catamorphisms Motivation: generality Nil: . . . B Cons: foldr: ( A ) ([ B ]) [ A ] [ B ] [ B ] [ B ]
Method 2: catamorphisms . Nil: foldr: Cons: B Motivation: generality . . Nil: Nil: ( A ) ([ B ]) [ A ] [ B ] [ B ] [ B ] ⇝ [ B ]
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 ]
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 ]
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
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
Differences
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
Differences B foldr: B . . . B B GE for lists B . . . B ( A ) , ([ A ]) ( A ) , ( B ) � �� � � �� � [ A ] [ A ] [ ] GE:
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: ⇝ ⇝
Recommend
More recommend