Acciones

Diferencia entre revisiones de «Relación 7»

De Razonamiento automático (2018-19)

Línea 1: Línea 1:
 
<source lang="isabelle">
 
<source lang="isabelle">
chapter {* R6: Deducción natural proposicional *}
+
chapter {* R7: Deducción natural de primer orden *}
  
theory R6_Deduccion_natural_proposicional
+
theory R7_Deduccion_natural_de_primer_orden_alu
 
imports Main  
 
imports Main  
 
begin
 
begin
+
 
 
text {*
 
text {*
   ---------------------------------------------------------------------
+
   Demostrar o refutar los siguientes lemas usando sólo las reglas
  El objetivo de esta relación es demostrar cada uno de los ejercicios
+
  básicas de deducción natural de la lógica proposicional, de los
  usando sólo las reglas básicas de deducción natural de la lógica
+
   cuantificadores y de la igualdad:  
  proposicional (sin usar el método auto).
 
 
 
   Las reglas básicas de la deducción natural son las siguientes:
 
 
   · conjI:      ⟦P; Q⟧ ⟹ P ∧ Q
 
   · conjI:      ⟦P; Q⟧ ⟹ P ∧ Q
 
   · conjunct1:  P ∧ Q ⟹ P
 
   · conjunct1:  P ∧ Q ⟹ P
 
   · conjunct2:  P ∧ Q ⟹ Q   
 
   · conjunct2:  P ∧ Q ⟹ Q   
 
   · notnotD:    ¬¬ P ⟹ P
 
   · notnotD:    ¬¬ P ⟹ P
  · notnotI:    P ⟹ ¬¬ P
 
 
   · mp:        ⟦P ⟶ Q; P⟧ ⟹ Q  
 
   · mp:        ⟦P ⟶ Q; P⟧ ⟹ Q  
  · mt:        ⟦F ⟶ G; ¬G⟧ ⟹ ¬F
 
 
   · impI:      (P ⟹ Q) ⟹ P ⟶ Q
 
   · impI:      (P ⟹ Q) ⟹ P ⟶ Q
 
   · disjI1:    P ⟹ P ∨ Q
 
   · disjI1:    P ⟹ P ∨ Q
Línea 31: Línea 26:
 
   · iffD2:      ⟦P = Q; Q⟧ ⟹ P
 
   · iffD2:      ⟦P = Q; Q⟧ ⟹ P
 
   · ccontr:    (¬P ⟹ False) ⟹ P
 
   · ccontr:    (¬P ⟹ False) ⟹ P
   ---------------------------------------------------------------------
+
 
 +
   · allI:      ⟦∀x. P x; P x ⟹ R⟧ ⟹ R
 +
  · allE:      (⋀x. P x) ⟹ ∀x. P x
 +
  · exI:        P x ⟹ ∃x. P x
 +
  · exE:        ⟦∃x. P x; ⋀x. P x ⟹ Q⟧ ⟹ Q
 +
 
 +
  · refl:      t = t
 +
  · subst:      ⟦s = t; P s⟧ ⟹ P t
 +
  · trans:      ⟦r = s; s = t⟧ ⟹ r = t
 +
  · sym:        s = t ⟹ t = s
 +
  · not_sym:    t ≠ s ⟹ s ≠ t
 +
  · ssubst:    ⟦t = s; P s⟧ ⟹ P t
 +
  · box_equals: ⟦a = b; a = c; b = d⟧ ⟹ a: = d
 +
  · arg_cong:  x = y ⟹ f x = f y
 +
  · fun_cong:  f = g ⟹ f x = g x
 +
  · cong:      ⟦f = g; x = y⟧ ⟹ f x = g y
 
*}
 
*}
  
 
text {*
 
text {*
   Se usarán las reglas notnotI y mt que demostramos a continuación. *}
+
   Se usarán las reglas notnotI, mt y not_ex que demostramos a  
 +
  continuación. *}
  
 
lemma notnotI: "P ⟹ ¬¬ P"
 
lemma notnotI: "P ⟹ ¬¬ P"
Línea 43: Línea 54:
 
by auto
 
by auto
  
section {* Implicaciones *}
+
lemma no_ex: "¬(∃x. P(x)) ⟹ ∀x. ¬P(x)"
 +
by auto
  
 
text {* ---------------------------------------------------------------  
 
text {* ---------------------------------------------------------------  
 
   Ejercicio 1. Demostrar
 
   Ejercicio 1. Demostrar
       p q, p q
+
       P a (∃x. Q x) ∃x. P a ⟶ Q x
 
   ------------------------------------------------------------------ *}
 
   ------------------------------------------------------------------ *}
 
(* pabalagon manperjim josgomrom4 cammonagu raffergon2 chrgencar
 
  gleherlop giafus1 marfruman1 enrparalv pabbergue antramhur alikan
 
  juacanrod hugrubsan aribatval*)
 
lemma ejercicio_1:
 
  assumes 1: "p ⟶ q" and
 
          2: "p"
 
  shows "q"
 
proof -
 
  show "q" using 1 2 by (rule mp)
 
qed
 
 
(* benber alfmarcua *)
 
lemma ejercicio_1_1:
 
  assumes "p ⟶ q"
 
          "p"
 
  shows "q"
 
  using assms by (rule mp)
 
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 2. Demostrar
 
    p ⟶ q, q ⟶ r, p ⊢ r
 
  ------------------------------------------------------------------ *}
 
 
(* pabalagon manperjim josgomrom4 cammonagu gleherlop raffergon2
 
  chrgencar giafus1 marfruman1 alfmarcua enrparalv pabbergue antramhur
 
  alikan juacanrod hugrubsan aribatval*)
 
lemma ejercicio_2:
 
  assumes 1: "p ⟶ q" and
 
          2: "q ⟶ r" and
 
          3: "p"
 
  shows "r"
 
proof -
 
  have 4: "q" using 1 3 by (rule mp)
 
  show "r" using 2 4 by (rule mp)
 
qed
 
  
 
(* benber *)
 
(* benber *)
lemma ejercicio_2_1:
+
lemma
   assumes "p q"
+
   assumes "P a ⟶ (∃x. Q x)"
          "q ⟶ r"
+
   shows "∃x. P a Q x"
          "p"
+
proof (rule ccontr)
  shows "r"
+
   assume "∄x. P a Q x"
proof -
+
   have "P a ⟶ (∃x. P a Q x)"
  have "q" using `p ⟶ q` `p` by (rule mp)
 
  with `q ⟶ r` show "r" by (rule mp)
 
qed
 
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 3. Demostrar
 
    p ⟶ (q ⟶ r), p ⟶ q, p ⊢ r
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim josgomrom4 cammonagu gleherlop raffergon2
 
  chrgencar giafus1 marfruman1 alfmarcua enrparalv pabbergue antramhur
 
  alikan juacanrod hugrubsan aribatval*)
 
lemma ejercicio_3:
 
  assumes 1: "p ⟶ (q ⟶ r)" and
 
          2: "p ⟶ q" and
 
          3: "p"
 
  shows "r"
 
proof -
 
  have 4: "q ⟶ r" using 1 3 by (rule mp)
 
  have 5: "q" using 2 3 by (rule mp)
 
  show "r" using 4 5 by (rule mp)
 
qed
 
 
 
(* benber *)
 
lemma ejercicio_3_1:
 
  assumes "p ⟶ (q ⟶ r)"
 
          "p ⟶ q"
 
          "p"
 
   shows "r"
 
proof -
 
  have "q ⟶ r" using `p ⟶ (q ⟶ r)` `p` by (rule mp)
 
  moreover have "q" using `p ⟶ q` `p` by (rule mp)
 
  ultimately show "r" by (rule mp)
 
qed
 
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 4. Demostrar
 
    p ⟶ q, q ⟶ r ⊢ p ⟶ r
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim josgomrom4 cammonagu chrgencar raffergon2
 
  gleherlop giafus1 marfruman1 alfmarcua enrparalv pabbergue antramhur
 
  alikan juacanrod hugrubsan aribatval*)
 
lemma ejercicio_4:
 
  assumes 1: "p q" and
 
          2: "q ⟶ r"
 
  shows "p ⟶ r"
 
proof -
 
  { assume 3: "p"
 
    have 4: "q" using 1 3 by (rule mp)  
 
    have 5: "r" using 2 4 by (rule mp)}
 
  thus "p ⟶ r" by (rule impI)
 
qed
 
 
 
(* benber *)
 
lemma ejercicio_4_1:
 
  assumes "p ⟶ q"
 
          "q ⟶ r"
 
  shows "p ⟶ r"
 
proof
 
   assume p
 
  with `p ⟶ q` have "q" by (rule mp)
 
  with `q ⟶ r` show "r" by (rule mp)
 
qed
 
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 5. Demostrar
 
    p ⟶ (q ⟶ r) ⊢ q ⟶ (p r)
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim raffergon2 giafus1 gleherlop marfruman1 alfmarcua
 
  enrparalv chrgencar pabbergue antramhur alikan hugrubsan aribatval*)
 
lemma ejercicio_5:
 
  assumes 1: "p ⟶ (q ⟶ r)"
 
  shows  "q ⟶ (p ⟶ r)"
 
proof (rule impI)
 
  assume 2: "q"
 
  show "p ⟶ r"
 
   proof (rule impI)
 
    assume 3: "p"
 
    have 4: "q r" using 1 3 by (rule mp)
 
    show "r" using 4 2 by (rule mp)
 
  qed
 
qed
 
 
 
(* benber josgomrom4 juacanrod cammonagu  *)
 
lemma ejercicio_5_1:
 
  assumes "p ⟶ (q r)"
 
  shows  "q ⟶ (p ⟶ r)"
 
proof
 
  assume "q"
 
  show "p ⟶ r"
 
 
   proof
 
   proof
     assume "p"
+
     assume "P a"
     with `p ⟶ (q ⟶ r)` have "q r" by (rule mp)
+
     with assms have "∃x. Q x" by (rule mp)
     thus "r" using `q` by (rule mp)
+
    moreover have "⋀x. Q x ⟹ ∃x'. P a Q x'"
 +
    proof -
 +
      fix x
 +
      assume "Q x"
 +
      hence "P a ⟶ Q x" by (rule impI)
 +
      thus "∃x'. P a Q x'" by (rule exI)
 +
     qed
 +
    ultimately show "∃x. P a ⟶ Q x" by (rule exE)
 
   qed
 
   qed
qed
+
   moreover note `∄x. P a Q x`
 
+
   ultimately have "¬(P a)" by (rule mt)
(* pabalagon *)
+
  have "¬(P a) ⟶ (∃x. P a Q x)"
lemma ejercicio_5_2:
+
   proof
   assumes 1: "p (q ⟶ r)"
+
    fix x
   shows  "q ⟶ (p ⟶ r)"
+
    assume "¬(P a)"
proof -
+
    have "P a Q x"
  { assume 2: "q"
+
    proof
    { assume 3: "p"
+
      assume "P a"
      have 4: "q ⟶ r" using 1 3 by (rule mp)
+
      with `¬(P a)` have "False" by (rule notE)
      have 5: "r" using 4 2 by (rule mp)}
+
      thus "Q x" by (rule FalseE)
    hence "p r" by (rule impI)
+
     qed
  }
+
    thus "∃x. P a ⟶ Q x" by (rule exI)
  thus "q (p ⟶ r)" by (rule impI)
 
qed
 
 
 
text {* ---------------------------------------------------------------
 
   Ejercicio 6. Demostrar
 
    p ⟶ (q ⟶ r) ⊢ (p ⟶ q) ⟶ (p ⟶ r)
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim cammonagu chrgencar raffergon2 gleherlop giafus1
 
  marfruman1 alfmarcua enrparalv pabbergue  antramhur alikan juacanrod
 
  hugrubsan aribatval*)
 
lemma ejercicio_6:
 
  assumes 1: "p ⟶ (q ⟶ r)"  
 
  shows  "(p ⟶ q) ⟶ (p r)"
 
proof (rule impI)
 
  assume 2: "p ⟶ q"
 
  show "p ⟶ r"
 
  proof (rule impI)
 
    assume 3: "p"
 
    have 4: "q ⟶ r" using 1 3 by (rule mp)
 
    have 5: "q" using 2 3 by (rule mp)
 
     show "r" using 4 5 by (rule mp)
 
 
   qed
 
   qed
 +
  moreover note `∄x. P a ⟶ Q x`
 +
  ultimately have "¬¬(P a)" by (rule mt)
 +
  moreover note `¬(P a)`
 +
  ultimately show "False" by (rule notE)
 
qed
 
qed
  
(* benber josgomrom4 *)
+
(* alfmarcua *)
lemma ejercicio_6_1:
+
lemma ejercicio_52:
   assumes "p ⟶ (q ⟶ r)"  
+
   "p ∨ ¬p"
  shows  "(p ⟶ q) ⟶ (p ⟶ r)"
+
proof (rule ccontr)
proof
+
   assume 1: "¬(p ∨ ¬p)"
   assume "p ⟶ q"
+
   have 2: "¬p" proof (rule notI)
   show "p ⟶ r"
+
     assume p hence 3: "p ∨ ¬p" by (rule disjI1)
  proof
+
     show "False" using 1 3 by (rule notE)
    assume "p"
 
    with `p ⟶ (q ⟶ r)` have "q ⟶ r" by (rule mp)
 
     moreover from `p ⟶ q` `p` have "q" by (rule mp)
 
     ultimately show "r" by (rule mp)
 
 
   qed
 
   qed
 +
  have 4: "p ∨ ¬p" using 2 by (rule disjI2)
 +
  show "False" using 1 4 by (rule notE)
 
qed
 
qed
  
text {* ---------------------------------------------------------------
+
lemma ejercicio_1:
  Ejercicio 7. Demostrar
+
   assumes "P a ⟶ (∃x. Q x)"
    p ⊢ q ⟶ p
+
   shows "∃x. P a Q x"
  ------------------------------------------------------------------ *}
+
proof (rule disjE)
 
+
   show "P a ∨ ¬ P a" by (rule ejercicio_52)
(* pabalagon manperjim josgomrom4 raffergon2 giafus1 gleherlop
+
next
  marfruman1 enrparalv pabbergue antramhur alikan hugrubsan aribatval*)
+
   assume "P a"
lemma ejercicio_7:
+
   have "∃x. Q x" using assms `P a` by (rule mp)
   assumes 1: "p"
+
   then obtain b where "Q b" by (rule exE)
   shows   "q p"
+
   have "P a ⟹ Q b" using `P a` `Q b` by simp
proof (rule impI)
+
   have "P a Q b" using `P a ⟹ Q b` by (rule impI)
  assume 2: "q"
+
   then show "∃x. P a Q x" by (rule exI)
   show "p" using 1 by this
+
next
qed
+
   assume "¬ P a"
 
+
   fix b
(* benber cammonagu juacanrod chrgencar *)
+
   have "P a Q b"
lemma ejercicio_7_1:
 
   assumes "p"
 
   shows  "q ⟶ p"
 
proof
 
   show "p" using `p` .
 
qed
 
 
 
(* alfmarcua *)
 
lemma ejercicio_7_2:
 
   assumes "p"
 
   shows  "q p"
 
  using assms by (rule impI)
 
 
 
text {* ---------------------------------------------------------------
 
   Ejercicio 8. Demostrar
 
    ⊢ p ⟶ (q ⟶ p)
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim josgomrom4 raffergon2 giafus1 marfruman1
 
  enrparalv pabbergue antramhur alikan hugrubsan aribatval*)  
 
lemma ejercicio_8:
 
   "p ⟶ (q ⟶ p)"
 
proof (rule impI)
 
   assume 1: "p"
 
   show "q p"
 
 
   proof (rule impI)
 
   proof (rule impI)
     assume 2: "q"
+
     assume "P a"
     show "p" using 1 by this
+
     with `¬(P a)` have "False" by (rule notE)
 +
    then show "Q b" by (rule FalseE)
 
   qed
 
   qed
 +
  thus "∃x. P a ⟶ Q x" by (rule exI)
 
qed
 
qed
  
(* benber cammonagu gleherlop chrgencar juacanrod alfmarcua *)
+
(* pabalagon manperjim josgomrom4 gleherlop marfruman1 raffergon2
lemma ejercicio_8_1:
+
   hugrubsan pabbergue enrparalv giafus1 antramhur *)  
  "p ⟶ (q ⟶ p)"
+
lemma ejercicio_1b:
  using ejercicio_7_1 by (rule impI)
+
   assumes "P a (∃x. Q x)"
 
+
   shows "∃x. P a Q x"
text {* ---------------------------------------------------------------
+
proof (rule disjE)
  Ejercicio 9. Demostrar
+
  show "¬P a ∨ P a" by (rule excluded_middle)
    p ⟶ q ⊢ (q ⟶ r) ⟶ (p ⟶ r)
+
next
  ------------------------------------------------------------------ *}
+
  fix b
 
+
   assume 3: "¬P a"
(* pabalagon manperjim raffergon2 giafus1 marfruman1 alfmarcua enrparalv
+
   have "P a Q b" proof (rule impI)
   gleherlop antramhur alikan hugrubsan aribatval*)  
+
     assume 4: "P a" show "Q b" using 3 4 by (rule notE)
lemma ejercicio_9:
 
   assumes 1: "p q"  
 
   shows   "(q ⟶ r) ⟶ (p ⟶ r)"
 
proof (rule impI)
 
   assume 2: "q ⟶ r"
 
   show "p r"
 
  proof (rule impI)
 
     assume 3: "p"
 
    have 4: "q" using 1 3 by (rule mp)
 
    show "r" using 2 4 by (rule mp)
 
 
   qed
 
   qed
qed
+
  thus ?thesis by (rule exI)
 
+
next
(* benber josgomrom4 cammonagu chrgencar juacanrod pabbergue *)
+
   assume 1: "P a"
lemma ejercicio_9_1:
+
   have "∃x. Q x" using assms(1) 1 by (rule mp)
   assumes "p ⟶ q"  
+
   then obtain b where 2: "Q b" by (rule exE)
   shows  "(q ⟶ r) (p ⟶ r)"
+
   have "P a Q b" proof (rule impI)
proof
+
     assume "P a" show "Q b" using 2 .
   assume "q ⟶ r"
 
   show "p r"
 
  proof
 
     assume "p"
 
    with `p ⟶ q` have "q" by (rule mp)
 
    with `q ⟶ r` show "r" by (rule mp)
 
 
   qed
 
   qed
 +
  thus ?thesis by (rule exI)
 
qed
 
qed
  
 
text {* ---------------------------------------------------------------  
 
text {* ---------------------------------------------------------------  
   Ejercicio 10. Demostrar
+
   Ejercicio 2. Demostrar
    p ⟶ (q ⟶ (r ⟶ s)) ⊢ r ⟶ (q ⟶ (p ⟶ s))
+
      {∀x y z. R x y ∧ R y z R x z,
 +
        ∀x. ¬(R x x)}
 +
      ∀x y. R x y ¬(R y x)
 
   ------------------------------------------------------------------ *}
 
   ------------------------------------------------------------------ *}
  
(* pabalagon manperjim raffergon2 marfruman1 gleherlop alfmarcua
+
(* benber *)
  enrparalv pabbergue antramhur alikan juacanrod hugrubsan aribatval*)  
+
lemma
lemma ejercicio_10:
+
   assumes A1: "∀x y z. R x y ∧ R y z R x z"
   assumes 1: "p ⟶ (q ⟶ (r s))"  
