Skip to content
Snippets Groups Projects
ifs.lp 2.21 KiB
Newer Older
gabrielhdt's avatar
gabrielhdt committed
require open personoj.encodings.lhol
  personoj.encodings.pvs_cert
  personoj.encodings.booleans
require personoj.encodings.deferred as Deferred
require open personoj.encodings.subtype //FIXME: why must it be the last import?

symbol if {U: Set} {V: Set} (S: Set)
gabrielhdt's avatar
gabrielhdt committed
: ε (U ⊑ S) → ε (V ⊑ S) → Bool → η U → η V → η S
gabrielhdt's avatar
gabrielhdt committed

symbol lif {U: Set} {V: Set} (S: Set)
gabrielhdt's avatar
gabrielhdt committed
: Deferred.p (U ⊑ S) → Deferred.p (V ⊑ S) → Bool → Deferred.t U → Deferred.t V → η S
gabrielhdt's avatar
gabrielhdt committed

// lazy if
set flag "print_implicits" on
gabrielhdt's avatar
gabrielhdt committed
rule lif _ $pr _ true $t _ ↪ ↑ (Deferred.unquote_p $pr) (Deferred.unquote $t)
rule lif _ _ $pr false _ $f ↪ ↑ (Deferred.unquote_p $pr) (Deferred.unquote $f)
gabrielhdt's avatar
gabrielhdt committed

// The if is lazy, that is, the expression [if true 2 (1/0)] must type check and
// return 2. For this, we use the [Deferred.t] datatype. But remember that [if]
// is typed by a super type of [2] and [1/0]. This super type is provided as
// argument, and the types of the expressions must be verified to be sub-types
// of this super-types. Since these arguments are deferred and can be ill-typed,
// we want to defer the verification of sub-type as well. Therefore, we
// introduce the [lifSet] type to type the [lif].
gabrielhdt's avatar
gabrielhdt committed
// [lifset $T $F $S p] reduces to the type of the function that maps a proof of
// $T is a sub-type of $S to $S if [p] is true and the function that maps a
// proof of $F is a sub-type of $S if [p] is false.
gabrielhdt's avatar
gabrielhdt committed
// The result of [lif S true e1 e2] is the function that maps the proof of
// sub-typing [Te1 ⊑ S] to the evaluation (or unquoting) of [e1].
gabrielhdt's avatar
gabrielhdt committed
type λ (T S: Set), ε (T ⊑ S) → η S
symbol lifSet (T U S: Set): Bool → TYPE
gabrielhdt's avatar
gabrielhdt committed
symbol tt: Bool
symbol ff: Bool
gabrielhdt's avatar
gabrielhdt committed
rule lifSet $U _ $S true ↪ ε ($U ⊑ $S) → η $S
rule lifSet _ $F $S false ↪ ε ($F ⊑ $S) → η $S
gabrielhdt's avatar
gabrielhdt committed

compute λ(U V S: Set), lifSet U V S tt

symbol lifn {U: Set} {V: Set} (S: Set) (p: Bool)
gabrielhdt's avatar
gabrielhdt committed
: Deferred.t U → Deferred.t V → lifSet U V S p
gabrielhdt's avatar
gabrielhdt committed
rule lifn {$U} {$V} $S true $t $f ↪ λh:ε ($U ⊑ $S), ↑ {$U} {$S} h (Deferred.unquote $t)
gabrielhdt's avatar
gabrielhdt committed

symbol if3 {u: Set} {v: Set} (s: Set) (_: ε (u ⊑ s)) (_: ε (v ⊑ s)) (p: Bool):
gabrielhdt's avatar
gabrielhdt committed
  (ε p → η u) → (ε (¬ p) → η v) → η s
gabrielhdt's avatar
gabrielhdt committed
rule if3 $s $pr _ true $bh _ ↪ ↑ $pr ($bh (λx, x))
 and if3 $s _ $pr false _ $bh ↪ ↑ $pr ($bh (λx, x))