feat(library): reorganize and declare some notation

This commit is contained in:
Jeremy Avigad 2014-11-28 07:06:46 -05:00 committed by Leonardo de Moura
parent 58e325f0af
commit 89380f088e
4 changed files with 66 additions and 41 deletions

View file

@ -1,6 +1,15 @@
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved. /-
-- Released under Apache 2.0 license as described in the file LICENSE. Copyright (c) 2014 Microsoft Corporation. All rights reserved.
-- Author: Leonardo de Moura Released under Apache 2.0 license as described in the file LICENSE.
Module: algebra.function
Author: Leonardo de Moura
General operations on functions.
-/
import general_notation
namespace function namespace function
variables {A : Type} {B : Type} {C : Type} {D : Type} {E : Type} variables {A : Type} {B : Type} {C : Type} {D : Type} {E : Type}
@ -20,7 +29,8 @@ definition combine (f : A → B → C) (op : C → D → E) (g : A → B → D)
definition const {A : Type} (B : Type) (a : A) : B → A := definition const {A : Type} (B : Type) (a : A) : B → A :=
λx, a λx, a
definition dcompose {A : Type} {B : A → Type} {C : Π {x : A}, B x → Type} (f : Π {x : A} (y : B x), C y) (g : Πx, B x) : Πx, C (g x) := definition dcompose {A : Type} {B : A → Type} {C : Π {x : A}, B x → Type}
(f : Π {x : A} (y : B x), C y) (g : Πx, B x) : Πx, C (g x) :=
λx, f (g x) λx, f (g x)
definition flip {A : Type} {B : Type} {C : A → B → Type} (f : Πx y, C x y) : Πy x, C x y := definition flip {A : Type} {B : Type} {C : A → B → Type} (f : Πx y, C x y) : Πy x, C x y :=
@ -29,7 +39,6 @@ definition flip {A : Type} {B : Type} {C : A → B → Type} (f : Πx y, C x y)
definition app {A : Type} {B : A → Type} (f : Πx, B x) (x : A) : B x := definition app {A : Type} {B : A → Type} (f : Πx, B x) (x : A) : B x :=
f x f x
precedence `∘`:60
precedence `∘'`:60 precedence `∘'`:60
precedence `on`:1 precedence `on`:1
precedence `$`:1 precedence `$`:1

View file

@ -1,6 +1,11 @@
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved. /-
-- Released under Apache 2.0 license as described in the file LICENSE. Copyright (c) 2014 Microsoft Corporation. All rights reserved.
-- Author: Leonardo de Moura, Jeremy Avigad Released under Apache 2.0 license as described in the file LICENSE.
Module: data.prod.decl
Author: Leonardo de Moura, Jeremy Avigad
-/
import data.unit.decl logic.eq import data.unit.decl logic.eq
structure prod (A B : Type) := structure prod (A B : Type) :=
@ -10,6 +15,12 @@ definition pair := @prod.mk
namespace prod namespace prod
notation A × B := prod A B notation A × B := prod A B
notation A * B := prod A B
namespace low_precedence_times
reserve infixr `*`:30 -- conflicts with notation for multiplication
infixr `*` := prod
end low_precedence_times
notation `pr₁` := pr1 notation `pr₁` := pr1
notation `pr₂` := pr2 notation `pr₂` := pr2

View file