+
    and A2: "∀x. ¬(R x x)"
  shows  "r ⟶ (q ⟶ (p ⟶ s))"
+
   shows "∀x y. R x y ¬(R y x)"
proof (rule impI)
+
proof -
   assume 2: "r"
+
  {
  show "q ⟶ (p ⟶ s)"
+
     fix x y
  proof (rule impI)
+
     {
    assume 3: "q"
+
       assume "R x y"
     show "p ⟶ s"
+
       have "¬ (R y x)"
     proof (rule impI)
+
       proof (rule ccontr)
       assume 4: "p"
+
        assume "¬ ¬ (R y x)"
       have 5: "q ⟶ (r ⟶ s)" using 1 4 by (rule mp)
+
         hence "R y x" by (rule notnotD)
       have 6: "r ⟶ s" using 5 3 by (rule mp)
 
      show "s" using 6 2 by (rule mp)
 
    qed
 
  qed
 
qed
 
 
 
(* benber josgomrom4 cammonagu chrgencar giafus1 *)
 
lemma ejercicio_10_1:
 
  assumes "p ⟶ (q ⟶ (r ⟶ s))"
 
  shows  "r ⟶ (q ⟶ (p ⟶ s))"
 
proof
 
  assume "r"
 
  show "q ⟶ (p ⟶ s)"
 
  proof
 
    assume "q"
 
    show "p ⟶ s"
 
    proof
 
      assume "p"
 
      with `p ⟶ (q ⟶ (r ⟶ s))`
 
         have "q ⟶ (r ⟶ s)" by (rule mp)
 
      hence "r ⟶ s" using `q` by (rule mp)
 
      thus "s" using `r` by (rule mp)
 
    qed
 
  qed
 
qed
 
  
text {* ---------------------------------------------------------------  
+
        note `∀x y z. R x y ∧ R y z ⟶ R x z`
  Ejercicio 11. Demostrar
+
        moreover have "∀ y z. R x y ∧ R y z ⟶ R x z ⟹ False"
    ⊢ (p (q r)) ((p ⟶ q) ⟶ (p ⟶ r))
+
        proof -
  ------------------------------------------------------------------ *}
+
          assume "∀ y z. R x y ∧ R y z ⟶ R x z"
 +
          moreover have "∀ z. R x y ∧ R y z R x z ⟹ False"
 +
          proof -
 +
            assume "∀ z. R x y ∧ R y z R x z"
 +
            moreover have "R x y ∧ R y x R x x ⟹ False"
 +
            proof -
 +
              assume "R x y ∧ R y x R x x"
 +
              moreover {
 +
                note `R x y`
 +
                moreover note `R y x`
 +
                ultimately have "R x y ∧ R y x" by (rule conjI)
 +
              }
 +
              ultimately have "R x x" by (rule mp)
  
(* pabalagon manperjim josgomrom4 gleherlop cammonagu giafus1 alfmarcua
+
              note `∀x. ¬(R x x)`
  chrgencar pabbergue alikan juacanrod hugrubsan aribatval*)  
+
              moreover {
lemma ejercicio_11:
+
                assume "¬(R x x)"
  "(p ⟶ (q ⟶ r)) ((p ⟶ q) ⟶ (p ⟶ r))"
+
                moreover note `R x x`
proof (rule impI)
+
                ultimately have "False" by (rule notE)
   assume 1: "p ⟶ (q ⟶ r)"
+
              }
   show "(p ⟶ q) ⟶ (p ⟶ r)" using 1 ejercicio_6 by simp
+
              ultimately show "False" by (rule allE)
 +
            qed
 +
            ultimately show "False" by (rule allE)
 +
          qed
 +
          ultimately show "False" by (rule allE)
 +
        qed
 +
        ultimately show "False" by (rule allE)
 +
      qed
 +
    }
 +
    hence "R x y ¬ (R y x)" by (rule impI)
 +
   }
 +
  hence "⋀x. ∀y. R x y ¬ (R y x)" by (rule allI)
 +
   thus ?thesis by (rule allI)
 
qed
 
qed
  
(* pabalagon raffergon2 marfruman1 enrparalv antramhur *)
+
(* alfmarcua marfruman1 enrparalv*)
lemma ejercicio_11_2:
+
lemma ejercicio_2:
   "(p ⟶ (q ⟶ r)) ⟶ ((p ⟶ q) ⟶ (p ⟶ r))"
+
   assumes "∀x y z. R x y ∧ R y z R x z"
proof (rule impI)
+
          "∀x. ¬(R x x)"
   assume 1: "p ⟶ (q ⟶ r)"
+
        shows "∀x y. R x y ¬(R y x)"
   show "(p ⟶ q) ⟶ (p r)"
+
proof (rule allI)
   proof (rule impI)
+
   fix a
     assume 2: "p ⟶ q"
+
   show "∀y. R a y ¬ R y a"
     show "p ⟶ r"
+
   proof (rule allI, rule impI)
     proof (rule impI)
+
    fix b
       assume 3: "p"
+
     assume "R a b"
       have 4: "q ⟶ r" using 1 3 by (rule mp)
+
     show "¬ R b a"
       have 5: "q" using 2 3 by (rule mp)
+
     proof (rule notI)
       show "r" using 4 5 by (rule mp)
+
       assume "R b a"
    qed
+
       have "R a b ∧ R b a" using `R a b` `R b a` by (rule conjI)
  qed
+
       have "∀y z. R a y ∧ R y z ⟶ R a z" using assms(1) by (rule allE)
qed
+
       then have "∀z. R a b ∧ R b z ⟶ R a z" by (rule allE)
 
+
      then have "R a b ∧ R b a R a a" by (rule allE)
(* benber *)
+
      then have "R a a" using `R a b ∧ R b a` by (rule mp)
lemma ejercicio_11_1:
+
       have "¬ (R a a)" using assms(2) by (rule allE)
  "(p ⟶ (q ⟶ r)) ⟶ ((p ⟶ q) ⟶ (p ⟶ r))"
+
       then show False using `R a a` by (rule notE)
proof
 
  assume "p (q ⟶ r)"
 
  show "(p ⟶ q) ⟶ (p ⟶ r)"
 
  proof
 
    assume "p ⟶ q"
 
    show "p ⟶ r"
 
    proof
 
      assume p
 
      with `p ⟶ (q ⟶ r)` have "q ⟶ r" by (rule mp)
 
       moreover have "q" using `p ⟶ q` `p` by (rule mp)
 
       ultimately show r by (rule mp)
 
 
     qed
 
     qed
 
   qed
 
   qed
 
qed
 
qed
  
text {* ---------------------------------------------------------------
 
  Ejercicio 12. Demostrar
 
    (p ⟶ q) ⟶ r ⊢ p ⟶ (q ⟶ r)
 
  ------------------------------------------------------------------ *}
 
  
(* pabalagon manperjim raffergon2 marfruman1 gleherlop enrparalv
+
(* pabalagon manperjim josgomrom4 gleherlop raffergon2 hugrubsan
   pabbergue antramhur alikan juacanrod hugrubsan aribatval*)  
+
   pabbergue giafus1 antramhur *)  
lemma ejercicio_12:
+
lemma ejercicio_2b:
   assumes 1: "(p ⟶ q) ⟶ r"  
+
   assumes "∀x y z. R x y ∧ R y z ⟶ R x z"
   shows   "p ⟶ (q ⟶ r)"
+
          "∀x. ¬(R x x)"
proof (rule impI)
+
   shows "∀x y. R x y ¬(R y x)"
   assume 2: "p"
+
proof (rule allI)
   show "q r"
+
   fix a
   proof (rule impI)
+
   show "∀y. R a y ¬(R y a)"
     assume 3: "q"
+
   proof (rule allI)
     have 4: "p ⟶ q"
+
    fix b
     proof (rule impI)
+
    have "∀y z. R a y ∧ R y z ⟶ R a z" using assms(1) by (rule allE)
       assume 5: "p"
+
    hence "∀z. R a b ∧ R b z ⟶ R a z" by (rule allE)
       show "q" using 3 by this
+
     hence 1: "R a b ∧ R b a ⟶ R a a" by (rule allE)
 +
     have 2: "¬(R a a)" using assms(2) by (rule allE)
 +
     show "R a b ⟶ ¬(R b a)" proof (rule impI)
 +
       assume 3: "R a b"
 +
       show "¬(R b a)"
 +
      proof (rule ccontr)
 +
        assume "¬¬R b a"
 +
        hence 4: "R b a" by (rule notnotD)
 +
        have 5: "R a b ∧ R b a" using 3 4 by (rule conjI)
 +
        have 6: "R a a" using 1 5 by (rule mp)
 +
        show False using 2 6 by (rule notE)
 +
      qed
 
     qed
 
     qed
    show "r" using 1 4 by (rule mp)
 
  qed
 
qed
 
 
(* benber  josgomrom4 cammonagu giafus1 alfmarcua chrgencar *)
 
lemma ejercicio_12_1:
 
  assumes "(p ⟶ q) ⟶ r"
 
  shows  "p ⟶ (q ⟶ r)"
 
proof
 
  assume "p"
 
  show "q ⟶ r"
 
  proof
 
    assume "q"
 
    hence "p ⟶ q" by (rule impI)
 
    with `(p ⟶ q) ⟶ r` show "r" by (rule mp)
 
 
   qed
 
   qed
 
qed
 
qed
 
section {* Conjunciones *}
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 13. Demostrar
 
    p, q ⊢  p ∧ q
 
  ------------------------------------------------------------------ *}
 
  
 
(* pabalagon *)
 
(* pabalagon *)
lemma ejercicio_13:
+
lemma ejercicio_2_2:  
   assumes "p"
+
   assumes "∀x y z. R x y R y z ⟶ R x z"
          "q"
+
           "∀x. ¬(R x x)"
  shows "p q"
+
   shows "∀x y. R x y ⟶ ¬(R y x)"
using assms(1, 2) by (rule conjI)
 
 
 
(* benber manperjim josgomrom4 cammonagu raffergon2 marfruman1 alfmarcua
 
  enrparalv chrgencar gleherlop pabbergue antramhur juacanrod hugrubsan 
 
  alikan aribatval*)
 
lemma ejercicio_13_1:
 
  assumes "p"
 
           "q"
 
  shows "p ∧ q"
 
  using assms by (rule conjI)
 
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 14. Demostrar
 
    p ∧ q ⊢ p
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon  josgomrom4 *)
 
lemma ejercicio_14:
 
  assumes "p ∧ q" 
 
  shows  "p"
 
  using assms(1) by (rule conjunct1)
 
 
 
(* benber manperjim cammonagu raffergon2 marfruman1 alfmarcua enrparalv
 
  chrgencar pabbergue gleherlop antramhur hugrubsan juacanrod alikan aribatval*)
 
lemma ejercicio_14_1:
 
  assumes "p ∧ q" 
 
  shows  "p"
 
  using assms by (rule conjunct1)
 
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 15. Demostrar
 
    p ∧ q ⊢ q
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim juacanrod josgomrom4 *)
 
lemma ejercicio_15:
 
  assumes "p ∧ q"  
 
   shows   "q"
 
  using assms(1) by (rule conjunct2)
 
 
 
(* benber cammonagu raffergon2 marfruman1 alfmarcua enrparalv chrgencar
 
  pabbergue antramhur gleherlop hugrubsan alikan aribatval*)
 
lemma ejercicio_15_1:
 
  assumes "p ∧ q"
 
  shows  "q"
 
  using assms by (rule conjunct2)
 
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 16. Demostrar
 
    p ∧ (q ∧ r) ⊢ (p ∧ q) ∧ r
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim josgomrom4 raffergon2 marfruman1 alfmarcua
 
  cammmonagu enrparalv chrgencar gleherlop pabbergue antramhur
 
  hugrubsan alikan juacanrod cammonagu aribatval*) 
 
lemma ejercicio_16:
 
  assumes "p ∧ (q ∧ r)"
 
  shows  "(p ∧ q) ∧ r"
 
 
proof -
 
proof -
   have 1: "p" using assms(1) by (rule conjunct1)
+
   { fix a
  have 2: "q r" using assms(1) by (rule conjunct2)
+
    { fix b
  have 3: "q" using 2 by (rule conjunct1)
+
      have "∀y z. R a y ∧ R y z ⟶ R a z" using assms(1) by (rule allE)
  have 4: "r" using 2 by (rule conjunct2)
+
      hence "∀z. R a b R b z ⟶ R a z" by (rule allE)
  have 5: "p ∧ q" using 1 3 by (rule conjI)
+
      hence 1: "R a b ∧ R b a ⟶ R a a" by (rule allE)
  show "(p ∧ q) ∧ r" using 5 4 by (rule conjI)
+
      have 2: "¬(R a a)" using assms(2) by (rule allE)
qed
+
      have "R a b ⟶ ¬(R b a)" proof (rule impI)
 
+
        assume 3: "R a b"
(* benber *)
+
        show "¬(R b a)"
lemma ejercicio_16_1:
+
        proof (rule ccontr)
  assumes "p ∧ (q ∧ r)"
+
          assume "¬¬R b a"
  shows  "(p ∧ q) ∧ r"
+
          hence 4: "R b a" by (rule notnotD)
proof - (* TODO? *)
+
          have 5: "R a b ∧ R b a" using 3 4 by (rule conjI)
  have "q ∧ r" using assms by (rule conjunct2)
+
          have 6: "R a a" using 1 5 by (rule mp)
  have "p" using assms by (rule conjunct1)
+
          show False using 2 6 by (rule notE)
  moreover have "q" using `q ∧ r` by (rule conjunct1)
+
        qed
  ultimately have "p ∧ q" by (rule conjI)
+
      qed}
  moreover have "r" using `q ∧ r` by (rule conjunct2)
+
    hence "∀y. R a y ⟶ ¬(R y a)" by (rule allI)}
   ultimately show "(p ∧ q) ∧ r" by (rule conjI)
+
   thus "∀x y. R x y ⟶ ¬(R y x)" by (rule allI)
 
qed
 
qed
  
 
text {* ---------------------------------------------------------------  
 
text {* ---------------------------------------------------------------  
   Ejercicio 17. Demostrar
+
   Ejercicio 3. Demostrar o refutar
    (p ∧ q) ∧ r ⊢ p ∧ (q ∧ r)
+
      (∀x. ∃y. P x y) (∃y. ∀x. P x y)
 
   ------------------------------------------------------------------ *}
 
   ------------------------------------------------------------------ *}
  
(* pabalagon manperjim josgomrom4 raffergon2 marfruman1 alfmarcua
+
(* benber pabbergue*)
  cammonagu chrgencar gleherlop pabbergue antramhur enrparalv hugrubsan
+
(* No es cierto si el universo consiste en más que un objeto. En ese
  juacanrod alikan aribatval*)
+
  caso, asignar la igualdad (=) a P es un contraejemplo. *)
lemma ejercicio_17:
 
  assumes 1: "(p ∧ q) ∧ r"
 
  shows  "p ∧ (q ∧ r)"
 
proof -
 
  have 2: "r" using 1 by (rule conjunct2)
 
  have 3: "p ∧ q" using 1 by (rule conjunct1)
 
  have 4: "p" using 3 by (rule conjunct1)
 
  have 5: "q" using 3 by (rule conjunct2)
 
  have 6: "q ∧ r" using 5 2 by (rule conjI)
 
  show ?thesis using 4 6 by (rule conjI)
 
qed
 
  
(* benber *)
+
(* alfmarcua marfruman1 raffergon2 enrparalv*)
lemma ejercicio_17_1:
+
lemma ejercicio_3:
   assumes "(p ∧ q) ∧ r"
+
   "(∀x. ∃y. P x y) (∃y. ∀x. P x y)"
  shows  "p ∧ (q ∧ r)"
+
   quickcheck
proof -
+
   oops
   have "p ∧ q" using assms by (rule conjunct1)
 
   have "p" using `p ∧ q` by (rule conjunct1)
 
  moreover have "q ∧ r"
 
  proof (rule conjI)
 
    show "q" using `p ∧ q` by (rule conjunct2)
 
  next
 
    show "r" using assms by (rule conjunct2)
 
  qed
 
  ultimately show ?thesis by (rule conjI)
 
qed
 
  
text {* ---------------------------------------------------------------
+
(* pabalagon manperjim pabbergue josgomrom4 gleherlop hugrubsan giafus1
   Ejercicio 18. Demostrar
+
  antramhur *)
    p ∧ q ⊢ p ⟶ q
+
text{*
  ------------------------------------------------------------------ *}
+
   Contraejemplo en los naturales, para todo x existe y tal que x < y, pero no
 
+
  existe y tal que para todo x, x < y
(* pabalagon raffergon2 marfruman1 juacanrod alikan aribatval*)
+
*}
lemma ejercicio_18:
+
lemma ejercicio_3: "(∀x. ∃y. P x y) (∃y. ∀x. P x y)"
  assumes "p ∧ q"
+
   quickcheck
  shows  "p ⟶ q"
+
   oops
proof (rule impI)
 
  assume "p"
 
  show "q" using assms(1) by (rule conjunct2)
 
qed
 
 
 
(* benber manperjim josgomrom4 cammonagu alfmarcua chrgencar pabbergue
 
  gleherlop antramhur enrparalv hugrubsan *)  
 
lemma ejercicio_18_1:
 
  assumes "p ∧ q"  
 
   shows  "p ⟶ q"
 
proof
 
   show "q" using assms by (rule conjunct2)
 
qed
 
  
 
text {* ---------------------------------------------------------------  
 
text {* ---------------------------------------------------------------  
   Ejercicio 19. Demostrar
+
   Ejercicio 4. Demostrar o refutar
    (p q) ∧ (p ⟶ r) ⊢ p ⟶ q ∧ r 
+
      (∃y. ∀x. P x y) ⟶ (∀x. ∃y. P x y)
 
   ------------------------------------------------------------------ *}
 
   ------------------------------------------------------------------ *}
  
(* pabalagon manperjim josgomrom4 raffergon2 marfruman1 alfmarcua
+
(* benber *)
  cammonagu chrgencar gleherlop pabbergue antramhur enrparalv juacanrod
+
lemma "(∃y. ∀x. P x y) ⟶ (∀x. ∃y. P x y)"
  hugrubsan alikan aribatval*)
 
lemma ejercicio_19:
 
  assumes 1: "(p ⟶ q) ∧ (p r)"
 
  shows  "p ⟶ q ∧ r"
 
proof (rule impI)
 
  assume 2: "p"
 
  have 3: "p ⟶ q" using 1 by (rule conjunct1)
 
  have 4: "p ⟶ r" using 1 by (rule conjunct2)
 
  have 5: "q" using 3 2 by (rule mp)
 
  have 6: "r" using 4 2 by (rule mp)
 
  show "q ∧ r" using 5 6 by (rule conjI)
 
qed
 
 
 
(* benber cammonagu *)
 
lemma ejercicio_19_1:
 
  assumes "(p ⟶ q) ∧ (p ⟶ r)"
 
  shows  "p ⟶ q ∧ r"
 
 
proof
 
proof
   assume p
+
   assume "∃y. ∀x. P x y"
   show "q ∧ r"
+
   moreover have "⋀y. ∀x. P x y ⟹ ∀x. ∃y'. P x y'"
 
   proof
 
   proof
     have "p ⟶ q" using assms by (rule conjunct1)
