Acciones

Diferencia entre revisiones de «Relación 4»

De Razonamiento automático (2017-18)

m (Protegió «Relación 4» ([edit=sysop] (indefinido) [move=sysop] (indefinido)))
Línea 19: Línea 19:
 
*}
 
*}
  
(*anddonram edupalhid luicedval cesgongut jescudero rafcabgon diwu2 macmerflo rafferrod*)
+
(* anddonram edupalhid luicedval cesgongut jescudero rafcabgon diwu2
 +
  macmerflo rafferrod *)  
 
fun todos :: "('a ⇒ bool) ⇒ 'a list ⇒ bool" where
 
fun todos :: "('a ⇒ bool) ⇒ 'a list ⇒ bool" where
   "todos p [] = True"
+
   "todos p []     = True"
 
| "todos p (x#xs) = (p x ∧ todos p xs)"
 
| "todos p (x#xs) = (p x ∧ todos p xs)"
 
  
 
value "todos (λx. 1<length x) [[2,1,4],[1,3::nat]] = True"
 
value "todos (λx. 1<length x) [[2,1,4],[1,3::nat]] = True"
Línea 41: Línea 41:
 
*}
 
*}
  
(*anddonram edupalhid luicedval cesgongut jescudero rafcabgon diwu2 macmerflo rafferrod*)
+
(* anddonram edupalhid luicedval cesgongut jescudero rafcabgon diwu2
 +
  macmerflo rafferrod *)  
 
fun algunos  :: "('a ⇒ bool) ⇒ 'a list ⇒ bool" where
 
fun algunos  :: "('a ⇒ bool) ⇒ 'a list ⇒ bool" where
   "algunos p [] = False"
+
   "algunos p []     = False"
 
|  "algunos p (x#xs) = (p x ∨ algunos p xs)"
 
|  "algunos p (x#xs) = (p x ∨ algunos p xs)"
  
Línea 55: Línea 56:
 
   ---------------------------------------------------------------------  
 
   ---------------------------------------------------------------------  
 
*}
 
*}
  (*anddonram edupalhid luicedval cesgongut jescudero rafcabgon diwu2 macmerflo rafferrod*)
+
  (* anddonram edupalhid luicedval cesgongut jescudero rafcabgon diwu2
 +
    macmerflo rafferrod *)  
 
lemma "todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)"
 
lemma "todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)"
 
   by (induct xs) auto
 
   by (induct xs) auto
 
   
 
   
 
 
text {*
 
text {*
 
   ---------------------------------------------------------------------  
 
   ---------------------------------------------------------------------  
Línea 67: Línea 68:
 
*}
 
*}
  
 
+
(* anddonram [conmutatividad and porque no sé hacerlo de otra forma] *)
(*anddonram[conmutatividad and porque no sé hacerlo de otra forma] *)
 
 
lemma and_comm: "(a ∧ b) = (b ∧ a)"
 
lemma and_comm: "(a ∧ b) = (b ∧ a)"
 
   by (cases a) auto
 
   by (cases a) auto
  
(*anddonram diwu2*)
+
(* anddonram diwu2 *)
 
lemma "todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)"
 
lemma "todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)"
 
proof (induct xs)
 
proof (induct xs)
Línea 79: Línea 79:
 
   fix a xs
 
   fix a xs
 
   assume HI:"todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)"
 
   assume HI:"todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)"
   have "todos (λx. P x ∧ Q x) (a # xs) = (P a ∧ Q a ∧ todos (λx. P x ∧ Q x) xs)" by simp
+
   have "todos (λx. P x ∧ Q x) (a # xs) =  
   also have "... = (P a ∧ Q a ∧ todos P xs ∧ todos Q xs)" using HI by simp
+
      (P a ∧ Q a ∧ todos (λx. P x ∧ Q x) xs)" by simp
   also have "... = (P a ∧ Q a ∧ todos Q xs ∧ todos P xs)" by (simp add:and_comm)
+
   also have "... = (P a ∧ Q a ∧ todos P xs ∧ todos Q xs)"  
 +
    using HI by simp
 +
   also have "... = (P a ∧ Q a ∧ todos Q xs ∧ todos P xs)"  
 +
    by (simp add: and_comm)
 
   also have "... = (P a ∧ todos Q (a # xs) ∧ todos P xs)" by simp
 
   also have "... = (P a ∧ todos Q (a # xs) ∧ todos P xs)" by simp
   also have "... = (P a ∧ todos P xs ∧ Q a ∧ todos Q xs)" by (simp add:and_comm)
+
   also have "... = (P a ∧ todos P xs ∧ Q a ∧ todos Q xs)"  
   finally show "todos (λx. P x ∧ Q x) (a # xs) = (todos P (a # xs) ∧ todos Q (a # xs))"
+
    by (simp add: and_comm)
 +
   finally show "todos (λx. P x ∧ Q x) (a # xs) =  
 +
                (todos P (a # xs) ∧ todos Q (a # xs))"
 
     by simp
 
     by simp
 
qed
 
qed
Línea 103: Línea 108:
 
qed
 
qed
  
(*rafferrod*)
+
(* rafferrod *)
 
lemma "todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)"
 
lemma "todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)"
 
proof (induct xs)
 
proof (induct xs)
Línea 110: Línea 115:
 
   fix a xs
 
   fix a xs
 
   assume HI: "todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)"
 
   assume HI: "todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)"
   have "todos (λx. P x ∧ Q x) (a#xs) = (P a ∧ Q a ∧ todos (λx. P x ∧ Q x) xs)" by simp
+
   have "todos (λx. P x ∧ Q x) (a#xs) =  
   also have "... = (P a ∧ Q a ∧ todos P xs ∧ todos Q xs)" using HI by simp
+
      (P a ∧ Q a ∧ todos (λx. P x ∧ Q x) xs)" by simp
 +
   also have "... = (P a ∧ Q a ∧ todos P xs ∧ todos Q xs)"  
 +
    using HI by simp
 
   also have "... = (P a ∧ todos P (xs) ∧ Q a ∧ todos Q (xs))" by auto
 
   also have "... = (P a ∧ todos P (xs) ∧ Q a ∧ todos Q (xs))" by auto
   finally show "todos (λx. P x ∧ Q x) (a#xs) = (todos P (a#xs) ∧ todos Q (a#xs))" by simp
+
   finally show "todos (λx. P x ∧ Q x) (a#xs) =  
 +
                (todos P (a#xs) ∧ todos Q (a#xs))" by simp
 
qed
 
qed
  
Línea 123: Línea 131:
 
*}
 
*}
  
(*anddonram edupalhid cesgongut luicedval jescudero rafcabgon diwu2 macmerflo cesgongut rafferrod*)
+
(* anddonram edupalhid cesgongut luicedval jescudero rafcabgon diwu2
 +
  macmerflo cesgongut rafferrod *)  
 
lemma "todos P (x @ y) = (todos P x ∧ todos P y)"
 
lemma "todos P (x @ y) = (todos P x ∧ todos P y)"
 
   by (induct x) auto
 
   by (induct x) auto
 
  
 
text {*
 
text {*
Línea 135: Línea 143:
 
*}
 
*}
  
 
+
(* anddonram edupalhid luicedval rafcabgon diwu2 jescudero macmerflo
(*anddonram edupalhid luicedval rafcabgon diwu2 jescudero macmerflo cesgongut rafferrod*)
+
  cesgongut rafferrod *)  
 
lemma todos_append:
 
lemma todos_append:
 
   "todos P (x @ y) = (todos P x ∧ todos P y)"
 
   "todos P (x @ y) = (todos P x ∧ todos P y)"
Línea 146: Línea 154:
 
   have "todos P ((a # x) @ y) = (P a ∧ todos P (x @ y))" by simp
 
   have "todos P ((a # x) @ y) = (P a ∧ todos P (x @ y))" by simp
 
   also have "... = (P a ∧ todos P x ∧ todos P y)" using HI by simp
 
   also have "... = (P a ∧ todos P x ∧ todos P y)" using HI by simp
   finally show "todos P ((a # x) @ y) = (todos P (a # x) ∧ todos P y)" by simp
+
   finally show "todos P ((a # x) @ y) = (todos P (a # x) ∧ todos P y)"  
 +
    by simp
 
qed
 
qed
  
Línea 155: Línea 164:
 
   ---------------------------------------------------------------------  
 
   ---------------------------------------------------------------------  
 
*}
 
*}
 
  
 
