(* File: Forms.v  (last edited on 27/10/2000) (c) Klaus Weich  *)
Require Export ML_Int.
Require Export My_Nth.
(*******   forms    ***********************************************)
Inductive form : Set :=
| Falsum : form
| Atom : Int -> form
| AndF : form -> form -> form
| OrF : form -> form -> form
| Imp : form -> form -> form.
Definition flist := list form.
Definition fnil := nil (A:=form).
(* vimp qs a := vec(qs) imp a *)
Fixpoint vimp (qs : list Int) : form -> form :=
match qs with
| nil => fun a : form => a
| q :: qs => fun a : form => vimp qs (Imp (Atom q) a)
end.
(*********************************************************************)
(* Substitute (Atom i) by a in b:                                    *)
Fixpoint subst_form (i : Int) (a b : form) {struct b} : form :=
match b with
| Falsum => Falsum
| Atom j => match equal_dec i j with
| left _ => a
| right _ => Atom j
end
| OrF b0 b1 => OrF (subst_form i a b0) (subst_form i a b1)
| AndF b0 b1 => AndF (subst_form i a b0) (subst_form i a b1)
| Imp b0 b1 => Imp (subst_form i a b0) (subst_form i a b1)
end.
Definition subst_list (i : Int) (a : form) (l : flist) :=
map (subst_form i a) l.
intros i g n; elim n; clear n.
intros l a nth; inversion_clear nth.
simpl in |- *.
apply My_NthO.
intros n ih l a nth.
inversion_clear nth.
simpl in |- *.
apply My_NthS.
apply ih.
assumption.
Qed.
(************************************************************************)
Fixpoint below_form (a : form) (i : Int) {struct a} : Prop :=
match a with
| Falsum => True
| Atom j => Less j i
| AndF a0 a1 => below_form a0 i /\ below_form a1 i
| OrF a0 a1 => below_form a0 i /\ below_form a1 i
| Imp a0 a1 => below_form a0 i /\ below_form a1 i
end.
Definition below_list (L : flist) (i : Int) :=
forall a : form, In a L -> below_form a i.
(********************************************************************)
intros a i j.
elim a; clear a.
intros; trivial.
simpl in |- *.
intros i0 less_i0 less_i.
apply less_trans with i; assumption.
intros a ih_a b ih_b below_ab less_ij.
elim below_ab; clear below_ab.
intros below_a below_b.
split.
apply ih_a; assumption.
apply ih_b; assumption.
intros a ih_a b ih_b below_ab less_ij.
elim below_ab; clear below_ab.
intros below_a below_b.
split.
apply ih_a; assumption.
apply ih_b; assumption.
intros a ih_a b ih_b below_ab less_ij.
elim below_ab; clear below_ab.
intros below_a below_b.
split.
apply ih_a; assumption.
apply ih_b; assumption.
Qed.
intros l i j below_l less_ij.
unfold below_list in |- *.
intros a in_a.
apply below_form_less_below_form with i.
apply below_l; assumption.
assumption.
Qed.
intros a l i below_l.
apply below_l.
left; trivial.
Qed.
intros a l i below_l.
unfold below_list in |- *.
intros b in_b.
apply below_l.
right; assumption.
Qed.

Lemma below_cons_list :
forall (a : form) (l : flist) (i : Int),
below_form a i -> below_list l i -> below_list (a :: l) i.