+
     fix x y
     thus "q" using `p` by (rule mp)
+
     assume "∀x'. P x' y"
  next
+
     hence "P x y" by (rule allE)
     have "p ⟶ r" using assms by (rule conjunct2)
+
     thus "∃y'. P x y'" by (rule exI)
     thus "r" using `p` by (rule mp)
 
 
   qed
 
   qed
 +
  ultimately show "∀x. ∃y. P x y" by (rule exE)
 
qed
 
qed
  
text {* ---------------------------------------------------------------
+
(* alfmarcua marfruman1 raffergon2 enrparalv *)
  Ejercicio 20. Demostrar
+
lemma ejercicio_4:  
    p ⟶ q ∧ r ⊢ (p ⟶ q) ∧ (p ⟶ r)
+
   "(∃y. ∀x. P x y) ⟶ (∀x. ∃y. P x y)"
  ------------------------------------------------------------------ *}
+
proof (rule impI, rule allI)
 
+
   fix a
(* pabalagon manperjim josgomrom4 raffergon2 marfruman1 alfmarcua
+
   assume "∃y. ∀x. P x y"
  cammonagu chrgencar gleherlop pabbergue antramhur enrparalv juacanrod
+
  then obtain b where "∀x. P x b" by (rule exE)
  hugrubsan alikan aribatval*)
+
   then have "P a b" by (rule allE)
lemma ejercicio_20:
+
  then show "∃y. P a y" by (rule exI)
  assumes 1: "p ⟶ q ∧ r"
 
  shows   "(p q) ∧ (p ⟶ r)"
 
proof (rule conjI)
 
   show "p ⟶ q"
 
   proof (rule impI)
 
    assume 2: "p"
 
    have 3: "q ∧ r" using 1 2 by (rule mp)
 
    show 4: "q" using 3 by (rule conjunct1)
 
   qed
 
  show "p ⟶ r"
 
  proof (rule impI)
 
    assume 2: "p"
 
    have 3: "q ∧ r" using 1 2 by (rule mp)
 
    show 4: "r" using 3 by (rule conjunct2)
 
  qed
 
 
qed
 
qed
  
(* benber *)
+
(* pabalagon manperjim josgomrom4 gleherlop hugrubsan pabbergue
lemma ejercicio_20_1:
+
  antramhur *)  
  assumes "p ⟶ q ∧ r"
+
lemma ejercicio_4_2: "(∃y. ∀x. P x y) ⟶ (∀x. ∃y. P x y)"
  shows  "(p q) ∧ (p ⟶ r)"
+
proof (rule impI)
proof
+
   assume "∃y. ∀x. P x y"
   show "p ⟶ q"
+
  moreover have "⋀y. ∀x. P x y ⟹ ∀x. ∃y. P x y"
 
   proof
 
   proof
     assume "p"
+
     fix x0 y0
    with assms have "q ∧ r" by (rule mp)
+
     assume "∀x. P x y0"
    thus "q" by (rule conjunct1)
+
     hence "P x0 y0" by (rule allE)
  qed
+
     thus "∃y. P x0 y" by (rule exI)
next
 
  show "p ⟶ r"
 
  proof
 
     assume "p"
 
     with assms have "q ∧ r" by (rule mp)
 
     thus "r" by (rule conjunct2)
 
 
   qed
 
   qed
 +
  ultimately show "∀x. ∃y. P x y" by (rule exE)
 
qed
 
qed
  
 
text {* ---------------------------------------------------------------  
 
text {* ---------------------------------------------------------------  
   Ejercicio 21. Demostrar
+
   Ejercicio 5. Demostrar o refutar
     p ⟶ (q ⟶ r) ⊢ p ∧ q ⟶ r
+
     {∀x. P a x x,
 +
      ∀x y z. P x y z P (f x) y (f z)
 +
    ∃z. P (f a) z (f (f a))
 
   ------------------------------------------------------------------ *}
 
   ------------------------------------------------------------------ *}
 
(* pabalagon manperjim josgomrom4 raffergon2 marfruman1 alfmarcua
 
  cammonagu chrgencar pabbergue gleherlop antramhur enrparalv juacanrod
 
  hugrubsan alikan aribatval*) 
 
lemma ejercicio_21:
 
  assumes 1: "p ⟶ (q ⟶ r)"
 
  shows  "p ∧ q ⟶ r"
 
proof (rule impI)
 
  assume 2: "p ∧ q"
 
  have 3: "p" using 2 by (rule conjunct1)
 
  have 4: "q ⟶ r" using 1 3 by (rule mp)
 
  have 5: "q" using 2 by (rule conjunct2)
 
  show "r" using 4 5 by (rule mp)
 
qed
 
  
 
(* benber *)
 
(* benber *)
lemma ejercicio_21_1:
+
lemma
   assumes "p ⟶ (q ⟶ r)"  
+
   assumes A1: "∀ x. P a x x"
   shows   "p ∧ q ⟶ r"
+
    and A2: "∀x y z. P x y z P (f x) y (f z)"
 +
   shows "∃z. P (f a) z (f (f a))"
 
proof
 
proof
   assume "p ∧ q"
+
   from A2
   hence "p" by (rule conjunct1)
+
  have "∀y z. P a y z ⟶ P (f a) y (f z)" by (rule allE)
   with `p ⟶ (q ⟶ r)` have "q ⟶ r" by (rule mp)
+
   hence "∀z. P a (f a) z ⟶ P (f a) (f a) (f z)" by (rule allE)
   moreover from `p ∧ q` have "q" by (rule conjunct2)
+
   hence "P a (f a) (f a) P (f a) (f a) (f (f a))" by (rule allE)
   ultimately show "r" by (rule mp)
+
   moreover have "P a (f a) (f a)" using A1 by (rule allE)
 +
   ultimately show "P (f a) (f a) (f (f a))" by (rule mp)
 
qed
 
qed
  
text {* ---------------------------------------------------------------
+
(* alfmarcua enrparalv *)
  Ejercicio 22. Demostrar
+
lemma ejercicio_5:
    p ∧ q ⟶ r ⊢ p ⟶ (q ⟶ r)
+
   assumes "∀x. P a x x"
  ------------------------------------------------------------------ *}
+
          "∀x y z. P x y z P (f x) y (f z)"
 
+
        shows "∃z. P (f a) z (f (f a))"
(* pabalagon manperjim josgomrom4 raffergon2 marfruman1 alfmarcua
+
proof (rule exI, rule mp)
  chrgencar pabbergue gleherlop antramhur enrparalv juacanrod hugrubsan
+
   show "P a (f a) (f a)" using assms(1) by (rule allE)
  alikan aribatval*)
+
next
lemma ejercicio_22:
+
   have "∀y z. P a y z P (f a) y (f z)" using assms(2) by (rule allE)
   assumes 1: "p ∧ q r"  
+
  then have "∀z. P a (f a) z ⟶ P (f a) (f a) (f z)" by (rule allE)
  shows   "p ⟶ (q ⟶ r)"
+
  then show "P a (f a) (f a) ⟶ P (f a) (f a) (f (f a))" by (rule allE)
proof (rule impI)
 
   assume 2: "p"
 
   show "q r"
 
  proof (rule impI)
 
    assume 3: "q"
 
    have 4: "p ∧ q" using 2 3 by (rule conjI)
 
    show "r" using 1 4 by (rule mp)
 
  qed
 
 
qed
 
qed
  
(* benber cammonagu *)
+
(* pabalagon manperjim josgomrom4 gleherlop marfruman1 raffergon2
lemma ejercicio_22_1:
+
  hugrubsan pabbergue giafus1 antramhur *)  
   assumes "p ∧ q r"  
+
lemma ejercicio_5_2:
   shows   "p ⟶ (q ⟶ r)"
+
   assumes "∀x. P a x x"
proof
+
          "∀x y z. P x y z P (f x) y (f z)"
   assume "p"
+
   shows "∃z. P (f a) z (f (f a))"
   show "q r"
+
proof (rule exI)
   proof
+
   have "∀y z. P a y z ⟶ P (f a) y (f z)" using assms(2) ..
    assume "q"
+
   hence "∀z. P a (f a) z P (f a) (f a) (f z)" ..
    with `p` have "p ∧ q" by (rule conjI)
+
   hence "P a (f a) (f a) ⟶ P (f a) (f a) (f (f a))" ..
    with `p ∧ q ⟶ r` show "r" by (rule mp)
+
  moreover have "P a (f a) (f a)" using assms(1) by (rule allE)
  qed
+
  ultimately show "P (f a) (f a) (f (f a))" by (rule mp)
 
qed
 
qed
  
 
text {* ---------------------------------------------------------------  
 
text {* ---------------------------------------------------------------  
   Ejercicio 23. Demostrar
+
   Ejercicio 6. Demostrar o refutar
     (p ⟶ q) ⟶ r p q ⟶ r
+
     {∀y. Q a y,
 +
      ∀x y. Q x y ⟶ Q (s x) (s y)}
 +
    ∃z. Qa z Q z (s (s a))
 
   ------------------------------------------------------------------ *}
 
   ------------------------------------------------------------------ *}
  
(* pabalagon manperjim josgomrom4 raffergon2 marfruman1 alfmarcua
+
(* benber alfmarcua giafus1 *)
  chrgencar pabbergue gleherlop antramhur enrparalv juacanrod hugrubsan
+
lemma
  alikan aribatval*)
+
   assumes "∀y. Q a y"
lemma ejercicio_23:
+
      and "∀x y. Q x y ⟶ Q (s x) (s y)"
   assumes 1: "(p ⟶ q) ⟶ r"  
+
    shows "∃z. Q a z Q z (s (s a))"
  shows   "p q ⟶ r"
+
proof
proof (rule impI)
+
   have "Q a a" using `∀y. Q a y` by (rule allE)
   assume 2: "p ∧ q"
+
   moreover have "Q a (s (s a))" using `∀y. Q a y` by (rule allE)
   have 3: "p ⟶ q"
+
   ultimately show "Q a a ∧ Q a (s (s a))" by (rule conjI)
  proof (rule impI)
 
    assume "p"
 
    show "q" using 2 by (rule conjunct2)
 
   qed
 
  show "r" using 1 3 by (rule mp)
 
 
qed
 
qed
  
(* benber cammonagu *)
+
(* pabalagon manperjim josgomrom4 gleherlop marfruman1 raffergon2
lemma ejercicio_23_1:
+
  hugrubsan pabbergue enrparalv antramhur *)  
   assumes "(p ⟶ q) ⟶ r"  
+
lemma ejercicio_6:
   shows   "p q ⟶ r"
+
   assumes "∀y. Q a y"
proof
+
          "∀x y. Q x y ⟶ Q (s x) (s y)"
   assume "p ∧ q"
+
   shows "∃z. Q a z Q z (s (s a))"
   hence "q" by (rule conjunct2)
+
proof (rule exI)
   hence "p ⟶ q" by (rule impI)
+
   have "∀y. Q a y ⟶ Q (s a) (s y)" using assms(2) by (rule allE)
   with `(p ⟶ q) ⟶ r` show "r" by (rule mp)
+
   hence "Q a (s a) ⟶ Q (s a) (s (s a))" by (rule allE)
 +
  moreover have "Q a (s a)" using assms(1) by (rule allE)
 +
   ultimately have "Q (s a) (s (s a))" by (rule mp)
 +
   with `Q a (s a)` show "Q a (s a) ∧ Q (s a) (s (s a))" by (rule conjI)
 
qed
 
qed
  
 
text {* ---------------------------------------------------------------  
 
text {* ---------------------------------------------------------------  
   Ejercicio 24. Demostrar
+
   Ejercicio 7. (En APLI2 el ejercicio 13 de LP) Formalizar, y demostrar
     p ∧ (q ⟶ r) ⊢ (p ⟶ q) ⟶ r
+
  la corrección, del siguiente argumento
 +
    Si la válvula está abierta o la monitorización está preparada,
 +
    entonces se envía una señal de reconocimiento y un mensaje de
 +
    funcionamiento al controlador del ordenador. Si se envía un mensaje
 +
    de funcionamiento al controlador del ordenador o el sistema está en
 +
    estado normal, entonces se aceptan las órdenes del operador. Por lo
 +
    tanto, si la válvula está abierta, entonces se aceptan las órdenes
 +
     del operador.
 +
  Usar A : La válvula está abierta.
 +
      P : La monitorización está preparada.
 +
      R : Envía una señal de reconocimiento.
 +
      F : Envía un mensaje de funcionamiento.
 +
      N : El sistema está en estado normal.
 +
      Or : Se aceptan órdenes del operador.
 
   ------------------------------------------------------------------ *}
 
   ------------------------------------------------------------------ *}
  
(* pabalagon manperjim josgomrom4 raffergon2 marfruman1 alfmarcua
+
(* benber manperjim alfmarcua pabalagon marfruman1 josgomrom4 gleherlop
   chrgencar pabbergue gleherlop antramhur enrparalv hugrubsan juacanrod
+
   raffergon2 hugrubsan pabbergue enrparalv giafus1 antramhur *)
  cammonagu alikan aribatval*)
+
lemma
lemma ejercicio_24:
+
   assumes "A ∨ P ⟶ R F"
   assumes 1: "p (q ⟶ r)"
+
    and "F ∨ N Or"
  shows  "(p ⟶ q) ⟶ r"
+
   shows "A Or"
proof (rule impI)
 
  assume 2: "p q"
 
  have 3: "p" using 1 by (rule conjunct1)
 
  have 4: "q ⟶ r" using 1 by (rule conjunct2)
 
  have 5: "q" using 2 3 by (rule mp)
 
  show 6: "r" using 4 5 by (rule mp)
 
qed
 
 
 
(* benber *)
 
lemma ejercicio_24_1:
 
  assumes "p ∧ (q ⟶ r)"  
 
   shows   "(p ⟶ q) r"
 
 
proof
 
proof
   have "q ⟶ r" using assms by (rule conjunct2)
+
   assume "A"
   assume "p ⟶ q"
+
  hence "A ∨ P" by (rule disjI1)
   moreover have "p" using assms by (rule conjunct1)
+
   with `A ∨ P ⟶ R ∧ F` have "R ∧ F" by (rule mp)
   ultimately have "q" by (rule mp)
+
   hence "F" by (rule conjunct2)
   with `q r` show r by (rule mp)
+
   hence "F ∨ N" by (rule disjI1)
 +
   with `F ∨ N Or` show "Or" by (rule mp)
 
qed
 
qed
 
section {* Disyunciones *}
 
  
 
text {* ---------------------------------------------------------------  
 
text {* ---------------------------------------------------------------  
   Ejercicio 25. Demostrar
+
   Ejercicio 8. (En APLI2 el ejercicio 5 de LP) Formalizar, y demostrar
     p ⊢ p ∨ q
+
  la corrección, del siguiente argumento
 +
    En cierto experimento, cuando hemos empleado un fármaco A, el
 +
    paciente ha mejorado considerablemente en el caso, y sólo en el
 +
    caso, en que no se haya empleado también un fármaco B. Además, o se
 +
    ha empleado el fármaco A o se ha empleado el fármaco B. En
 +
     consecuencia, podemos afirmar que si no hemos empleado el fármaco
 +
    B, el paciente ha mejorado considerablemente.
 +
  Usar A: Hemos empleado el fármaco A.
 +
      B: Hemos empleado el fármaco B.
 +
      M: El paciente ha mejorado notablemente.
 
   ------------------------------------------------------------------ *}
 
   ------------------------------------------------------------------ *}
 
(* pabalagon manperjim josgomrom4 benber cammonagu raffergon2 marfruman1
 
  alfmarcua chrgencar gleherlop pabbergue antramhur enrparalv juacanrod
 
  hugrubsan alikan aribatval*) 
 
lemma ejercicio_25:
 
  assumes "p"
 
  shows  "p ∨ q"
 
  using assms(1) by (rule disjI1)
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 26. Demostrar
 
    q ⊢ p ∨ q
 
  ------------------------------------------------------------------ *}
 
 
(* pabalagon manperjim josgomrom4 benber cammonagu marfruman1 alfmarcua
 
  chrgencar pabbergue gleherlop antramhur enrparalv juacanrod hugrubsan
 
  alikan aribatval*) 
 
lemma ejercicio_26:
 
  assumes "q"
 
  shows  "p ∨ q"
 
  using assms(1) by (rule disjI2)
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 27. Demostrar
 
    p ∨ q ⊢ q ∨ p
 
  ------------------------------------------------------------------ *}
 
 
(* pabalagon manperjim josgomrom4 raffergon2 marfruman1 chrgencar
 
  pabbergue antramhur enrparalv juacanrod hugrubsan cammonagu alikan aribatval*)
 
lemma ejercicio_27:
 
  assumes 1: "p ∨ q"
 
  shows  "q ∨ p"
 
using 1 proof (rule disjE)
 
  assume 2: "p" thus "q ∨ p" by (rule disjI2)
 
next
 
  assume 3: "q" thus "q ∨ p" by (rule disjI1)
 
qed
 
 
(* benber alfmarcua gleherlop *)
 
lemma ejercicio_27_1:
 
  assumes "p ∨ q"
 
  shows  "q ∨ p"
 
proof -
 
  have "p ∨ q" using assms .
 
  moreover have "p ⟹ q ∨ p" by (rule disjI2)
 
  moreover have "q ⟹ q ∨ p" by (rule disjI1)
 
  ultimately show "q ∨ p" by (rule disjE)
 
qed
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 28. Demostrar
 
    q ⟶ r ⊢ p ∨ q ⟶ p ∨ r
 
  ------------------------------------------------------------------ *}
 
 
(* pabalagon manperjim josgomrom4 raffergon2 marfruman1 chrgencar
 
  gleherlop alfmarcua pabbergue antramhur enrparalv juacanrod hugrubsan
 
  cammonagu alikan aribatval*)
 
lemma ejercicio_28:
 
  assumes 1: "q ⟶ r"
 
  shows  "p ∨ q ⟶ p ∨ r"
 
proof (rule impI)
 
  assume 2: "p ∨ q" show "p ∨ r" using 2
 
  proof (rule disjE)
 
    assume 3: p thus "p ∨ r" by (rule disjI1)
 
  next
 
    assume 4: q have r using 1 4 by (rule mp)
 
    thus "p ∨ r" by (rule disjI2)
 
  qed
 
qed
 
  
 
(* benber *)
 
(* benber *)
lemma ejercicio_28_1:
+
lemma
   assumes "q r"  
+
   assumes "A (M ⟷ ¬B)"
   shows   "p ∨ q p ∨ r"
+
    and "A ∨ B"
 +
   shows "¬B M"
 
proof
 
proof
   assume "p ∨ q"
+
   assume "¬B"
   moreover have "p ⟹ p r" by (rule disjI1)
+
   note `A B`
  moreover have "q ⟹ p ∨ r"
 
  proof (rule disjI2)
 
    assume "q"
 
    with `q ⟶ r` show "r" by (rule mp)
 
  qed
 
  ultimately show "p ∨ r" by (rule disjE)
 
qed
 
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 29. Demostrar
 
    p ∨ p ⊢ p
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon juacanrod marfruman1 *)
 
lemma ejercicio_29:
 
  assumes 1: "p ∨ p"
 
  shows  "p"
 
using 1 proof (rule disjE)
 
  assume "p" thus "p" .
 
next
 
  assume "p" thus "p" .
 
qed
 
 
 