(*anddonram*)
 
(*anddonram*)
Línea 172: Línea 180:
 
*}
 
*}
  
 
+
(* anddonram diwu2 *)
(*anddonram diwu2*)
 
 
lemma "todos P (rev xs) = todos P xs"
 
lemma "todos P (rev xs) = todos P xs"
 
proof (induct xs)
 
proof (induct xs)
Línea 181: Línea 188:
 
   assume HI: "todos P (rev xs) = todos P xs"
 
   assume HI: "todos P (rev xs) = todos P xs"
 
   have " todos P (rev (a # xs)) = todos P (rev xs @ [a])" by simp
 
   have " todos P (rev (a # xs)) = todos P (rev xs @ [a])" by simp
   also have "... =  (todos P (rev xs) ∧ todos P [a])" by (simp add:todos_append)
+
   also have "... =  (todos P (rev xs) ∧ todos P [a])"  
 +
    by (simp add: todos_append)
 
   also have "... =  (todos P xs ∧ todos P [a])" using HI by simp
 
   also have "... =  (todos P xs ∧ todos P [a])" using HI by simp
   finally show "todos P (rev (a # xs)) = todos P (a # xs)" by (simp add:and_comm)
+
   finally show "todos P (rev (a # xs)) = todos P (a # xs)"  
 +
    by (simp add: and_comm)
 
qed
 
qed
  
Línea 195: Línea 204:
 
   have "todos P (rev (a # xs)) = (todos P ((rev xs)@[a]))" by simp
 
   have "todos P (rev (a # xs)) = (todos P ((rev xs)@[a]))" by simp
 
   also have "... = (todos P (rev xs) ∧ todos P [a])"  
 
   also have "... = (todos P (rev xs) ∧ todos P [a])"  
     by (simp add:todos_append)
+
     by (simp add: todos_append)
 
   also have "... = (todos P xs ∧ P a)" using HI by simp
 
   also have "... = (todos P xs ∧ P a)" using HI by simp
 
   also have "... = (P a ∧ todos P xs)" by arith
 
   also have "... = (P a ∧ todos P xs)" by arith
Línea 202: Línea 211:
 
qed
 
qed
  
(*rafferrod*)
+
(* rafferrod *)
 
lemma "todos P (rev xs) = todos P xs"
 
lemma "todos P (rev xs) = todos P xs"
 
proof (induct xs)
 
proof (induct xs)
Línea 210: Línea 219:
 
     assume HI: "todos P (rev xs) = todos P xs"
 
     assume HI: "todos P (rev xs) = todos P xs"
 
     have "todos P (rev (a#xs)) = todos P (rev xs @ [a])" by simp
 
     have "todos P (rev (a#xs)) = todos P (rev xs @ [a])" by simp
     also have "... = (todos P (rev xs) ∧ todos P [a])" by (simp add: todos_append)
+
     also have "... = (todos P (rev xs) ∧ todos P [a])"  
 +
      by (simp add: todos_append)
 
     also have "... = (todos P xs ∧ todos P [a])" using HI by simp
 
     also have "... = (todos P xs ∧ todos P [a])" using HI by simp
 
     also have "... = (todos P [a] ∧ todos P xs)" by auto
 
     also have "... = (todos P [a] ∧ todos P xs)" by auto
Línea 223: Línea 233:
 
*}
 
*}
  
(*anddonram Contraejemplo*)
+
(* anddonram Contraejemplo*)
value "let xs=[True,False]     
+
value "let xs=[True,False]     
 
   in (algunos (λx. (λx. (x=False)) x ∧ (λx. x) x) xs =
 
   in (algunos (λx. (λx. (x=False)) x ∧ (λx. x) x) xs =
 
     (algunos (λx. (x=False)) xs ∧ algunos (λx. x) xs))"
 
     (algunos (λx. (x=False)) xs ∧ algunos (λx. x) xs))"
Línea 240: Línea 250:
 
*}
 
*}
  
(*anddonram edupalhid jescudero luicedval rafcabgon diwu2 macmerflo cesgongut rafferrod*)
+
(* anddonram edupalhid jescudero luicedval rafcabgon diwu2 macmerflo
 +
  cesgongut rafferrod *)  
 
lemma "algunos P (map f xs) = algunos (P o f) xs"
 
lemma "algunos P (map f xs) = algunos (P o f) xs"
 
   by (induct xs) auto
 
   by (induct xs) auto
 
  
 
text {*
 
text {*
Línea 252: Línea 262:
 
*}
 
*}
  
(*anddonram edupalhid luicedval rafcabgon diwu2 jescudero macmerflo rafferrod*)
+
(* anddonram edupalhid luicedval rafcabgon diwu2 jescudero macmerflo
 +
  rafferrod *)  
 
lemma "algunos P (map f xs) = algunos (P o f) xs"
 
lemma "algunos P (map f xs) = algunos (P o f) xs"
 
proof(induct xs)
 
