LMF2014: Ejercicios de deducción en lógica de primer orden con Isabelle/HOL
En la clase de hoy del curso Lógica matemática y fundamentos se ha explicado cómo demostrar mediante deducción natural teoremas de primer orden con Isabelle/HOL. En concreto, se han visto los ejercicios 1, 5, 9, 10, 20 y 27 de la relación 6.
Los ejercicios y sus soluciones se muestran a continuación:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
theory R6 imports Main begin text {* --------------------------------------------------------------- Ejercicio 1. Demostrar ∀x. P x ⟶ Q x ⊢ (∀x. P x) ⟶ (∀x. Q x) ------------------------------------------------------------------ *} -- "La demostración automática es" lemma ejercicio_1a: "∀x. P x ⟶ Q x ⟹ (∀x. P x) ⟶ (∀x. Q x)" by auto -- "La demostración estructurada es" lemma ejercicio_1b: assumes "∀x. P x ⟶ Q x" shows "(∀x. P x) ⟶ (∀x. Q x)" proof assume "∀x. P x" show "∀x. Q x" proof fix a have "P a" using `∀x. P x` .. have "P a ⟶ Q a" using assms(1) .. thus "Q a" using `P a` .. qed qed -- "La demostración detallada es" lemma ejercicio_1c: assumes "∀x. P x ⟶ Q x" shows "(∀x. P x) ⟶ (∀x. Q x)" proof (rule impI) assume "∀x. P x" show "∀x. Q x" proof (rule allI) fix a have "P a" using `∀x. P x` by (rule allE) have "P a ⟶ Q a" using assms(1) by (rule allE) thus "Q a" using `P a` by (rule mp) qed qed text {* --------------------------------------------------------------- Ejercicio 5. Demostrar ∀x. P x ⟶ ¬(Q x) ⊢ ¬(∃x. P x ∧ Q x) ------------------------------------------------------------------ *} -- "La demostración automática es" lemma ejercicio_5a: "∀x. P x ⟶ ¬(Q x) ⟹ ¬(∃x. P x ∧ Q x)" by auto -- "La demostración estructurada es" lemma ejercicio_5b: assumes "∀x. P x ⟶ ¬(Q x)" shows "¬(∃x. P x ∧ Q x)" proof assume "∃x. P x ∧ Q x" then obtain a where "P a ∧ Q a" .. hence "P a" .. have "P a ⟶ ¬(Q a)" using assms .. hence "¬(Q a)" using `P a` .. have "Q a" using `P a ∧ Q a` .. with `¬(Q a)` show False .. qed -- "La demostración estructurada es" lemma ejercicio_5c: assumes "∀x. P x ⟶ ¬(Q x)" shows "¬(∃x. P x ∧ Q x)" proof (rule notI) assume "∃x. P x ∧ Q x" then obtain a where "P a ∧ Q a" by (rule exE) hence "P a" by (rule conjunct1) have "P a ⟶ ¬(Q a)" using assms by (rule allE) hence "¬(Q a)" using `P a` by (rule mp) have "Q a" using `P a ∧ Q a` by (rule conjunct2) with `¬(Q a)` show False by (rule notE) qed text {* --------------------------------------------------------------- Ejercicio 9. Demostrar ∃x. P a ⟶ Q x ⊢ P a ⟶ (∃x. Q x) ------------------------------------------------------------------ *} -- "La demostración automática es" lemma ejercicio_9a: "∃x. P a ⟶ Q x ⟹ P a ⟶ (∃x. Q x)" by auto -- "La demostración estructurada es" lemma ejercicio_9b: assumes "∃x. P a ⟶ Q x" shows "P a ⟶ (∃x. Q x)" proof assume "P a" obtain b where "P a ⟶ Q b" using assms .. hence "Q b" using `P a` .. thus "∃x. Q x" .. qed -- "La demostración detallada es" lemma ejercicio_9c: assumes "∃x. P a ⟶ Q x" shows "P a ⟶ (∃x. Q x)" proof (rule impI) assume "P a" obtain b where "P a ⟶ Q b" using assms by (rule exE) hence "Q b" using `P a` by (rule mp) thus "∃x. Q x" by (rule exI) qed text {* --------------------------------------------------------------- Ejercicio 10. Demostrar P a ⟶ (∃x. Q x) ⊢ ∃x. P a ⟶ Q x ------------------------------------------------------------------ *} -- "La demostración automática es" lemma ejercicio_10a: "P a ⟶ (∃x. Q x) ⟹ ∃x. P a ⟶ Q x" by auto -- "La demostración estructurada es" lemma ejercicio_10b: fixes P Q :: "'b ⇒ bool" assumes "P a ⟶ (∃x. Q x)" shows "∃x. P a ⟶ Q x" proof - have "¬(P a) ∨ P a" .. thus "∃x. P a ⟶ Q x" proof assume "¬(P a)" have "P a ⟶ Q a" proof assume "P a" with `¬(P a)` show "Q a" .. qed thus "∃x. P a ⟶ Q x" .. next assume "P a" with assms have "∃x. Q x" by (rule mp) then obtain b where "Q b" .. have "P a ⟶ Q b" proof assume "P a" note `Q b` thus "Q b" . qed thus "∃x. P a ⟶ Q x" .. qed qed -- "La demostración detallada es" lemma ejercicio_10c: fixes P Q :: "'b ⇒ bool" assumes "P a ⟶ (∃x. Q x)" shows "∃x. P a ⟶ Q x" proof - have "¬(P a) ∨ P a" by (rule excluded_middle) thus "∃x. P a ⟶ Q x" proof (rule disjE) assume "¬(P a)" have "P a ⟶ Q a" proof (rule impI) assume "P a" with `¬(P a)` show "Q a" by (rule notE) qed thus "∃x. P a ⟶ Q x" by (rule exI) next assume "P a" with assms have "∃x. Q x" by (rule mp) then obtain b where "Q b" by (rule exE) have "P a ⟶ Q b" proof (rule impI) assume "P a" note `Q b` thus "Q b" by this qed thus "∃x. P a ⟶ Q x" by (rule exI) qed qed text {* --------------------------------------------------------------- Ejercicio 20. Demostrar {∀x y z. R x y ∧ R y z ⟶ R x z, ∀x. ¬(R x x)} ⊢ ∀x y. R x y ⟶ ¬(R y x) ------------------------------------------------------------------ *} -- "La demostración automática es" lemma ejercicio_20a: "⟦∀x y z. R x y ∧ R y z ⟶ R x z; ∀x. ¬(R x x)⟧ ⟹ ∀x y. R x y ⟶ ¬(R y x)" by metis -- "La demostración estructurada es" lemma ejercicio_20b: assumes "∀x y z. R x y ∧ R y z ⟶ R x z" "∀x. ¬(R x x)" shows "∀x y. R x y ⟶ ¬(R y x)" proof (rule allI)+ fix a b show "R a b ⟶ ¬(R b a)" proof assume "R a b" show "¬(R b a)" proof assume "R b a" show False proof - have "R a b ∧ R b a" using `R a b` `R b a` .. have "∀y z. R a y ∧ R y z ⟶ R a z" using assms(1) .. hence "∀z. R a b ∧ R b z ⟶ R a z" .. hence "R a b ∧ R b a ⟶ R a a" .. hence "R a a" using `R a b ∧ R b a` .. have "¬(R a a)" using assms(2) .. thus False using `R a a` .. qed qed qed qed -- "La demostración detallada es" lemma ejercicio_20c: assumes "∀x y z. R x y ∧ R y z ⟶ R x z" "∀x. ¬(R x x)" shows "∀x y. R x y ⟶ ¬(R y x)" proof (rule allI)+ fix a b show "R a b ⟶ ¬(R b a)" proof (rule impI) assume "R a b" show "¬(R b a)" proof (rule notI) assume "R b a" show False proof - have "R a b ∧ R b a" using `R a b` `R b a` by (rule conjI) have "∀y z. R a y ∧ R y z ⟶ R a z" using assms(1) by (rule allE) hence "∀z. R a b ∧ R b z ⟶ R a z" by (rule allE) hence "R a b ∧ R b a ⟶ R a a" by (rule allE) hence "R a a" using `R a b ∧ R b a` by (rule mp) have "¬(R a a)" using assms(2) by (rule allE) thus False using `R a a` by (rule notE) qed qed qed qed text {* --------------------------------------------------------------- Ejercicio 27. Demostrar o refutar ((\<forall>x. P x) \<or> (\<forall>x. Q x)) \<longleftrightarrow> (\<forall>x. P x \<or> Q x) ------------------------------------------------------------------ *} lemma ejercicio_27: "((\<forall>x. P x) \<or> (\<forall>x. Q x)) \<longleftrightarrow> (\<forall>x. P x \<or> Q x)" oops (* Auto Quickcheck found a counterexample: P = {a1} Q = {a2} *) end |