2014-12-01 04:34:12 +00:00
|
|
|
/-
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
2015-02-28 00:02:18 +00:00
|
|
|
Module: init.datatypes
|
2014-12-01 04:34:12 +00:00
|
|
|
Authors: Leonardo de Moura
|
|
|
|
|
|
|
|
Basic datatypes
|
|
|
|
-/
|
|
|
|
prelude
|
|
|
|
notation `Prop` := Type.{0}
|
|
|
|
notation [parsing-only] `Type'` := Type.{_+1}
|
|
|
|
notation [parsing-only] `Type₊` := Type.{_+1}
|
|
|
|
notation `Type₁` := Type.{1}
|
|
|
|
notation `Type₂` := Type.{2}
|
|
|
|
notation `Type₃` := Type.{3}
|
|
|
|
|
2014-12-09 20:40:09 +00:00
|
|
|
set_option structure.eta_thm true
|
|
|
|
set_option structure.proj_mk_thm true
|
|
|
|
|
2014-12-01 04:34:12 +00:00
|
|
|
inductive unit.{l} : Type.{l} :=
|
|
|
|
star : unit
|
|
|
|
|
|
|
|
inductive true : Prop :=
|
|
|
|
intro : true
|
|
|
|
|
|
|
|
inductive false : Prop
|
|
|
|
|
|
|
|
inductive empty : Type
|
|
|
|
|
|
|
|
inductive eq {A : Type} (a : A) : A → Prop :=
|
|
|
|
refl : eq a a
|
|
|
|
|
|
|
|
inductive heq {A : Type} (a : A) : Π {B : Type}, B → Prop :=
|
|
|
|
refl : heq a a
|
|
|
|
|
|
|
|
structure prod (A B : Type) :=
|
|
|
|
mk :: (pr1 : A) (pr2 : B)
|
|
|
|
|
|
|
|
inductive and (a b : Prop) : Prop :=
|
|
|
|
intro : a → b → and a b
|
|
|
|
|
2014-12-03 18:39:22 +00:00
|
|
|
definition and.elim_left {a b : Prop} (H : and a b) : a :=
|
|
|
|
and.rec (λa b, a) H
|
|
|
|
|
2015-01-07 01:44:04 +00:00
|
|
|
definition and.left := @and.elim_left
|
|
|
|
|
2014-12-03 18:39:22 +00:00
|
|
|
definition and.elim_right {a b : Prop} (H : and a b) : b :=
|
|
|
|
and.rec (λa b, b) H
|
|
|
|
|
2015-01-07 01:44:04 +00:00
|
|
|
definition and.right := @and.elim_right
|
|
|
|
|
2014-12-01 04:34:12 +00:00
|
|
|
inductive sum (A B : Type) : Type :=
|
2015-02-26 01:00:10 +00:00
|
|
|
| inl {} : A → sum A B
|
|
|
|
| inr {} : B → sum A B
|
2014-12-20 02:07:13 +00:00
|
|
|
|
|
|
|
definition sum.intro_left [reducible] {A : Type} (B : Type) (a : A) : sum A B :=
|
|
|
|
sum.inl a
|
|
|
|
|
|
|
|
definition sum.intro_right [reducible] (A : Type) {B : Type} (b : B) : sum A B :=
|
|
|
|
sum.inr b
|
2014-12-01 04:34:12 +00:00
|
|
|
|
|
|
|
inductive or (a b : Prop) : Prop :=
|
2015-02-26 01:00:10 +00:00
|
|
|
| inl {} : a → or a b
|
|
|
|
| inr {} : b → or a b
|
2014-12-20 02:07:13 +00:00
|
|
|
|
|
|
|
definition or.intro_left {a : Prop} (b : Prop) (Ha : a) : or a b :=
|
|
|
|
or.inl Ha
|
|
|
|
|
|
|
|
definition or.intro_right (a : Prop) {b : Prop} (Hb : b) : or a b :=
|
|
|
|
or.inr Hb
|
2014-12-01 04:34:12 +00:00
|
|
|
|
2015-02-01 19:14:01 +00:00
|
|
|
structure sigma {A : Type} (B : A → Type) :=
|
|
|
|
mk :: (pr1 : A) (pr2 : B pr1)
|
|
|
|
|
2014-12-01 04:34:12 +00:00
|
|
|
-- pos_num and num are two auxiliary datatypes used when parsing numerals such as 13, 0, 26.
|
|
|
|
-- The parser will generate the terms (pos (bit1 (bit1 (bit0 one)))), zero, and (pos (bit0 (bit1 (bit1 one)))).
|
|
|
|
-- This representation can be coerced in whatever we want (e.g., naturals, integers, reals, etc).
|
|
|
|
inductive pos_num : Type :=
|
2015-02-26 01:00:10 +00:00
|
|
|
| one : pos_num
|
|
|
|
| bit1 : pos_num → pos_num
|
|
|
|
| bit0 : pos_num → pos_num
|
2014-12-01 04:34:12 +00:00
|
|
|
|
2015-01-05 18:29:06 +00:00
|
|
|
namespace pos_num
|
|
|
|
definition succ (a : pos_num) : pos_num :=
|
2015-02-11 20:49:27 +00:00
|
|
|
pos_num.rec_on a (bit0 one) (λn r, bit0 r) (λn r, bit1 n)
|
2015-01-05 18:29:06 +00:00
|
|
|
end pos_num
|
|
|
|
|
2014-12-01 04:34:12 +00:00
|
|
|
inductive num : Type :=
|
2015-02-26 01:00:10 +00:00
|
|
|
| zero : num
|
|
|
|
| pos : pos_num → num
|
2014-12-01 04:34:12 +00:00
|
|
|
|
2015-01-05 18:29:06 +00:00
|
|
|
namespace num
|
|
|
|
open pos_num
|
|
|
|
definition succ (a : num) : num :=
|
2015-02-11 20:49:27 +00:00
|
|
|
num.rec_on a (pos one) (λp, pos (succ p))
|
2015-01-05 18:29:06 +00:00
|
|
|
end num
|
|
|
|
|
2014-12-01 04:34:12 +00:00
|
|
|
inductive bool : Type :=
|
2015-02-26 01:00:10 +00:00
|
|
|
| ff : bool
|
|
|
|
| tt : bool
|
2014-12-01 04:34:12 +00:00
|
|
|
|
|
|
|
inductive char : Type :=
|
|
|
|
mk : bool → bool → bool → bool → bool → bool → bool → bool → char
|
|
|
|
|
|
|
|
inductive string : Type :=
|
2015-02-26 01:00:10 +00:00
|
|
|
| empty : string
|
|
|
|
| str : char → string → string
|
2014-12-01 04:34:12 +00:00
|
|
|
|
|
|
|
inductive nat :=
|
2015-02-26 01:00:10 +00:00
|
|
|
| zero : nat
|
|
|
|
| succ : nat → nat
|
2014-12-04 02:53:23 +00:00
|
|
|
|
|
|
|
inductive option (A : Type) : Type :=
|
2015-02-26 01:00:10 +00:00
|
|
|
| none {} : option A
|
|
|
|
| some : A → option A
|