proof(induct xs)
Línea 262: Línea 273:
 
   also have "... = ((P ∘ f) a ∨ algunos P (map f xs))" by simp
 
   also have "... = ((P ∘ f) a ∨ algunos P (map f xs))" by simp
 
   also have "... = ((P ∘ f) a ∨ algunos (P ∘ f) xs) " using HI by simp
 
   also have "... = ((P ∘ f) a ∨ algunos (P ∘ f) xs) " using HI by simp
   finally show "algunos P (map f (a # xs)) = algunos (P ∘ f) (a # xs)" by simp
+
   finally show "algunos P (map f (a # xs)) = algunos (P ∘ f) (a # xs)"  
 +
    by simp
 
qed
 
qed
  
Línea 272: Línea 284:
 
   fix x xs
 
   fix x xs
 
   assume HI: "algunos P (map f xs) = algunos (P o f) xs"
 
   assume HI: "algunos P (map f xs) = algunos (P o f) xs"
   have "algunos P (map f (x#xs)) = (P (f x) ∨ algunos P (map f xs))" by simp
+
   have "algunos P (map f (x#xs)) = (P (f x) ∨ algunos P (map f xs))"  
 +
    by simp
 
   also have "... = (P (f x) ∨ algunos (P o f) xs)" using HI by simp
 
   also have "... = (P (f x) ∨ algunos (P o f) xs)" using HI by simp
   finally show "algunos P (map f (x#xs)) = algunos (P o f) (x#xs)" by simp
+
   finally show "algunos P (map f (x#xs)) = algunos (P o f) (x#xs)"  
 +
    by simp
 
qed
 
qed
  
Línea 284: Línea 298:
 
*}
 
*}
  
(*anddonram edupalhid luicedval rafcabgon diwu2 jescudero macmerflo cesgongut rafferrod*)
+
(* anddonram edupalhid luicedval rafcabgon diwu2 jescudero macmerflo
 +
  cesgongut rafferrod *)  
 
lemma "algunos P (xs @ ys) = (algunos P xs ∨ algunos P ys)"
 
lemma "algunos P (xs @ ys) = (algunos P xs ∨ algunos P ys)"
 
   by (induct xs) auto
 
   by (induct xs) auto
 
  
 
text {*
 
text {*
Línea 296: Línea 310:
 
*}
 
*}
  
(*anddonram edupalhid luicedval rafcabgon diwu2 jescudero macmerflo cesgongut rafferrod*)
+
(* anddonram edupalhid luicedval rafcabgon diwu2 jescudero macmerflo
 +
  cesgongut rafferrod *)  
 
lemma algunos_append:
 
lemma algunos_append:
 
   "algunos P (xs @ ys) = (algunos P xs ∨ algunos P ys)"
 
   "algunos P (xs @ ys) = (algunos P xs ∨ algunos P ys)"
Línea 305: Línea 320:
 
   assume HI: "algunos P (xs @ ys) = (algunos P xs ∨ algunos P ys)"
 
   assume HI: "algunos P (xs @ ys) = (algunos P xs ∨ algunos P ys)"
 
   have "algunos P ((a # xs) @ ys) = (P a ∨ algunos P (xs@ys) )" by simp
 
   have "algunos P ((a # xs) @ ys) = (P a ∨ algunos P (xs@ys) )" by simp
   also have "... = (P a ∨ (algunos P xs ∨ algunos P ys))" using HI by simp
+
   also have "... = (P a ∨ (algunos P xs ∨ algunos P ys))" using HI  
   finally show "algunos P ((a # xs) @ ys) = (algunos P (a # xs) ∨ algunos P ys)" by simp
+
    by simp
 +
   finally show "algunos P ((a # xs) @ ys) =  
 +
                (algunos P (a # xs) ∨ algunos P ys)" by simp
 
qed
 
qed
  
Línea 316: Línea 333:
 
*}
 
*}
  
(*anddonram[conmutatividad or porque no sé hacerlo de otra forma] *)
+
(* anddonram [conmutatividad or porque no sé hacerlo de otra forma] *)
 
lemma or_comm: "(a ∨ b) = (b ∨ a)"
 
lemma or_comm: "(a ∨ b) = (b ∨ a)"
 
   by (cases a) auto
 
   by (cases a) auto
  
(*anddonram*)
+
(* anddonram *)
 
lemma "algunos P (rev xs) = algunos P xs"
 
lemma "algunos P (rev xs) = algunos P xs"
 
   by (induct xs) (simp_all add: algunos_append or_comm)
 
   by (induct xs) (simp_all add: algunos_append or_comm)
Línea 335: Línea 352:
 
*}
 
*}
  
(*anddonram diwu2*)
+
(* anddonram diwu2 *)
 
lemma "algunos P (rev xs) = algunos P xs"
 
lemma "algunos P (rev xs) = algunos P xs"
 
proof (induct xs)
 
proof (induct xs)
Línea 343: Línea 360:
 
   assume HI:" algunos P (rev xs) = algunos P xs"
 
   assume HI:" algunos P (rev xs) = algunos P xs"
 
   have " algunos P (rev (a # xs)) = algunos P (rev xs @[a]) " by simp
 
   have " algunos P (rev (a # xs)) = algunos P (rev xs @[a]) " by simp
   also have "... = (algunos P (rev xs) ∨ algunos P [a])" by (simp add: algunos_append)
+
   also have "... = (algunos P (rev xs) ∨ algunos P [a])"  
 +
    by (simp add: algunos_append)
 
   also have "... = (algunos P xs ∨ P a)" using HI by simp
 
   also have "... = (algunos P xs ∨ P a)" using HI by simp
 
   also have "... = (P a ∨ algunos P xs)" by (simp add:or_comm)
 
   also have "... = (P a ∨ algunos P xs)" by (simp add:or_comm)
   finally show " algunos P (rev (a # xs)) = algunos P (a # xs) " by simp
+
   finally show " algunos P (rev (a # xs)) = algunos P (a # xs) "  
 +
    by simp
 
qed
 
qed
  
Línea 372: Línea 391:
 
   assume HI: "algunos P (rev xs) = algunos P xs"
 
   assume HI: "algunos P (rev xs) = algunos P xs"
 
   have "algunos P (rev (a#xs)) = algunos P (rev xs @ [a])" by simp
 
   have "algunos P (rev (a#xs)) = algunos P (rev xs @ [a])" by simp
   also have "... = (algunos P (rev xs) ∨ algunos P [a])" by (simp add: algunos_append)
+
   also have "... = (algunos P (rev xs) ∨ algunos P [a])"  
 +
    by (simp add: algunos_append)
 
   also have "... = (algunos P xs ∨ algunos P [a])" using HI by simp
 
   also have "... = (algunos P xs ∨ algunos P [a])" using HI by simp
 
   also have "... = (algunos P [a] ∨ algunos P xs)" by auto
 
   also have "... = (algunos P [a] ∨ algunos P xs)" by auto
Línea 387: Línea 407:
 
*}
 
*}
  
