feat(library/init/core): add notation for out_param

This commit is contained in:
Leonardo de Moura 2017-05-01 13:52:17 -07:00
parent 949ed3ac5c
commit 74550fbebc
6 changed files with 26 additions and 25 deletions

View file

@ -13,17 +13,16 @@ class is_commutative (α : Type u) (op : ααα) : Prop :=
class is_associative (α : Type u) (op : ααα) : Prop :=
(assoc : ∀ a b c, op (op a b) c = op a (op b c))
-- TODO: better notation for out_param
class is_left_id (α : Type u) (op : ααα) (o : out_param α) : Prop :=
class is_left_id (α : Type u) (op : ααα) (o : inout α) : Prop :=
(left_id : ∀ a, op o a = a)
class is_right_id (α : Type u) (op : ααα) (o : out_param α) : Prop :=
class is_right_id (α : Type u) (op : ααα) (o : inout α) : Prop :=
(right_id : ∀ a, op a o = a)
class is_left_null (α : Type u) (op : ααα) (o : out_param α) : Prop :=
class is_left_null (α : Type u) (op : ααα) (o : inout α) : Prop :=
(left_null : ∀ a, op o a = o)
class is_right_null (α : Type u) (op : ααα) (o : out_param α) : Prop :=
class is_right_null (α : Type u) (op : ααα) (o : inout α) : Prop :=
(right_null : ∀ a, op a o = o)
class is_left_cancel (α : Type u) (op : ααα) : Prop :=
@ -35,22 +34,22 @@ class is_right_cancel (α : Type u) (op : ααα) : Prop :=
class is_idempotent (α : Type u) (op : ααα) : Prop :=
(idempotent : ∀ a, op a a = a)
class is_left_distrib (α : Type u) (op₁ : ααα) (op₂ : out_param $ ααα) : Prop :=
class is_left_distrib (α : Type u) (op₁ : ααα) (op₂ : inout ααα) : Prop :=
(left_distrib : ∀ a b c, op₁ a (op₂ b c) = op₂ (op₁ a b) (op₁ a c))
class is_right_distrib (α : Type u) (op₁ : ααα) (op₂ : out_param $ ααα) : Prop :=
class is_right_distrib (α : Type u) (op₁ : ααα) (op₂ : inout ααα) : Prop :=
(right_distrib : ∀ a b c, op₁ (op₂ a b) c = op₂ (op₁ a c) (op₁ b c))
class is_left_inv (α : Type u) (op : ααα) (inv : out_param $ αα) (o : out_param α) : Prop :=
class is_left_inv (α : Type u) (op : ααα) (inv : inout αα) (o : inout α) : Prop :=
(left_inv : ∀ a, op (inv a) a = o)
class is_right_inv (α : Type u) (op : ααα) (inv : out_param $ αα) (o : out_param α) : Prop :=
class is_right_inv (α : Type u) (op : ααα) (inv : inout αα) (o : inout α) : Prop :=
(right_inv : ∀ a, op a (inv a) = o)
class is_cond_left_inv (α : Type u) (op : ααα) (inv : out_param $ αα) (o : out_param α) (p : out_param $ α → Prop) : Prop :=
class is_cond_left_inv (α : Type u) (op : ααα) (inv : inout αα) (o : inout α) (p : inout α → Prop) : Prop :=
(left_inv : ∀ a, p a → op (inv a) a = o)
class is_cond_right_inv (α : Type u) (op : ααα) (inv : out_param $ αα) (o : out_param α) (p : out_param $ α → Prop) : Prop :=
class is_cond_right_inv (α : Type u) (op : ααα) (inv : inout αα) (o : inout α) (p : inout α → Prop) : Prop :=
(right_inv : ∀ a, p a → op a (inv a) = o)
class is_distinct (α : Type u) (a : α) (b : α) : Prop :=
@ -58,7 +57,7 @@ class is_distinct (α : Type u) (a : α) (b : α) : Prop :=
/-
-- The following type class doesn't seem very useful, a regular simp lemma should work for this.
class is_inv (α : Type u) (β : Type v) (f : α → β) (g : out_param $ β → α) : Prop :=
class is_inv (α : Type u) (β : Type v) (f : α → β) (g : inout β → α) : Prop :=
(inv : ∀ a, g (f a) = a)
-- The following one can also be handled using a regular simp lemma