@ -1,25 +1,25 @@
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved. /-
-- Released under Apache 2.0 license as described in the file LICENSE. Copyright (c) 2014 Microsoft Corporation. All rights reserved.
-- Author: Leonardo de Moura, Jeremy Avigad Released under Apache 2.0 license as described in the file LICENSE.
Module: data.sum
Authors: Leonardo de Moura, Jeremy Avigad
The sum type, aka disjoint union.
-/
import logic.prop logic.inhabited logic.decidable import logic.prop logic.inhabited logic.decidable
open inhabited decidable eq.ops open inhabited decidable eq.ops
-- data.sum
-- ========
-- The sum type, aka disjoint union.
inductive sum (A B : Type) : Type := inductive sum (A B : Type) : Type :=
inl : A → sum A B, inl : A → sum A B,
inr : B → sum A B inr : B → sum A B
namespace sum namespace sum
notation A ⊎ B := sum A B notation A ⊎ B := sum A B
notation A + B := sum A B notation A + B := sum A B
namespace low_precedence_plus namespace low_precedence_plus
reserve infixr `+`:25 -- conflicts with notation for addition reserve infixr `+`:25 -- conflicts with notation for addition
infixr `+` := sum infixr `+` := sum
end low_precedence_plus end low_precedence_plus
@ -35,15 +35,16 @@ namespace sum
theorem inr_inj : inr A b₁ = inr A b₂ → b₁ = b₂ := theorem inr_inj : inr A b₁ = inr A b₂ → b₁ = b₂ :=
assume H, no_confusion H (λe, e) assume H, no_confusion H (λe, e)
protected definition is_inhabited_left [instance] : inhabited A → inhabited (A B) := protected definition is_inhabited_left [instance] : inhabited A → inhabited (A + B) :=
assume H : inhabited A, inhabited.mk (inl B (default A)) assume H : inhabited A, inhabited.mk (inl B (default A))
protected definition is_inhabited_right [instance] : inhabited B → inhabited (A B) := protected definition is_inhabited_right [instance] : inhabited B → inhabited (A + B) :=
assume H : inhabited B, inhabited.mk (inr A (default B)) assume H : inhabited B, inhabited.mk (inr A (default B))
protected definition has_eq_decidable [instance] : decidable_eq A → decidable_eq B → decidable_eq (A ⊎ B) := protected definition has_eq_decidable [instance] :
decidable_eq A → decidable_eq B → decidable_eq (A + B) :=
assume (H₁ : decidable_eq A) (H₂ : decidable_eq B), assume (H₁ : decidable_eq A) (H₂ : decidable_eq B),
take s₁ s₂ : A B, take s₁ s₂ : A + B,
rec_on s₁ rec_on s₁
(take a₁, show decidable (inl B a₁ = s₂), from (take a₁, show decidable (inl B a₁ = s₂), from
rec_on s₂ rec_on s₂

View file

@ -1,25 +1,27 @@
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved. /-
-- Released under Apache 2.0 license as described in the file LICENSE. Copyright (c) 2014 Microsoft Corporation. All rights reserved.
-- Author: Leonardo de Moura, Jeremy Avigad Released under Apache 2.0 license as described in the file LICENSE.
-- general_notation Module: general_notation
-- ================ Authors: Leonardo de Moura, Jeremy Avigad
-/
-- General operations /- General operations -/
-- ------------------
notation `assume` binders `,` r:(scoped f, f) := r notation `assume` binders `,` r:(scoped f, f) := r
notation `take` binders `,` r:(scoped f, f) := r notation `take` binders `,` r:(scoped f, f) := r
-- Global declarations of right binding strength /-
-- --------------------------------------------- Global declarations of right binding strength
-- If a module reassigns these, it will be incompatible with other modules that adhere to these If a module reassigns these, it will be incompatible with other modules that adhere to these
-- conventions. conventions.
-- When hovering over a symbol, use "C-u C-x =" to see how to input it When hovering over a symbol, use "C-u C-x =" to see how to input it.
-/
/- Logical operations and relations -/
-- ### Logical operations and relations
reserve prefix `¬`:40 reserve prefix `¬`:40
reserve prefix `~`:40 reserve prefix `~`:40
reserve infixr `∧`:35 reserve infixr `∧`:35
@ -33,16 +35,17 @@ reserve infix `≠`:50
reserve infix `≈`:50 reserve infix `≈`:50
reserve infix ``:50 reserve infix ``:50
reserve postfix `⁻¹`:100 --input with \sy or \-1 or \inv reserve infix `∘`:60 -- input with \comp
reserve postfix `⁻¹`:100 --input with \sy or \-1 or \inv
reserve infixl `⬝`:75 reserve infixl `⬝`:75
reserve infixr `▸`:75 reserve infixr `▸`:75
-- ### types and type constructors /- types and type constructors -/
reserve infixl `⊎`:25 reserve infixl `⊎`:25
reserve infixl `×`:30 reserve infixl `×`:30
-- ### arithmetic operations /- arithmetic operations -/
reserve infixl `+`:65 reserve infixl `+`:65
reserve infixl `-`:65 reserve infixl `-`:65
@ -58,18 +61,19 @@ reserve infix `>=`:50
reserve infix `≥`:50 reserve infix `≥`:50
reserve infix `>`:50 reserve infix `>`:50
-- ### boolean operations /- boolean operations -/
reserve infixl `&&`:70 reserve infixl `&&`:70
reserve infixl `||`:65 reserve infixl `||`:65
-- ### set operations /- set operations -/
reserve infix `∈`:50 reserve infix `∈`:50
reserve infixl `∩`:70 reserve infixl `∩`:70
reserve infixl ``:65 reserve infixl ``:65
-- ### other symbols /- other symbols -/
precedence `|`:55 precedence `|`:55
reserve notation | a:55 | reserve notation | a:55 |
reserve infixl `++`:65 reserve infixl `++`:65