(*anddonram edupalhid diwu2 jescudero macmerflo rafferrod rafcabgon*)
+
(* anddonram edupalhid diwu2 jescudero macmerflo rafferrod rafcabgon *)
 
lemma "algunos (λx. P x ∨ Q x) xs = (algunos P xs ∨ algunos Q xs)"
 
lemma "algunos (λx. P x ∨ Q x) xs = (algunos P xs ∨ algunos Q xs)"
 
  by (induct xs) auto
 
  by (induct xs) auto
 
   
 
   
(*anddonram*)
+
(* anddonram *)
 
lemma "algunos (λx. P x ∨ Q x) xs = (algunos P xs ∨ algunos Q xs)"
 
lemma "algunos (λx. P x ∨ Q x) xs = (algunos P xs ∨ algunos Q xs)"
 
proof (induct xs)
 
proof (induct xs)
   show "algunos (λx. P x ∨ Q x) [] = (algunos P [] ∨ algunos Q [])" by simp
+
   show "algunos (λx. P x ∨ Q x) [] = (algunos P [] ∨ algunos Q [])"  
 +
    by simp
 
next
 
next
 
   fix a xs
 
   fix a xs
   assume HI: " algunos (λx. P x ∨ Q x) xs = (algunos P xs ∨ algunos Q xs)"
+
   assume HI: "algunos (λx. P x ∨ Q x) xs = (algunos P xs ∨ algunos Q xs)"
   have "algunos (λx. P x ∨ Q x) (a # xs) = (P a ∨ Q a ∨ algunos (λx. P x ∨ Q x) xs)"  
+
   have "algunos (λx. P x ∨ Q x) (a # xs) =  
    by simp
+
        (P a ∨ Q a ∨ algunos (λx. P x ∨ Q x) xs)" by simp
   also have "... = (P a ∨ Q a ∨ algunos P xs ∨ algunos Q xs)" using HI by simp
+
   also have "... = (P a ∨ Q a ∨ algunos P xs ∨ algunos Q xs)"  
   also have "... = (P a ∨ Q a ∨ algunos Q xs ∨ algunos P xs)" by (simp add: or_comm)
+
    using HI by simp
 +
   also have "... = (P a ∨ Q a ∨ algunos Q xs ∨ algunos P xs)"  
 +
    by (simp add: or_comm)
 
   also have "... = (P a ∨  algunos Q (a#xs) ∨ algunos P xs)"  by simp  
 
   also have "... = (P a ∨  algunos Q (a#xs) ∨ algunos P xs)"  by simp  
   also have "... = (P a ∨  algunos P xs ∨ algunos Q (a#xs))" by (simp add: or_comm)
+
   also have "... = (P a ∨  algunos P xs ∨ algunos Q (a#xs))"  
   finally show "algunos (λx. P x ∨ Q x) (a # xs) = (algunos P (a # xs) ∨ algunos Q (a # xs))"
+
    by (simp add: or_comm)
 +
   finally show "algunos (λx. P x ∨ Q x) (a # xs) =  
 +
                (algunos P (a # xs) ∨ algunos Q (a # xs))"
 
     by simp
 
     by simp
 
qed
 
qed
Línea 428: Línea 453:
 
qed
 
qed
  
(*rafferrod*)
+
(* rafferrod *)
 
lemma "algunos (λx. P x ∨ Q x) xs = (algunos P xs ∨ algunos Q xs)"
 
lemma "algunos (λx. P x ∨ Q x) xs = (algunos P xs ∨ algunos Q xs)"
 
proof (induct xs)
 
proof (induct xs)
   show "algunos (λx. P x ∨ Q x) [] = (algunos P [] ∨ algunos Q [])" by simp
+
   show "algunos (λx. P x ∨ Q x) [] = (algunos P [] ∨ algunos Q [])"  
 +
    by simp
 
next
 
next
 
   fix a xs
 
   fix a xs
 
   assume HI: "algunos (λx. P x ∨ Q x) xs = (algunos P xs ∨ algunos Q xs)"
 
   assume HI: "algunos (λx. P x ∨ Q x) xs = (algunos P xs ∨ algunos Q xs)"
   have "algunos (λx. P x ∨ Q x) (a#xs) = (P a ∨ Q a ∨ algunos (λx. P x ∨ Q x) xs)" by simp
+
   have "algunos (λx. P x ∨ Q x) (a#xs) =  
   also have "... = (P a ∨ Q a ∨ algunos P xs ∨ algunos Q xs)" using HI by simp
+
      (P a ∨ Q a ∨ algunos (λx. P x ∨ Q x) xs)" by simp
 +
   also have "... = (P a ∨ Q a ∨ algunos P xs ∨ algunos Q xs)"  
 +
    using HI by simp
 
   also have "... = (P a ∨ algunos P xs ∨ Q a ∨ algunos Q xs)" by auto
 
   also have "... = (P a ∨ algunos P xs ∨ Q a ∨ algunos Q xs)" by auto
   finally show "algunos (λx. P x ∨ Q x) (a#xs) = (algunos P (a#xs) ∨ algunos Q (a#xs))" by simp
+
   finally show "algunos (λx. P x ∨ Q x) (a#xs) =  
 +
                (algunos P (a#xs) ∨ algunos Q (a#xs))" by simp
 
qed
 
qed
  
Línea 448: Línea 477:
 
*}
 
*}
  
(*anddonram edupalhid diwu2 cesgongut rafferrod rafcabgon*)
+
(* anddonram edupalhid diwu2 cesgongut rafferrod rafcabgon *)
 
lemma "algunos P xs = (¬ todos (λx. (¬ P x)) xs)"
 
lemma "algunos P xs = (¬ todos (λx. (¬ P x)) xs)"
 
  by (induct xs) auto
 
  by (induct xs) auto
Línea 459: Línea 488:
 
*}
 
*}
  
(*anddonram edupalhid diwu2 rafferrod*)
+
(*anddonram edupalhid diwu2 rafferrod*)
 
lemma "algunos P xs = (¬ todos (λx. (¬ P x)) xs)"
 
lemma "algunos P xs = (¬ todos (λx. (¬ P x)) xs)"
 
proof (induct xs)
 
proof (induct xs)
Línea 466: Línea 495:
 
   fix a xs
 
   fix a xs
 
   assume HI:"algunos P xs = (¬ todos (λx. ¬ P x) xs)"
 
   assume HI:"algunos P xs = (¬ todos (λx. ¬ P x) xs)"
   have " algunos P (a # xs) =(P a ∨ algunos P xs)" by simp
