Suggerimento: non è necessario usare il costrutto if_then_else
e tantomento il predicato di maggiore o uguale.
*)
-let rec sem (v: nat → nat) (F: Formula) on F ≝
+let rec sem (v: nat → nat) (F: Formula) on F : nat ≝
match F with
[ FBot ⇒ 0
| FTop ⇒ 1
Ad esempio la formula `(A ∨ (⊤ → B))` deve diventare
`¬A ∨ (⊤ → ¬B)`.
*)
-let rec negate (F: Formula) on F ≝
+let rec negate (F: Formula) on F : Formula ≝
match F with
- [ FBot ⇒ FBot
+ [ (*BEGIN*)FBot ⇒ FBot
| FTop ⇒ FTop
| FAtom n ⇒ FNot (FAtom n)
| FAnd F1 F2 ⇒ FAnd (negate F1) (negate F2)
| FOr F1 F2 ⇒ FOr (negate F1) (negate F2)
| FImpl F1 F2 ⇒ FImpl (negate F1) (negate F2)
- | FNot F ⇒ FNot (negate F)
+ | FNot F ⇒ FNot (negate F)(*END*)
].
(* Test 2
* `symmetry`
Quando la conclusuine è `a = b` permette di cambiarla in `b = a`.
+
+* by H1, H2 we proved P (H)
+
+ Il comando `by ... we proved` visto nella scorsa esercitazione
+ permette di utilizzare più ipotesi o lemmi alla volta
+ separandoli con una virgola.
DOCEND*)
assume F:Formula.
assume v:(ℕ→ℕ).
we proceed by induction on F to prove ([[ negate F ]]_v=[[ F ]]_(invert v)).
- case FBot .
+ case FBot.
+ (*BEGIN*)
the thesis becomes ([[ negate FBot ]]_v=[[ FBot ]]_(invert v)).
+ (*END*)
done.
- case FTop .
+ case FTop.
+ (*BEGIN*)
the thesis becomes ([[ negate FTop ]]_v=[[ FTop ]]_(invert v)).
+ (*END*)
done.
case FAtom.
assume n : ℕ.
the thesis becomes ([[ negate (FAtom n) ]]_v=[[ FAtom n ]]_(invert v)).
the thesis becomes (1 - (min (v n) 1)= min (invert v n) 1).
the thesis becomes (1 - (min (v n) 1)= min (if eqb (min (v n) 1) 0 then 1 else 0) 1).
- by min_bool we proved (min (v n) 1 = 0 ∨ min (v n) 1 = 1) (H1);
+ by min_bool we proved ((*BEGIN*)min (v n) 1 = 0 ∨ min (v n) 1 = 1(*END*)) (H1);
we proceed by cases on (H1) to prove (1 - (min (v n) 1)= min (if eqb (min (v n) 1) 0 then 1 else 0) 1).
case Left.
conclude
= 1.
done.
case Right.
+ (*BEGIN*)
conclude
(1 - (min (v n) 1))
= (1 - 1) by H.
= (min (if eqb 1 0 then 1 else O) 1) by H.
= (min 0 1).
= 0.
+ (*END*)
done.
case FAnd.
assume f : Formula.
conclude
(min [[ negate f ]]_v [[ negate f1]]_v)
= (min [[ f ]]_(invert v) [[ negate f1]]_v) by H.
- = (min [[ f ]]_(invert v) [[ f1]]_(invert v)) by H1.
+ = (min [[ f ]]_(invert v) [[ f1]]_(invert v)) by (*BEGIN*)H1(*END*).
done.
case FOr.
+ (*BEGIN*)
assume f : Formula.
by induction hypothesis we know
([[ negate f ]]_v=[[ f ]]_(invert v)) (H).
(max [[ negate f ]]_v [[ negate f1]]_v)
= (max [[ f ]]_(invert v) [[ negate f1]]_v) by H.
= (max [[ f ]]_(invert v) [[ f1]]_(invert v)) by H1.
+ (*END*)
done.
case FImpl.
+ (*BEGIN*)
assume f : Formula.
by induction hypothesis we know
([[ negate f ]]_v=[[ f ]]_(invert v)) (H).
(max (1 - [[ negate f ]]_v) [[ negate f1]]_v)
= (max (1 - [[ f ]]_(invert v)) [[ negate f1]]_v) by H.
= (max (1 - [[ f ]]_(invert v)) [[ f1]]_(invert v)) by H1.
+ (*END*)
done.
case FNot.
+ (*BEGIN*)
assume f : Formula.
by induction hypothesis we know
([[ negate f ]]_v=[[ f ]]_(invert v)) (H).
- the thesis becomes
- ([[ negate (FNot f) ]]_v=[[ FNot f ]]_(invert v)).
- the thesis becomes
- (1 - [[ negate f ]]_v=[[ FNot f ]]_(invert v)).
- conclude (1 - [[ negate f ]]_v) = (1 - [[f]]_(invert v)) by H.
- done.
+ the thesis becomes
+ ([[ negate (FNot f) ]]_v=[[ FNot f ]]_(invert v)).
+ the thesis becomes
+ (1 - [[ negate f ]]_v=[[ FNot f ]]_(invert v)).
+ conclude (1 - [[ negate f ]]_v) = (1 - [[f]]_(invert v)) by H.
+ (*END*)
+ done.
qed.
(* Esercizio 5
*)
lemma negate_fun:
∀F:Formula.∀G:Formula.F ≡ G→negate F ≡ negate G.
+ (*BEGIN*)
assume F:Formula.
assume G:Formula.
suppose (F ≡ G) (H).
the thesis becomes (negate F ≡ negate G).
the thesis becomes (∀v:ℕ→ℕ.[[ negate F ]]_v=[[ negate G ]]_v).
+ (*END*)
assume v:(ℕ→ℕ).
conclude
[[ negate F ]]_v
= [[ F ]]_(invert v) by negate_invert.
- = [[ G ]]_(invert v) by H.
- = [[ negate G ]]_v by negate_invert.
+ = [[ G ]]_((*BEGIN*)invert v(*BEGIN*)) by (*BEGIN*)H(*BEGIN*).
+ = [[ negate G ]]_(*BEGIN*)v(*BEGIN*) by (*BEGIN*)negate_invert(*END*).
done.
qed.
*)
lemma not_dualize_eq_negate:
∀F:Formula.negate F ≡ FNot (dualize F).
+ (*BEGIN*)
assume F:Formula.
the thesis becomes (∀v:ℕ→ℕ.[[negate F]]_v=[[FNot (dualize F)]]_v).
+ (*END*)
assume v:(ℕ→ℕ).
we proceed by induction on F to prove ([[negate F]]_v=[[FNot (dualize F)]]_v).
- case FBot .
+ case FBot.
+ (*BEGIN*)
the thesis becomes ([[ negate FBot ]]_v=[[ FNot (dualize FBot) ]]_v).
+ (*END*)
done.
- case FTop .
+ case FTop.
+ (*BEGIN*)
the thesis becomes ([[ negate FTop ]]_v=[[ FNot (dualize FTop) ]]_v).
+ (*END*)
done.
case FAtom.
+ (*BEGIN*)
assume n : ℕ.
the thesis becomes ([[ negate (FAtom n) ]]_v=[[ FNot (dualize (FAtom n)) ]]_v).
+ (*END*)
done.
case FAnd.
assume f : Formula.
= (1 - (max [[ dualize f ]]_v [[ dualize f1 ]]_v)) by min_max.
done.
case FOr.
+ (*BEGIN*)
assume f : Formula.
by induction hypothesis we know
([[ negate f ]]_v=[[ FNot (dualize f) ]]_v) (H).
= (max [[ FNot (dualize f) ]]_v [[ FNot (dualize f1) ]]_v) by H1.
= (max (1 - [[ dualize f ]]_v) (1 - [[ dualize f1 ]]_v)).
= (1 - (min [[ dualize f ]]_v [[ dualize f1 ]]_v)) by max_min.
+ (*END*)
done.
case FImpl.
+ (*BEGIN*)
assume f : Formula.
by induction hypothesis we know
([[ negate f ]]_v=[[ FNot (dualize f) ]]_v) (H).
= (max (1-[[ FNot (dualize f) ]]_v) [[ FNot (dualize f1) ]]_v) by H1.
= (max (1 - [[ FNot (dualize f) ]]_v) (1 - [[ dualize f1 ]]_v)).
= (1 - (min [[ FNot (dualize f) ]]_v [[ dualize f1 ]]_v)) by max_min.
+ (*END*)
done.
- case FNot.
+ case FNot.
+ (*BEGIN*)
assume f : Formula.
by induction hypothesis we know
([[ negate f ]]_v=[[ FNot (dualize f) ]]_v) (H).
the thesis becomes
(1 - [[ negate f ]]_v=[[ FNot (dualize (FNot f)) ]]_v).
conclude (1 - [[ negate f ]]_v) = (1 - [[ FNot (dualize f) ]]_v) by H.
+ (*END*)
done.
qed.
*)
theorem not_inj:
∀F,G:Formula.FNot F ≡ FNot G→F ≡ G.
+ (*BEGIN*)
assume F:Formula.
assume G:Formula.
suppose (FNot F ≡ FNot G) (H).
the thesis becomes (F ≡ G).
the thesis becomes (∀v:ℕ→ℕ.[[ F ]]_v=[[ G ]]_v).
+ (*END*)
assume v:(ℕ→ℕ).
by H we proved ([[ FNot F ]]_v=[[ FNot G ]]_v) (H1).
- by sem_bool we proved ([[ F ]]_v=O∨[[ F ]]_v=1) (H2).
- by sem_bool we proved ([[ G ]]_v=O∨[[ G ]]_v=1) (H3).
+ by sem_bool we proved ([[ F ]]_v=O ∨ [[ F ]]_v=1) (H2).
+ by (*BEGIN*)sem_bool(*END*) we proved ([[ G ]]_v=(*BEGIN*)O ∨ [[ G ]]_v=1(*END*)) (H3).
we proceed by cases on H2 to prove ([[ F ]]_v=[[ G ]]_v).
case Left.
we proceed by cases on H3 to prove ([[ F ]]_v=[[ G ]]_v).
= 1.
done.
case Right.
+ (*BEGIN*)
we proceed by cases on H3 to prove ([[ F ]]_v=[[ G ]]_v).
case Left.
conclude
= 0.
done.
case Right.
- done.
+ (*END*)
+ done.
qed.
(*DOCBEGIN
assume F2:Formula.
suppose (F1 ≡ F2) (H).
the thesis becomes (dualize F1 ≡ dualize F2).
- by negate_fun we proved (negate F1 ≡ negate F2) (H1).
- by not_dualize_eq_negate, equiv_rewrite we proved (FNot (dualize F1) ≡ negate F2) (H2).
- by not_dualize_eq_negate, equiv_rewrite we proved (FNot (dualize F1) ≡ FNot (dualize F2)) (H3).
- by not_inj we proved (dualize F1 ≡ dualize F2) (H4).
+ by (*BEGIN*)negate_fun(*END*) we proved (negate F1 ≡ negate F2) (H1).
+ by (*BEGIN*)not_dualize_eq_negate(*END*), (*BEGIN*)equiv_rewrite(*END*), H1 we proved (FNot (dualize F1) ≡ negate F2) (H2).
+ by (*BEGIN*)not_dualize_eq_negate(*END*), (*BEGIN*)equiv_rewrite(*END*), H2 we proved (FNot (dualize F1) ≡ FNot (dualize F2)) (H3).
+ by (*BEGIN*)not_inj(*END*), H3 we proved (dualize F1 ≡ dualize F2) (H4).
done.
qed.