2014-12-05 22:34:02 +00:00
|
|
|
/-
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
2014-12-12 18:17:50 +00:00
|
|
|
Authors: Leonardo de Moura, Jakob von Raumer
|
2014-12-05 22:34:02 +00:00
|
|
|
|
|
|
|
Basic datatypes
|
|
|
|
-/
|
2015-02-26 18:19:54 +00:00
|
|
|
|
2014-12-05 22:34:02 +00:00
|
|
|
prelude
|
|
|
|
notation [parsing-only] `Type'` := Type.{_+1}
|
|
|
|
notation [parsing-only] `Type₊` := Type.{_+1}
|
|
|
|
notation `Type₀` := Type.{0}
|
|
|
|
notation `Type₁` := Type.{1}
|
|
|
|
notation `Type₂` := Type.{2}
|
|
|
|
notation `Type₃` := Type.{3}
|
|
|
|
|
2015-06-24 21:59:17 +00:00
|
|
|
inductive poly_unit.{l} : Type.{l} :=
|
|
|
|
star : poly_unit
|
|
|
|
|
|
|
|
inductive unit : Type₀ :=
|
2014-12-05 22:34:02 +00:00
|
|
|
star : unit
|
|
|
|
|
2015-05-05 22:05:07 +00:00
|
|
|
inductive empty : Type₀
|
2014-12-05 22:34:02 +00:00
|
|
|
|
2014-12-06 17:43:42 +00:00
|
|
|
inductive eq.{l} {A : Type.{l}} (a : A) : A → Type.{l} :=
|
2014-12-05 23:47:04 +00:00
|
|
|
refl : eq a a
|
|
|
|
|
2014-12-08 20:09:41 +00:00
|
|
|
structure lift.{l₁ l₂} (A : Type.{l₁}) : Type.{max l₁ l₂} :=
|
|
|
|
up :: (down : A)
|
|
|
|
|
2015-06-27 00:09:50 +00:00
|
|
|
inductive prod (A B : Type) :=
|
|
|
|
mk : A → B → prod A B
|
|
|
|
|
2015-07-07 23:37:06 +00:00
|
|
|
definition prod.pr1 [reducible] [unfold 3] {A B : Type} (p : prod A B) : A :=
|
2015-06-27 00:09:50 +00:00
|
|
|
prod.rec (λ a b, a) p
|
|
|
|
|
2015-07-07 23:37:06 +00:00
|
|
|
definition prod.pr2 [reducible] [unfold 3] {A B : Type} (p : prod A B) : B :=
|
2015-06-27 00:09:50 +00:00
|
|
|
prod.rec (λ a b, b) p
|
|
|
|
|
|
|
|
definition prod.destruct [reducible] := @prod.cases_on
|
2014-12-05 23:47:04 +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-05 23:47:04 +00:00
|
|
|
|
2014-12-20 01:56:44 +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
|
|
|
|
|
2015-06-27 00:09:50 +00:00
|
|
|
inductive sigma {A : Type} (B : A → Type) :=
|
|
|
|
mk : Π (a : A), B a → sigma B
|
|
|
|
|
2015-07-07 23:37:06 +00:00
|
|
|
definition sigma.pr1 [reducible] [unfold 3] {A : Type} {B : A → Type} (p : sigma B) : A :=
|
2015-06-27 00:09:50 +00:00
|
|
|
sigma.rec (λ a b, a) p
|
|
|
|
|
2015-07-07 23:37:06 +00:00
|
|
|
definition sigma.pr2 [reducible] [unfold 3] {A : Type} {B : A → Type} (p : sigma B) : B (sigma.pr1 p) :=
|
2015-06-27 00:09:50 +00:00
|
|
|
sigma.rec (λ a b, b) p
|
2015-04-24 23:58:50 +00:00
|
|
|
|
2014-12-05 23:47:04 +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-05 23:47:04 +00:00
|
|
|
|
2015-02-28 00:02:18 +00:00
|
|
|
namespace pos_num
|
|
|
|
definition succ (a : pos_num) : pos_num :=
|
|
|
|
pos_num.rec_on a (bit0 one) (λn r, bit0 r) (λn r, bit1 n)
|
|
|
|
end pos_num
|
|
|
|
|
2014-12-05 23:47:04 +00:00
|
|
|
inductive num : Type :=
|
2015-02-26 01:00:10 +00:00
|
|
|
| zero : num
|
|
|
|
| pos : pos_num → num
|
2014-12-05 23:47:04 +00:00
|
|
|
|
2015-02-28 00:02:18 +00:00
|
|
|
namespace num
|
|
|
|
open pos_num
|
|
|
|
definition succ (a : num) : num :=
|
|
|
|
num.rec_on a (pos one) (λp, pos (succ p))
|
|
|
|
end num
|
|
|
|
|
2014-12-05 23:47:04 +00:00
|
|
|
inductive bool : Type :=
|
2015-02-26 01:00:10 +00:00
|
|
|
| ff : bool
|
|
|
|
| tt : bool
|
2014-12-05 23:47:04 +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-05 23:47:04 +00:00
|
|
|
|
|
|
|
inductive nat :=
|
2015-02-26 01:00:10 +00:00
|
|
|
| zero : nat
|
|
|
|
| succ : nat → nat
|
2014-12-05 23:47:04 +00:00
|
|
|
|
|
|
|
inductive option (A : Type) : Type :=
|
2015-02-26 01:00:10 +00:00
|
|
|
| none {} : option A
|
|
|
|
| some : A → option A
|