+
   have "algunos P (a # xs) =(P a ∨ algunos P xs)" by simp
 
   also have "... = (P a ∨ (¬ todos (λx. ¬ P x) xs))" using HI by simp
 
   also have "... = (P a ∨ (¬ todos (λx. ¬ P x) xs))" using HI by simp
 
   also have "... = (¬ (¬ P a ∧ todos (λx. ¬ P x) xs))" by simp
 
   also have "... = (¬ (¬ P a ∧ todos (λx. ¬ P x) xs))" by simp
   finally show "  algunos P (a # xs) = (¬ todos (λx. ¬ P x) (a # xs))" by simp
+
   finally show "  algunos P (a # xs) = (¬ todos (λx. ¬ P x) (a # xs))"  
 +
    by simp
 
qed
 
qed
 
   
 
   
Línea 483: Línea 513:
 
*}
 
*}
  
(*anddonram edupalhd luicedval rafcabgon diwu2 jescudero macmerflo cesgongut rafferrod*)
+
(* anddonram edupalhd luicedval rafcabgon diwu2 jescudero macmerflo
 +
  cesgongut rafferrod *)  
 
fun estaEn :: "'a ⇒ 'a list ⇒ bool" where
 
fun estaEn :: "'a ⇒ 'a list ⇒ bool" where
   "estaEn x [] = False"
+
   "estaEn x []     = False"
 
| "estaEn x (a#xs) = ((a=x) ∨ estaEn x xs)"
 
| "estaEn x (a#xs) = ((a=x) ∨ estaEn x xs)"
  
Línea 498: Línea 529:
 
*}
 
*}
  
(*anddonram edupalhid luicedval rafcabgon diwu2 jescudero macmerflo cesgongut rafferrod*)
+
(* anddonram edupalhid luicedval rafcabgon diwu2 jescudero macmerflo
 +
  cesgongut rafferrod *)  
 
lemma "estaEn x xs=algunos (λy.(y=x)) xs"
 
lemma "estaEn x xs=algunos (λy.(y=x)) xs"
 
   by (induct xs) auto
 
   by (induct xs) auto
  
(*anddonram edupalhid luicedval rafcabgon jescudero macmerflo cesgongut rafferrod*)
+
(* anddonram edupalhid luicedval rafcabgon jescudero macmerflo cesgongut
 +
  rafferrod *)  
 
lemma "estaEn x xs=algunos (λy.(y=x)) xs"
 
lemma "estaEn x xs=algunos (λy.(y=x)) xs"
 
proof (induct xs)
 
proof (induct xs)
Línea 513: Línea 546:
 
   finally show "estaEn x (a # xs) = algunos (λy. y = x) (a # xs)" by simp
 
   finally show "estaEn x (a # xs) = algunos (λy. y = x) (a # xs)" by simp
 
qed
 
qed
 
  
 
end
 
end
 
</source>
 
</source>

Revisión del 10:11 14 dic 2017

chapter {* R4: Cuantificadores sobre listas *}

theory R4_Cuantificadores_sobre_listas
imports Main 
begin

text {* 
  --------------------------------------------------------------------- 
  Ejercicio 1. Definir la función 
     todos :: ('a ⇒ bool) ⇒ 'a list ⇒ bool
  tal que (todos p xs) se verifica si todos los elementos de la lista 
  xs cumplen la propiedad p. Por ejemplo, se verifica 
     todos (λx. 1<length x) [[2,1,4],[1,3]]
     ¬todos (λx. 1<length x) [[2,1,4],[3]]

  Nota: La función todos es equivalente a la predefinida list_all. 
  --------------------------------------------------------------------- 
*}

(* anddonram edupalhid luicedval cesgongut jescudero rafcabgon diwu2
   macmerflo rafferrod *) 
fun todos :: "('a ⇒ bool) ⇒ 'a list ⇒ bool" where
  "todos p []     = True"
| "todos p (x#xs) = (p x ∧ todos p xs)"

value "todos (λx. 1<length x) [[2,1,4],[1,3::nat]] = True"
value " ¬todos (λx. 1<length x) [[2,1,4],[3::nat]] = True"

text {* 
  --------------------------------------------------------------------- 
  Ejercicio 2. Definir la función 
     algunos :: ('a ⇒ bool) ⇒ 'a list ⇒ bool
  tal que (algunos p xs) se verifica si algunos elementos de la lista 
  xs cumplen la propiedad p. Por ejemplo, se verifica 
     algunos (λx. 1<length x) [[2,1,4],[3]]
     ¬algunos (λx. 1<length x) [[],[3]]"

  Nota: La función algunos es equivalente a la predefinida list_ex. 
  --------------------------------------------------------------------- 
*}

(* anddonram edupalhid luicedval cesgongut jescudero rafcabgon diwu2
   macmerflo rafferrod *) 
fun algunos  :: "('a ⇒ bool) ⇒ 'a list ⇒ bool" where
  "algunos p []      = False"
|  "algunos p (x#xs) = (p x ∨ algunos p xs)"

value " algunos (λx. 1<length x) [[2::nat,1,4],[3]] = True"
value " ¬algunos (λx. 1<length x) [[],[3::nat]] = True"

text {*
  --------------------------------------------------------------------- 
  Ejercicio 3.1. Demostrar o refutar automáticamente 
     todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)
  --------------------------------------------------------------------- 
*}
 (* anddonram edupalhid luicedval cesgongut jescudero rafcabgon diwu2
    macmerflo rafferrod *) 
lemma "todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)"
  by (induct xs) auto
 
text {*
  --------------------------------------------------------------------- 
  Ejercicio 3.2. Demostrar o refutar detalladamente
     todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)
  --------------------------------------------------------------------- 
*}

(* anddonram [conmutatividad and porque no sé hacerlo de otra forma] *)
lemma and_comm: "(a ∧ b) = (b ∧ a)"
  by (cases a) auto

(* anddonram diwu2 *)
lemma "todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)"
proof (induct xs)
  show "todos (λx. P x ∧ Q x) [] = (todos P [] ∧ todos Q [])" by simp