View file

@ -87,6 +87,8 @@ universes u v w
/-- Gadget for marking output parameters in type classes. -/
@[reducible] def out_param (α : Sort u) : Sort u := α
notation `inout`:1024 a:0 := out_param a
inductive punit : Sort u
| star : punit
@ -316,12 +318,12 @@ class has_ssubset (α : Type u) := (ssubset : αα → Prop)
used to implement polymorphic notation for collections.
Example: {a, b, c}. -/
class has_emptyc (α : Type u) := (emptyc : α)
class has_insert (α : out_param (Type u)) (γ : Type v) := (insert : αγγ)
class has_insert (α : inout Type u) (γ : Type v) := (insert : αγγ)
/- Type class used to implement the notation { a ∈ c | p a } -/
class has_sep (α : out_param (Type u)) (γ : Type v) :=
class has_sep (α : inout Type u) (γ : Type v) :=
(sep : (α → Prop) → γγ)
/- Type class for set-like membership -/
class has_mem (α : out_param (Type u)) (γ : Type v) := (mem : αγ → Prop)
class has_mem (α : inout Type u) (γ : Type v) := (mem : αγ → Prop)
infix ∈ := has_mem.mem
notation a ∉ s := ¬ has_mem.mem a s

View file

@ -34,7 +34,7 @@ infixr ⇒ := lift_fun
end
section
variables {α : Type u₁} {β : out_param (Type u₂)} (R : out_param (α → β → Prop))
variables {α : Type u₁} {β : inout Type u₂} (R : inout α → β → Prop)
@[class] def right_total := ∀b, ∃a, R a b
@[class] def left_total := ∀a, ∃b, R a b

View file

@ -11,7 +11,7 @@
'("import" "prelude" "protected" "private" "noncomputable" "definition" "meta" "renaming"
"hiding" "exposing" "parameter" "parameters" "begin" "constant" "constants"
"lemma" "variable" "variables" "theorem" "example"
"open" "export" "axiom" "axioms" "inductive" "with" "without"
"open" "export" "axiom" "axioms" "inductive" "with" "without" "inout"
"structure" "universe" "universes"
"precedence" "reserve" "declare_trace" "add_key_equivalence"
"match" "infix" "infixl" "infixr" "notation" "postfix" "prefix" "instance"

View file