(* benber manperjim cammonagu josgomrom4 raffergon2 chrgencar alfmarcua
 
  gleherlop pabbergue antramhur enrparalv hugrubsan alikan aribatval*)
 
lemma ejercicio_29_1:
 
  assumes "p ∨ p"
 
  shows  "p"
 
  using assms by (rule disjE)
 
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 30. Demostrar
 
    p ⊢ p ∨ p
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim  benber josgomrom4 raffergon2 marfruman1
 
  chrgencar alfmarcua pabbergue gleherlop antramhur enrparalv hugrubsan
 
  juacanrod cammonagu alikan aribatval*) 
 
lemma ejercicio_30:
 
  assumes "p"
 
  shows  "p ∨ p"
 
  using assms(1) by (rule disjI1)
 
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 31. Demostrar
 
    p ∨ (q ∨ r) ⊢ (p ∨ q) ∨ r
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim marfruman1 josgomrom4 alfmarcua pabbergue
 
  gleherlop antramhur enrparalv juacanrod hugrubsan alikan chrgencar aribatval*)
 
lemma ejercicio_31:
 
  assumes 1: "p ∨ (q ∨ r)"
 
  shows  "(p ∨ q) ∨ r" (is "?R")
 
using 1 proof (rule disjE)
 
  assume "p" hence "p ∨ q" by (rule disjI1)
 
  thus ?R by (rule disjI1)
 
next
 
  assume "q ∨ r" thus ?R
 
  proof (rule disjE)
 
    assume "q" hence "p ∨ q" by (rule disjI2)
 
    thus "(p ∨ q) ∨ r" by (rule disjI1)
 
  next
 
    assume "r" thus ?thesis by (rule disjI2)
 
  qed
 
qed
 
 
 
(* benber cammonagu *)
 
lemma ejercicio_31_1:
 
  assumes "p ∨ (q ∨ r)"
 
  shows  "(p ∨ q) ∨ r"
 
proof -
 
  have "p ∨ (q ∨ r)" using assms .
 
 
   moreover {
 
   moreover {
     assume "p"
+
     assume "A"
     hence "p ∨ q" by (rule disjI1)
+
     with `A ⟶ (M ⟷ ¬B)` have "M ⟷ ¬B" by (rule mp)
     hence "(p ∨ q) ∨ r" by (rule disjI1)
+
     hence "¬B ⟹ M" by (rule iffD2)
 +
    hence "M" using `¬B` .
 
   }
 
   }
 
   moreover {
 
   moreover {
     assume "q ∨ r"
+
     note `¬B`
    moreover {
+
     moreover assume "B"
      assume "q"
+
     ultimately have "M" by (rule notE)
      hence "p ∨ q" by (rule disjI2)
 
      hence "(p ∨ q) ∨ r" by (rule disjI1)
 
    }
 
     moreover {
 
      assume "r"
 
      hence "(p ∨ q) ∨ r" by (rule disjI2)
 
    }
 
     ultimately have "(p ∨ q) ∨ r" by (rule disjE)
 
 
   }
 
   }
   ultimately show "(p ∨ q) ∨ r" by (rule disjE)
+
   ultimately show "M" by (rule disjE)
 
qed
 
qed
  
 
+
(* alfmarcua marfruman1 *)
text {* ---------------------------------------------------------------
+
lemma ejercicio_8:
  Ejercicio 32. Demostrar
+
   assumes "A ∧ ¬ B ⟶ M"
    (p ∨ q) ∨ r ⊢ p ∨ (q ∨ r)
+
          "A B"
  ------------------------------------------------------------------ *}
+
   shows "¬ B ⟶ M"
 
+
proof (rule impI)
(* pabalagon manperjim marfruman1 josgomrom4 alfmarcua gleherlop
+
   assume "¬B"
  pabbergue antramhur enrparalv juacanrod hugrubsan alikan chrgencar aribatval*)  
+
  show "M" using assms(2)
lemma ejercicio_32:
 
   assumes 1: "(p q) ∨ r"  
 
   shows   "p ∨ (q ∨ r)"
 
using 1 proof (rule disjE)
 
   assume "p ∨ q" thus ?thesis
 
 
   proof (rule disjE)
 
   proof (rule disjE)
     assume p thus ?thesis by (rule disjI1)
+
     assume "A"
 +
    then have "A ∧ ¬ B" using `¬ B` by (rule conjI)
 +
    show "M" using assms(1) `A ∧ ¬ B` by (rule mp)
 
   next
 
   next
     assume q hence "q ∨ r" by (rule disjI1)
+
     assume "B"
     thus ?thesis by (rule disjI2)
+
     show "M" using `¬ B` `B` by (rule notE)
 
   qed
 
   qed
next
 
  assume r hence "q ∨ r" by (rule disjI2)
 
  thus ?thesis by (rule disjI2)
 
qed
 
 
(* benber cammonagu *)
 
lemma ejercicio_32_1:
 
  assumes "(p ∨ q) ∨ r"
 
  shows  "p ∨ (q ∨ r)"
 
proof -
 
  have "(p ∨ q) ∨ r" using assms .
 
  moreover {
 
    assume "p ∨ q"
 
    moreover {
 
      assume "p"
 
      hence ?thesis by (rule disjI1)
 
    }
 
    moreover {
 
      assume "q"
 
      hence "q ∨ r" by (rule disjI1)
 
      hence ?thesis by (rule disjI2)
 
    }
 
    ultimately have ?thesis by (rule disjE)
 
  }
 
  moreover {
 
    assume "r"
 
    hence "q ∨ r" by (rule disjI2)
 
    hence ?thesis by (rule disjI2)
 
  }
 
  ultimately show ?thesis by (rule disjE)
 
 
qed
 
qed
  
text {* ---------------------------------------------------------------
+
(* pabalagon manperjim josgomrom4 gleherlop raffergon2 hugrubsan
  Ejercicio 33. Demostrar
+
   pabbergue enrparalv giafus1 antramhur *)  
    p ∧ (q ∨ r) ⊢ (p ∧ q) ∨ (p ∧ r)
+
lemma ejercicio_8_2:
  ------------------------------------------------------------------ *}
+
   assumes "A ⟶ (M ⟷ ¬B)"
 
+
          "A B"
(* pabalagon manperjim marfruman1 josgomrom4 chrgencar gleherlop
+
        shows "¬B ⟶ M"
   alfmarcua pabbergue antramhur enrparalv juacanrod hugrubsan alikan
+
using assms(2) proof (rule disjE)
  chrgencar aribatval*)  
+
  assume 1: A
lemma ejercicio_33:
+
  have 2: "M ⟷ ¬B" using assms(1) 1 by (rule mp)
   assumes 1: "p ∧ (q ∨ r)"  
+
   show "¬B ⟶ M" proof (rule impI)
  shows  "(p ∧ q) (p ∧ r)"
+
     assume 3: "¬B" show M using 2 3 by (rule iffD2)
proof -
 
  have 2: p using 1 by (rule conjunct1)
 
  show ?thesis
 
  proof (rule disjE)
 
    assume 3: q have "p ∧ q" using 2 3 by (rule conjI)
 
    thus ?thesis by (rule disjI1)
 
   next
 
    assume 4: r have "p ∧ r" using 2 4 by (rule conjI)
 
     thus ?thesis by (rule disjI2)
 
  next
 
    show "q ∨ r" using 1 by (rule conjunct2)
 
 
   qed
 
   qed
qed
 
 
(* benber cammonagu *)
 
lemma ejercicio_33_1:
 
  assumes "p ∧ (q ∨ r)"
 
  shows  "(p ∧ q) ∨ (p ∧ r)"
 
proof -
 
  have "p" using assms by (rule conjunct1)
 
  have "q ∨ r" using assms by (rule conjunct2)
 
  moreover {
 
    assume "q"
 
    with `p` have "p ∧ q" by (rule conjI)
 
    hence ?thesis by (rule disjI1)
 
  }
 
  moreover {
 
    assume "r"
 
    with `p` have "p ∧ r" by (rule conjI)
 
    hence ?thesis by (rule disjI2)
 
  }
 
  ultimately show ?thesis by (rule disjE)
 
qed
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 34. Demostrar
 
    (p ∧ q) ∨ (p ∧ r) ⊢ p ∧ (q ∨ r)
 
  ------------------------------------------------------------------ *}
 
 
(* pabalagon manperjim marfruman1 josgomrom4 chrgencar alfmarcua
 
  gleherlop pabbergue antramhur enrparalv juacanrod hugrubsan alikan aribatval*)
 
lemma ejercicio_34:
 
  assumes "(p ∧ q) ∨ (p ∧ r)"
 
  shows  "p ∧ (q ∨ r)"
 
using assms(1) proof (rule disjE)
 
  assume 2: "p ∧ q" hence q by (rule conjunct2)
 
  hence 3: "q ∨ r" by (rule disjI1)
 
  have p using 2 by (rule conjunct1)
 
  thus ?thesis using 3 by (rule conjI)
 
 
next
 
next
   assume 4: "p ∧ r" hence r by (rule conjunct2)
+
   assume 4: B
   hence 5: "q ∨ r" by (rule disjI2)
+
   show ?thesis proof (rule impI)
  have p using 4 by (rule conjunct1)
+
     assume "¬B" thus M using 4 by (rule notE)
  thus ?thesis using 5 by (rule conjI)
+
   qed
qed
 
 
 
(* benber cammonagu *)
 
lemma ejercicio_34_1:
 
  assumes "(p ∧ q) ∨ (p ∧ r)"
 
  shows  "p ∧ (q ∨ r)"
 
proof -
 
  have "(p ∧ q) ∨ (p ∧ r)" using assms .
 
  moreover {
 
    assume "p ∧ q"
 
    hence "p" by (rule conjunct1)
 
    moreover {
 
      have "q" using `p ∧ q` by (rule conjunct2)
 
      hence "q ∨ r" by (rule disjI1)
 
    }
 
    ultimately have ?thesis by (rule conjI)
 
  }
 
  moreover {
 
     assume "p ∧ r"
 
    hence "p" by (rule conjunct1)
 
    moreover {
 
      have "r" using `p ∧ r` by (rule conjunct2)
 
      hence "q ∨ r" by (rule disjI2)
 
    }
 
    ultimately have ?thesis by (rule conjI)
 
   }
 
  ultimately show ?thesis by (rule disjE)
 
 
qed
 
qed
  
 
text {* ---------------------------------------------------------------  
 
text {* ---------------------------------------------------------------  
   Ejercicio 35. Demostrar
+
   Ejercicio 9. (En APLI2 el ejercicio 13 de LPO) Formalizar, y decidir
     p ∨ (q ∧ r) ⊢ (p ∨ q) ∧ (p ∨ r)
+
  la corrección, del siguiente argumento
 +
     Toda persona pobre tiene un padre rico. Por tanto, existe una
 +
    persona rica que tiene un abuelo rico.
 +
  Usar R(x) para x es rico
 +
      p(x) para el padre de x
 
   ------------------------------------------------------------------ *}
 
   ------------------------------------------------------------------ *}
  
(* pabalagon manperjim marfruman1 josgomrom4 chrgencar alfmarcua
+
(* benber *)
  gleherlop pabbergue antramhur enrparalv juacanrod hugrubsan alikan aribatval*)  
+
lemma
lemma ejercicio_35:
+
   assumes "∀x. ¬ R x ⟶ R (p x)"
   assumes "p ∨ (q ∧ r)"  
+
   shows "∃x. R x R (p (p x))"
   shows   "(p ∨ q) ∧ (p ∨ r)"
 
using assms(1) proof (rule disjE)
 
  assume 1: p hence 2: "p ∨ r" by (rule disjI1)
 
  have "p ∨ q" using 1 by (rule disjI1)
 
  thus ?thesis using 2 by (rule conjI)
 
next
 
  assume 3: "q r" hence r by (rule conjunct2)
 
  hence 4: "p ∨ r" by (rule disjI2)
 
  have q using 3 by (rule conjunct1)
 
  hence "p ∨ q" by (rule disjI2)
 
  thus ?thesis using 4 by (rule conjI)
 
qed
 
 
 
(* benber cammonagu *)
 
lemma ejercicio_35_1:
 
  assumes "p ∨ (q ∧ r)"
 
  shows  "(p ∨ q) ∧ (p ∨ r)"
 
 
proof -
 
proof -
   have "p ∨ (q ∧ r)" using assms .
+
   have 0: "p ∨ ¬ p" for p
  moreover {
+
  proof (rule ccontr)
    assume "p"
+
     assume "¬ (p ∨ ¬ p)"
    hence "p ∨ q" by (rule disjI1)
 
    moreover have "p ∨ r" using `p` by (rule disjI1)
 
    ultimately have ?thesis by (rule conjI)
 
  }
 
  moreover {
 
     assume "q ∧ r"
 
    {
 
      have "q" using `q ∧ r` by (rule conjunct1)
 
      hence "p ∨ q" by (rule disjI2)
 
    }
 
 
     moreover {
 
     moreover {
       have "r" using `q ∧ r` by (rule conjunct2)
+
       have "p"
       hence "p ∨ r" by (rule disjI2)
+
      proof (rule ccontr)
 +
        assume "¬ p"
 +
        hence "p ∨ ¬ p" by (rule disjI2)
 +
        with `¬ (p ∨ ¬ p)` show "False" by (rule notE)
 +
      qed
 +
       hence "p ∨ ¬ p" by (rule disjI1)
 
     }
 
     }
     ultimately have ?thesis by (rule conjI)
+
     ultimately show "False" by (rule notE)
   }
+
   qed
  ultimately show ?thesis by (rule disjE)
 
qed
 
  
text {* ---------------------------------------------------------------
+
   have "¬ R x ⟶ R (p x)" for x using assms(1) by (rule allE)
   Ejercicio 36. Demostrar
+
   hence 1: "¬ R x ⟹ R (p x)" for x by (rule mp)
    (p ∨ q) (p ∨ r) ⊢ p ∨ (q ∧ r)
 
   ------------------------------------------------------------------ *}
 
  
(* pabalagon manperjim marfruman1 josgomrom4 chrgencar alfmarcua
+
   have 2: "⟦R y; ¬ R (p y)⟧ ⟹ ?thesis" for y
  gleherlop pabbergue antramhur enrparalv juacanrod hugrubsan alikan aribatval*)
+
   proof
lemma ejercicio_36:
+
    assume "R y"
   assumes 1: "(p ∨ q) ∧ (p ∨ r)"
+
    assume "¬ R (p y)"
   shows  "p ∨ (q ∧ r)"
+
    hence "R (p (p y))" by (rule 1)
proof -
+
     with `R y` show "R y ∧ R (p (p y))" by (rule conjI)
  have 2: "p ∨ q" using 1 by (rule conjunct1)
 
  have 3: "p ∨ r" using 1 by (rule conjunct2)
 
  show ?thesis using 2
 
  proof (rule disjE)
 
    assume p thus ?thesis by (rule disjI1)
 
  next
 
     assume 4: q show ?thesis using 3
 
    proof (rule disjE)
 
      assume p thus ?thesis by (rule disjI1)
 
    next
 
      assume 5: r have "q ∧ r" using 4 5 by (rule conjI)
 
      thus ?thesis by (rule disjI2)
 
    qed
 
 
   qed
 
   qed
qed
 
  
(* benber cammonagu *)
+
  have 3: "R y ⟹ ?thesis" for y
lemma ejercicio_36_1:
+
   proof -
  assumes "(p ∨ q) ∧ (p ∨ r)"
+
     assume "R y"
   shows  "p ∨ (q ∧ r)"
+
 
proof -
+
     have "R (p y) ¬ R (p y)" by (rule 0)
  have "p ∨ q" using assms by (rule conjunct1)
 
  moreover {
 
     assume "p"
 
    hence ?thesis by (rule disjI1)
 
  }
 
  moreover {
 
    assume "q"
 
     have "p ∨ r" using assms by (rule conjunct2)
 
 
     moreover {
 
     moreover {
       assume "p"
+
       assume "R (p y)"
       hence ?thesis by (rule disjI1)
+
      have "R (p (p y)) ∨ ¬ R (p (p y))" by (rule 0)
 +
       moreover {
 +
        assume "R (p (p y))"
 +
        with `R y` have "R y ∧ R (p (p y))" by (rule conjI)
 +
        hence ?thesis by (rule exI)
 +
      }
 +
      moreover {
 +
        assume "¬ R (p (p y))"
 +
        with `R (p y)` have ?thesis by (rule 2)
 +
      }
 +
      ultimately have ?thesis by (rule disjE)
 
     }
 
     }
 
     moreover {
 
     moreover {
       assume "r"
+
       assume "¬ R (p y)"
       with `q` have "q ∧ r" by (rule conjI)
+
       with `R y` have ?thesis by (rule 2)
      hence ?thesis by (rule disjI2)
 
 
     }
 
     }
     ultimately have ?thesis by (rule disjE)
+
     ultimately show ?thesis by (rule disjE)
  }
 
  ultimately show ?thesis by (rule disjE)
 
qed
 
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 37. Demostrar
 
    (p ⟶ r) ∧ (q ⟶ r) ⊢ p ∨ q ⟶ r
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim marfruman1 josgomrom4 alfmarcua gleherlop
 
  pabbergue antramhur enrparalv juacanrod hugrubsan alikan chrgencar aribatval*)
 
lemma ejercicio_37:
 
  assumes 1: "(p ⟶ r) ∧ (q ⟶ r)"
 
  shows  "p ∨ q ⟶ r"
 
proof (rule impI)
 
  have 2: "p ⟶ r" using 1 by (rule conjunct1)
 
  have 3: "q ⟶ r" using 1 by (rule conjunct2)
 
  assume 4: "p ∨ q" show "r" using 4
 
  proof (rule disjE)
 
    assume 5: "p" show "r" using 2 5 by (rule mp)
 
  next
 
    assume 6: "q" show "r" using 3 6 by (rule mp)
 
 
   qed
 
   qed
qed
 
  
(* benber cammonagu *)
+
   fix y
lemma ejercicio_37_1:
+
   have "R y ¬ R y" by (rule 0)
   assumes "(p ⟶ r) ∧ (q ⟶ r)"
 
   shows  "p q ⟶ r"
 
proof
 
  assume "p ∨ q"
 
 
   moreover {
 
   moreover {
     have "p ⟶ r" using assms by (rule conjunct1)
+
     assume "R y"
    moreover assume "p"
+
     hence ?thesis by (rule 3)
     ultimately have "r" by (rule mp)
 
 
   }
 
   }
 
   moreover {
 
   moreover {
     have "q ⟶ r" using assms by (rule conjunct2)
+
     assume "¬ R y"
     moreover assume "q"
+
    hence "R (p y)" by (rule 1)
    ultimately have "r" by (rule mp)
+
     hence ?thesis by (rule 3)
 
   }
 
   }
   ultimately show "r" by (rule disjE)
+
   ultimately show ?thesis by (rule disjE)
 
qed
 
qed
  
text {* ---------------------------------------------------------------
+
(* alfmarcua *)
  Ejercicio 38. Demostrar
+
lemma ejercicio_9_2:
    p ∨ q ⟶ r ⊢ (p ⟶ r) ∧ (q ⟶ r)
+
   assumes "∀ x. ¬ R x ⟶ R (p x)"
  ------------------------------------------------------------------ *}
+
   shows "∃x. R x ∧ R (p (p x))"
 
