# HG changeset patch # User wenzelm # Date 1416664624 -3600 # Node ID 4c3bb56b8ce754132122f31df71018e89ea7dff7 # Parent 67baff6f697cd4d619c66dbf53e44915d9196dc1 misc tuning and modernization; diff -r 67baff6f697c -r 4c3bb56b8ce7 src/HOL/ex/Abstract_NAT.thy --- a/src/HOL/ex/Abstract_NAT.thy Sat Nov 22 14:13:36 2014 +0100 +++ b/src/HOL/ex/Abstract_NAT.thy Sat Nov 22 14:57:04 2014 +0100 @@ -2,18 +2,18 @@ Author: Makarius *) -section {* Abstract Natural Numbers primitive recursion *} +section \Abstract Natural Numbers primitive recursion\ theory Abstract_NAT imports Main begin -text {* Axiomatic Natural Numbers (Peano) -- a monomorphic theory. *} +text \Axiomatic Natural Numbers (Peano) -- a monomorphic theory.\ locale NAT = fixes zero :: 'n and succ :: "'n \ 'n" - assumes succ_inject [simp]: "(succ m = succ n) = (m = n)" + assumes succ_inject [simp]: "succ m = succ n \ m = n" and succ_neq_zero [simp]: "succ m \ zero" and induct [case_names zero succ, induct type: 'n]: "P zero \ (\n. P n \ P (succ n)) \ P n" @@ -23,7 +23,7 @@ by (rule succ_neq_zero [symmetric]) -text {* \medskip Primitive recursion as a (functional) relation -- polymorphic! *} +text \\medskip Primitive recursion as a (functional) relation -- polymorphic!\ inductive Rec :: "'a \ ('n \ 'a \ 'a) \ 'n \ 'a \ bool" for e :: 'a and r :: "'n \ 'a \ 'a" @@ -47,7 +47,7 @@ qed next case (succ m) - from `\!y. ?R m y` + from \\!y. ?R m y\ obtain y where y: "?R m y" and yy': "\y'. ?R m y' \ y = y'" by blast show "\!z. ?R (succ m) z" @@ -61,7 +61,7 @@ qed -text {* \medskip The recursion operator -- polymorphic! *} +text \\medskip The recursion operator -- polymorphic!\ definition rec :: "'a \ ('n \ 'a \ 'a) \ 'n \ 'a" where "rec e r x = (THE y. Rec e r x y)" @@ -86,7 +86,7 @@ qed -text {* \medskip Example: addition (monomorphic) *} +text \\medskip Example: addition (monomorphic)\ definition add :: "'n \ 'n \ 'n" where "add m n = rec n (\_ k. succ k) m" @@ -109,7 +109,7 @@ by simp -text {* \medskip Example: replication (polymorphic) *} +text \\medskip Example: replication (polymorphic)\ definition repl :: "'n \ 'a \ 'a list" where "repl n x = rec [] (\_ xs. x # xs) n" @@ -124,12 +124,12 @@ end -text {* \medskip Just see that our abstract specification makes sense \dots *} +text \\medskip Just see that our abstract specification makes sense \dots\ interpretation NAT 0 Suc proof (rule NAT.intro) fix m n - show "(Suc m = Suc n) = (m = n)" by simp + show "Suc m = Suc n \ m = n" by simp show "Suc m \ 0" by simp fix P assume zero: "P 0" diff -r 67baff6f697c -r 4c3bb56b8ce7 src/HOL/ex/Antiquote.thy --- a/src/HOL/ex/Antiquote.thy Sat Nov 22 14:13:36 2014 +0100 +++ b/src/HOL/ex/Antiquote.thy Sat Nov 22 14:57:04 2014 +0100 @@ -2,16 +2,13 @@ Author: Markus Wenzel, TU Muenchen *) -section {* Antiquotations *} +section \Antiquotations\ theory Antiquote imports Main begin -text {* - A simple example on quote / antiquote in higher-order abstract - syntax. -*} +text \A simple example on quote / antiquote in higher-order abstract syntax.\ definition var :: "'a \ ('a \ nat) \ nat" ("VAR _" [1000] 999) where "var x env = env x" @@ -22,23 +19,21 @@ syntax "_Expr" :: "'a \ 'a" ("EXPR _" [1000] 999) -parse_translation {* - [Syntax_Trans.quote_antiquote_tr - @{syntax_const "_Expr"} @{const_syntax var} @{const_syntax Expr}] -*} +parse_translation + \[Syntax_Trans.quote_antiquote_tr + @{syntax_const "_Expr"} @{const_syntax var} @{const_syntax Expr}]\ -print_translation {* - [Syntax_Trans.quote_antiquote_tr' - @{syntax_const "_Expr"} @{const_syntax var} @{const_syntax Expr}] -*} +print_translation + \[Syntax_Trans.quote_antiquote_tr' + @{syntax_const "_Expr"} @{const_syntax var} @{const_syntax Expr}]\ term "EXPR (a + b + c)" term "EXPR (a + b + c + VAR x + VAR y + 1)" term "EXPR (VAR (f w) + VAR x)" -term "Expr (\env. env x)" -- {* improper *} +term "Expr (\env. env x)" -- \improper\ term "Expr (\env. f env)" -term "Expr (\env. f env + env x)" -- {* improper *} +term "Expr (\env. f env + env x)" -- \improper\ term "Expr (\env. f env y z)" term "Expr (\env. f env + g y env)" term "Expr (\env. f env + g env y + h a env z)" diff -r 67baff6f697c -r 4c3bb56b8ce7 src/HOL/ex/Guess.thy --- a/src/HOL/ex/Guess.thy Sat Nov 22 14:13:36 2014 +0100 +++ b/src/HOL/ex/Guess.thy Sat Nov 22 14:57:04 2014 +0100 @@ -8,9 +8,8 @@ imports Main begin -lemma True -proof - +notepad +begin have 1: "\x. x = x" by simp from 1 guess .. @@ -18,13 +17,12 @@ from 1 guess x :: 'a .. from 1 guess x :: nat .. - have 2: "\x y. x = x & y = y" by simp + have 2: "\x y. x = x \ y = y" by simp from 2 guess apply - apply (erule exE conjE)+ done from 2 guess x apply - apply (erule exE conjE)+ done from 2 guess x y apply - apply (erule exE conjE)+ done from 2 guess x :: 'a and y :: 'b apply - apply (erule exE conjE)+ done from 2 guess x y :: nat apply - apply (erule exE conjE)+ done - -qed +end end diff -r 67baff6f697c -r 4c3bb56b8ce7 src/HOL/ex/Hebrew.thy --- a/src/HOL/ex/Hebrew.thy Sat Nov 22 14:13:36 2014 +0100 +++ b/src/HOL/ex/Hebrew.thy Sat Nov 22 14:57:04 2014 +0100 @@ -4,13 +4,13 @@ formal and informal ones. *) -section {* A Hebrew theory *} +section \A Hebrew theory\ theory Hebrew imports Main begin -text {* The Hebrew Alef-Bet (א-ב). *} +text \The Hebrew Alef-Bet (א-ב).\ datatype alef_bet = Alef ("א") @@ -39,9 +39,10 @@ thm alef_bet.induct -text {* Interpreting Hebrew letters as numbers. *} +text \Interpreting Hebrew letters as numbers.\ -primrec mispar :: "alef_bet => nat" where +primrec mispar :: "alef_bet => nat" +where "mispar א = 1" | "mispar ב = 2" | "mispar ג = 3" diff -r 67baff6f697c -r 4c3bb56b8ce7 src/HOL/ex/Higher_Order_Logic.thy --- a/src/HOL/ex/Higher_Order_Logic.thy Sat Nov 22 14:13:36 2014 +0100 +++ b/src/HOL/ex/Higher_Order_Logic.thy Sat Nov 22 14:57:04 2014 +0100 @@ -2,21 +2,21 @@ Author: Gertrud Bauer and Markus Wenzel, TU Muenchen *) -section {* Foundations of HOL *} +section \Foundations of HOL\ theory Higher_Order_Logic imports Pure begin -text {* +text \ The following theory development demonstrates Higher-Order Logic itself, represented directly within the Pure framework of Isabelle. The ``HOL'' logic given here is essentially that of Gordon @{cite "Gordon:1985:HOL"}, although we prefer to present basic concepts in a slightly more conventional manner oriented towards plain Natural Deduction. -*} +\ -subsection {* Pure Logic *} +subsection \Pure Logic\ class type default_sort type @@ -26,7 +26,7 @@ instance "fun" :: (type, type) type .. -subsubsection {* Basic logical connectives *} +subsubsection \Basic logical connectives\ judgment Trueprop :: "o \ prop" ("_" 5) @@ -41,7 +41,7 @@ allE [dest]: "\x. P x \ P a" -subsubsection {* Extensional equality *} +subsubsection \Extensional equality\ axiomatization equal :: "'a \ 'a \ o" (infixl "=" 50) @@ -75,35 +75,26 @@ by (rule subst) (rule sym) -subsubsection {* Derived connectives *} +subsubsection \Derived connectives\ -definition - false :: o ("\") where - "\ \ \A. A" +definition false :: o ("\") where "\ \ \A. A" -definition - true :: o ("\") where - "\ \ \ \ \" +definition true :: o ("\") where "\ \ \ \ \" -definition - not :: "o \ o" ("\ _" [40] 40) where - "not \ \A. A \ \" +definition not :: "o \ o" ("\ _" [40] 40) + where "not \ \A. A \ \" -definition - conj :: "o \ o \ o" (infixr "\" 35) where - "conj \ \A B. \C. (A \ B \ C) \ C" +definition conj :: "o \ o \ o" (infixr "\" 35) + where "conj \ \A B. \C. (A \ B \ C) \ C" -definition - disj :: "o \ o \ o" (infixr "\" 30) where - "disj \ \A B. \C. (A \ C) \ (B \ C) \ C" +definition disj :: "o \ o \ o" (infixr "\" 30) + where "disj \ \A B. \C. (A \ C) \ (B \ C) \ C" -definition - Ex :: "('a \ o) \ o" (binder "\" 10) where - "\x. P x \ \C. (\x. P x \ C) \ C" +definition Ex :: "('a \ o) \ o" (binder "\" 10) + where "\x. P x \ \C. (\x. P x \ C) \ C" -abbreviation - not_equal :: "'a \ 'a \ o" (infixl "\" 50) where - "x \ y \ \ (x = y)" +abbreviation not_equal :: "'a \ 'a \ o" (infixl "\" 50) + where "x \ y \ \ (x = y)" theorem falseE [elim]: "\ \ A" proof (unfold false_def) @@ -133,7 +124,7 @@ lemma notE': "A \ \ A \ B" by (rule notE) -lemmas contradiction = notE notE' -- {* proof by contradiction in any order *} +lemmas contradiction = notE notE' -- \proof by contradiction in any order\ theorem conjI [intro]: "A \ B \ A \ B" proof (unfold conj_def) @@ -143,8 +134,8 @@ fix C show "(A \ B \ C) \ C" proof assume "A \ B \ C" - also note `A` - also note `B` + also note \A\ + also note \B\ finally show C . qed qed @@ -180,7 +171,7 @@ fix C show "(A \ C) \ (B \ C) \ C" proof assume "A \ C" - also note `A` + also note \A\ finally have C . then show "(B \ C) \ C" .. qed @@ -197,7 +188,7 @@ show "(B \ C) \ C" proof assume "B \ C" - also note `B` + also note \B\ finally show C . qed qed @@ -229,7 +220,7 @@ proof assume "\x. P x \ C" then have "P a \ C" .. - also note `P a` + also note \P a\ finally show C . qed qed @@ -252,7 +243,7 @@ qed -subsection {* Classical logic *} +subsection \Classical logic\ locale classical = assumes classical: "(\ A \ A) \ A" @@ -267,7 +258,7 @@ have "A \ B" proof assume A - with `\ A` show B by (rule contradiction) + with \\ A\ show B by (rule contradiction) qed with a show A .. qed @@ -280,7 +271,7 @@ show A proof (rule classical) assume "\ A" - with `\ \ A` show ?thesis by (rule contradiction) + with \\ \ A\ show ?thesis by (rule contradiction) qed qed @@ -293,10 +284,10 @@ have "\ A" proof assume A then have "A \ \ A" .. - with `\ (A \ \ A)` show \ by (rule contradiction) + with \\ (A \ \ A)\ show \ by (rule contradiction) qed then have "A \ \ A" .. - with `\ (A \ \ A)` show \ by (rule contradiction) + with \\ (A \ \ A)\ show \ by (rule contradiction) qed qed diff -r 67baff6f697c -r 4c3bb56b8ce7 src/HOL/ex/Multiquote.thy --- a/src/HOL/ex/Multiquote.thy Sat Nov 22 14:13:36 2014 +0100 +++ b/src/HOL/ex/Multiquote.thy Sat Nov 22 14:57:04 2014 +0100 @@ -2,22 +2,22 @@ Author: Markus Wenzel, TU Muenchen *) -section {* Multiple nested quotations and anti-quotations *} +section \Multiple nested quotations and anti-quotations\ theory Multiquote imports Main begin -text {* +text \ Multiple nested quotations and anti-quotations -- basically a generalized version of de-Bruijn representation. -*} +\ syntax "_quote" :: "'b \ ('a \ 'b)" ("\_\" [0] 1000) "_antiquote" :: "('a \ 'b) \ 'b" ("\_" [1000] 1000) -parse_translation {* +parse_translation \ let fun antiquote_tr i (Const (@{syntax_const "_antiquote"}, _) $ (t as Const (@{syntax_const "_antiquote"}, _) $ _)) = skip_antiquote_tr i t @@ -33,15 +33,15 @@ fun quote_tr [t] = Abs ("s", dummyT, antiquote_tr 0 (Term.incr_boundvars 1 t)) | quote_tr ts = raise TERM ("quote_tr", ts); in [(@{syntax_const "_quote"}, K quote_tr)] end -*} +\ -text {* basic examples *} +text \basic examples\ term "\a + b + c\" term "\a + b + c + \x + \y + 1\" term "\\(f w) + \x\" term "\f \x \y z\" -text {* advanced examples *} +text \advanced examples\ term "\\\\x + \y\\" term "\\\\x + \y\ \ \f\" term "\\(f \ \g)\" diff -r 67baff6f697c -r 4c3bb56b8ce7 src/HOL/ex/PER.thy --- a/src/HOL/ex/PER.thy Sat Nov 22 14:13:36 2014 +0100 +++ b/src/HOL/ex/PER.thy Sat Nov 22 14:57:04 2014 +0100 @@ -2,11 +2,13 @@ Author: Oscar Slotosch and Markus Wenzel, TU Muenchen *) -section {* Partial equivalence relations *} +section \Partial equivalence relations\ -theory PER imports Main begin +theory PER +imports Main +begin -text {* +text \ Higher-order quotients are defined over partial equivalence relations (PERs) instead of total ones. We provide axiomatic type classes @{text "equiv < partial_equiv"} and a type constructor @@ -17,41 +19,41 @@ Implementation in Isabelle HOL.} Elsa L. Gunter and Amy Felty, editors, Theorem Proving in Higher Order Logics: TPHOLs '97, Springer LNCS 1275, 1997. -*} +\ -subsection {* Partial equivalence *} +subsection \Partial equivalence\ -text {* +text \ Type class @{text partial_equiv} models partial equivalence - relations (PERs) using the polymorphic @{text "\ :: 'a => 'a => + relations (PERs) using the polymorphic @{text "\ :: 'a \ 'a \ bool"} relation, which is required to be symmetric and transitive, but not necessarily reflexive. -*} +\ class partial_equiv = - fixes eqv :: "'a => 'a => bool" (infixl "\" 50) - assumes partial_equiv_sym [elim?]: "x \ y ==> y \ x" - assumes partial_equiv_trans [trans]: "x \ y ==> y \ z ==> x \ z" + fixes eqv :: "'a \ 'a \ bool" (infixl "\" 50) + assumes partial_equiv_sym [elim?]: "x \ y \ y \ x" + assumes partial_equiv_trans [trans]: "x \ y \ y \ z \ x \ z" -text {* +text \ \medskip The domain of a partial equivalence relation is the set of reflexive elements. Due to symmetry and transitivity this characterizes exactly those elements that are connected with \emph{any} other one. -*} +\ definition "domain" :: "'a::partial_equiv set" where "domain = {x. x \ x}" -lemma domainI [intro]: "x \ x ==> x \ domain" +lemma domainI [intro]: "x \ x \ x \ domain" unfolding domain_def by blast -lemma domainD [dest]: "x \ domain ==> x \ x" +lemma domainD [dest]: "x \ domain \ x \ x" unfolding domain_def by blast -theorem domainI' [elim?]: "x \ y ==> x \ domain" +theorem domainI' [elim?]: "x \ y \ x \ domain" proof assume xy: "x \ y" also from xy have "y \ x" .. @@ -59,35 +61,34 @@ qed -subsection {* Equivalence on function spaces *} +subsection \Equivalence on function spaces\ -text {* +text \ The @{text \} relation is lifted to function spaces. It is important to note that this is \emph{not} the direct product, but a structural one corresponding to the congruence property. -*} +\ instantiation "fun" :: (partial_equiv, partial_equiv) partial_equiv begin -definition - eqv_fun_def: "f \ g == \x \ domain. \y \ domain. x \ y --> f x \ g y" +definition "f \ g \ (\x \ domain. \y \ domain. x \ y \ f x \ g y)" lemma partial_equiv_funI [intro?]: - "(!!x y. x \ domain ==> y \ domain ==> x \ y ==> f x \ g y) ==> f \ g" + "(\x y. x \ domain \ y \ domain \ x \ y \ f x \ g y) \ f \ g" unfolding eqv_fun_def by blast lemma partial_equiv_funD [dest?]: - "f \ g ==> x \ domain ==> y \ domain ==> x \ y ==> f x \ g y" + "f \ g \ x \ domain \ y \ domain \ x \ y \ f x \ g y" unfolding eqv_fun_def by blast -text {* +text \ The class of partial equivalence relations is closed under function spaces (in \emph{both} argument positions). -*} +\ instance proof - fix f g h :: "'a::partial_equiv => 'b::partial_equiv" + fix f g h :: "'a::partial_equiv \ 'b::partial_equiv" assume fg: "f \ g" show "g \ f" proof @@ -112,29 +113,29 @@ end -subsection {* Total equivalence *} +subsection \Total equivalence\ -text {* +text \ The class of total equivalence relations on top of PERs. It coincides with the standard notion of equivalence, i.e.\ @{text "\ - :: 'a => 'a => bool"} is required to be reflexive, transitive and + :: 'a \ 'a \ bool"} is required to be reflexive, transitive and symmetric. -*} +\ class equiv = assumes eqv_refl [intro]: "x \ x" -text {* +text \ On total equivalences all elements are reflexive, and congruence holds unconditionally. -*} +\ theorem equiv_domain [intro]: "(x::'a::equiv) \ domain" proof show "x \ x" .. qed -theorem equiv_cong [dest?]: "f \ g ==> x \ y ==> f x \ g (y::'a::equiv)" +theorem equiv_cong [dest?]: "f \ g \ x \ y \ f x \ g (y::'a::equiv)" proof - assume "f \ g" moreover have "x \ domain" .. @@ -144,12 +145,12 @@ qed -subsection {* Quotient types *} +subsection \Quotient types\ -text {* +text \ The quotient type @{text "'a quot"} consists of all \emph{equivalence classes} over elements of the base type @{typ 'a}. -*} +\ definition "quot = {{x. a \ x}| a::'a::partial_equiv. True}" @@ -159,17 +160,16 @@ lemma quotI [intro]: "{x. a \ x} \ quot" unfolding quot_def by blast -lemma quotE [elim]: "R \ quot ==> (!!a. R = {x. a \ x} ==> C) ==> C" +lemma quotE [elim]: "R \ quot \ (\a. R = {x. a \ x} \ C) \ C" unfolding quot_def by blast -text {* +text \ \medskip Abstracted equivalence classes are the canonical representation of elements of a quotient type. -*} +\ -definition - eqv_class :: "('a::partial_equiv) => 'a quot" ("\_\") where - "\a\ = Abs_quot {x. a \ x}" +definition eqv_class :: "('a::partial_equiv) \ 'a quot" ("\_\") + where "\a\ = Abs_quot {x. a \ x}" theorem quot_rep: "\a. A = \a\" proof (cases A) @@ -184,19 +184,19 @@ using quot_rep by blast -subsection {* Equality on quotients *} +subsection \Equality on quotients\ -text {* +text \ Equality of canonical quotient elements corresponds to the original relation as follows. -*} +\ -theorem eqv_class_eqI [intro]: "a \ b ==> \a\ = \b\" +theorem eqv_class_eqI [intro]: "a \ b \ \a\ = \b\" proof - assume ab: "a \ b" have "{x. a \ x} = {x. b \ x}" proof (rule Collect_cong) - fix x show "(a \ x) = (b \ x)" + fix x show "a \ x \ b \ x" proof from ab have "b \ a" .. also assume "a \ x" @@ -210,7 +210,7 @@ then show ?thesis by (simp only: eqv_class_def) qed -theorem eqv_class_eqD' [dest?]: "\a\ = \b\ ==> a \ domain ==> a \ b" +theorem eqv_class_eqD' [dest?]: "\a\ = \b\ \ a \ domain \ a \ b" proof (unfold eqv_class_def) assume "Abs_quot {x. a \ x} = Abs_quot {x. b \ x}" then have "{x. a \ x} = {x. b \ x}" by (simp only: Abs_quot_inject quotI) @@ -220,25 +220,24 @@ then show "a \ b" .. qed -theorem eqv_class_eqD [dest?]: "\a\ = \b\ ==> a \ (b::'a::equiv)" +theorem eqv_class_eqD [dest?]: "\a\ = \b\ \ a \ (b::'a::equiv)" proof (rule eqv_class_eqD') show "a \ domain" .. qed -lemma eqv_class_eq' [simp]: "a \ domain ==> (\a\ = \b\) = (a \ b)" +lemma eqv_class_eq' [simp]: "a \ domain \ \a\ = \b\ \ a \ b" using eqv_class_eqI eqv_class_eqD' by (blast del: eqv_refl) -lemma eqv_class_eq [simp]: "(\a\ = \b\) = (a \ (b::'a::equiv))" +lemma eqv_class_eq [simp]: "\a\ = \b\ \ a \ (b::'a::equiv)" using eqv_class_eqI eqv_class_eqD by blast -subsection {* Picking representing elements *} +subsection \Picking representing elements\ -definition - pick :: "'a::partial_equiv quot => 'a" where - "pick A = (SOME a. A = \a\)" +definition pick :: "'a::partial_equiv quot \ 'a" + where "pick A = (SOME a. A = \a\)" -theorem pick_eqv' [intro?, simp]: "a \ domain ==> pick \a\ \ a" +theorem pick_eqv' [intro?, simp]: "a \ domain \ pick \a\ \ a" proof (unfold pick_def) assume a: "a \ domain" show "(SOME x. \a\ = \x\) \ a" diff -r 67baff6f697c -r 4c3bb56b8ce7 src/HOL/ex/Sqrt.thy --- a/src/HOL/ex/Sqrt.thy Sat Nov 22 14:13:36 2014 +0100 +++ b/src/HOL/ex/Sqrt.thy Sat Nov 22 14:57:04 2014 +0100 @@ -2,19 +2,19 @@ Author: Markus Wenzel, Tobias Nipkow, TU Muenchen *) -section {* Square roots of primes are irrational *} +section \Square roots of primes are irrational\ theory Sqrt imports Complex_Main "~~/src/HOL/Number_Theory/Primes" begin -text {* The square root of any prime number (including 2) is irrational. *} +text \The square root of any prime number (including 2) is irrational.\ theorem sqrt_prime_irrational: assumes "prime (p::nat)" shows "sqrt p \ \" proof - from `prime p` have p: "1 < p" by (simp add: prime_nat_def) + from \prime p\ have p: "1 < p" by (simp add: prime_nat_def) assume "sqrt p \ \" then obtain m n :: nat where n: "n \ 0" and sqrt_rat: "\sqrt p\ = m / n" @@ -31,12 +31,12 @@ have "p dvd m \ p dvd n" proof from eq have "p dvd m\<^sup>2" .. - with `prime p` show "p dvd m" by (rule prime_dvd_power_nat) + with \prime p\ show "p dvd m" by (rule prime_dvd_power_nat) then obtain k where "m = p * k" .. with eq have "p * n\<^sup>2 = p\<^sup>2 * k\<^sup>2" by (auto simp add: power2_eq_square ac_simps) with p have "n\<^sup>2 = p * k\<^sup>2" by (simp add: power2_eq_square) then have "p dvd n\<^sup>2" .. - with `prime p` show "p dvd n" by (rule prime_dvd_power_nat) + with \prime p\ show "p dvd n" by (rule prime_dvd_power_nat) qed then have "p dvd gcd m n" .. with gcd have "p dvd 1" by simp @@ -47,19 +47,20 @@ corollary sqrt_2_not_rat: "sqrt 2 \ \" using sqrt_prime_irrational[of 2] by simp -subsection {* Variations *} -text {* +subsection \Variations\ + +text \ Here is an alternative version of the main proof, using mostly linear forward-reasoning. While this results in less top-down structure, it is probably closer to proofs seen in mathematics. -*} +\ theorem assumes "prime (p::nat)" shows "sqrt p \ \" proof - from `prime p` have p: "1 < p" by (simp add: prime_nat_def) + from \prime p\ have p: "1 < p" by (simp add: prime_nat_def) assume "sqrt p \ \" then obtain m n :: nat where n: "n \ 0" and sqrt_rat: "\sqrt p\ = m / n" @@ -71,12 +72,12 @@ also have "\ * n\<^sup>2 = p * n\<^sup>2" by simp finally have eq: "m\<^sup>2 = p * n\<^sup>2" .. then have "p dvd m\<^sup>2" .. - with `prime p` have dvd_m: "p dvd m" by (rule prime_dvd_power_nat) + with \prime p\ have dvd_m: "p dvd m" by (rule prime_dvd_power_nat) then obtain k where "m = p * k" .. with eq have "p * n\<^sup>2 = p\<^sup>2 * k\<^sup>2" by (auto simp add: power2_eq_square ac_simps) with p have "n\<^sup>2 = p * k\<^sup>2" by (simp add: power2_eq_square) then have "p dvd n\<^sup>2" .. - with `prime p` have "p dvd n" by (rule prime_dvd_power_nat) + with \prime p\ have "p dvd n" by (rule prime_dvd_power_nat) with dvd_m have "p dvd gcd m n" by (rule gcd_greatest_nat) with gcd have "p dvd 1" by simp then have "p \ 1" by (simp add: dvd_imp_le) @@ -84,9 +85,9 @@ qed -text {* Another old chestnut, which is a consequence of the irrationality of 2. *} +text \Another old chestnut, which is a consequence of the irrationality of 2.\ -lemma "\a b::real. a \ \ \ b \ \ \ a powr b \ \" (is "EX a b. ?P a b") +lemma "\a b::real. a \ \ \ b \ \ \ a powr b \ \" (is "\a b. ?P a b") proof cases assume "sqrt 2 powr sqrt 2 \ \" then have "?P (sqrt 2) (sqrt 2)"