@ -5,5 +5,5 @@
{"message":"file invalidated","response":"ok","seq_num":0}
{"completions":[{"source":,"text":"left","type":"?a ∧ ?b → ?a"},{"source":{"column":14,"file":"/library/init/logic.lean","line":405},"text":"left_comm","type":"?a ∧ ?b ∧ ?c ↔ ?b ∧ ?a ∧ ?c"}],"prefix":"l","response":"ok","seq_num":5}
{"completions":[{"source":,"text":"left","type":"?a ∧ ?b → ?a"},{"source":{"column":14,"file":"/library/init/logic.lean","line":405},"text":"left_comm","type":"?a ∧ ?b ∧ ?c ↔ ?b ∧ ?a ∧ ?c"}],"prefix":"le","response":"ok","seq_num":9}
{"completions":[{"source":,"text":"rec","type":"(?a → ?b → ?C) → ?a ∧ ?b → ?C"},{"source":{"column":10,"file":"/library/init/core.lean","line":134},"text":"rec_on","type":"?a ∧ ?b → (?a → ?b → ?C) → ?C"},{"source":{"column":4,"file":"/library/init/core.lean","line":145},"text":"right","type":"?a ∧ ?b → ?b"}],"prefix":"r","response":"ok","seq_num":13}
{"completions":[{"source":,"text":"assoc","type":"(?a ∧ ?b) ∧ ?c ↔ ?a ∧ ?b ∧ ?c"},{"source":{"column":10,"file":"/library/init/core.lean","line":134},"text":"cases_on","type":"?a ∧ ?b → (?a → ?b → ?C) → ?C"},{"source":{"column":14,"file":"/library/init/logic.lean","line":393},"text":"comm","type":"?a ∧ ?b ↔ ?b ∧ ?a"},{"source":{"column":10,"file":"/library/init/core.lean","line":134},"text":"dcases_on","type":"Π (n : ?a ∧ ?b), (Π (a : ?a) (a_1 : ?b), ?C (and.intro a a_1)) → ?C n"},{"source":{"column":11,"file":"/library/init/logic.lean","line":653},"text":"decidable","type":"decidable (?p ∧ ?q)"},{"source":{"column":10,"file":"/library/init/core.lean","line":134},"text":"drec","type":"(Π (a : ?a) (a_1 : ?b), ?C (and.intro a a_1)) → Π (n : ?a ∧ ?b), ?C n"},{"source":{"column":10,"file":"/library/init/core.lean","line":134},"text":"drec_on","type":"Π (n : ?a ∧ ?b), (Π (a : ?a) (a_1 : ?b), ?C (and.intro a a_1)) → ?C n"},{"source":{"column":6,"file":"/library/init/logic.lean","line":201},"text":"elim","type":"?a ∧ ?b → (?a → ?b → ?c) → ?c"},{"source":{"column":4,"file":"/library/init/core.lean","line":137},"text":"elim_left","type":"?a ∧ ?b → ?a"},{"source":{"column":4,"file":"/library/init/core.lean","line":142},"text":"elim_right","type":"?a ∧ ?b → ?b"},{"source":{"column":6,"file":"/library/init/logic.lean","line":380},"text":"imp","type":"(?a → ?c) → (?b → ?d) → ?a ∧ ?b → ?c ∧ ?d"},{"source":{"column":10,"file":"/library/init/core.lean","line":134},"text":"intro","type":"?a → ?b → ?a ∧ ?b"},{"source":{"column":4,"file":"/library/init/core.lean","line":140},"text":"left","type":"?a ∧ ?b → ?a"},{"source":{"column":14,"file":"/library/init/logic.lean","line":405},"text":"left_comm","type":"?a ∧ ?b ∧ ?c ↔ ?b ∧ ?a ∧ ?c"},{"source":{"column":10,"file":"/library/init/core.lean","line":134},"text":"rec","type":"(?a → ?b → ?C) → ?a ∧ ?b → ?C"},{"source":{"column":10,"file":"/library/init/core.lean","line":134},"text":"rec_on","type":"?a ∧ ?b → (?a → ?b → ?C) → ?C"},{"source":{"column":4,"file":"/library/init/core.lean","line":145},"text":"right","type":"?a ∧ ?b → ?b"},{"source":{"column":6,"file":"/library/init/logic.lean","line":204},"text":"swap","type":"?a ∧ ?b → ?b ∧ ?a"},{"source":{"column":4,"file":"/library/init/logic.lean","line":207},"text":"symm","type":"?a ∧ ?b → ?b ∧ ?a"}],"prefix":"","response":"ok","seq_num":17}
{"completions":[{"source":,"text":"rec","type":"(?a → ?b → ?C) → ?a ∧ ?b → ?C"},{"source":{"column":10,"file":"/library/init/core.lean","line":136},"text":"rec_on","type":"?a ∧ ?b → (?a → ?b → ?C) → ?C"},{"source":{"column":4,"file":"/library/init/core.lean","line":147},"text":"right","type":"?a ∧ ?b → ?b"}],"prefix":"r","response":"ok","seq_num":13}
{"completions":[{"source":,"text":"assoc","type":"(?a ∧ ?b) ∧ ?c ↔ ?a ∧ ?b ∧ ?c"},{"source":{"column":10,"file":"/library/init/core.lean","line":136},"text":"cases_on","type":"?a ∧ ?b → (?a → ?b → ?C) → ?C"},{"source":{"column":14,"file":"/library/init/logic.lean","line":393},"text":"comm","type":"?a ∧ ?b ↔ ?b ∧ ?a"},{"source":{"column":10,"file":"/library/init/core.lean","line":136},"text":"dcases_on","type":"Π (n : ?a ∧ ?b), (Π (a : ?a) (a_1 : ?b), ?C (and.intro a a_1)) → ?C n"},{"source":{"column":11,"file":"/library/init/logic.lean","line":653},"text":"decidable","type":"decidable (?p ∧ ?q)"},{"source":{"column":10,"file":"/library/init/core.lean","line":136},"text":"drec","type":"(Π (a : ?a) (a_1 : ?b), ?C (and.intro a a_1)) → Π (n : ?a ∧ ?b), ?C n"},{"source":{"column":10,"file":"/library/init/core.lean","line":136},"text":"drec_on","type":"Π (n : ?a ∧ ?b), (Π (a : ?a) (a_1 : ?b), ?C (and.intro a a_1)) → ?C n"},{"source":{"column":6,"file":"/library/init/logic.lean","line":201},"text":"elim","type":"?a ∧ ?b → (?a → ?b → ?c) → ?c"},{"source":{"column":4,"file":"/library/init/core.lean","line":139},"text":"elim_left","type":"?a ∧ ?b → ?a"},{"source":{"column":4,"file":"/library/init/core.lean","line":144},"text":"elim_right","type":"?a ∧ ?b → ?b"},{"source":{"column":6,"file":"/library/init/logic.lean","line":380},"text":"imp","type":"(?a → ?c) → (?b → ?d) → ?a ∧ ?b → ?c ∧ ?d"},{"source":{"column":10,"file":"/library/init/core.lean","line":136},"text":"intro","type":"?a → ?b → ?a ∧ ?b"},{"source":{"column":4,"file":"/library/init/core.lean","line":142},"text":"left","type":"?a ∧ ?b → ?a"},{"source":{"column":14,"file":"/library/init/logic.lean","line":405},"text":"left_comm","type":"?a ∧ ?b ∧ ?c ↔ ?b ∧ ?a ∧ ?c"},{"source":{"column":10,"file":"/library/init/core.lean","line":136},"text":"rec","type":"(?a → ?b → ?C) → ?a ∧ ?b → ?C"},{"source":{"column":10,"file":"/library/init/core.lean","line":136},"text":"rec_on","type":"?a ∧ ?b → (?a → ?b → ?C) → ?C"},{"source":{"column":4,"file":"/library/init/core.lean","line":147},"text":"right","type":"?a ∧ ?b → ?b"},{"source":{"column":6,"file":"/library/init/logic.lean","line":204},"text":"swap","type":"?a ∧ ?b → ?b ∧ ?a"},{"source":{"column":4,"file":"/library/init/logic.lean","line":207},"text":"symm","type":"?a ∧ ?b → ?b ∧ ?a"}],"prefix":"","response":"ok","seq_num":17}