+
proof (rule disjE, rule ejercicio_52)
(* pabalagon manperjim marfruman1 josgomrom4 alfmarcua gleherlop
+
   have prelemma:"(∃y. ¬ R (p y)) ?thesis"
  pabbergue antramhur enrparalv juacanrod hugrubsan alikan chrgencar aribatval*)  
 
lemma ejercicio_38:
 
   assumes "p ∨ q ⟶ r"  
 
   shows   "(p ⟶ r) ∧ (q ⟶ r)"
 
proof (rule conjI)
 
   show "p ⟶ r"
 
 
   proof (rule impI)
 
   proof (rule impI)
     assume "p" hence 1: "p ∨ q" by (rule disjI1)
+
     assume "∃y. ¬ R (p y)"
     show "r" using assms(1) 1 by (rule mp)
+
    then obtain b where  "¬ R (p b)" by (rule exE)
 +
     have "¬ R (p b) ⟶ R (p (p b))" using assms by (rule allE)
 +
    then have "R (p (p b))" using `¬ R (p b)` by (rule mp)
 +
    have "¬ R b ⟶ R (p b)" using assms by (rule allE)
 +
    then have "¬¬ R b" using `¬ R (p b)` by (rule mt)
 +
    then have "R b" by (rule notnotD)
 +
    then have "R b ∧ R (p (p b))" using `R (p (p b))` by (rule conjI)
 +
    then show "∃x. R x ∧ R (p (p x))" by (rule exI)
 
   qed
 
   qed
next
+
 
   show "q ⟶ r"
+
  fix a
   proof (rule impI)
+
   show "R (p a) ⟹ ?thesis"
     assume q hence 2: "p ∨ q" by (rule disjI2)
+
   proof (rule disjE, rule ejercicio_52)
     show r using assms(1) 2 by (rule mp)
+
     assume "R (p a)"
  qed
+
     show "R (p (p a)) ⟹ ?thesis"
qed
+
    proof (rule disjE, rule ejercicio_52)
 
+
      assume "R (p (p (p a)))"
(* benber cammonagu*)
+
      have "R (p a) ∧ R (p (p (p a)))" using `R (p a)` `R (p (p (p a)))`  by (rule conjI)
lemma ejercicio_38_1:
+
      then show ?thesis by (rule exI)
  assumes "p ∨ q ⟶ r"  
+
    next
  shows  "(p ⟶ r) ∧ (q ⟶ r)"
+
      assume "¬ R (p (p (p a)))"
proof
+
      then have "∃y. ¬ R (p y)" by (rule exI)
  show "p ⟶ r"
+
      show ?thesis using prelemma `∃y. ¬ R (p y)` by (rule mp)
  proof
+
    qed
    assume "p"
+
  next
    hence "p ∨ q" by (rule disjI1)
+
     assume "¬ R (p (p a))"
    with assms show "r" by (rule mp)
+
     then have "∃y. ¬ R (p y)" by (rule exI)
  qed
+
     show ?thesis using prelemma `∃y. ¬ R (p y)` by (rule mp)
next
 
  show "q ⟶ r"
 
  proof
 
     assume "q"
 
     hence "p ∨ q" by (rule disjI2)
 
     with assms show "r" by (rule mp)
 
 
   qed
 
   qed
qed
 
  
section {* Negaciones *}
+
   assume "¬ R (p a)"
 
+
   then have "∃y. ¬ R (p y)" by (rule exI)
text {* ---------------------------------------------------------------
+
   show ?thesis using prelemma `∃y. ¬ R (p y)` by (rule mp)
   Ejercicio 39. Demostrar
 
    p ⊢ ¬¬p
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim  benber josgomrom4 raffergon2 gleherlop
 
  marfruman1 chrgencar alfmarcua pabbergue enrparalv juacanrod
 
  hugrubsan cammonagu alikan aribatval*)
 
lemma ejercicio_39:
 
  assumes "p"
 
   shows  "¬¬p"
 
  using assms(1) by (rule notnotI)
 
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 40. Demostrar
 
    ¬p ⊢ p ⟶ q
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim marfruman1 josgomrom4 alfmarcua pabbergue
 
  gleherlop juacanrod enrparalv hugrubsan alikan chrgencar aribatval*)  
 
lemma ejercicio_40:
 
  assumes 1: "¬p"
 
  shows  "p ⟶ q"
 
proof (rule impI)
 
   assume 2: p show q using 1 2 by (rule notE)
 
qed
 
 
 
(* benber cammonagu *)
 
lemma ejercicio_40_1:
 
  assumes "¬p"
 
  shows  "p ⟶ q"
 
proof
 
  assume "p"
 
  with `¬p` show "q" by (rule notE)
 
 
qed
 
qed
  
text {* ---------------------------------------------------------------
+
(* pabalagon manperjim marfruman1 josgomrom4 gleherlop raffergon2
  Ejercicio 41. Demostrar
+
   hugrubsan pabbergue enrparalv giafus1 antramhur *)  
    p ⟶ q ⊢ ¬q ⟶ ¬p
+
lemma ejercicio_9_3:
  ------------------------------------------------------------------ *}
+
   assumes "∀x. ¬R x R (p x)"
 
+
   shows "∃x. R x ∧ R (p (p x))"
(* pabalagon manperjim raffergon2 josgomrom4 marfruman1 alfmarcua
 
   pabbergue gleherlop chrgencar enrparalv juacanrod hugrubsan alikan aribatval*)  
 
lemma ejercicio_41:
 
   assumes 1: "p q"
 
  shows  "¬q ⟶ ¬p"
 
proof (rule impI)
 
  assume 2: "¬q" show "¬p" using 1 2 by (rule mt)
 
qed
 
 
 
(* benber cammonagu *)
 
lemma ejercicio_41_1:
 
  assumes "p ⟶ q"
 
   shows   "¬q ⟶ ¬p"
 
proof
 
  assume "¬q"
 
  with `p ⟶ q` show "¬p" by (rule mt)
 
qed
 
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 42. Demostrar
 
    p∨q, ¬q ⊢ p
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim raffergon2 josgomrom4 marfruman1 alfmarcua
 
  pabbergue gleherlop chrgencar enrparalv juacanrod hugrubsan alikan aribatval*)
 
lemma ejercicio_42:
 
  assumes "p∨q"
 
          "¬q"
 
  shows  "p"
 
using assms(1) proof (rule disjE)
 
  assume "p" thus "p" .
 
next
 
  assume 2: "q" show "p" using assms(2) 2 by (rule notE)
 
qed
 
 
 
(* benber cammonagu *)
 
lemma ejercicio_42_1:
 
  assumes "p∨q"
 
          "¬q"
 
  shows  "p"
 
 
proof -
 
proof -
   note `p ∨ q`
+
   fix y
   moreover have "p ⟹ p" .
+
   have s1: "⟦¬R (p y)⟧ ?thesis" for y proof (rule exI)
  moreover {
+
     assume 2: "¬R (p y)"
     assume "q"
+
     have "¬R (p y) ⟶ R (p (p y))" using assms(1) by (rule allE)
     with `¬q` have "p" by (rule notE)
+
    hence 3: "R (p (p y))" using 2 by (rule mp)
  }
+
     have "¬R y ⟶ R (p y)" using assms(1) by (rule allE)
  ultimately show "p" by (rule disjE)
+
    hence "¬¬R y" using 2 by (rule mt)
qed
+
    hence "R y" by (rule notnotD)
 
+
    thus "R y ∧ R (p (p y))" using 3 by (rule conjI)
text {* ---------------------------------------------------------------
 
  Ejercicio 43. Demostrar
 
    p ∨ q, ¬p ⊢ q
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim raffergon2 josgomrom4 marfruman1 alfmarcua
 
  pabbergue gleherlop chrgencar enrparalv juacanrod hugrubsan alikan aribatval*)  
 
lemma ejercicio_43:
 
  assumes "p ∨ q"
 
          "¬p"  
 
  shows  "q"
 
using assms(1) proof (rule disjE)
 
  assume 1: "p" show "q" using assms(2) 1 by (rule notE)
 
next
 
  assume "q" thus "q" .
 
qed
 
 
 
(* benber cammonagu*)
 
lemma ejercicio_43_1:
 
  assumes "p ∨ q"
 
          "¬p"
 
  shows  "q"
 
proof -
 
  note `p ∨ q`
 
  moreover {
 
     assume "p"
 
    with `¬p` have "q" by (rule notE)
 
  }
 
  moreover have "q ⟹ q" .
 
  ultimately show "q" by (rule disjE)
 
qed
 
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 44. Demostrar
 
    p ∨ q ⊢ ¬(¬p ∧ ¬q)
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim gleherlop josgomrom4 marfruman1 pabbergue
 
  juacanrod hugrubsan alikan chrgencar aribatval*)
 
lemma ejercicio_44:
 
  assumes "p ∨ q"
 
  shows  "¬(¬p ∧ ¬q)"
 
proof (rule notI)
 
  assume 1: "¬p ∧ ¬q" hence 2: "¬p" by (rule conjunct1)
 
  have 3: "¬q" using 1 by (rule conjunct2)
 
  show "False"
 
  using assms(1) proof (rule disjE)
 
    assume 4: "p" show ?thesis using 2 4 by (rule notE)
 
  next
 
    assume 5: "q" show ?thesis using 3 5 by (rule notE)
 
 
   qed
 
   qed
qed
+
  have s2: "R y ⟹ ?thesis" for y proof -
 
+
    assume 2: "R y"
(* benber alfmarcua cammonagu *)
+
     have "¬R (p y) ∨ R (p y)" by (rule excluded_middle)
lemma ejercicio_44_1:
+
     thus ?thesis proof (rule disjE)
  assumes "p ∨ q"
+
      assume 3: "¬R (p y)" thus ?thesis by (rule s1)
  shows  "¬(¬p ∧ ¬q)"
+
    next
proof
+
      assume 4: "R (p y)"
  assume "¬p ∧ ¬q"
+
      have "¬R (p (p y)) ∨ R (p (p y))" by (rule excluded_middle)
  note `p ∨ q`
+
      thus ?thesis proof (rule disjE)
  moreover {
+
        assume "¬R (p (p y))" thus ?thesis by (rule s1)
     from `¬p ∧ ¬q` have "¬p" by (rule conjunct1)
+
      next
    moreover assume "p"
+
        assume "R (p (p y))"
    ultimately have "False" by (rule notE)
+
        with `R y` have "R y ∧ R (p (p y))" by (rule conjI)
  }
+
        thus ?thesis by (rule exI)
  moreover {
+
      qed
     from `¬p ∧ ¬q` have "¬q" by (rule conjunct2)
+
    qed
    moreover assume "q"
 
    ultimately have "False" by (rule notE)
 
  }
 
  ultimately show "False" by (rule disjE)
 
qed
 
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 45. Demostrar
 
    p ∧ q ⊢ ¬(¬p ∨ ¬q)
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim marfruman1 josgomrom4 gleherlop pabbergue
 
  juacanrod hugrubsan alikan chrgencar aribatval*)
 
lemma ejercicio_45:
 
  assumes 1: "p ∧ q"  
 
  shows  "¬(¬p ∨ ¬q)"
 
proof (rule notI)
 
  assume 2: "¬p ¬q" have 3: "p" using 1 by (rule conjunct1)
 
  have 4: "q" using 1 by (rule conjunct2)
 
  show "False" using 2
 
  proof (rule disjE)
 
    assume "¬p" thus ?thesis using 3 by (rule notE)
 
  next
 
    assume "¬q" thus ?thesis using 4 by (rule notE)
 
 
   qed
 
   qed
qed
+
   have "¬R y R y" by (rule excluded_middle)
 
+
   thus ?thesis proof (rule disjE)
(* benber alfmarcua cammonagu *)
+
     assume 2: "R y" thus ?thesis by (rule s2)
lemma ejercicio_45_1:
 
  assumes "p ∧ q"
 
  shows  "¬(¬p ∨ ¬q)"
 
proof
 
  assume "¬p ∨ ¬q"
 
  moreover {
 
    assume "¬p"
 
    moreover have "p" using `p ∧ q` by (rule conjunct1)
 
    ultimately have "False" by (rule notE)
 
  }
 
   moreover {
 
    assume "¬q"
 
    moreover have "q" using `p ∧ q` by (rule conjunct2)
 
    ultimately have "False" by (rule notE)
 
  }
 
  ultimately show False by (rule disjE)
 
qed
 
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 46. Demostrar
 
    ¬(p ∨ q) ⊢ ¬p ∧ ¬q
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim marfruman1 josgomrom4 gleherlop pabbergue
 
  juacanrod hugrubsan alikan chrgencar aribatval*)
 
lemma ejercicio_46:
 
  assumes 1: "¬(p q)"  
 
  shows  "¬p ∧ ¬q"
 
proof (rule conjI)
 
  show "¬p"
 
  proof (rule notI)
 
    assume p hence 2: "p ∨ q" by (rule disjI1)
 
    show False using 1 2 by (rule notE)
 
   qed
 
  show "¬q"
 
  proof (rule notI)
 
     assume q hence 3: "p ∨ q" by (rule disjI2)
 
    show False using 1 3 by (rule notE)
 
  qed
 
qed
 
 
 
(* benber cammmonagu *)
 
lemma ejercicio_46_1:
 
  assumes "¬(p ∨ q)"
 
  shows  "¬p ∧ ¬q"
 
proof
 
  show "¬p"
 
  proof (rule ccontr)
 
    assume "¬¬p"
 
    hence "p" by (rule notnotD)
 
    hence "p ∨ q" by (rule disjI1)
 
    with assms show "False" by (rule notE)
 
  qed
 
next
 
  show "¬q"
 
  proof (rule ccontr)
 
    assume "¬¬q"
 
    hence "q" by (rule notnotD)
 
    hence "p ∨ q" by (rule disjI2)
 
    with assms show "False" by (rule notE)
 
  qed
 
qed
 
 
 
(* alfmarcua *)
 
lemma ejercicio_46_2:
 
  assumes "¬(p ∨ q)"
 
  shows  "¬p ∧ ¬q"
 
proof (rule conjI)
 
  have "p ⟹ p ∨ q" by (rule disjI1)
 
  then have "p ⟶ p ∨ q" by (rule impI)
 
  then show "¬ p" using assms by (rule mt)
 
next
 
  have "q ⟹ p ∨ q" by (rule disjI2)
 
  then have "q ⟶ p ∨ q" by (rule impI)
 
  then show "¬ q" using assms by (rule mt)
 
qed
 
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 47. Demostrar
 
    ¬p ∧ ¬q ⊢ ¬(p ∨ q)
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon manperjim marfruman1 josgomrom4 pabbregue juacanrod
 
  hugrubsan alikan aribatval*)
 
lemma ejercicio_47:
 
  assumes 1: "¬p ∧ ¬q"
 
  shows  "¬(p ∨ q)"
 
proof (rule notI)
 
  have 2: "¬p" using 1 by (rule conjunct1)
 
  have 3: "¬q" using 1 by (rule conjunct2)
 
  assume 4: "p ∨ q"
 
  show False
 
  using 4 proof (rule disjE)
 
    assume 5: p show ?thesis using 2 5 by (rule notE)
 
 
   next
 
   next
     assume 6: q show ?thesis using 3 6 by (rule notE)
+
     assume 4: "¬R y"
 +
    have "¬R y ⟶ R (p y)" using assms(1) by (rule allE)
 +
    hence "R (p y)" using 4 by (rule mp)
 +
    thus ?thesis by (rule s2)
 
   qed
 
   qed
qed
 
 
(* benber gleherlop cammonagu chrgencar *)
 
lemma ejercicio_47_1:
 
  assumes "¬p ∧ ¬q"
 
  shows  "¬(p ∨ q)"
 
proof
 
  assume "p ∨ q"
 
  hence "¬(¬p ∧ ¬q)" by (rule ejercicio_44_1)
 
  thus "False" using assms by (rule notE)
 
qed
 
 
(* alfmarcua *)
 
lemma ejercicio_47_2:
 
  assumes "¬p ∧ ¬q"
 
  shows  "¬(p ∨ q)"
 
proof (rule notI)
 
  have "¬ p" using assms by (rule conjunct1)
 
  have "¬ q" using assms by (rule conjunct2)
 
  assume "p ∨ q"
 
  then have "q" using `¬ p` by (rule ejercicio_43)
 
  show False using `¬ q` `q` by (rule notE)
 
qed
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 48. Demostrar
 
    ¬p ∨ ¬q ⊢ ¬(p ∧ q)
 
  ------------------------------------------------------------------ *}
 
 
(* pabalagon manperjim marfruman1 josgomrom4 pabbergue juacanrod
 
  hugrubsan alikan aribatval*)
 
lemma ejercicio_48:
 
  assumes 1: "¬p ∨ ¬q"
 
  shows  "¬(p ∧ q)"
 
proof (rule notI)
 
  assume 2: "p ∧ q" hence 3: p by (rule conjunct1)
 
  have 4: q using 2 by (rule conjunct2)
 
  show False
 
  using 1 proof (rule disjE)
 
    assume "¬p" thus ?thesis using 3 by (rule notE)
 
  next
 
    assume "¬q" thus ?thesis using 4 by (rule notE)
 
  qed
 
qed
 
 
(* benber alfmarcua gleherlop cammonagu chrgencar *)
 
lemma ejercicio_48_1:
 
  assumes "¬p ∨ ¬q"
 
  shows  "¬(p ∧ q)"
 
proof
 
  assume "p ∧ q"
 
  hence "¬(¬p ∨ ¬q)" by (rule ejercicio_45_1)
 
  thus "False" using assms by (rule notE)
 
 
qed
 
qed
  
 
text {* ---------------------------------------------------------------  
 
text {* ---------------------------------------------------------------  
   Ejercicio 49. Demostrar
+
   Ejercicio 10. (En APLI2 el ejercicio 10 de LPO) Formalizar, y decidir
     ⊢ ¬(p ∧ ¬p)
+
  la corrección, del siguiente argumento
 +
    Los aficionados al fútbol aplauden a cualquier futbolista
 +
    extranjero. Juanito no aplaude a futbolistas extranjeros. Por
 +
    tanto, si hay algún futbolista extranjero nacionalizado español,
 +
     Juanito no es aficionado al fútbol.
 +
  Usar Af(x)  para x es aficicionado al fútbol
 +
      Ap(x,y) para x aplaude a y
 +
      E(x)    para x es un futbolista extranjero
 +
      N(x)    para x es un futbolista nacionalizado español
 +
      j      para Juanito
 
   ------------------------------------------------------------------ *}
 
   ------------------------------------------------------------------ *}
 
(* pabalagon manperjim marfruman1 josgomrom4 alfmarcu gleherlop
 
  hugrubsan juacanrod cammonagu alikan chrgencar aribatval*)
 
lemma ejercicio_49:
 
  "¬(p ∧ ¬p)"
 
proof (rule notI)
 
  assume 1: "p ∧ ¬p" hence 2: p by (rule conjunct1)
 
  have "¬p" using 1 by (rule conjunct2)
 
  thus "False" using 2 by (rule notE)
 
qed
 
  
 
(* benber *)
 
(* benber *)
lemma ejercicio_49_1:
+
lemma
   "¬(p ¬p)"
+
   assumes "∀x. Af x ⟶ (∀y. E y ⟶ Ap x y)"
 +
    and "∀x. E x ⟶ ¬ Ap j x"
 +
  shows "(∃x. E x N x) ⟶ ¬ Af j"
 
proof
 
