Lvc.Infra.Relations

Require Import Arith Coq.Lists.List Setoid Coq.Lists.SetoidList Util.
Require Export Infra.Option EqDec AutoIndTac Tactics.

Set Implicit Arguments.

Relations

The development in this file are based on the material of the Semantics lecture 2011 at Saarland University.

Section Relations.
  Variable X:Type.

  Definition rel : Type := XXProp.

Unary functions and predicates on relations

  Section Unary.
    Variable R : rel.

    Definition reflexive :=
       x, R x x.

    Definition symmetric :=
       x y, R x yR y x.

    Definition transitive :=
       x y z, R x yR y zR x z.

    Definition functional :=
       x y z, R x yR x zy=z.

    Definition reducible (x : X) :=
       y, R x y.

    Definition normal (x : X) :=
      ¬ reducible x.

    Definition total :=
       x, reducible x.

    Hint Unfold symmetric transitive functional reducible normal total.

The transitive reflexive closure of a relation


    Inductive star : rel :=
    | star_refl : x, star x x
    | S_star : y x z, R x ystar y zstar x z.

    CoInductive diverges : XProp :=
    | DivergesI x y : R x ydiverges ydiverges x.

    Lemma star_trans (x y z:X)
      : star x ystar y zstar x z.

    Lemma star_right (x y z:X)
      : star x yR y zstar x z.

The transitive reflexive closure of a relation with size index


    Inductive starn : natXXProp :=
    | starn_refl : a, starn 0 a a
    | S_starn : x y z n, R x ystarn n y zstarn (S n) x z.

    Lemma starn_one
      : x y, R x ystarn (S 0) x y.

    Lemma starn_trans n m :
       x y, starn n x y z, starn m y zstarn (n+m) x z.

    Lemma star0_is_eq a b
      : starn 0 a ba = b.

    Lemma starn_iff_star a b
      : star a b n, starn n a b.

The transitive closure of a relation.

    Inductive plus : rel :=
    | plusO x y : R x yplus x y
    | plusS x y z : R x yplus y zplus x z.

    Lemma plus_trans x y z :
      plus x yplus y zplus x z.

    Lemma star_plus x y z:
      R x ystar y zplus x z.

    Lemma plus_right x y z :
      plus x yR y zplus x z.

    Lemma plus_star x y :
      plus x ystar x y.

    Lemma star_plus_plus : x y z, star x yplus y zplus x z.

    Lemma plus_destr x z
    : plus x z y, R x y star y z.

    Lemma star_destr : x z, star x z(x = z) plus x z.

Termination and Normalization

Also know as must-termination and may-termination

    Inductive terminates : XProp :=
    | terminatesI x : ( y, R x yterminates y) → terminates x.

    Definition terminating : Prop :=
       x, terminates x.

    Definition normalizes´ (x:X) : Prop :=
       y, inhabited (star x y) normal y.

    Inductive normalizes : XProp :=
    | normalizesI1 x : normal xnormalizes x
    | normalizesI2 x y : R x ynormalizes ynormalizes x.

    Lemma normalizes_normalizes´_agree (x:X) :
      normalizes´ x normalizes x.

    Definition normalizing : Prop :=
       x, normalizes x.

    Lemma functional_normalizes_terminates x
      : functionalnormalizes xterminates x.

  End Unary.

  Lemma star_starplus (R : rel) (x y : X)
    : star R x ystar (plus R) x y.

  Lemma star_idem_1 R x y
    : star (star R) x ystar R x y.

  Lemma star_idem_2 R x y
    : star R x ystar (star R) x y.

  Lemma div_plus´ : (R : rel) (x y : X), star R x ydiverges (plus R) ydiverges R x.

  Lemma div_ext_star : (R : rel) (x y : X), star R x ydiverges (plus R) ydiverges (plus R) x.

  Lemma div_plus : (R : rel) (x : X), diverges (plus R) xdiverges R x.

  Lemma div_ext_star_2 (R: rel) x y
  : functional Rdiverges R xstar R x ydiverges R y.

  Lemma div_ext_plus (R: rel) x y
  : functional Rdiverges R xplus R x ydiverges R y.

  Lemma normal_terminates (R: rel) s
  : normal R sterminates R s.

Relational approximation

  Definition rle (R : rel) :=
     x y, R x y x y.

  Definition req (R : rel) :=
    (rle R × rle R)%type.

Reduction decidability

  Definition reddec R :=
     x, reducible R x normal R x.

End Relations.

Global Hint Unfold symmetric transitive functional reducible normal total.

complete induction and size induction


Require Import Omega.

Lemma complete_induction (p : natProp) (x : nat)
  : ( x, ( y, y<xp y) → p x) → p x.

Lemma gt_terminates
  : terminating gt.

Lemma size_induction (X : Type) (f : Xnat) (p: XProp) (x : X)
  : ( x, ( y, f y < f xp y) → p x) → p x.

Definition size_recursion (X : Type) (f : Xnat) (p: XType) (x : X)
  : ( x, ( y, f y < f xp y) → p x) → p x.

Inductive fstNoneOrR {X Y:Type} (R:XYProp)
  : option Xoption YProp :=
| fstNone (x:option Y) : fstNoneOrR R None x
| bothR (x:X) (y:Y) : R x yfstNoneOrR R (Some x) (Some y)
.

Instance fstNoneOrR_Reflexive {A : Type} {R : relation A} {Rrefl: Reflexive R}
: Reflexive (fstNoneOrR R).