LMF2019: Desarrollo de teorías formalizadas con Isabelle/HOL
En la clase de hoy del curso de Lógica matemática y fundamentos se ha estudiado cómo desarrollar en Isabelle/HOL teorías axiomáticas usando entornos locales (“locales”) y clases de tipos (“class”). Se ha aplicado al desarrollo de las teorías de grupos y a las de órdenes. videoconferencia.
La clase se ha dado mediante videoconferencia y los vídeos correspondientes son:
- Primera parte:
- Segunda parte:
La teoría con los ejemplos presentados en la clase es la siguiente:
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 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
chapter ‹Desarrollo de teorías formalizadas› theory T11_Desarrollo_de_teorias_formalizadas imports Main begin section ‹Desarrollo de la teoría de grupos› text ‹El objetivo de este tema es mostrar cómo se puede trabajar en estructuras algebraicas por medio de locales. Se usará como ejemplo la teoría de grupos.› text ‹Ejemplo 1. Un grupo es una estructura (G,·,𝟭,^) tal que * G es un conjunto, * · es una operación binaria en G, * 𝟭 es un elemento de G y * ^ es una función de G en G tales que se cumplen las siguientes propiedades: * asociativa: ∀x y z. x ⋅ (y ⋅ z) = (x ⋅ y) ⋅ z * neutro por la izquierda: ∀x. 𝟭 ⋅ x = x * inverso por la izquierda: ∀x. x^ ⋅ x = 𝟭 Definir el entorno axiomático de los grupos.› locale grupo = fixes prod :: "['a, 'a] ⇒ 'a" (infixl "⋅" 70) and neutro ("𝟭") and inverso ("_^" [100] 100) assumes asociativa: "(x ⋅ y) ⋅ z = x ⋅ (y ⋅ z)" and neutro_i: "𝟭 ⋅ x = x" and inverso_i: "x^ ⋅ x = 𝟭" text ‹Notas sobre notación: * El producto es ⋅ y se escribe con \ cdot (sin espacio entre ellos). * El neutro es 𝟭 y se escribe con \ y one (sin espacio entre ellos). * El inverso de x es x^ y se escribe pulsando 2 veces en ^.› text ‹A continuación se crea un contexto en el que se supone la notación y axiomas de grupos. En el contexto se demuestran propiedades de los grupos.› context grupo begin thm neutro_i text ‹Ejemplo 2. En los grupos, x^ también es el inverso de x por la derecha; es decir x ⋅ x^ = 𝟭› ― ‹La demostración automática (obtenida con Sledgehammer) es› lemma "x ⋅ x^ = 𝟭" (* sledgehammer *) by (metis asociativa inverso_i neutro_i) ― ‹La demostración detallada es› lemma inverso_d: "x ⋅ x^ = 𝟭" proof - have "x ⋅ x^ = 𝟭 ⋅ (x ⋅ x^)" by (simp only: neutro_i) also have "… = (𝟭 ⋅ x) ⋅ x^" by (simp only: asociativa) also have "… = (((x^)^ ⋅ x^) ⋅ x) ⋅ x^" by (simp only: inverso_i) also have "… = ((x^)^ ⋅ (x^ ⋅ x)) ⋅ x^" by (simp only: asociativa) also have "… = ((x^)^ ⋅ 𝟭) ⋅ x^" by (simp only: inverso_i) also have "… = (x^)^ ⋅ (𝟭 ⋅ x^)" by (simp only: asociativa) also have "… = (x^)^ ⋅ x^" by (simp only: neutro_i) also have "… = 𝟭" by (simp only: inverso_i) finally show ?thesis by this qed text ‹Ejemplo 2. En los grupos, 𝟭 también es el neutro por la derecha; es decir x ⋅ 𝟭 = x› ― ‹La demostración automática (obtenida con Sledgehammer) es› lemma "x ⋅ 𝟭 = x" by (metis asociativa inverso_i neutro_i) ― ‹La demostración detallada es› lemma neutro_d: "x ⋅ 𝟭 = x" proof - have "x ⋅ 𝟭 = x ⋅ (x^ ⋅ x)" by (simp only: inverso_i) also have "… = (x ⋅ x^) ⋅ x" by (simp only: asociativa) also have "… = 𝟭 ⋅ x" by (simp only: inverso_d) also have "… = x" by (simp only: neutro_i) finally show "x ⋅ 𝟭 = x" by this qed text ‹Ejemplo 3. En los grupos, se tiene la propiedad cancelativa por la izquierda; es decir, x ⋅ y = x ⋅ z syss y = z› ― ‹La demostración automática (obtenida con Sledgehammer) es› lemma "(x ⋅ y = x ⋅ z) = (y = z)" by (metis asociativa inverso_i neutro_i) ― ‹La demostración detallada es› lemma cancelativa_i: "(x ⋅ y = x ⋅ z) = (y = z)" proof assume "x ⋅ y = x ⋅ z" then have "x^ ⋅ (x ⋅ y) = x^ ⋅ (x ⋅ z)" (* thm arg_cong arg_cong[of "x ⋅ y"] arg_cong[of "x ⋅ y" "x ⋅ z"] *) by (simp only: arg_cong[of "x ⋅ y" "x ⋅ z"]) then have "(x^ ⋅ x) ⋅ y = (x^ ⋅ x) ⋅ z" by (simp only: asociativa) then have "𝟭 ⋅ y = 𝟭 ⋅ z" by (simp only: inverso_i) thus "y = z" by (simp only: neutro_i) next assume "y = z" then show "x ⋅ y = x ⋅ z" (* thm arg_cong arg_cong [of "y" "z"] arg_cong [of _ "z"] *) by (simp only: arg_cong [of "y" "z"]) qed text ‹Ejemplo 4. En los grupos, el elemento neutro por la izquierda es único; es decir, si e es un elemento tal que para todo x se tiene que e ⋅ x = x, entonces e = 𝟭.› ― ‹La demostración automática es (obtenida con Sledgehammer) es› lemma assumes "e ⋅ x = x" shows "𝟭 = e" using assms by (metis asociativa inverso_d neutro_d) ― ‹La demostración estructurada es› lemma unicidad_neutro_i: assumes "e ⋅ x = x" shows "𝟭 = e" proof - have "𝟭 = x ⋅ x^" by (simp only: inverso_d) also have "... = (e ⋅ x) ⋅ x^" (* thm assms assms[symmetric] *) using assms [symmetric] (* thm arg_cong arg_cong [of "x" "e ⋅ x" "λy. y ⋅ x^"] *) by (rule arg_cong [of "x" "e ⋅ x" "λy. y ⋅ x^"]) also have "... = e ⋅ (x ⋅ x^)" by (simp only: asociativa) also have "... = e ⋅ 𝟭" by (simp only: inverso_d) also have "... = e" by (simp only: neutro_d) finally show ?thesis by this qed text ‹Ejemplo 5. En los grupos, los inversos por la izquierda son únicos; es decir, si x' es un elemento tal que x' ⋅ x = 𝟭, entonces x^ = x'.› ― ‹La demostración automática (obtenida con Sledgehammer) es› lemma assumes "x' ⋅ x = 𝟭" shows "x^ = x'" using assms by (metis asociativa inverso_i neutro_i) ― ‹La demostración estructurada es› lemma unicidad_inverso_i: assumes "x' ⋅ x = 𝟭" shows "x^ = x'" proof - have "x^ = 𝟭 ⋅ x^" by (simp only: neutro_i) also have "... = (x' ⋅ x) ⋅ x^" using assms [symmetric] by (simp only: arg_cong [of "𝟭" "x' ⋅ x"]) also have "... = x' ⋅ (x ⋅ x^)" by (simp only: asociativa) also have "... = x' ⋅ 𝟭" by (simp only: inverso_d) also have "... = x'" by (simp only: neutro_d) finally show ?thesis by this qed text ‹Ejemplo 6. En los grupos, es inverso de un producto es el producto de los inversos cambiados de orden; es decir, (x ⋅ y)^ = y^ ⋅ x^› ― ‹La demostración automática (obtenida con Sledgehammer) es› lemma "(x ⋅ y)^ = y^ ⋅ x^" by (metis asociativa inverso_d neutro_d) ― ‹La demostración detallada es› lemma inversa_producto: "(x ⋅ y)^ = y^ ⋅ x^" proof (rule unicidad_inverso_i) show "(y^ ⋅ x^) ⋅ (x ⋅ y) = 𝟭" proof - have "(y^ ⋅ x^) ⋅ (x ⋅ y) = (y^ ⋅ (x^ ⋅ x)) ⋅ y" by (simp only: asociativa) also have "... = (y^ ⋅ 𝟭) ⋅ y" by (simp only: inverso_i) also have "... = y^ ⋅ y" by (simp only: neutro_d) also have "... = 𝟭" by (simp only: inverso_i) finally show ?thesis by this qed qed text ‹Ejemplo 7. En los grupos, el inverso del inverso es el propio elemento; es decir, (x^)^ = x› ― ‹La demostración automática (obtenida con Sledgehammer) es› lemma "(x^)^ = x" using inverso_d unicidad_inverso_i by blast ― ‹La demostración estructurada es› lemma inverso_inverso: "(x^)^ = x" proof (rule unicidad_inverso_i) show "x ⋅ x^ = 𝟭" by (simp only: inverso_d) qed text ‹Ejemplo 8. En los grupos, la función inversa es inyectiva; es decir, si x e y tienen los mismos inversos, entonces son iguales.› ― ‹La demostración automática es (obtenida con Sledgehammer) es› lemma assumes "x^ = y^" shows "x = y" using assms by (metis inverso_inverso) ― ‹La demostración automática estructurada es› lemma inversa_inyectiva: assumes "x^ = y^" shows "x = y" proof - have "(x^)^ = (y^)^" using assms by (simp only: arg_cong [of "x^" "y^"]) then show "x = y" by (simp only: inverso_inverso) qed thm neutro_i thm inversa_inyectiva end section ‹Teorías de órdenes mediante clases› text ‹El tutorial sobre clases está en la teoría Clases.thy. La clase de los órdenes es la colección de los tipos que poseen una relación ≼ verificando las siguientes propiedades · reflexiva: x ≼ x · transitiva: ⟦x ≼ y; y ≼ z⟧ ⟹ x ≼ z · antisimétrica: ⟦x ≼ y; y ≼ x⟧ ⟹ x = y › class orden = fixes menor_ig :: "'a ⇒ 'a ⇒ bool" (infix "≼" 50) assumes refl: "x ≼ x" and trans: "⟦x ≼ y; y ≼ z⟧ ⟹ x ≼ z" and antisim: "⟦x ≼ y; y ≼ x⟧ ⟹ x = y" text ‹Ha generado los teoremas correspondientes a los axiomas. Pueden consultarse mediante thm como se muestra a continuación.› thm trans text ‹Se inicia el contexto orden en el que se van a realizar definiciones y demostraciones.› context orden begin text ‹x es menor que y si x es menor o igual que y y no es menos o igual que x.› definition menor :: "'a ⇒ 'a ⇒ bool" (infix "≺" 50) where "x ≺ y ⟷ x ≼ y ∧ ¬ y ≼ x" thm menor_def text ‹La relación menor es irreflexiva.› lemma irrefl: "¬ x ≺ x" by (simp add: menor_def) text ‹La relación menor es transitiva.› (* Demostración declarativa *) lemma assumes "x ≺ y" "y ≺ z" shows "x ≺ z" proof - have 1: "x ≼ y ∧ ¬ y ≼ x" using assms(1) by (simp add: menor_def) have 2: "y ≼ z ∧ ¬ z ≼ y" using assms(2) by (simp add: menor_def) have "x ≼ z" proof - have "x ≼ y" using 1 by (rule conjunct1) moreover have "y ≼ z" using 2 by (rule conjunct1) ultimately show "x ≼ z" by (rule trans) qed moreover have "¬ z ≼ x" proof (rule notI) assume "z ≼ x" moreover have "x ≼ y" using 1 by (rule conjunct1) ultimately have "z ≼ y" by (rule trans) have "¬ z ≼ y" using 2 by (rule conjunct2) then show False using ‹z ≼ y› by (rule notE) qed have "x ≼ z ∧ ¬ z ≼ x" using ‹x ≼ z› ‹¬ z ≼ x› by (rule conjI) then show "x ≺ z" by (simp add: menor_def) qed (* Demostración aplicativa *) lemma "⟦x ≺ y; y ≺ z⟧ ⟹ x ≺ z" apply (unfold menor_def) (* ⟦x ≼ y ∧ ¬ y ≼ x; y ≼ z ∧ ¬ z ≼ y⟧ ⟹ x ≼ z ∧ ¬ z ≼ x *) apply (auto intro: trans) (* *) done (* Demostración automática *) lemma menor_trans: "⟦x ≺ y; y ≺ z⟧ ⟹ x ≺ z" by (auto simp: menor_def intro: trans) text ‹La relación menor es asimétrica; es decir, si x ≺ y e y ≺ x, entonces se verifica cualquier propiedad P. › lemma asimetrica: "x ≺ y ⟹ y ≺ x ⟹ P" by (simp add: menor_def) end subsection ‹Subclase› text ‹Un orden lineal es un orden en que cada par de elementos son comparables.› class ordenLineal = orden + assumes lineal: "x ≼ y ∨ y ≼ x" begin text ‹En los órdenes lineales se tiene que x ≺ y ∨ x = y ∨ y ≺ x.› (* Demostración automática *) lemma "x ≺ y ∨ x = y ∨ y ≺ x" using antisim lineal menor_def by auto (* Demostración aplicativa *) lemma "x ≺ y ∨ x = y ∨ y ≺ x" apply (unfold menor_def) (* (x ≼ y ∧ ¬ y ≼ x) ∨ x = y ∨ (y ≼ x ∧ ¬ x ≼ y) *) apply auto (* 1. ⟦x ≠ y; ¬ x ≼ y⟧ ⟹ y ≼ x 2. ⟦x ≠ y; y ≼ x; x ≼ y⟧ ⟹ False *) apply (cut_tac x=x and y=y in lineal) (* 1. ⟦x ≠ y; ¬ x ≼ y; x ≼ y ∨ y ≼ x⟧ ⟹ y ≼ x 2. ⟦x ≠ y; y ≼ x; x ≼ y⟧ ⟹ False *) apply (erule disjE) (* 1. ⟦x ≠ y; ¬ x ≼ y; x ≼ y⟧ ⟹ y ≼ x 2. ⟦x ≠ y; ¬ x ≼ y; y ≼ x⟧ ⟹ y ≼ x 3. ⟦x ≠ y; y ≼ x; x ≼ y⟧ ⟹ False *) apply (erule_tac P="x ≼ y" in notE) (* 1. ⟦x ≠ y; x ≼ y⟧ ⟹ x ≼ y 2. ⟦x ≠ y; ¬ x ≼ y; y ≼ x⟧ ⟹ y ≼ x 3. ⟦x ≠ y; y ≼ x; x ≼ y⟧ ⟹ False *) apply assumption (* 1. ⟦x ≠ y; ¬ x ≼ y; y ≼ x⟧ ⟹ y ≼ x 2. ⟦x ≠ y; y ≼ x; x ≼ y⟧ ⟹ False *) apply assumption (* 1. ⟦x ≠ y; y ≼ x; x ≼ y⟧ ⟹ False *) apply (drule antisim) (* 1. ⟦x ≠ y; x ≼ y⟧ ⟹ x ≼ y 2. ⟦x ≠ y; x ≼ y; y = x⟧ ⟹ False *) apply assumption (* 1. ⟦x ≠ y; x ≼ y; y = x⟧ ⟹ False *) apply (erule notE) (* 1. ⟦x ≼ y; y = x⟧ ⟹ x = y *) apply (erule sym) (* *) done end section ‹Teoría de órdenes mediante ámbitos ("Locales")› text ‹Un orden es una estructura con una relación reflexiva, transitiva y antisimétrica.› locale Orden = fixes menor_ig :: "'a ⇒ 'a ⇒ bool" (infix "⊑" 50) assumes refl: "x ⊑ x" and trans: "⟦x ⊑ y; y ⊑ z⟧ ⟹ x ⊑ z" and antisim: "⟦x ⊑ y; y ⊑ x⟧ ⟹ x = y" text ‹Los teoremas se diferencian por el nombre y el ámbito. Por ejemplo, refl: ?x ≼ ?x Orden.refl: Orden ?menor_ig ⟹ ?menor_ig ?x ?x Orden_def: Orden ?menor_ig ≡ (∀x. ?menor_ig x x) ∧ (∀x y z. ?menor_ig x y ⟶ ?menor_ig y z ⟶ ?menor_ig x z) ∧ (∀x y. ?menor_ig x y ⟶ ?menor_ig y x ⟶ x = y) › thm refl thm Orden.refl thm Orden_def text ‹Un orden lineal es un orden en el que todos los pares de elementos son comparables.› locale OrdenLineal = Orden + assumes lineal: "x ⊑ y ∨ y ⊑ x" text ‹Los boooleanos está ordenados con el condicional.› interpretation Orden_imp: Orden "λx y. x ⟶ y" proof fix P show "P ⟶ P" by simp next fix P Q R show "P ⟶ Q ⟹ Q ⟶ R ⟹ P ⟶ R" by simp next fix P Q show "P ⟶ Q ⟹ Q ⟶ P ⟹ P = Q" by blast qed text ‹Los naturales con la relación de divisibilidad es un conjunto ordenado.› interpretation Orden_dvd: Orden "(dvd) :: nat ⇒ nat ⇒ bool" proof fix x :: nat show "x dvd x" by simp next fix x y z :: nat show "⟦x dvd y; y dvd z⟧ ⟹ x dvd z" using dvd_trans by blast next fix x y :: nat show "⟦x dvd y; y dvd x⟧ ⟹ x = y" by (simp add: dvd_antisym) qed section ‹Bibliografía› text ‹ + "Haskell-style type classes with Isabelle/Isar" ~ F. Haftmann. http://bit.ly/2E55pAJ + "Tutorial to locales and locale interpretation" ~ C. Ballarin. http://bit.ly/2E3ozXB › end |