Diferencia entre revisiones de «Relación 4»
De Razonamiento automático (2014-15)
(Página creada con '<source lang="isar"> header {* R4: Cons inverso *} theory R4 imports Main begin text {* --------------------------------------------------------------------- Ejercicio 1...') |
m (Texto reemplazado: «"isar"» por «"isabelle"») |
||
(No se muestran 10 ediciones intermedias de 9 usuarios) | |||
Línea 1: | Línea 1: | ||
− | <source lang=" | + | <source lang="isabelle"> |
header {* R4: Cons inverso *} | header {* R4: Cons inverso *} | ||
Línea 17: | Línea 17: | ||
--------------------------------------------------------------------- | --------------------------------------------------------------------- | ||
*} | *} | ||
+ | |||
+ | -- "davoremar,javrodviv1, jeshorcob, emimarriv, juacorvic, marnajgom, domcadgom, carvelcab" | ||
fun snoc :: "'a list ⇒ 'a ⇒ 'a list" where | fun snoc :: "'a list ⇒ 'a ⇒ 'a list" where | ||
− | "snoc xs a = | + | "snoc [] a = [a]" |
+ | | "snoc (x#xs) a = x # (snoc xs a)" | ||
text {* | text {* | ||
Línea 27: | Línea 30: | ||
--------------------------------------------------------------------- | --------------------------------------------------------------------- | ||
*} | *} | ||
+ | |||
+ | -- "davoremar,javrodviv1, jeshorcob, emimarriv, juacorvic, marnajgom, domcadgom, carvelcab" | ||
lemma "snoc xs a = xs @ [a]" | lemma "snoc xs a = xs @ [a]" | ||
− | + | by (induct xs) auto | |
+ | |||
+ | (*Pedrosrei:no hace falta usar auto, sirve simp_all*) | ||
text {* | text {* | ||
Línea 37: | Línea 44: | ||
--------------------------------------------------------------------- | --------------------------------------------------------------------- | ||
*} | *} | ||
+ | |||
+ | -- "davoremar,javrodviv1, jeshorcob, emimarriv, juacorvic, marnajgom, domcadgom, carvelcab" | ||
lemma snoc_append: "snoc xs a = xs @ [a]" | lemma snoc_append: "snoc xs a = xs @ [a]" | ||
− | + | proof (induct xs) | |
+ | show "snoc [] a = [] @ [a]" by simp | ||
+ | next | ||
+ | fix x xs | ||
+ | assume HI: "snoc xs a = xs @ [a]" | ||
+ | have "snoc (x#xs) a = x # (snoc xs a)" by simp | ||
+ | also have "... = x # (xs @ [a])" using HI by simp | ||
+ | finally show "snoc (x#xs) a = (x#xs) @ [a]" by simp | ||
+ | qed | ||
text {* | text {* | ||
Línea 47: | Línea 64: | ||
--------------------------------------------------------------------- | --------------------------------------------------------------------- | ||
*} | *} | ||
+ | |||
+ | -- "davoremar,javrodviv1, jeshorcob, marnajgom" | ||
lemma "rev (x # xs) = snoc (rev xs) x" | lemma "rev (x # xs) = snoc (rev xs) x" | ||
− | + | by (auto simp add: snoc_append) | |
+ | |||
+ | (*Pedrosrei:no hace falta usar auto, sirve simp*) | ||
+ | |||
+ | -- "juacorvic, domcadgom" | ||
+ | lemma "rev (x # xs) = snoc (rev xs) x" | ||
+ | by (simp add: snoc_append) | ||
+ | |||
+ | --"carvelcab" | ||
+ | lemma "rev (x # xs) = snoc (rev xs) x" | ||
+ | by (cases xs) auto | ||
text {* | text {* | ||
Línea 57: | Línea 86: | ||
--------------------------------------------------------------------- | --------------------------------------------------------------------- | ||
*} | *} | ||
+ | |||
+ | -- "davoremar,javrodviv1, jeshorcob, juacorvic, marnajgom, domcadgom, carvelcab" | ||
lemma "rev (x # xs) = snoc (rev xs) x" | lemma "rev (x # xs) = snoc (rev xs) x" | ||
− | + | proof - | |
+ | have "rev (x # xs) = (rev xs) @ [x]" by simp | ||
+ | also have "... = snoc (rev xs) x" by (simp add:snoc_append) | ||
+ | finally show "rev (x # xs) = snoc (rev xs) x" by simp | ||
+ | qed | ||
end | end | ||
</source> | </source> |
Revisión actual del 10:23 16 jul 2018
header {* R4: Cons inverso *}
theory R4
imports Main
begin
text {*
---------------------------------------------------------------------
Ejercicio 1. Definir recursivamente la función
snoc :: "'a list ⇒ 'a ⇒ 'a list"
tal que (snoc xs a) es la lista obtenida al añadir el elemento a al
final de la lista xs. Por ejemplo,
value "snoc [2,5] (3::int)" == [2,5,3]
Nota: No usar @.
---------------------------------------------------------------------
*}
-- "davoremar,javrodviv1, jeshorcob, emimarriv, juacorvic, marnajgom, domcadgom, carvelcab"
fun snoc :: "'a list ⇒ 'a ⇒ 'a list" where
"snoc [] a = [a]"
| "snoc (x#xs) a = x # (snoc xs a)"
text {*
---------------------------------------------------------------------
Ejercicio 2. Demostrar automáticamente el siguiente teorema
snoc xs a = xs @ [a]
---------------------------------------------------------------------
*}
-- "davoremar,javrodviv1, jeshorcob, emimarriv, juacorvic, marnajgom, domcadgom, carvelcab"
lemma "snoc xs a = xs @ [a]"
by (induct xs) auto
(*Pedrosrei:no hace falta usar auto, sirve simp_all*)
text {*
---------------------------------------------------------------------
Ejercicio 3. Demostrar detalladamente el siguiente teorema
snoc xs a = xs @ [a]
---------------------------------------------------------------------
*}
-- "davoremar,javrodviv1, jeshorcob, emimarriv, juacorvic, marnajgom, domcadgom, carvelcab"
lemma snoc_append: "snoc xs a = xs @ [a]"
proof (induct xs)
show "snoc [] a = [] @ [a]" by simp
next
fix x xs
assume HI: "snoc xs a = xs @ [a]"
have "snoc (x#xs) a = x # (snoc xs a)" by simp
also have "... = x # (xs @ [a])" using HI by simp
finally show "snoc (x#xs) a = (x#xs) @ [a]" by simp
qed
text {*
---------------------------------------------------------------------
Ejercicio 4. Demostrar automáticamente el siguiente lema
rev (x # xs) = snoc (rev xs) x"
---------------------------------------------------------------------
*}
-- "davoremar,javrodviv1, jeshorcob, marnajgom"
lemma "rev (x # xs) = snoc (rev xs) x"
by (auto simp add: snoc_append)
(*Pedrosrei:no hace falta usar auto, sirve simp*)
-- "juacorvic, domcadgom"
lemma "rev (x # xs) = snoc (rev xs) x"
by (simp add: snoc_append)
--"carvelcab"
lemma "rev (x # xs) = snoc (rev xs) x"
by (cases xs) auto
text {*
---------------------------------------------------------------------
Ejercicio 5. Demostrar detalladamente el siguiente lema
rev (x # xs) = snoc (rev xs) x"
---------------------------------------------------------------------
*}
-- "davoremar,javrodviv1, jeshorcob, juacorvic, marnajgom, domcadgom, carvelcab"
lemma "rev (x # xs) = snoc (rev xs) x"
proof -
have "rev (x # xs) = (rev xs) @ [x]" by simp
also have "... = snoc (rev xs) x" by (simp add:snoc_append)
finally show "rev (x # xs) = snoc (rev xs) x" by simp
qed
end