proof
   assume "p ¬p"
+
   assume "∃x. E x N x"
  hence "¬p" by (rule conjunct2)
 
  moreover have "p" using `p ∧ ¬p` by (rule conjunct1)
 
  ultimately show "False" by (rule notE)
 
qed
 
  
text {* ---------------------------------------------------------------
+
  show "¬ Af j"
   Ejercicio 50. Demostrar
+
   proof (rule ccontr)
    p ∧ ¬p ⊢ q
+
    assume "¬ ¬ Af j"
  ------------------------------------------------------------------ *}
+
    hence "Af j" by (rule notnotD)
  
(* pabalagon manperjim raffergon2 josgomrom4 marfruman1 gleherlop
+
    note `∀x. Af x ⟶ (∀y. E y ⟶ Ap x y)`
  alfmarcua enrparalv pabbergue juacanrod hugrubsan alikan chrgencar aribatval*)  
+
    hence "Af j ⟶ (∀x. E x ⟶ Ap j x)" by (rule allE)
lemma ejercicio_50:
+
    moreover note `Af j`
  assumes 1: "p ∧ ¬p"
+
    ultimately have "∀x. E x ⟶ Ap j x" by (rule mp)
  shows  "q"
 
proof (rule notE)
 
  show p using 1 by (rule conjunct1)
 
  show "¬p" using 1 by (rule conjunct2)
 
qed
 
 
 
(* benber cammonagu*)
 
lemma ejercicio_50_1:
 
  assumes "p ∧ ¬p"
 
  shows  "q"
 
proof -
 
  have "¬p" using `p ∧ ¬p` by (rule conjunct2)
 
  moreover have "p" using `p ∧ ¬p` by (rule conjunct1)
 
  ultimately show "q" by (rule notE)
 
qed
 
  
text {* ---------------------------------------------------------------
+
    note `∃x. E x ∧ N x`
  Ejercicio 51. Demostrar
+
    moreover have "E x ∧ N x ⟹ False" for x
    ¬¬p ⊢ p
+
    proof -
  ------------------------------------------------------------------ *}
+
      assume "E x ∧ N x"
 +
      hence "E x" by (rule conjunct1)
  
(* pabalagon manperjim benber raffergon2 josgomrom4 marfruman1 gleherlop
+
      note `∀x. E x ⟶ Ap j x`
  alfmarcua enrparalv pabbergue juacanrod hugrubsan cammmonagu alikan
+
      hence "E x ⟶ Ap j x" by (rule allE)
  chrgencar aribatval*)
+
      hence "Ap j x" using `E x`  by (rule mp)
lemma ejercicio_51:
 
  assumes "¬¬p"
 
  shows  "p"
 
  using assms(1) by (rule notnotD)
 
  
text {* ---------------------------------------------------------------
+
      note `∀x. E x ⟶ ¬ Ap j x`
  Ejercicio 52. Demostrar
+
      hence "E x ⟶ ¬ Ap j x" by (rule allE)
    ⊢ p ∨ ¬p
+
      hence Ap j x" using `E x` by (rule mp)
  ------------------------------------------------------------------ *}
+
      thus "False" using `Ap j x` by (rule notE)
 
+
     qed
(* pabalagon manperjim marfruman1 josgomrom4 juacanrod pabbergue alikan enrparalv
+
    ultimately show "False" by (rule exE)
  chrgencar aribatval*)
 
lemma ejercicio_52:
 
  "p ∨ ¬p"
 
proof (rule ccontr)
 
  assume 1: (p ∨ ¬p)"
 
  have 2: "¬p" proof (rule notI)
 
    assume p hence 3: "p ∨ ¬p" by (rule disjI1)
 
     show "False" using 1 3 by (rule notE)
 
 
   qed
 
   qed
  have 4: "p ∨ ¬p" using 2 by (rule disjI2)
 
  show "False" using 1 4 by (rule notE)
 
 
qed
 
qed
  
(* benber cammonagu *)
+
(* alfmarcua marfruman1 *)
lemma ejercicio_52_1:
+
lemma ejercicio_10_2:
   "p ∨ ¬p"
+
   assumes "∀x y. Af x ∧ E y ⟶ Ap x y"
proof (rule ccontr)
+
          "∀y. E y ⟶ ¬ Ap j y"
   assume "¬ (p ∨ ¬ p)"
+
  shows "(∃y. E y ∧ N y) ⟶ ¬ Af j"
   hence "¬p ¬¬p" by (rule ejercicio_46_1)
+
proof (rule impI)
   hence "¬p" by (rule conjunct1)
+
   assume "∃x. E x ∧ N x"
   moreover {
+
   then obtain a where "E a N a" by (rule exE)
     have "¬¬p" using `¬p ∧ ¬¬p` by (rule conjunct2)
+
   then have "E a" by (rule conjunct1)
     hence "p" by (rule notnotD)
+
   show "¬ Af j"
  }
+
  proof (rule notI, rule notE)
  ultimately show "False" by (rule notE)
+
     assume "Af j"
qed
+
    then show "Af j ∧ E a" using `E a` by (rule conjI)
 
+
  next
(* alfmarcua *)
+
     have "E a ⟶ ¬ Ap j a" using assms(2) by (rule allE)
lemma ejercicio_52_2:
+
    then have "¬ Ap j a" using `E a` by (rule mp)
  "p ∨ ¬p"
+
    have "∀y. Af j ∧ E y ⟶ Ap j y" using assms(1) by (rule allE)
proof (rule ccontr)
+
    then have "Af j E a ⟶ Ap j a" by (rule allE)
  assume "¬ (p ∨ ¬ p)"
+
    then show "¬ (Af j ∧ E a)" using `¬ Ap j a` by (rule mt)
  then have "¬ p ¬¬ p" by (rule ejercicio_46)
+
  qed
  then show False by (rule ejercicio_50)
 
 
qed
 
qed
  
text {* ---------------------------------------------------------------
+
(* pabalagon manperjim josgomrom4 gleherlop raffergon2 hugrubsan
  Ejercicio 53. Demostrar
+
   pabbergue enrparalv giafus1 antramhur *)  
    ⊢ ((p ⟶ q) ⟶ p) ⟶ p
+
lemma ejercicio_10_3:
  ------------------------------------------------------------------ *}
+
   assumes "∀x y. Af x ∧ E y ⟶ Ap x y"
 
+
          "∀x y. x = j ∧ E y ⟶ ¬(Ap x y)"
(* pabalagon manperjim marfruman1 josgomrom4 alfmarcua gleherlop
+
  shows "(∃ x. (E x ∧ N x)) ⟶ ¬(Af j)"
   juacanrod pabbergue enrparalv chrgencar aribatval*)  
 
lemma ejercicio_53:
 
   "((p ⟶ q) ⟶ p) ⟶ p"
 
 
proof (rule impI)
 
proof (rule impI)
   assume 1: "(p ⟶ q) ⟶ p"
+
   assume 1: "∃x. E x ∧ N x"
   show p proof (rule ccontr)
+
   show "¬(Af j)" proof (rule ccontr)
     assume 2: "¬p"
+
    fix a
     have 3: "¬(p ⟶ q)" using 1 2 by (rule mt)
+
     assume "¬¬Af j" hence 2: "Af j" by (rule notnotD)
     have 4: "p q" proof (rule impI)
+
    obtain a where 3: "E a ∧ N a" using 1 by (rule exE)
      assume 5: p show q using 2 5 by (rule notE)
+
    hence 4: "E a" by (rule conjunct1)
     qed
+
     have 5: "N a" using 3 by (rule conjunct2)
     show False using 3 4 by (rule notE)
+
    have "∀y. Af j ∧ E y ⟶ Ap j y" using assms(1) by (rule allE)
 +
    hence 6: "Af j ∧ E a ⟶ Ap j a" by (rule allE)
 +
    have 7: "Af j ∧ E a" using 2 4 by (rule conjI)
 +
    have 8: "Ap j a" using 6 7 by (rule mp)
 +
    have "∀y. j = j ∧ E y ⟶ ¬(Ap j y)" using assms(2) by (rule allE)
 +
     hence 9: "j = j ∧ E a ¬(Ap j a)" by (rule allE)
 +
    have "j = j" by (rule refl)
 +
    hence 10: "j = j ∧ E a" using 4 by (rule conjI)
 +
     have "¬(Ap j a)" using 9 10 by (rule mp)
 +
     thus False using 8 by (rule notE)
 
   qed
 
   qed
qed
 
 
(* benber cammonagu *)
 
lemma ejercicio_53_1:
 
  "((p ⟶ q) ⟶ p) ⟶ p"
 
proof
 
  assume "(p ⟶ q) ⟶ p"
 
  have "p ∨ ¬p" by (rule ejercicio_52_1)
 
  moreover have "p ⟹ p" .
 
  moreover {
 
    assume "¬ p"
 
    hence "p ⟶ q" by (rule ejercicio_40_1)
 
    with `(p ⟶ q) ⟶ p` have "p" by (rule mp)
 
  }
 
  ultimately show "p" by (rule disjE)
 
 
qed
 
qed
  
 
text {* ---------------------------------------------------------------  
 
text {* ---------------------------------------------------------------  
   Ejercicio 54. Demostrar
+
   Ejercicio 11. Formalizar, y decidir la corrección, del siguiente
     ¬q ⟶ ¬p ⊢ p ⟶ q
+
  argumento
   ------------------------------------------------------------------ *}
+
    Ningún socio del club está en deuda con el tesorero del club. Si
 +
    un socio del club no paga su cuota está en deuda con el tesorero
 +
     del club. Por tanto, si el tesorero del club es socio del club,
 +
    entonces paga su cuota.
 +
   Usar P(x) para x es socio del club
 +
      Q(x) para x paga su cuota
 +
      R(x) para x está en deuda con el tesorero
 +
      a    para el tesorero del club
 +
  ------------------------------------------------------------------ *}
  
(* pabalagon manperjim marfruman1 josgomrom4 gleherlop juacanrod
+
(* benber *)
  pabbergue enrparalv chrgencar aribatval*)  
+
lemma
lemma ejercicio_54:
+
   assumes A1: "∀x. P x R x"
   assumes 1: "¬q ¬p"
+
    and A2: "∀x. P x ⟶ (¬(Q x) ⟶ R x)"
  shows  "p q"
+
    and "¬(R a)"
proof (rule impI)
+
   shows "P a Q a"
  assume 2: "p" hence 3: "¬¬p" by (rule notnotI)
 
  have "¬¬q" using 1 3 by (rule mt)
 
  thus "q" by (rule notnotD)
 
qed
 
 
 
(* benber alfmarcua  cammonagu *)
 
lemma ejercicio_54_1:
 
  assumes "¬q ⟶ ¬p"
 
   shows   "p q"
 
 
proof
 
proof
   assume "p"
+
   have "P a ⟶ (¬(Q a) ⟶ R a)" using A2 by (rule allE)
  hence "¬¬p" by (rule notnotI)
+
   moreover assume "P a"
   with assms have "¬¬q" by (rule mt)
+
   ultimately have "¬(Q a) ⟶ R a" by (rule mp)
   thus "q" by (rule notnotD)
 
qed
 
  
text {* ---------------------------------------------------------------
+
   show "Q a"
   Ejercicio 55. Demostrar
 
    ¬(¬p ∧ ¬q) ⊢ p ∨ q
 
  ------------------------------------------------------------------ *}
 
 
 
(* pabalagon marfruman1*)
 
lemma ejercicio_55:
 
  assumes 1: "¬(¬p ∧ ¬q)"
 
  shows  "p ∨ q"
 
proof (rule ccontr)
 
  assume 2: "¬(p ∨ q)"
 
  have 3: "p"
 
 
   proof (rule ccontr)
 
   proof (rule ccontr)
     assume 4: "¬p"
+
     assume "¬(Q a)"
    have 5: "q"
+
     with `¬(Q a) ⟶ R a` have "R a" by (rule mp)
     proof (rule ccontr)
+
     with `¬(R a)` show "False" by (rule notE)
      assume 6: "¬q" have 7: "¬p ∧ ¬q" using 4 6 by (rule conjI)
 
      show False using 1 7 by (rule notE)
 
     qed
 
    have 8: "p ∨ q" using 5 by (rule disjI2)
 
    show False using 2 8 by (rule notE)
 
 
   qed
 
   qed
  have 9: "p ∨ q" using 3 by (rule disjI1)
 
  show False using 2 9 by (rule notE)
 
 
qed
 
qed
  
(* benber alfmarcua josgomrom4 manperjim pabbergue juacanrod cammonagu enrparalv aribatval*)
+
(* alfmarcua *)
lemma ejercicio_55_1:
+
lemma ejercicio_11:
   assumes "¬(¬p ∧ ¬q)"
+
   assumes "∄x. P x ∧ R x"
   shows   "p ∨ q"
+
          "∀x. P x ∧ (¬ Q x) ⟶ R x"
proof (rule ccontr)
+
   shows "P a ⟶ Q a"
   assume "¬(p ∨ q)"
+
proof (rule impI, rule ccontr)
   hence "¬p ¬q" by (rule ejercicio_46_1)
+
   assume "P a" Q a"
   with assms show False by (rule notE)
+
  then have "P a ∧ (¬ Q a)" by (rule conjI)
 +
   have "P a (¬ Q a) ⟶ R a" using assms(2) by (rule allE)
 +
  then have "R a" using `P a ∧ (¬ Q a)` by (rule mp)
 +
  have "P a ∧ R a" using `P a` `R a` by (rule conjI)
 +
  then have "∃x. P x ∧ R x" by (rule exI)
 +
   show False using assms(1) `∃x. P x ∧ R x` by (rule notE)
 
qed
 
qed
  
text {* ---------------------------------------------------------------
+
(* pabalagon manperjim marfruman1 josgomrom4 gleherlop hugrubsan
  Ejercicio 56. Demostrar
+
   pabbergue enrparalv giafus1 antramhur *)  
    ¬(¬p ∨ ¬q) ⊢ p ∧ q
+
lemma ejercicio_11_2:
  ------------------------------------------------------------------ *}
+
   assumes "¬(∃x. P x ∧ R x)"
 
+
          "∀x. P x ∧ ¬Q x ⟶ R x"
(* pabalagon manperjim marfruman1 josgomrom4 gleherlop juacanrod
+
   shows "P a ⟶ Q a"
   pabbergue enrparalv chrgencar *)  
+
proof (rule impI)
lemma ejercicio_56:
+
   assume 1: "P a"
   assumes 1: "¬(¬p ∨ ¬q)"  
+
   show "Q a" proof (rule ccontr)
   shows   "p ∧ q"
+
     assume 2: "¬Q a"
proof (rule conjI)
+
    have 3: "P a ∧ ¬Q a" using 1 2 by (rule conjI)
   show 3: p
+
    have 4: "P a ∧ ¬ Q a ⟶R a" using assms(2) by (rule allE)
   proof (rule ccontr)
+
    hence 5: "R a" using 3 by (rule mp)
     assume "¬p" hence 4: "¬p ∨ ¬q" by (rule disjI1)
+
    have 6: "P a ∧ R a" using 1 5 by (rule conjI)
     show False using 1 4 by (rule notE)
+
    hence 7: "∃x. P x ∧ R x" by (rule exI)
 +
     show False using assms(1) 7 by (rule notE)
 
   qed
 
   qed
  show 5: q
 
  proof (rule ccontr)
 
    assume "¬q" hence 6: "¬p ∨ ¬q" by (rule disjI2)
 
    show False using 1 6 by (rule notE)
 
  qed
 
qed
 
 
(* benber alfmarcua cammonagu *)
 
lemma ejercicio_56_1:
 
  assumes "¬(¬p ∨ ¬q)"
 
  shows  "p ∧ q"
 
proof -
 
  have "¬¬p ∧ ¬¬q" using assms by (rule ejercicio_46_1)
 
  hence "¬¬p" by (rule conjunct1)
 
  hence "p" by (rule notnotD)
 
  moreover {
 
    have "¬¬q" using `¬¬p ∧ ¬¬q` by (rule conjunct2)
 
    hence "q" by (rule notnotD)
 
  }
 
  ultimately show "p ∧ q" by (rule conjI)
 
qed
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 57. Demostrar
 
    ¬(p ∧ q) ⊢ ¬p ∨ ¬q
 
  ------------------------------------------------------------------ *}
 
 
(* pabalagon manperjim marfruman1 josgomrom4 gleherlop juacanrod
 
  pabbergue enrparalv chrgencar *)
 
lemma ejercicio_57:
 
  assumes 1: "¬(p ∧ q)"
 
  shows  "¬p ∨ ¬q"
 
proof (rule ccontr)
 
  assume 2: "¬(¬p ∨ ¬q)"
 
  show False using 1
 
  proof (rule notE)
 
    show 3: "p ∧ q"
 
    proof (rule conjI)
 
      show p
 
      proof (rule ccontr)
 
        assume "¬p" hence 4: "¬p ∨ ¬q" by (rule disjI1)
 
        show False using 2 4 by (rule notE)
 
      qed
 
    next
 
      show q
 
      proof (rule ccontr)
 
        assume "¬q" hence 5: "¬p ∨ ¬q" by (rule disjI2)
 
        show False using 2 5 by (rule notE)
 
      qed
 
    qed
 
  qed
 
qed
 
 
(* benber alfmarcua cammonagu *)
 
lemma ejercicio_57_1:
 
  assumes "¬(p ∧ q)"
 
  shows  "¬p ∨ ¬q"
 
proof (rule ccontr)
 
  assume "¬(¬p ∨ ¬q)"
 
  hence "p ∧ q" by (rule ejercicio_56_1)
 
  with assms show "False" by (rule notE)
 
qed
 
 
text {* ---------------------------------------------------------------
 
  Ejercicio 58. Demostrar
 
    ⊢ (p ⟶ q) ∨ (q ⟶ p)
 
  ------------------------------------------------------------------ *}
 
 
(* pabalagon manperjim josgomrom4 marfruman1 juacanrod pabbergue enrparalv *)
 
lemma ejercicio_58:
 
  "(p ⟶ q) ∨ (q ⟶ p)"
 
proof -
 
  have "(p ⟶ q) ∨ ¬(p ⟶ q)" proof (rule ccontr)
 
    assume 1: "¬((p ⟶ q) ∨ ¬(p ⟶ q))"
 
    have 2: "¬(p ⟶ q)" proof (rule notI)
 
      assume "p ⟶ q"
 
      hence 3: "(p ⟶ q) ∨ ¬(p ⟶ q)" by (rule disjI1)
 
      show False using 1 3 by (rule notE)
 
    qed
 
    hence 4: "(p ⟶ q) ∨ ¬(p ⟶ q)" by (rule disjI2)
 
    show "False" using 1 4 by (rule notE)
 
  qed
 
  thus ?thesis proof (rule disjE)
 
    assume "p ⟶ q" thus ?thesis by (rule disjI1)
 
  next
 
    assume 1: "¬(p ⟶ q)"
 
    have "q ⟶ p" proof (rule impI)
 
      assume 2: q
 
      have 3: "p ⟶ q" proof (rule impI)
 
        assume p show q using 2 .
 
      qed
 
      show p using 1 3 by (rule notE)
 
    qed
 
    thus ?thesis by (rule disjI2)
 
  qed
 
qed
 
 
(* pabalagon gleherlop chrgencar *)
 
lemma ejercicio_58_2:
 
  "(p ⟶ q) ∨ (q ⟶ p)"
 