View file

@ -5,18 +5,18 @@ has_append : Type u → Type u
has_div : Type u → Type u
has_dvd : Type u → Type u
has_emptyc : Type u → Type u
has_insert : out_param Type u → Type v → Type (max u v)
has_insert : (inout Type u) → Type v → Type (max u v)
has_inter : Type u → Type u
has_inv : Type u → Type u
has_le : Type u → Type u
has_lt : Type u → Type u
has_mem : out_param Type u → Type v → Type (max u v)
has_mem : (inout Type u) → Type v → Type (max u v)
has_mod : Type u → Type u
has_mul : Type u → Type u
has_neg : Type u → Type u
has_one : Type u → Type u
has_sdiff : Type u → Type u
has_sep : out_param Type u → Type v → Type (max u v)
has_sep : (inout Type u) → Type v → Type (max u v)
has_sizeof : Sort u → Sort (max 1 u)
has_ssubset : Type u → Type u
has_sub : Type u → Type u
@ -31,18 +31,18 @@ has_append : Type u → Type u
has_div : Type u → Type u
has_dvd : Type u → Type u
has_emptyc : Type u → Type u
has_insert : out_param Type u → Type v → Type (max u v)
has_insert : (inout Type u) → Type v → Type (max u v)
has_inter : Type u → Type u
has_inv : Type u → Type u
has_le : Type u → Type u
has_lt : Type u → Type u
has_mem : out_param Type u → Type v → Type (max u v)
has_mem : (inout Type u) → Type v → Type (max u v)
has_mod : Type u → Type u
has_mul : Type u → Type u
has_neg : Type u → Type u
has_one : Type u → Type u
has_sdiff : Type u → Type u
has_sep : out_param Type u → Type v → Type (max u v)
has_sep : (inout Type u) → Type v → Type (max u v)
has_sizeof : Sort u → Sort (max 1 u)
has_ssubset : Type u → Type u
has_sub : Type u → Type u