2014-12-04 02:54:24 +00:00
|
|
|
/-
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
Authors: Leonardo de Moura
|
2014-12-15 21:43:42 +00:00
|
|
|
|
|
|
|
Types with a nat-valued complexity measure.
|
2014-12-04 02:54:24 +00:00
|
|
|
-/
|
|
|
|
prelude
|
|
|
|
import init.nat
|
|
|
|
open nat
|
|
|
|
|
|
|
|
inductive measurable [class] (A : Type) :=
|
|
|
|
mk : (A → nat) → measurable A
|
|
|
|
|
2015-07-24 15:56:18 +00:00
|
|
|
definition size_of {A : Type} [s : measurable A] : A → nat :=
|
|
|
|
measurable.rec_on s (λ f, f)
|
2014-12-04 02:54:24 +00:00
|
|
|
|
|
|
|
definition nat.measurable [instance] : measurable nat :=
|
|
|
|
measurable.mk (λ a, a)
|
|
|
|
|
2015-02-24 23:25:02 +00:00
|
|
|
definition option.measurable [instance] (A : Type) [s : measurable A] : measurable (option A) :=
|
2015-07-24 15:56:18 +00:00
|
|
|
measurable.mk (λ a, option.cases_on a zero size_of)
|
2014-12-04 02:54:24 +00:00
|
|
|
|
2015-02-24 23:25:02 +00:00
|
|
|
definition prod.measurable [instance] (A B : Type) [sa : measurable A] [sb : measurable B] : measurable (prod A B) :=
|
2014-12-04 02:54:24 +00:00
|
|
|
measurable.mk (λ p, prod.cases_on p (λ a b, size_of a + size_of b))
|
|
|
|
|
2015-02-24 23:25:02 +00:00
|
|
|
definition sum.measurable [instance] (A B : Type) [sa : measurable A] [sb : measurable B] : measurable (sum A B) :=
|
2014-12-04 02:54:24 +00:00
|
|
|
measurable.mk (λ s, sum.cases_on s (λ a, size_of a) (λ b, size_of b))
|
|
|
|
|
|
|
|
definition bool.measurable [instance] : measurable bool :=
|
|
|
|
measurable.mk (λb, zero)
|
|
|
|
|
|
|
|
definition Prop.measurable [instance] : measurable Prop :=
|
|
|
|
measurable.mk (λp, zero)
|
|
|
|
|
|
|
|
definition unit.measurable [instance] : measurable unit :=
|
|
|
|
measurable.mk (λu, zero)
|
|
|
|
|
|
|
|
definition fn.measurable [instance] (A : Type) (B : A → Type) : measurable (Π x, B x) :=
|
|
|
|
measurable.mk (λf, zero)
|