proof (rule ccontr)
 
  assume 1: "¬((p ⟶ q) ∨ (q ⟶ p))"
 
  hence 1: "(p ∧ ¬q) ∧ (q ∧ ¬p)" by simp
 
  hence "p ∧ ¬q" ..
 
  hence 2: p ..
 
  have "q ∧ ¬p" using 1 ..
 
  hence 3: "¬p" ..
 
  show False using 3 2 by (rule notE)
 
qed
 
 
(* benber cammonagu *)
 
lemma ejercicio_58_1:
 
  "(p ⟶ q) ∨ (q ⟶ p)"
 
proof (rule ccontr)
 
  assume "¬ ((p ⟶ q) ∨ (q ⟶ p))"
 
  hence 1: "¬(p ⟶ q) ∧ ¬(q ⟶ p)" by (rule ejercicio_46_1)
 
 
  have "p ∨ ¬p" by (rule ejercicio_52_1)
 
  moreover {
 
    assume "p"
 
    hence "q ⟶ p" by (rule ejercicio_7_1)
 
 
    have "¬(q ⟶ p)" using 1 by (rule conjunct2)
 
    hence "False" using `q ⟶ p` by (rule notE)
 
  }
 
  moreover {
 
    assume "¬p"
 
    hence "p ⟶ q" by (rule ejercicio_40_1)
 
 
    have "¬(p ⟶ q)" using 1 by (rule conjunct1)
 
    hence "False" using `p ⟶ q` by (rule notE)
 
  }
 
  ultimately show "False" by (rule disjE)
 
  moreover {
 
    assume "p"
 
    hence "q ⟶ p" by (rule ejercicio_7_1)
 
 
    have "¬(q ⟶ p)" using 1 by (rule conjunct2)
 
    hence "False" using `q ⟶ p` by (rule notE)
 
  }
 
qed
 
 
(* alfmarcua *)
 
lemma ejercicio_58_3:
 
  "(p ⟶ q) ∨ (q ⟶ p)"
 
proof (rule disjE)
 
  show "p ∨ ¬ p" by (rule ejercicio_52)
 
next
 
  assume "¬p"
 
  then have "p ⟶ q" by (rule ejercicio_40)
 
  then show ?thesis by (rule disjI1)
 
next
 
  assume "p"
 
  then have "q ⟶ p" by (rule ejercicio_7)
 
  then show ?thesis by (rule disjI2)
 
 
qed
 
qed
  
 
end
 
end
 
</source>
 
</source>

Revisión del 19:22 4 mar 2019

chapter {* R7: Deducción natural de primer orden *}

theory R7_Deduccion_natural_de_primer_orden_alu
imports Main 
begin

text {*
  Demostrar o refutar los siguientes lemas usando sólo las reglas
  básicas de deducción natural de la lógica proposicional, de los
  cuantificadores y de la igualdad: 
  · conjI:      ⟦P; Q⟧ ⟹ P ∧ Q
  · conjunct1:  P ∧ Q ⟹ P
  · conjunct2:  P ∧ Q ⟹ Q  
  · notnotD:    ¬¬ P ⟹ P
  · mp:         ⟦P ⟶ Q; P⟧ ⟹ Q 
  · impI:       (P ⟹ Q) ⟹ P ⟶ Q
  · disjI1:     P ⟹ P ∨ Q
  · disjI2:     Q ⟹ P ∨ Q
  · disjE:      ⟦P ∨ Q; P ⟹ R; Q ⟹ R⟧ ⟹ R 
  · FalseE:     False ⟹ P
  · notE:       ⟦¬P; P⟧ ⟹ R
  · notI:       (P ⟹ False) ⟹ ¬P
  · iffI:       ⟦P ⟹ Q; Q ⟹ P⟧ ⟹ P = Q
  · iffD1:      ⟦Q = P; Q⟧ ⟹ P 
  · iffD2:      ⟦P = Q; Q⟧ ⟹ P
  · ccontr:     (¬P ⟹ False) ⟹ P

  · allI:       ⟦∀x. P x; P x ⟹ R⟧ ⟹ R
  · allE:       (⋀x. P x) ⟹ ∀x. P x
  · exI:        P x ⟹ ∃x. P x
  · exE:        ⟦∃x. P x; ⋀x. P x ⟹ Q⟧ ⟹ Q

  · refl:       t = t
  · subst:      ⟦s = t; P s⟧ ⟹ P t
  · trans:      ⟦r = s; s = t⟧ ⟹ r = t
  · sym:        s = t ⟹ t = s
  · not_sym:    t ≠ s ⟹ s ≠ t
  · ssubst:     ⟦t = s; P s⟧ ⟹ P t
  · box_equals: ⟦a = b; a = c; b = d⟧ ⟹ a: = d
  · arg_cong:   x = y ⟹ f x = f y
  · fun_cong:   f = g ⟹ f x = g x
  · cong:       ⟦f = g; x = y⟧ ⟹ f x = g y
*}

text {*
  Se usarán las reglas notnotI, mt y not_ex que demostramos a 
  continuación. *}

lemma notnotI: "P ⟹ ¬¬ P"
by auto

lemma mt: "⟦F ⟶ G; ¬G⟧ ⟹ ¬F"
by auto

lemma no_ex: "¬(∃x. P(x)) ⟹ ∀x. ¬P(x)"
by auto

text {* --------------------------------------------------------------- 
  Ejercicio 1. Demostrar
       P a ⟶ (∃x. Q x) ⊢ ∃x. P a ⟶ Q x 
  ------------------------------------------------------------------ *}

(* benber *)
lemma
  assumes "P a ⟶ (∃x. Q x)"
  shows "∃x. P a ⟶ Q x"
proof (rule ccontr)
  assume "∄x. P a ⟶ Q x"
  have "P a ⟶ (∃x. P a ⟶ Q x)"
  proof
    assume "P a"
    with assms have "∃x. Q x" by (rule mp)
    moreover have "⋀x. Q x ⟹ ∃x'. P a ⟶ Q x'"
    proof -
      fix x
      assume "Q x"
      hence "P a ⟶ Q x" by (rule impI)
      thus "∃x'. P a ⟶ Q x'" by (rule exI)
    qed
    ultimately show "∃x. P a ⟶ Q x" by (rule exE)
  qed
  moreover note `∄x. P a ⟶ Q x`
  ultimately have "¬(P a)" by (rule mt)
  have "¬(P a) ⟶ (∃x. P a ⟶ Q x)"
  proof 
    fix x
    assume "¬(P a)"
    have "P a ⟶ Q x"
    proof
      assume "P a"
      with `¬(P a)` have "False" by (rule notE)
      thus "Q x" by (rule FalseE)
    qed
    thus "∃x. P a ⟶ Q x" by (rule exI)
  qed
  moreover note `∄x. P a ⟶ Q x`
  ultimately have "¬¬(P a)" by (rule mt)
  moreover note `¬(P a)`
  ultimately show "False" by (rule notE)
qed

(* alfmarcua *)
lemma ejercicio_52:
  "p ∨ ¬p"
proof (rule ccontr)
  assume 1: "¬(p ∨ ¬p)"
  have 2: "¬p" proof (rule notI)
    assume p hence 3: "p ∨ ¬p" by (rule disjI1)
    show "False" using 1 3 by (rule notE)
  qed
  have 4: "p ∨ ¬p" using 2 by (rule disjI2)
  show "False" using 1 4 by (rule notE)
qed

lemma ejercicio_1:
  assumes "P a ⟶ (∃x. Q x)"
  shows "∃x. P a ⟶ Q x"
proof (rule disjE)
  show "P a ∨ ¬ P a" by (rule ejercicio_52)
next
  assume "P a"
  have "∃x. Q x" using assms `P a` by (rule mp)
  then obtain b where "Q b" by (rule exE)
  have "P a ⟹ Q b" using `P a` `Q b` by simp
  have "P a ⟶ Q b" using `P a ⟹ Q b` by (rule impI)
  then show "∃x. P a ⟶ Q x" by (rule exI)
next
  assume "¬ P a"
  fix b
  have "P a ⟶ Q b"
  proof (rule impI)
    assume "P a"
    with `¬(P a)` have "False" by (rule notE)
    then show "Q b" by (rule FalseE)
  qed
  thus "∃x. P a ⟶ Q x" by (rule exI)
qed

(* pabalagon manperjim josgomrom4 gleherlop marfruman1 raffergon2
   hugrubsan pabbergue enrparalv giafus1 antramhur *) 
lemma ejercicio_1b:
  assumes "P a ⟶ (∃x. Q x)"
  shows "∃x. P a ⟶ Q x"
proof (rule disjE)
  show "¬P a ∨ P a" by (rule excluded_middle)
next
  fix b
  assume 3: "¬P a"
  have "P a ⟶ Q b" proof (rule impI)
    assume 4: "P a" show "Q b" using 3 4 by (rule notE)
  qed
  thus ?thesis by (rule exI)
next
  assume 1: "P a"
  have "∃x. Q x" using assms(1) 1 by (rule mp)
  then obtain b where 2: "Q b" by (rule exE)
  have "P a ⟶ Q b" proof (rule impI)
    assume "P a" show "Q b" using 2 .
  qed
  thus ?thesis by (rule exI)
qed

text {* --------------------------------------------------------------- 
  Ejercicio 2. 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)
  ------------------------------------------------------------------ *}

(* benber *)
lemma
  assumes A1: "∀x y z. R x y ∧ R y z ⟶ R x z"
    and A2: "∀x. ¬(R x x)"
  shows "∀x y. R x y ⟶ ¬(R y x)"
proof -
  {
    fix x y
    {
      assume "R x y"
      have "¬ (R y x)"
      proof (rule ccontr)
        assume "¬ ¬ (R y x)"
        hence "R y x" by (rule notnotD)

        note `∀x y z. R x y ∧ R y z ⟶ R x z`
        moreover have "∀ y z. R x y ∧ R y z ⟶ R x z ⟹ False"
        proof -
          assume "∀ y z. R x y ∧ R y z ⟶ R x z"
          moreover have "∀ z. R x y ∧ R y z ⟶ R x z ⟹ False"
          proof -
            assume "∀ z. R x y ∧ R y z ⟶ R x z"
            moreover have "R x y ∧ R y x ⟶ R x x ⟹ False"
            proof -
              assume "R x y ∧ R y x ⟶ R x x"
              moreover {
                note `R x y`
                moreover note `R y x`
                ultimately have "R x y ∧ R y x" by (rule conjI)
              }
              ultimately have "R x x" by (rule mp)

              note `∀x. ¬(R x x)`
              moreover {
                assume "¬(R x x)"
                moreover note `R x x`
                ultimately have "False" by (rule notE)
              }
              ultimately show "False" by (rule allE)
            qed
            ultimately show "False" by (rule allE)
          qed
          ultimately show "False" by (rule allE)
        qed
        ultimately show "False" by (rule allE)
      qed
    }
    hence "R x y ⟶ ¬ (R y x)" by (rule impI)
  }
  hence "⋀x. ∀y. R x y ⟶ ¬ (R y x)" by (rule allI)
  thus ?thesis by (rule allI)
qed

(* alfmarcua marfruman1 enrparalv*)
lemma ejercicio_2:
  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
  show "∀y. R a y ⟶ ¬ R y a"
  proof (rule allI, rule impI)
    fix b
    assume "R a b"
    show "¬ R b a"
    proof (rule notI)
      assume "R b a"
      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)
      then have "∀z. R a b ∧ R b z ⟶ R a z" by (rule allE)
      then have "R a b ∧ R b a ⟶ R a a" by (rule allE)
      then have "R a a" using `R a b ∧ R b a` by (rule mp)
      have "¬ (R a a)" using assms(2) by (rule allE)
      then show False using `R a a` by (rule notE)
    qed
  qed
qed


(* pabalagon manperjim josgomrom4 gleherlop raffergon2 hugrubsan
   pabbergue giafus1 antramhur *) 
lemma ejercicio_2b:
  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
  show "∀y. R a y ⟶ ¬(R y a)"
  proof (rule allI)
    fix b
    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 1: "R a b ∧ R b a ⟶ R a a" by (rule allE)
    have 2: "¬(R a a)" using assms(2) by (rule allE)
    show "R a b ⟶ ¬(R b a)" proof (rule impI)
      assume 3: "R a b"
      show "¬(R b a)"
      proof (rule ccontr)
        assume "¬¬R b a"
        hence 4: "R b a" by (rule notnotD)
        have 5: "R a b ∧ R b a" using 3 4 by (rule conjI)
        have 6: "R a a" using 1 5 by (rule mp)
        show False using 2 6 by (rule notE)
      qed
    qed
  qed
qed

(* pabalagon *)
lemma ejercicio_2_2: 
  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 -
  { fix a
    { fix b
      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 1: "R a b ∧ R b a ⟶ R a a" by (rule allE)
      have 2: "¬(R a a)" using assms(2) by (rule allE)
      have "R a b ⟶ ¬(R b a)" proof (rule impI)
        assume 3: "R a b"
        show "¬(R b a)"
        proof (rule ccontr)
          assume "¬¬R b a"
          hence 4: "R b a" by (rule notnotD)
          have 5: "R a b ∧ R b a" using 3 4 by (rule conjI)
          have 6: "R a a" using 1 5 by (rule mp)
          show False using 2 6 by (rule notE)
        qed
      qed}
    hence "∀y. R a y ⟶ ¬(R y a)" by (rule allI)}
  thus "∀x y. R x y ⟶ ¬(R y x)" by (rule allI)
qed

text {* --------------------------------------------------------------- 
  Ejercicio 3. Demostrar o refutar
       (∀x. ∃y. P x y) ⟶ (∃y. ∀x. P x y)
  ------------------------------------------------------------------ *}

(* benber pabbergue*)
(* No es cierto si el universo consiste en más que un objeto. En ese
   caso, asignar la igualdad (=) a P es un contraejemplo. *)

(* alfmarcua marfruman1 raffergon2 enrparalv*)
lemma ejercicio_3:
  "(∀x. ∃y. P x y) ⟶ (∃y. ∀x. P x y)"
  quickcheck
  oops

(* pabalagon manperjim pabbergue josgomrom4 gleherlop hugrubsan giafus1
   antramhur *) 
text{*
  Contraejemplo en los naturales, para todo x existe y tal que x < y, pero no
  existe y tal que para todo x, x < y
*}
lemma ejercicio_3: "(∀x. ∃y. P x y) ⟶ (∃y. ∀x. P x y)"
  quickcheck
  oops

text {* --------------------------------------------------------------- 
  Ejercicio 4. Demostrar o refutar
       (∃y. ∀x. P x y) ⟶ (∀x. ∃y. P x y)
  ------------------------------------------------------------------ *}

(* benber *)
lemma "(∃y. ∀x. P x y) ⟶ (∀x. ∃y. P x y)"
proof
  assume "∃y. ∀x. P x y"
  moreover have "⋀y. ∀x. P x y ⟹ ∀x. ∃y'. P x y'"
  proof
    fix x y
    assume "∀x'. P x' y"
    hence "P x y" by (rule allE)
    thus "∃y'. P x y'" by (rule exI)
  qed
  ultimately show "∀x. ∃y. P x y" by (rule exE)
qed

(* alfmarcua marfruman1 raffergon2 enrparalv *)
lemma ejercicio_4: 
  "(∃y. ∀x. P x y) ⟶ (∀x. ∃y. P x y)"
proof (rule impI, rule allI)
  fix a
  assume "∃y. ∀x. P x y"
  then obtain b where "∀x. P x b" by (rule exE)
  then have "P a b" by (rule allE)
  then show "∃y. P a y" by (rule exI)
qed

(* pabalagon manperjim josgomrom4 gleherlop hugrubsan pabbergue
   antramhur *) 
lemma ejercicio_4_2: "(∃y. ∀x. P x y) ⟶ (∀x. ∃y. P x y)"
proof (rule impI)
  assume "∃y. ∀x. P x y"
  moreover have "⋀y. ∀x. P x y ⟹ ∀x. ∃y. P x y"
  proof
    fix x0 y0
    assume "∀x. P x y0"
    hence "P x0 y0" by (rule allE)
    thus "∃y. P x0 y" by (rule exI)
  qed
  ultimately show "∀x. ∃y. P x y" by (rule exE)
qed