next 
  fix a xs
  assume HI:"todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)"
  have "todos (λx. P x ∧ Q x) (a # xs) = 
       (P a ∧ Q a ∧ todos (λx. P x ∧ Q x) xs)" by simp
  also have "... = (P a ∧ Q a ∧ todos P xs ∧ todos Q xs)" 
    using HI by simp
  also have "... = (P a ∧ Q a ∧ todos Q xs ∧ todos P xs)" 
    by (simp add: and_comm)
  also have "... = (P a ∧ todos Q (a # xs) ∧ todos P xs)" by simp
  also have "... = (P a ∧ todos P xs ∧ Q a ∧ todos Q xs)" 
    by (simp add: and_comm)
  finally show "todos (λx. P x ∧ Q x) (a # xs) = 
                (todos P (a # xs) ∧ todos Q (a # xs))"
    by simp
qed

(* edupalhid *)
lemma "todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)"
proof (induct xs)
  show "todos (λx. P x ∧ Q x) [] = (todos P [] ∧ todos Q [])" by simp
next
  fix n xs
  assume HI: "todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)" 
  have "todos (λx. P x ∧ Q x) (n # xs) =  
        ((P n ∧ Q n) ∧ (todos P xs ∧ todos Q xs))" using HI by simp
  also have "... = ((P n ∧ todos P xs) ∧ (Q n ∧ todos Q xs))" by arith
  also have "... = ((todos P(n#xs)) ∧ (todos Q(n#xs)))" by simp
 finally show "todos (λx. P x ∧ Q x) (n#xs) = 
               (todos P (n#xs) ∧ todos Q (n#xs))" by simp 
qed

(* rafferrod *)
lemma "todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)"
proof (induct xs)
  show "todos (λx. P x ∧ Q x) [] = (todos P [] ∧ todos Q [])" by simp
next
  fix a xs
  assume HI: "todos (λx. P x ∧ Q x) xs = (todos P xs ∧ todos Q xs)"
  have "todos (λx. P x ∧ Q x) (a#xs) = 
       (P a ∧ Q a ∧ todos (λx. P x ∧ Q x) xs)" by simp
  also have "... = (P a ∧ Q a ∧ todos P xs ∧ todos Q xs)" 
    using HI by simp
  also have "... = (P a ∧ todos P (xs) ∧ Q a ∧ todos Q (xs))" by auto
  finally show "todos (λx. P x ∧ Q x) (a#xs) = 
                (todos P (a#xs) ∧ todos Q (a#xs))" by simp
qed

text {*
  --------------------------------------------------------------------- 
  Ejercicio 4.1. Demostrar o refutar automáticamente
     todos P (x @ y) = (todos P x ∧ todos P y)
  --------------------------------------------------------------------- 
*}

(* anddonram edupalhid cesgongut luicedval jescudero rafcabgon diwu2
   macmerflo cesgongut rafferrod *) 
lemma "todos P (x @ y) = (todos P x ∧ todos P y)"
  by (induct x) auto

text {*
  --------------------------------------------------------------------- 
  Ejercicio 4.2. Demostrar o refutar detalladamente
     todos P (x @ y) = (todos P x ∧ todos P y)
  --------------------------------------------------------------------- 
*}

(* anddonram edupalhid luicedval rafcabgon diwu2 jescudero macmerflo
   cesgongut rafferrod *) 
lemma todos_append:
  "todos P (x @ y) = (todos P x ∧ todos P y)"
proof (induct x)
  show "todos P ([] @ y) = (todos P [] ∧ todos P y)" by simp
next
  fix a x
  assume HI: "todos P (x @ y) = (todos P x ∧ todos P y)"
  have "todos P ((a # x) @ y) = (P a ∧ todos P (x @ y))" by simp
  also have "... = (P a ∧ todos P x ∧ todos P y)" using HI by simp
  finally show "todos P ((a # x) @ y) = (todos P (a # x) ∧ todos P y)" 
    by simp
qed

text {*
  --------------------------------------------------------------------- 
  Ejercicio 5.1. Demostrar o refutar automáticamente 
     todos P (rev xs) = todos P xs
  --------------------------------------------------------------------- 
*}

(*anddonram*)
lemma "todos P (rev xs) = todos P xs"
  by (induct xs) (simp_all add: todos_append and_comm)

(* edupalhid diwu2 macmerflo rafferrod*)
lemma "todos P (rev xs) = todos P xs"
by (induct xs) (auto simp add: todos_append)

text {*
  --------------------------------------------------------------------- 
  Ejercicio 5.2. Demostrar o refutar detalladamente
     todos P (rev xs) = todos P xs
  --------------------------------------------------------------------- 
*}

(* anddonram diwu2 *)
lemma "todos P (rev xs) = todos P xs"
proof (induct xs)
  show "todos P (rev []) = todos P []" by simp
 next
  fix a xs
  assume HI: "todos P (rev xs) = todos P xs"
  have " todos P (rev (a # xs)) = todos P (rev xs @ [a])" by simp
  also have "... =  (todos P (rev xs) ∧ todos P [a])" 
    by (simp add: todos_append)
  also have "... =  (todos P xs ∧ todos P [a])" using HI by simp
  finally show "todos P (rev (a # xs)) = todos P (a # xs)" 
    by (simp add: and_comm)
qed

(* edupalhid *)
lemma "todos P (rev xs) = todos P xs"
proof (induct xs)
show "todos P (rev []) = todos P []" by simp
next
fix a xs
  assume HI: "todos P (rev xs) = todos P xs"
  have "todos P (rev (a # xs)) = (todos P ((rev xs)@[a]))" by simp
  also have "... = (todos P (rev xs) ∧ todos P [a])" 
    by (simp add: todos_append)
  also have "... = (todos P xs ∧ P a)" using HI by simp
  also have "... = (P a ∧ todos P xs)" by arith
  also have "... = (todos P (a#xs))" by simp
  finally show "todos P (rev (a # xs)) = (todos P (a#xs))" by simp    
qed

(* rafferrod *)
lemma "todos P (rev xs) = todos P xs"
proof (induct xs)
  show "todos P (rev []) = todos P []" by simp
  next
    fix a xs
    assume HI: "todos P (rev xs) = todos P xs"
    have "todos P (rev (a#xs)) = todos P (rev xs @ [a])" by simp
    also have "... = (todos P (rev xs) ∧ todos P [a])" 
      by (simp add: todos_append)
    also have "... = (todos P xs ∧ todos P [a])" using HI by simp
    also have "... = (todos P [a] ∧ todos P xs)" by auto
    finally show "todos P (rev (a#xs)) = todos P (a#xs)" by simp
  qed

text {*
  --------------------------------------------------------------------- 
  Ejercicio 6. Demostrar o refutar:
    algunos (λx. P x ∧ Q x) xs = (algunos P xs ∧ algunos Q xs)
  --------------------------------------------------------------------- 
*}

(* anddonram Contraejemplo*)
value "let xs=[True,False]    
  in (algunos (λx. (λx. (x=False)) x ∧ (λx. x) x) xs =
     (algunos (λx. (x=False)) xs ∧ algunos (λx. x) xs))"

(* edupalhid diwu2 rafferrod*)
lemma "algunos (λx. P x ∧ Q x) xs = (algunos P xs ∧ algunos Q xs)"
  quickcheck
  oops

text {*
  --------------------------------------------------------------------- 
  Ejercicio 7.1. Demostrar o refutar automáticamente 
     algunos P (map f xs) = algunos (P ∘ f) xs
  --------------------------------------------------------------------- 
*}

(* anddonram edupalhid jescudero luicedval rafcabgon diwu2 macmerflo
   cesgongut rafferrod *) 
lemma "algunos P (map f xs) = algunos (P o f) xs"
  by (induct xs) auto

text {*
  --------------------------------------------------------------------- 
  Ejercicio 7.2. Demostrar o refutar datalladamente
     algunos P (map f xs) = algunos (P ∘ f) xs
  --------------------------------------------------------------------- 
*}

(* anddonram edupalhid luicedval rafcabgon diwu2 jescudero macmerflo
   rafferrod *) 
lemma "algunos P (map f xs) = algunos (P o f) xs"
proof(induct xs)
  show "algunos P (map f []) = algunos (P o f) []" by simp
next
  fix a xs
  assume HI: "algunos P (map f xs) = algunos (P ∘ f) xs"
  have "algunos P (map f (a # xs)) = algunos P (f a#map f xs)" by simp
  also have "... = ((P ∘ f) a ∨ algunos P (map f xs))" by simp
  also have "... = ((P ∘ f) a ∨ algunos (P ∘ f) xs) " using HI by simp
  finally show "algunos P (map f (a # xs)) = algunos (P ∘ f) (a # xs)" 
    by simp
qed

(* cesgongut *)
lemma "algunos P (map f xs) = algunos (P o f) xs"
proof (induct xs)
  show "algunos P (map f []) = algunos (P o f) []" by simp
next
  fix x xs
  assume HI: "algunos P (map f xs) = algunos (P o f) xs"
  have "algunos P (map f (x#xs)) = (P (f x) ∨ algunos P (map f xs))" 
    by simp
  also have "... = (P (f x) ∨ algunos (P o f) xs)" using HI by simp
  finally show "algunos P (map f (x#xs)) = algunos (P o f) (x#xs)" 
    by simp
qed

text {*
  --------------------------------------------------------------------- 
  Ejercicio 8.1. Demostrar o refutar automáticamente 
     algunos P (xs @ ys) = (algunos P xs ∨ algunos P ys)
  --------------------------------------------------------------------- 
*}

(* anddonram edupalhid luicedval rafcabgon diwu2 jescudero macmerflo
   cesgongut rafferrod *) 
lemma "algunos P (xs @ ys) = (algunos P xs ∨ algunos P ys)"
  by (induct xs) auto

text {*
  --------------------------------------------------------------------- 
  Ejercicio 8.2. Demostrar o refutar detalladamente
     algunos P (xs @ ys) = (algunos P xs ∨ algunos P ys)
  --------------------------------------------------------------------- 
*}

(* anddonram edupalhid luicedval rafcabgon diwu2 jescudero macmerflo
   cesgongut rafferrod *) 
lemma algunos_append:
  "algunos P (xs @ ys) = (algunos P xs ∨ algunos P ys)"
proof (induct xs)
  show "algunos P ([] @ ys) = (algunos P [] ∨ algunos P ys)" by simp
next 
  fix a xs
  assume HI: "algunos P (xs @ ys) = (algunos P xs ∨ algunos P ys)"
  have "algunos P ((a # xs) @ ys) = (P a ∨ algunos P (xs@ys) )" by simp
  also have "... = (P a ∨ (algunos P xs ∨ algunos P ys))" using HI 
    by simp
  finally show "algunos P ((a # xs) @ ys) = 
                (algunos P (a # xs) ∨ algunos P ys)" by simp
qed

text {*
  --------------------------------------------------------------------- 
  Ejercicio 9.1. Demostrar o refutar automáticamente
     algunos P (rev xs) = algunos P xs
  --------------------------------------------------------------------- 
*}

(* anddonram [conmutatividad or porque no sé hacerlo de otra forma] *)
lemma or_comm: "(a ∨ b) = (b ∨ a)"
  by (cases a) auto

(* anddonram *)
lemma "algunos P (rev xs) = algunos P xs"
  by (induct xs) (simp_all add: algunos_append or_comm)
 
(* edupalhid diwu2 rafferrod*)
lemma "algunos P (rev xs) = algunos P xs"
by (induct xs) (auto simp add: algunos_append)

text {*
  --------------------------------------------------------------------- 
  Ejercicio 9.2. Demostrar o refutar detalladamente
     algunos P (rev xs) = algunos P xs
  --------------------------------------------------------------------- 
*}

(* anddonram diwu2 *)
lemma "algunos P (rev xs) = algunos P xs"
proof (induct xs)
  show "algunos P (rev []) = algunos P []" by simp
next 
  fix a xs
  assume HI:" algunos P (rev xs) = algunos P xs"
  have " algunos P (rev (a # xs)) = algunos P (rev xs @[a]) " by simp
  also have "... = (algunos P (rev xs) ∨ algunos P [a])" 
    by (simp add: algunos_append)
  also have "... = (algunos P xs ∨ P a)" using HI by simp
  also have "... = (P a ∨ algunos P xs)" by (simp add:or_comm)
  finally show " algunos P (rev (a # xs)) = algunos P (a # xs) " 
    by simp
qed

(* edupalhid *)
lemma "algunos P (rev xs) = algunos P xs"
proof (induct xs)
  show "algunos P (rev []) = algunos P []" by simp
next
  fix a xs
  assume HI:"algunos P (rev xs) = algunos P xs"
  have "algunos P (rev (a # xs)) = algunos P ((rev xs) @ [a])" by simp
  also have "... = ((algunos P (rev xs)) ∨ (algunos P [a]))" 
    by (simp add: algunos_append)
  also have "... = ((algunos P xs) ∨ (algunos P [a]))" using HI by simp
  also have "... = ((algunos P [a]) ∨ (algunos P xs))" by arith
  finally show "algunos P (rev (a # xs)) = algunos P (a # xs)" by simp
qed

(*rafferrod*)
lemma "algunos P (rev xs) = algunos P xs"
proof (induct xs)
  show "algunos P (rev []) = algunos P []" by simp
next
  fix a xs
  assume HI: "algunos P (rev xs) = algunos P xs"
  have "algunos P (rev (a#xs)) = algunos P (rev xs @ [a])" by simp
  also have "... = (algunos P (rev xs) ∨ algunos P [a])" 
    by (simp add: algunos_append)
  also have "... = (algunos P xs ∨ algunos P [a])" using HI by simp
  also have "... = (algunos P [a] ∨ algunos P xs)" by auto
  finally show "algunos P (rev (a#xs)) = algunos P (a#xs)" by simp
qed

text {*
  --------------------------------------------------------------------- 
  Ejercicio 10. Encontrar un término no trivial Z tal que sea cierta la 
  siguiente ecuación:
     algunos (λx. P x ∨ Q x) xs = Z
  y demostrar la equivalencia de forma automática y detallada.
  --------------------------------------------------------------------- 
*}

(* anddonram edupalhid diwu2 jescudero macmerflo rafferrod rafcabgon *)
lemma "algunos (λx. P x ∨ Q x) xs = (algunos P xs ∨ algunos Q xs)"
 by (induct xs) auto
 
(* anddonram *)
lemma "algunos (λx. P x ∨ Q x) xs = (algunos P xs ∨ algunos Q xs)"
proof (induct xs)
  show "algunos (λx. P x ∨ Q x) [] = (algunos P [] ∨ algunos Q [])" 
    by simp
next
  fix a xs
  assume HI: "algunos (λx. P x ∨ Q x) xs = (algunos P xs ∨ algunos Q xs)"
  have "algunos (λx. P x ∨ Q x) (a # xs) = 
        (P a ∨ Q a ∨ algunos (λx. P x ∨ Q x) xs)" by simp
  also have "... = (P a ∨ Q a ∨ algunos P xs ∨ algunos Q xs)" 
    using HI by simp
  also have "... = (P a ∨ Q a ∨ algunos Q xs ∨ algunos P xs)" 
    by (simp add: or_comm)
  also have "... = (P a ∨  algunos Q (a#xs) ∨ algunos P xs)"  by simp 
  also have "... = (P a ∨  algunos P xs ∨ algunos Q (a#xs))" 
    by (simp add: or_comm)
  finally show "algunos (λx. P x ∨ Q x) (a # xs) = 
                (algunos P (a # xs) ∨ algunos Q (a # xs))"
    by simp
qed
 
(* edupalhid *)
lemma "algunos (λx. P x ∨ Q x) xs = (algunos P xs ∨ algunos Q xs)" 
      (is "?T xs")
proof (induct xs)
  show "?T []" by simp
next
  fix a xs assume HI: "?T xs"
    have p1:" (Q a ∨ algunos P xs) = (algunos P xs ∨ Q a)" 
      by (simp add: HOL.disj_commute)
    have "algunos (λx. P x ∨ Q x) (a # xs) = 
          (algunos P [a] ∨ algunos Q [a] ∨ algunos (λx. P x ∨ Q x) xs)" 
      by simp
    also have "… = (P a ∨ (Q a ∨ algunos P xs) ∨ algunos Q xs)" 
      using HI by simp
    also have "… = (P a ∨ algunos P xs ∨ Q a ∨ algunos Q xs)" 
      using p1 by simp
    also have "… = (algunos P (a # xs) ∨ algunos Q (a # xs))" by simp
    finally show "?T (a # xs)" by simp
qed

(* rafferrod *)
lemma "algunos (λx. P x ∨ Q x) xs = (algunos P xs ∨ algunos Q xs)"
proof (induct xs)
  show "algunos (λx. P x ∨ Q x) [] = (algunos P [] ∨ algunos Q [])" 
    by simp
next
  fix a xs
  assume HI: "algunos (λx. P x ∨ Q x) xs = (algunos P xs ∨ algunos Q xs)"
  have "algunos (λx. P x ∨ Q x) (a#xs) = 
       (P a ∨ Q a ∨ algunos (λx. P x ∨ Q x) xs)" by simp
  also have "... = (P a ∨ Q a ∨ algunos P xs ∨ algunos Q xs)" 
    using HI by simp
  also have "... = (P a ∨ algunos P xs ∨ Q a ∨ algunos Q xs)" by auto
  finally show "algunos (λx. P x ∨ Q x) (a#xs) = 
                (algunos P (a#xs) ∨ algunos Q (a#xs))" by simp
qed

text {*
  --------------------------------------------------------------------- 
  Ejercicio 11.1. Demostrar o refutar automáticamente
     algunos P xs = (¬ todos (λx. (¬ P x)) xs)
  --------------------------------------------------------------------- 
*}

(* anddonram edupalhid diwu2 cesgongut rafferrod rafcabgon *)
lemma "algunos P xs = (¬ todos (λx. (¬ P x)) xs)"
 by (induct xs) auto
 
text {*
  --------------------------------------------------------------------- 
  Ejercicio 11.2. Demostrar o refutar datalladamente
     algunos P xs = (¬ todos (λx. (¬ P x)) xs)
  --------------------------------------------------------------------- 
*}

(*anddonram edupalhid diwu2 rafferrod*)
lemma "algunos P xs = (¬ todos (λx. (¬ P x)) xs)"
proof (induct xs)
  show "algunos P [] = (¬ todos (λx. (¬ P x)) [])" by simp
next
  fix a xs
  assume HI:"algunos P xs = (¬ todos (λx. ¬ P x) xs)"
  have "algunos P (a # xs) =(P a ∨ algunos P xs)" by simp
  also have "... = (P a ∨ (¬ todos (λx. ¬ P x) xs))" using HI by simp
  also have "... = (¬ (¬ P a ∧ todos (λx. ¬ P x) xs))" by simp
  finally show "  algunos P (a # xs) = (¬ todos (λx. ¬ P x) (a # xs))" 
    by simp
qed
 
text {*
  --------------------------------------------------------------------- 
  Ejercicio 12. Definir la funcion primitiva recursiva 
     estaEn :: 'a ⇒ 'a list ⇒ bool
  tal que (estaEn x xs) se verifica si el elemento x está en la lista
  xs. Por ejemplo, 
     estaEn (2::nat) [3,2,4] = True
     estaEn (1::nat) [3,2,4] = False
  --------------------------------------------------------------------- 
*}

(* anddonram edupalhd luicedval rafcabgon diwu2 jescudero macmerflo
   cesgongut rafferrod *) 
fun estaEn :: "'a ⇒ 'a list ⇒ bool" where
  "estaEn x []     = False"
| "estaEn x (a#xs) = ((a=x) ∨ estaEn x xs)"

value " estaEn (2::nat) [3,2,4] = True"
value " estaEn (1::nat) [3,2,4] = False"

text {*
  --------------------------------------------------------------------- 
  Ejercicio 13. Expresar la relación existente entre estaEn y algunos. 
  Demostrar dicha relación de forma automática y detallada.
  --------------------------------------------------------------------- 
*}

(* anddonram edupalhid luicedval rafcabgon diwu2 jescudero macmerflo
   cesgongut rafferrod *) 
lemma "estaEn x xs=algunos (λy.(y=x)) xs"
  by (induct xs) auto

(* anddonram edupalhid luicedval rafcabgon jescudero macmerflo cesgongut
   rafferrod *) 
lemma "estaEn x xs=algunos (λy.(y=x)) xs"
proof (induct xs)
  show "estaEn x []=algunos (λy.(y=x)) []" by simp
next
  fix a xs
  assume HI:"estaEn x xs = algunos (λy. y = x) xs"
  have "estaEn x (a # xs) =((a=x) ∨ estaEn x xs)" by simp
  also have "... = ((a=x) ∨ algunos (λy. y = x) xs)" using HI by simp
  finally show "estaEn x (a # xs) = algunos (λy. y = x) (a # xs)" by simp
qed

end