text {* --------------------------------------------------------------- 
  Ejercicio 5. Demostrar o refutar
     {∀x. P a x x, 
      ∀x y z. P x y z ⟶ P (f x) y (f z)⟧
     ⊢ ∃z. P (f a) z (f (f a))
  ------------------------------------------------------------------ *}

(* benber *)
lemma
  assumes A1: "∀ x. P a x x"
    and A2: "∀x y z. P x y z ⟶ P (f x) y (f z)"
  shows "∃z. P (f a) z (f (f a))"
proof
  from A2
  have "∀y z. P a y z ⟶ P (f a) y (f z)" by (rule allE)
  hence "∀z. P a (f a) z ⟶ P (f a) (f a) (f z)" by (rule allE)
  hence "P a (f a) (f a) ⟶ P (f a) (f a) (f (f a))" by (rule allE)
  moreover have "P a (f a) (f a)" using A1 by (rule allE)
  ultimately show "P (f a) (f a) (f (f a))" by (rule mp)
qed

(* alfmarcua enrparalv *)
lemma ejercicio_5:
  assumes "∀x. P a x x"
          "∀x y z. P x y z ⟶ P (f x) y (f z)"
        shows "∃z. P (f a) z (f (f a))"
proof (rule exI, rule mp)
  show "P a (f a) (f a)" using assms(1) by (rule allE)
next
  have "∀y z. P a y z ⟶ P (f a) y (f z)" using assms(2) by (rule allE)
  then have "∀z. P a (f a) z ⟶ P (f a) (f a) (f z)" by (rule allE)
  then show "P a (f a) (f a) ⟶ P (f a) (f a) (f (f a))" by (rule allE)
qed

(* pabalagon manperjim josgomrom4 gleherlop marfruman1 raffergon2
   hugrubsan pabbergue giafus1 antramhur *) 
lemma ejercicio_5_2:
  assumes "∀x. P a x x"
          "∀x y z. P x y z ⟶ P (f x) y (f z)"
  shows "∃z. P (f a) z (f (f a))"
proof (rule exI)
  have "∀y z. P a y z ⟶ P (f a) y (f z)" using assms(2) ..
  hence "∀z. P a (f a) z ⟶ P (f a) (f a) (f z)" ..
  hence "P a (f a) (f a) ⟶ P (f a) (f a) (f (f a))" ..
  moreover have "P a (f a) (f a)" using assms(1) by (rule allE)
  ultimately show "P (f a) (f a) (f (f a))" by (rule mp)
qed

text {* --------------------------------------------------------------- 
  Ejercicio 6. Demostrar o refutar
     {∀y. Q a y, 
      ∀x y. Q x y ⟶ Q (s x) (s y)} 
     ⊢ ∃z. Qa z ∧ Q z (s (s a))
  ------------------------------------------------------------------ *}

(* benber alfmarcua giafus1 *)
lemma
  assumes "∀y. Q a y"
      and "∀x y. Q x y ⟶ Q (s x) (s y)"
    shows "∃z. Q a z ∧ Q z (s (s a))"
proof
  have "Q a a" using `∀y. Q a y` by (rule allE)
  moreover have "Q a (s (s a))" using `∀y. Q a y` by (rule allE)
  ultimately show "Q a a ∧ Q a (s (s a))" by (rule conjI)
qed

(* pabalagon manperjim josgomrom4 gleherlop marfruman1 raffergon2
   hugrubsan pabbergue enrparalv antramhur *) 
lemma ejercicio_6:
  assumes "∀y. Q a y"
          "∀x y. Q x y ⟶ Q (s x) (s y)"
  shows "∃z. Q a z ∧ Q z (s (s a))"
proof (rule exI)
  have "∀y. Q a y ⟶ Q (s a) (s y)" using assms(2) by (rule allE)
  hence "Q a (s a) ⟶ Q (s a) (s (s a))" by (rule allE)
  moreover have "Q a (s a)" using assms(1) by (rule allE)
  ultimately have "Q (s a) (s (s a))" by (rule mp)
  with `Q a (s a)` show "Q a (s a) ∧ Q (s a) (s (s a))" by (rule conjI)
qed

text {* --------------------------------------------------------------- 
  Ejercicio 7. (En APLI2 el ejercicio 13 de LP) Formalizar, y demostrar
  la corrección, del siguiente argumento 
     Si la válvula está abierta o la monitorización está preparada,
     entonces se envía una señal de reconocimiento y un mensaje de
     funcionamiento al controlador del ordenador. Si se envía un mensaje 
     de funcionamiento al controlador del ordenador o el sistema está en 
     estado normal, entonces se aceptan las órdenes del operador. Por lo
     tanto, si la válvula está abierta, entonces se aceptan las órdenes
     del operador. 
  Usar A : La válvula está abierta.
       P : La monitorización está preparada.
       R : Envía una señal de reconocimiento.
       F : Envía un mensaje de funcionamiento.
       N : El sistema está en estado normal.
       Or : Se aceptan órdenes del operador.
  ------------------------------------------------------------------ *}

(* benber manperjim alfmarcua pabalagon marfruman1 josgomrom4 gleherlop
   raffergon2 hugrubsan pabbergue enrparalv giafus1 antramhur *)
lemma
  assumes "A ∨ P ⟶ R ∧ F"
    and "F ∨ N ⟶ Or"
  shows "A ⟶ Or"
proof
  assume "A"
  hence "A ∨ P" by (rule disjI1)
  with `A ∨ P ⟶ R ∧ F` have "R ∧ F" by (rule mp)
  hence "F" by (rule conjunct2)
  hence "F ∨ N" by (rule disjI1)
  with `F ∨ N ⟶ Or` show "Or" by (rule mp)
qed

text {* --------------------------------------------------------------- 
  Ejercicio 8. (En APLI2 el ejercicio 5 de LP) Formalizar, y demostrar
  la corrección, del siguiente argumento 
     En cierto experimento, cuando hemos empleado un fármaco A, el
     paciente ha mejorado considerablemente en el caso, y sólo en el
     caso, en que no se haya empleado también un fármaco B. Además, o se
     ha empleado el fármaco A o se ha empleado el fármaco B. En
     consecuencia, podemos afirmar que si no hemos empleado el fármaco
     B, el paciente ha mejorado considerablemente. 
  Usar A: Hemos empleado el fármaco A.
       B: Hemos empleado el fármaco B.
       M: El paciente ha mejorado notablemente.
  ------------------------------------------------------------------ *}

(* benber *)
lemma
  assumes "A ⟶ (M ⟷ ¬B)"
    and "A ∨ B"
  shows "¬B ⟶ M"
proof
  assume "¬B"
  note `A ∨ B`
  moreover {
    assume "A"
    with `A ⟶ (M ⟷ ¬B)` have "M ⟷ ¬B" by (rule mp)
    hence "¬B ⟹ M" by (rule iffD2)
    hence "M" using `¬B` .
  }
  moreover {
    note `¬B`
    moreover assume "B"
    ultimately have "M" by (rule notE)
  }
  ultimately show "M" by (rule disjE)
qed

(* alfmarcua marfruman1 *)
lemma ejercicio_8:
  assumes "A ∧ ¬ B ⟶ M"
          "A ∨ B"
  shows "¬ B ⟶ M"
proof (rule impI)
  assume "¬B"
  show "M" using assms(2)
  proof (rule disjE)
    assume "A"
    then have "A ∧ ¬ B" using `¬ B` by (rule conjI)
    show "M" using assms(1) `A ∧ ¬ B` by (rule mp)
  next
    assume "B"
    show "M" using `¬ B` `B` by (rule notE)
  qed
qed

(* pabalagon manperjim josgomrom4 gleherlop raffergon2 hugrubsan
   pabbergue enrparalv giafus1 antramhur *) 
lemma ejercicio_8_2:
  assumes "A ⟶ (M ⟷ ¬B)"
          "A ∨ B"
        shows "¬B ⟶ M"
using assms(2) proof (rule disjE)
  assume 1: A
  have 2: "M ⟷ ¬B" using assms(1) 1 by (rule mp)
  show "¬B ⟶ M" proof (rule impI)
    assume 3: "¬B" show M using 2 3 by (rule iffD2)
  qed
next
  assume 4: B
  show ?thesis proof (rule impI)
    assume "¬B" thus M using 4 by (rule notE)
  qed
qed

text {* --------------------------------------------------------------- 
  Ejercicio 9. (En APLI2 el ejercicio 13 de LPO) Formalizar, y decidir
  la corrección, del siguiente argumento 
     Toda persona pobre tiene un padre rico. Por tanto, existe una
     persona rica que tiene un abuelo rico.
  Usar R(x) para x es rico
       p(x) para el padre de x
  ------------------------------------------------------------------ *}

(* benber *)
lemma
  assumes "∀x. ¬ R x ⟶ R (p x)"
  shows "∃x. R x ∧ R (p (p x))"
proof -
  have 0: "p ∨ ¬ p" for p
  proof (rule ccontr)
    assume "¬ (p ∨ ¬ p)"
    moreover {
      have "p"
      proof (rule ccontr)
        assume "¬ p"
        hence "p ∨ ¬ p" by (rule disjI2)
        with `¬ (p ∨ ¬ p)` show "False" by (rule notE)
      qed
      hence "p ∨ ¬ p" by (rule disjI1)
    }
    ultimately show "False" by (rule notE)
  qed

  have "¬ R x ⟶ R (p x)" for x using assms(1) by (rule allE)
  hence 1: "¬ R x ⟹ R (p x)" for x by (rule mp)

  have 2: "⟦R y; ¬ R (p y)⟧ ⟹ ?thesis" for y
  proof
    assume "R y"
    assume "¬ R (p y)"
    hence "R (p (p y))" by (rule 1)
    with `R y` show "R y ∧ R (p (p y))" by (rule conjI)
  qed

  have 3: "R y ⟹ ?thesis" for y
  proof -
    assume "R y"

    have "R (p y) ∨ ¬ R (p y)" by (rule 0)
    moreover {
      assume "R (p y)"
      have "R (p (p y)) ∨ ¬ R (p (p y))" by (rule 0)
      moreover {
        assume "R (p (p y))"
        with `R y` have "R y ∧ R (p (p y))" by (rule conjI)
        hence ?thesis by (rule exI)
      }
      moreover {
        assume "¬ R (p (p y))"
        with `R (p y)` have ?thesis by (rule 2)
      }
      ultimately have ?thesis by (rule disjE)
    }
    moreover {
      assume "¬ R (p y)"
      with `R y` have ?thesis by (rule 2)
    }
    ultimately show ?thesis by (rule disjE)
  qed

  fix y
  have "R y ∨ ¬ R y" by (rule 0)
  moreover {
    assume "R y"
    hence ?thesis by (rule 3)
  }
  moreover {
    assume "¬ R y"
    hence "R (p y)" by (rule 1)
    hence ?thesis by (rule 3)
  }
  ultimately show ?thesis by (rule disjE)
qed

(* alfmarcua *)
lemma ejercicio_9_2:
  assumes "∀ x. ¬ R x ⟶ R (p x)"
  shows "∃x. R x ∧ R (p (p x))"
proof (rule disjE, rule ejercicio_52)
  have prelemma:"(∃y. ¬ R (p y)) ⟶ ?thesis"
  proof (rule impI)
    assume "∃y. ¬ R (p y)"
    then obtain b where  "¬ R (p b)" by (rule exE)
    have "¬ R (p b) ⟶ R (p (p b))" using assms by (rule allE)
    then have "R (p (p b))" using `¬ R (p b)` by (rule mp)
    have "¬ R b ⟶ R (p b)" using assms by (rule allE)
    then have "¬¬ R b" using `¬ R (p b)` by (rule mt)
    then have "R b" by (rule notnotD)
    then have "R b ∧ R (p (p b))" using `R (p (p b))` by (rule conjI)
    then show "∃x. R x ∧ R (p (p x))" by (rule exI)
  qed
  
  fix a
  show "R (p a) ⟹ ?thesis"
  proof (rule disjE, rule ejercicio_52)
    assume "R (p a)"
    show "R (p (p a)) ⟹ ?thesis"
    proof (rule disjE, rule ejercicio_52)
      assume "R (p (p (p a)))"
      have "R (p a) ∧ R (p (p (p a)))" using `R (p a)` `R (p (p (p a)))`  by (rule conjI)
      then show ?thesis by (rule exI)
    next
      assume "¬ R (p (p (p a)))"
      then have "∃y. ¬ R (p y)" by (rule exI)
      show ?thesis using prelemma `∃y. ¬ R (p y)` by (rule mp)
    qed
  next
    assume "¬ R (p (p a))"
    then have "∃y. ¬ R (p y)" by (rule exI)
    show ?thesis using prelemma `∃y. ¬ R (p y)` by (rule mp)
  qed

  assume "¬ R (p a)"
  then have "∃y. ¬ R (p y)" by (rule exI)
  show ?thesis using prelemma `∃y. ¬ R (p y)` by (rule mp)
qed

(* pabalagon manperjim marfruman1 josgomrom4 gleherlop raffergon2
   hugrubsan pabbergue enrparalv giafus1 antramhur *) 
lemma ejercicio_9_3:
  assumes "∀x. ¬R x ⟶ R (p x)"
  shows "∃x. R x ∧ R (p (p x))"
proof -
  fix y
  have s1: "⟦¬R (p y)⟧ ⟹ ?thesis" for y proof (rule exI)
    assume 2: "¬R (p y)"
    have "¬R (p y) ⟶ R (p (p y))" using assms(1) by (rule allE)
    hence 3: "R (p (p y))" using 2 by (rule mp)
    have "¬R y ⟶ R (p y)" using assms(1) by (rule allE)
    hence "¬¬R y" using 2 by (rule mt)
    hence "R y" by (rule notnotD)
    thus "R y ∧ R (p (p y))" using 3 by (rule conjI)
  qed
  have s2: "R y ⟹ ?thesis" for y proof -
    assume 2: "R y"
    have "¬R (p y) ∨ R (p y)" by (rule excluded_middle)
    thus ?thesis proof (rule disjE)
      assume 3: "¬R (p y)" thus ?thesis by (rule s1)
    next
      assume 4: "R (p y)"
      have "¬R (p (p y)) ∨ R (p (p y))" by (rule excluded_middle)
      thus ?thesis proof (rule disjE)
        assume "¬R (p (p y))" thus ?thesis by (rule s1)
      next
        assume "R (p (p y))"
        with `R y` have "R y ∧ R (p (p y))" by (rule conjI)
        thus ?thesis by (rule exI)
      qed
    qed
  qed
  have "¬R y ∨ R y" by (rule excluded_middle)
  thus ?thesis proof (rule disjE)
    assume 2: "R y" thus ?thesis by (rule s2)
  next
    assume 4: "¬R y"
    have "¬R y ⟶ R (p y)" using assms(1) by (rule allE)
    hence "R (p y)" using 4 by (rule mp)
    thus ?thesis by (rule s2)
  qed
qed

text {* --------------------------------------------------------------- 
  Ejercicio 10. (En APLI2 el ejercicio 10 de LPO) Formalizar, y decidir
  la corrección, del siguiente argumento 
     Los aficionados al fútbol aplauden a cualquier futbolista
     extranjero. Juanito no aplaude a futbolistas extranjeros. Por
     tanto, si hay algún futbolista extranjero nacionalizado español,
     Juanito no es aficionado al fútbol.
  Usar Af(x)   para x es aficicionado al fútbol
       Ap(x,y) para x aplaude a y
       E(x)    para x es un futbolista extranjero
       N(x)    para x es un futbolista nacionalizado español
       j       para Juanito
  ------------------------------------------------------------------ *}

(* benber *)
lemma
  assumes "∀x. Af x ⟶ (∀y. E y ⟶ Ap x y)"
    and "∀x. E x ⟶ ¬ Ap j x"
  shows "(∃x. E x ∧ N x) ⟶ ¬ Af j"
proof
  assume "∃x. E x ∧ N x"

  show "¬ Af j"
  proof (rule ccontr)
    assume "¬ ¬ Af j"
    hence "Af j" by (rule notnotD)

    note `∀x. Af x ⟶ (∀y. E y ⟶ Ap x y)`
    hence "Af j ⟶ (∀x. E x ⟶ Ap j x)" by (rule allE)
    moreover note `Af j`
    ultimately have "∀x. E x ⟶ Ap j x" by (rule mp)

    note `∃x. E x ∧ N x`
    moreover have "E x ∧ N x ⟹ False" for x
    proof -
      assume "E x ∧ N x"
      hence "E x" by (rule conjunct1)

      note `∀x. E x ⟶ Ap j x`
      hence "E x ⟶ Ap j x" by (rule allE)
      hence "Ap j x" using `E x`  by (rule mp)

      note `∀x. E x ⟶ ¬ Ap j x`
      hence "E x ⟶ ¬ Ap j x" by (rule allE)
      hence "¬ Ap j x" using `E x` by (rule mp)
      thus "False" using `Ap j x` by (rule notE)
    qed
    ultimately show "False" by (rule exE)
  qed
qed

(* alfmarcua marfruman1 *)
lemma ejercicio_10_2:
  assumes "∀x y. Af x ∧ E y ⟶ Ap x y"
          "∀y. E y ⟶ ¬ Ap j y"
  shows "(∃y. E y ∧ N y) ⟶ ¬ Af j"
proof (rule impI)
  assume "∃x. E x ∧ N x"
  then obtain a where "E a ∧ N a" by (rule exE)
  then have "E a" by (rule conjunct1)
  show "¬ Af j"
  proof (rule notI, rule notE)
    assume "Af j"
    then show "Af j ∧ E a" using `E a` by (rule conjI)
  next
    have "E a ⟶ ¬ Ap j a" using assms(2) by (rule allE)
    then have "¬ Ap j a" using `E a` by (rule mp)
    have "∀y. Af j ∧ E y ⟶ Ap j y" using assms(1) by (rule allE)
    then have "Af j ∧ E a ⟶ Ap j a" by (rule allE)
    then show "¬ (Af j ∧ E a)" using `¬ Ap j a` by (rule mt)
  qed
qed

(* pabalagon manperjim josgomrom4 gleherlop raffergon2 hugrubsan
   pabbergue enrparalv giafus1 antramhur *) 
lemma ejercicio_10_3:
  assumes "∀x y. Af x ∧ E y ⟶ Ap x y"
          "∀x y. x = j ∧ E y ⟶ ¬(Ap x y)"
  shows "(∃ x. (E x ∧ N x)) ⟶ ¬(Af j)"
proof (rule impI)
  assume 1: "∃x. E x ∧ N x"
  show "¬(Af j)" proof (rule ccontr)
    fix a
    assume "¬¬Af j" hence 2: "Af j" by (rule notnotD)
    obtain a where 3: "E a ∧ N a" using 1 by (rule exE)
    hence 4: "E a" by (rule conjunct1)
    have 5: "N a" using 3 by (rule conjunct2)
    have "∀y. Af j ∧ E y ⟶ Ap j y" using assms(1) by (rule allE)
    hence 6: "Af j ∧ E a ⟶ Ap j a" by (rule allE)
    have 7: "Af j ∧ E a" using 2 4 by (rule conjI)
    have 8: "Ap j a" using 6 7 by (rule mp)
    have "∀y. j = j ∧ E y ⟶ ¬(Ap j y)" using assms(2) by (rule allE)
    hence 9: "j = j ∧ E a ⟶ ¬(Ap j a)" by (rule allE)
    have "j = j" by (rule refl)
    hence 10: "j = j ∧ E a" using 4 by (rule conjI)
    have "¬(Ap j a)" using 9 10 by (rule mp)
    thus False using 8 by (rule notE)
  qed
qed

text {* --------------------------------------------------------------- 
  Ejercicio 11. Formalizar, y decidir la corrección, del siguiente
  argumento
     Ningún socio del club está en deuda con el tesorero del club. Si
     un socio del club no paga su cuota está en deuda con el tesorero
     del club. Por tanto, si el tesorero del club es socio del club,
     entonces paga su cuota. 
  Usar P(x) para x es socio del club
       Q(x) para x paga su cuota
       R(x) para x está en deuda con el tesorero
       a    para el tesorero del club
   ------------------------------------------------------------------ *}

(* benber *)
lemma
  assumes A1: "∀x. P x ⟶ R x"
    and A2: "∀x. P x ⟶ (¬(Q x) ⟶ R x)"
    and "¬(R a)"
  shows "P a ⟶ Q a"
proof
  have "P a ⟶ (¬(Q a) ⟶ R a)" using A2 by (rule allE)
  moreover assume "P a"
  ultimately have "¬(Q a) ⟶ R a" by (rule mp)

  show "Q a"
  proof (rule ccontr)
    assume "¬(Q a)"
    with `¬(Q a) ⟶ R a` have "R a" by (rule mp)
    with `¬(R a)` show "False" by (rule notE)
  qed
qed

(* alfmarcua *)
lemma ejercicio_11:
  assumes "∄x. P x ∧ R x"
          "∀x. P x ∧ (¬ Q x) ⟶ R x"
  shows "P a ⟶ Q a"
proof (rule impI, rule ccontr)
  assume "P a" "¬ Q a"
  then have "P a ∧ (¬ Q a)" by (rule conjI)
  have "P a ∧ (¬ Q a) ⟶ R a" using assms(2) by (rule allE)
  then have "R a" using `P a ∧ (¬ Q a)` by (rule mp)
  have "P a ∧ R a" using `P a` `R a` by (rule conjI)
  then have "∃x. P x ∧ R x" by (rule exI)
  show False using assms(1) `∃x. P x ∧ R x` by (rule notE)
qed

(* pabalagon manperjim marfruman1 josgomrom4 gleherlop hugrubsan
   pabbergue enrparalv giafus1 antramhur *) 
lemma ejercicio_11_2:
  assumes "¬(∃x. P x ∧ R x)"
          "∀x. P x ∧ ¬Q x ⟶ R x"
  shows "P a ⟶ Q a"
proof (rule impI)
  assume 1: "P a"
  show "Q a" proof (rule ccontr)
    assume 2: "¬Q a"
    have 3: "P a ∧ ¬Q a" using 1 2 by (rule conjI)
    have 4: "P a ∧ ¬ Q a ⟶R a" using assms(2) by (rule allE)
    hence 5: "R a" using 3 by (rule mp)
    have 6: "P a ∧ R a" using 1 5 by (rule conjI)
    hence 7: "∃x. P x ∧ R x" by (rule exI)
    show False using assms(1) 7 by (rule notE)
  qed
qed

end