├── .gitignore
├── 404.html
├── Gemfile
├── Isabelle-Examples
├── AckermannM.thy
├── Baby.thy
├── Binary_Euclidean_Algorithm.thy
├── Binomial_Coeffs.thy
├── CTT_Examples.thy
├── Calculus.thy
├── CauchySchwarz.thy
├── Cbrt23_Irrational.thy
├── Dirichlet_approx_thm.thy
├── Fib_Iter.thy
├── Fibonacci.thy
├── Fibonacci_Newbie.thy
├── Fun_Semantics.thy
├── Gowers_Bijection.thy
├── Index_ex.thy
├── Index_sol.thy
├── Ln_lower_bound.thy
├── Numeric.thy
├── Probabilistic_Example_Erdos.thy
├── ROOT
├── Sqrt2_Irrational.thy
├── XsinX_lower_bounds.thy
├── document
│ ├── examples.bib
│ └── root.tex
└── output
│ ├── document.pdf
│ └── document
│ ├── AckermannM.tex
│ ├── Baby.tex
│ ├── Binary_Euclidean_Algorithm.tex
│ ├── Binomial_Coeffs.tex
│ ├── Calculus.tex
│ ├── CauchySchwarz.tex
│ ├── Cbrt23_Irrational.tex
│ ├── Dirichlet_approx_thm.tex
│ ├── Fib_Iter.tex
│ ├── Fibonacci.tex
│ ├── Fun_Semantics.tex
│ ├── Gowers_Bijection.tex
│ ├── Index_ex.tex
│ ├── Ln_lower_bound.tex
│ ├── Numeric.tex
│ ├── Probabilistic_Example_Erdos.tex
│ ├── Sqrt2_Irrational.tex
│ ├── XsinX_lower_bounds.tex
│ ├── comment.sty
│ ├── examples.bib
│ ├── isabelle.sty
│ ├── isabellesym.sty
│ ├── isabelletags.sty
│ ├── pdfsetup.sty
│ ├── railsetup.sty
│ ├── root.tex
│ ├── session.tex
│ └── session_graph.pdf
├── README.md
├── _config.yml
├── _drafts
├── 2025-05-22-Definitions.md
└── new post.md
├── _includes
├── analytics.html
├── archive.html
├── collecttags.html
├── head.html
├── page-footer.html
└── page-header.html
├── _layouts
├── default.html
├── home.html
├── page.html
├── post.html
└── tagpage.html
├── _posts
├── 2021-08-09-welcome.md
├── 2021-10-13-Fib-example.md
├── 2021-10-20-Fib-example-contd.md
├── 2021-10-27-formalisms.md
├── 2021-11-03-AUTOMATH.md
├── 2021-11-10-Axiom_of_Choice.md
├── 2021-11-17-Cauchy-Schwarz-example.md
├── 2021-11-24-Intuitionism.md
├── 2021-12-01-Undefined.md
├── 2021-12-08-ALEXANDRIA.md
├── 2021-12-15-Incompleteness.md
├── 2021-12-22-MVT-example.md
├── 2021-12-29-Ramsey-1.md
├── 2022-01-05-LCF.md
├── 2022-01-12-Proving-the-obvious.md
├── 2022-01-19-regular_pairs.md
├── 2022-01-26-Set_theory.md
├── 2022-02-02-Formalising_Math_Set_theory.md
├── 2022-02-09-Ackermann-example.md
├── 2022-02-16-Irrationals.md
├── 2022-02-23-Hereditarily_Finite.md
├── 2022-03-02-Type_classes.md
├── 2022-03-09-Quaternions.md
├── 2022-03-16-Types_vs_Sets.md
├── 2022-03-23-Locales.md
├── 2022-03-30-Quotienting.md
├── 2022-04-06-ZFC_in_HOL.md
├── 2022-04-13-Sledgehammer.md
├── 2022-04-20-Why-constructive.md
├── 2022-04-27-Wetzel.md
├── 2022-05-04-baby-examples.md
├── 2022-05-11-jEdit-tricks.md
├── 2022-05-18-Formalising-Incompleteness-I.md
├── 2022-05-25-Formalising-Incompleteness-II.md
├── 2022-06-01-Formalising-Incompleteness-III.md
├── 2022-06-08-baby-descriptions.md
├── 2022-06-15-Ramsey-2.md
├── 2022-06-22-Why-formalise.md
├── 2022-07-06-Turing_Machines.md
├── 2022-07-13-Isabelle_influences.md
├── 2022-07-27-Truth_Models.md
├── 2022-08-03-Small-Challenges-I.md
├── 2022-08-10-Nonstandard_Analysis.md
├── 2022-08-17-Gordon-BDDs-HOL.md
├── 2022-08-31-Ackermann-not-PR-I.md
├── 2022-09-07-Ackermann-not-PR-II.md
├── 2022-09-14-Libraries.md
├── 2022-09-28-Cambridge_LCF.md
├── 2022-10-05-Standard_ML.md
├── 2022-10-12-verifying-distributed-systems-isabelle.md
├── 2022-10-19-crypto-protocols.md
├── 2022-10-26-Multiset-Ordering.md
├── 2022-11-02-crypto-protocols-NS.md
├── 2022-11-09-Hilbert-Isabelle.md
├── 2022-11-16-automation_eng_in_math.md
├── 2022-11-23-CTT_in_Isabelle.md
├── 2022-11-30-CTT_in_Isabelle-II.md
├── 2022-12-07-Memories_first_exposure.md
├── 2022-12-14-User_interfaces.md
├── 2022-12-21-MetiTarski.md
├── 2023-01-04-Hardware_Verification.md
├── 2023-01-11-AI_at_Stanford.md
├── 2023-01-18-Sqrt2_irrational.md
├── 2023-02-01-On-the-infinite.md
├── 2023-02-08-Cbrt23_Irrational.md
├── 2023-02-22-Binary_GCD.md
├── 2023-03-08-Fun_Semantics.md
├── 2023-03-22-Binomial_Coeffs.md
├── 2023-04-12-Wittgenstein.md
├── 2023-04-27-ALEXANDRIA_outcomes.md
├── 2023-07-12-Metric_spaces.md
├── 2023-07-26-Wang.md
├── 2023-08-09-computer_proof.md
├── 2023-08-23-Propositions_as_Types.md
├── 2023-08-31-ALEXANDRIA_finished.md
├── 2023-10-04-Ochigame.md
├── 2023-11-01-Foundations.md
├── 2023-11-08-CoinductivePuzzle.md
├── 2024-01-31-Russells_Paradox.md
├── 2024-02-14-Contradiction.md
├── 2024-02-28-Gowers_bijection_example.md
├── 2024-07-25-Numeric_types.md
├── 2024-08-08-Ln_lower_bound.md
├── 2024-08-21-Probabilistic_Example.md
├── 2024-09-30-Intro_Lambda_Calculus.md
├── 2024-10-14-Church_Rosser.md
├── 2024-12-20-Quickstart.md
├── 2024-12-23-Holiday_Exercises.md
├── 2025-01-06-Code_Generation.md
├── 2025-01-22-Dirichlet_Approx.md
├── 2025-03-14-revisiting_demillo.md
├── 2025-03-19-Trickier_lower_bound.md
└── 2025-03-28-Induction_Fetzer.md
├── _sass
├── cayman.scss
├── jekyll-theme-cayman.scss
├── normalize.scss
├── rouge-github.scss
└── variables.scss
├── about.md
├── assets
└── css
│ └── style.scss
├── css
├── cayman.css
├── fonts
│ ├── IsabelleDejaVuSans-Bold.ttf
│ ├── IsabelleDejaVuSans-BoldOblique.ttf
│ ├── IsabelleDejaVuSans-Oblique.ttf
│ ├── IsabelleDejaVuSans.ttf
│ ├── IsabelleDejaVuSansMono-Bold.ttf
│ ├── IsabelleDejaVuSansMono-BoldOblique.ttf
│ ├── IsabelleDejaVuSansMono-Oblique.ttf
│ ├── IsabelleDejaVuSansMono.ttf
│ ├── IsabelleDejaVuSerif-Bold.ttf
│ ├── IsabelleDejaVuSerif-BoldItalic.ttf
│ ├── IsabelleDejaVuSerif-Italic.ttf
│ ├── IsabelleDejaVuSerif.ttf
│ └── Vacuous.ttf
├── isabelle.css
└── normalize.css
├── feed.xml
├── images
├── 2022-10-induction.png
├── 2022-10-system-model.png
├── 2022-10-time-steps.png
├── 3minus2.png
├── AUTOMATH-book-equality.png
├── CTT
│ ├── split-in1.png
│ ├── split-in2.png
│ ├── split-out1.png
│ ├── split-out2.png
│ ├── struct-AC.png
│ ├── struct-LEM.png
│ ├── typefm-in1.png
│ ├── typefm-in2.png
│ ├── typefm-in3.png
│ ├── typefm-in4.png
│ ├── typefm-out1.png
│ ├── typefm-out2.png
│ ├── typefm-out3.png
│ ├── typefm-out4.png
│ ├── typeinf-add-in.png
│ ├── typeinf-add-out.png
│ ├── typeinf-in.png
│ ├── typeinf-lemma.png
│ ├── typeinf-out1.png
│ ├── typeinf-out2.png
│ ├── typeinf-out3.png
│ └── typeinf-out4.png
├── ConcaveDef.png
├── Concave_ln.png
├── Dirichlet-approx-thm.png
├── Fib-newbie
│ ├── f1.png
│ ├── f10.png
│ ├── f11.png
│ ├── f2.png
│ ├── f3.png
│ ├── f4.png
│ ├── f5.png
│ ├── f6.png
│ ├── f7.png
│ ├── f8.png
│ └── f9.png
├── Gowers-example.jpeg
├── Hardy-MVT.png
├── Jech-118-footnotes.png
├── MT-examples.png
├── Metitarski-example.png
├── PPLAMBDA-proof.png
├── Strachey-halting.png
├── TypesOfConicSections.jpg
├── Univ-Machine-Structure.png
├── Univ-Machine.png
├── Why trust II.png
├── Why trust.png
├── chess-board.png
├── compose-devices.png
├── diamond-in-lambda-calc.png
├── diamond2-in-lambda-calc.png
├── equality-in-lambda-calc.png
├── frozen_friends.jpg
├── hw-device.png
├── isabelle_logo.gif
├── jEdit-tricks-bound.png
├── jEdit-tricks-click.png
├── jEdit-tricks-hanging.png
├── jEdit-tricks-looping-proof.png
├── jEdit-tricks-popup.png
├── jEdit-tricks-skolem.png
├── peg-solitaire.png
├── plot_x_ln_x.png
├── plot_x_sin_inv_x.png
├── pure-silver.jpg
├── sqrt2-figure.jpg
├── squared_square.png
├── transistor.png
└── tripartite graph.png
├── index.html
├── papers
├── Aczel-Inductive-Defs.pdf
├── Boolos-iterative-concept-of-set.pdf
├── Cohen-TAPS.pdf
├── Early-History-of-ATP.pdf
├── Edmonds-CPP2024.pdf
├── FloydMeaning.pdf
├── Knuth-TEX.pdf
├── Lam_finite_Proj_plane_order_10.pdf
├── ML-Int-TT.pdf
├── Matthews-parallel.pdf
├── Rosser-Lambda-Calculus.pdf
├── Russells-mathematical-logic.pdf
├── Scott-Models.pdf
├── Wang-Formalisation.pdf
├── Wang-Orginal-Sin.pdf
├── bachmair-hbar-resolution.pdf
├── deBruijn-nameless-dummies.pdf
├── on-the-infinite.pdf
└── unreasonable.pdf
├── tag
├── ALEXANDRIA.md
├── AUTOMATH.md
├── Ackermann's_function.md
├── Alan_Turing.md
├── Archive_of_Formal_Proofs.md
├── BDDs.md
├── Bertrand_Russell.md
├── Coq.md
├── Dana_Scott.md
├── David_Hilbert.md
├── Ernst_Zermelo.md
├── Fibonacci.md
├── HOL_Light.md
├── HOL_system.md
├── Hao_Wang.md
├── Imre_Lakatos.md
├── Isabelle.md
├── Isar.md
├── Jacques_Fleuriot.md
├── John_Littlewood.md
├── Kurt_Gödel.md
├── LCF.md
├── Leonhard_Euler.md
├── MJC_Gordon.md
├── Martin-Löf_type_theory.md
├── MetiTarski.md
├── Mizar.md
├── NG_de_Bruijn.md
├── PVS.md
├── Paul_Erdős.md
├── Principia_Mathematica.md
├── Proofs_from_THE_BOOK.md
├── QED_project.md
├── Ramsey's_theorem.md
├── Robin_Milner.md
├── Standard_ML.md
├── Stanford.md
├── Szemerédi’s_regularity_lemma.md
├── ZFC_in_HOL.md
├── analysis.md
├── automation.md
├── axiom_of_choice.md
├── constructive_logic.md
├── descriptions.md
├── examples.md
├── formalised_mathematics.md
├── gcd.md
├── general.md
├── incompleteness.md
├── inductive_definitions.md
├── intuitionism.md
├── jEdit.md
├── lambda_calculus.md
├── law_of_excluded_middle.md
├── locales.md
├── logic.md
├── memories.md
├── newbies.md
├── nominal_package.md
├── nonstandard_analysis.md
├── ordinal_partitions.md
├── philosophy.md
├── proof_documents.md
├── quaternions.md
├── quotients.md
├── recruitment.md
├── recursion.md
├── resolution.md
├── set_theory.md
├── sledgehammer.md
├── type_classes.md
├── type_theory.md
└── verification.md
└── tag_generator.py
/.gitignore:
--------------------------------------------------------------------------------
1 | _site/
2 | Gemfile.lock
3 | post.pdf
4 |
--------------------------------------------------------------------------------
/404.html:
--------------------------------------------------------------------------------
1 | ---
2 | permalink: /404.html
3 | layout: default
4 | ---
5 |
6 |
19 |
20 |
21 |
404
22 |
23 |
Page not found :(
24 |
The requested page could not be found.
25 |
Please notify Larry Paulson at lp15@cam.ac.uk
26 |
27 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source "https://rubygems.org"
2 | # Hello! This is where you manage which Jekyll version is used to run.
3 | # When you want to use a different version, change it below, save the
4 | # file and run `bundle install`. Run Jekyll with `bundle exec`, like so:
5 | #
6 | # bundle exec jekyll serve
7 | #
8 | # This will help ensure the proper Jekyll version is running.
9 | # Happy Jekylling!
10 | ##### gem "jekyll", "~> 4.2.0"
11 | # This is the default theme for new Jekyll sites. You may change this to anything you like.
12 | ## gem "jekyll-theme-cayman", "~> 0.2.0"
13 | # If you want to use GitHub Pages, remove the "gem "jekyll"" above and
14 | # uncomment the line below. To upgrade, run `bundle update github-pages`.
15 | gem "github-pages", group: :jekyll_plugins
16 | # If you have any plugins, put them here!
17 | group :jekyll_plugins do
18 | gem "jekyll-feed", "~> 0.12"
19 | end
20 |
21 | # Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
22 | # and associated library.
23 | platforms :mingw, :x64_mingw, :mswin, :jruby do
24 | gem "tzinfo", "~> 1.2"
25 | gem "tzinfo-data"
26 | end
27 |
28 | # Performance-booster for watching directories on Windows
29 | gem "wdm", "~> 0.1.1", :platforms => [:mingw, :x64_mingw, :mswin]
30 |
31 |
32 | gem "webrick", "~> 1.7"
33 |
--------------------------------------------------------------------------------
/Isabelle-Examples/AckermannM.thy:
--------------------------------------------------------------------------------
1 | (* Title: HOL/Examples/AckermannM.thy
2 | Author: Larry Paulson
3 | *)
4 |
5 | section \A Tail-Recursive, Stack-Based Ackermann's Function\
6 |
7 | text \Unlike the other Ackermann example, this termination proof uses the argument from
8 | Nachum Dershowitz and Zohar Manna. Proving termination with multiset orderings.
9 | Communications of the ACM 22 (8) 1979, 465–476.\
10 |
11 | theory AckermannM imports "HOL-Library.Multiset_Order" "HOL-Library.Product_Lexorder"
12 |
13 | begin
14 |
15 | text\This theory investigates a stack-based implementation of Ackermann's function.
16 | Let's recall the traditional definition,
17 | as modified by R{\'o}zsa P\'eter and Raphael Robinson.\
18 |
19 | fun ack :: "[nat,nat] \ nat" where
20 | "ack 0 n = Suc n"
21 | | "ack (Suc m) 0 = ack m 1"
22 | | "ack (Suc m) (Suc n) = ack m (ack (Suc m) n)"
23 |
24 | text\Setting up the termination proof for the stack-based version.\
25 |
26 | fun ack_mset :: "nat list \ (nat\nat) multiset" where
27 | "ack_mset [] = {#}"
28 | | "ack_mset [x] = {#}"
29 | | "ack_mset (z#y#l) = mset ((y,z) # map (\x. (Suc x, 0)) l)"
30 |
31 | lemma case1: "ack_mset (Suc n # l) < add_mset (0, n) {#(Suc x, 0). x \# mset l#}"
32 | proof (cases l)
33 | case (Cons m list)
34 | have "{#(m, Suc n)#} < {#(Suc m, 0)#}"
35 | by auto
36 | also have "\ \ {#(Suc m, 0), (0,n)#}"
37 | by auto
38 | finally show ?thesis
39 | by (simp add: Cons)
40 | qed auto
41 |
42 | text\Here is the stack-based version, which uses lists.\
43 |
44 | function ackloop :: "nat list \ nat" where
45 | "ackloop (n # 0 # l) = ackloop (Suc n # l)"
46 | | "ackloop (0 # Suc m # l) = ackloop (1 # m # l)"
47 | | "ackloop (Suc n # Suc m # l) = ackloop (n # Suc m # m # l)"
48 | | "ackloop [m] = m"
49 | | "ackloop [] = 0"
50 | by pat_completeness auto
51 |
52 | termination
53 | by (relation "inv_image {(x,y). xUnlike the other Ackermann theory, no extra function is needed to prove equivalence\
56 | lemma ackloop_ack: "ackloop (n # m # l) = ackloop (ack m n # l)"
57 | by (induction m n arbitrary: l rule: ack.induct) auto
58 |
59 | theorem ack: "ack m n = ackloop [n,m]"
60 | by (simp add: ackloop_ack)
61 |
62 | end
63 |
--------------------------------------------------------------------------------
/Isabelle-Examples/Baby.thy:
--------------------------------------------------------------------------------
1 | section \Baby examples\
2 |
3 | theory Baby
4 | imports "HOL-Library.Sum_of_Squares"
5 | "HOL-Decision_Procs.Approximation"
6 | "HOL-Analysis.Analysis"
7 |
8 | begin
9 |
10 | text \a simplification rule for powers\
11 | thm power_Suc
12 |
13 | text \Kevin Buzzard's examples\
14 | lemma
15 | fixes x::real
16 | shows "(x+y)*(x+2*y)*(x+3*y) = x^3 + 6*x^2*y + 11*x*y^2 + 6*y^3"
17 | by (simp add: algebra_simps eval_nat_numeral)
18 |
19 | lemma "sqrt 2 + sqrt 3 < sqrt 10"
20 | proof -
21 | have "(sqrt 2 + sqrt 3)^2 < (sqrt 10)^2"
22 | proof (simp add: algebra_simps eval_nat_numeral)
23 | have "(2 * (sqrt 2 * sqrt 3))^2 < 5 ^ 2"
24 | by (simp add: algebra_simps eval_nat_numeral)
25 | then show "2 * (sqrt 2 * sqrt 3) < 5"
26 | by (smt (verit, best) power_mono)
27 | qed
28 | then show ?thesis
29 | by (simp add: real_less_rsqrt)
30 | qed
31 |
32 | lemma "sqrt 2 + sqrt 3 < sqrt 10"
33 | by (approximation 10)
34 |
35 | lemma "x \ {0.999..1.001} \ \pi - 4 * arctan x\ < 0.0021"
36 | by (approximation 20)
37 |
38 | lemma "3.141592635389 < pi"
39 | by (approximation 30)
40 |
41 | lemma
42 | fixes a::real
43 | shows "(a*b + b * c + c*a)^3 \ (a^2 + a * b + b^2) * (b^2 + b * c + c^2) * (c^2 + c*a + a^2)"
44 | by sos
45 |
46 | lemma "sqrt 2 \ \"
47 | proof
48 | assume "sqrt 2 \ \"
49 | then obtain q::rat where "sqrt 2 = of_rat q"
50 | using Rats_cases by blast
51 | then have "q\<^sup>2 = 2"
52 | by (metis abs_numeral of_rat_eq_iff of_rat_numeral_eq of_rat_power real_sqrt_abs
53 | real_sqrt_power)
54 | then obtain m n where "coprime m n" "q = of_int m / of_int n"
55 | by (metis Fract_of_int_quotient Rat_cases)
56 | then have "(rat_of_int m)\<^sup>2 / (rat_of_int n)\<^sup>2 = 2"
57 | by (metis \q\<^sup>2 = 2\ power_divide)
58 | then have 2: "(rat_of_int m)\<^sup>2 = 2 * (rat_of_int n)\<^sup>2"
59 | by (metis div_by_0 nonzero_mult_div_cancel_right times_divide_eq_left zero_neq_numeral)
60 | then have "2 dvd m"
61 | by (metis (mono_tags, lifting) even_mult_iff even_numeral of_int_eq_iff of_int_mult
62 | of_int_numeral power2_eq_square)
63 | then have "2\<^sup>2 dvd m\<^sup>2"
64 | using dvd_power_same by blast
65 | then have "2 dvd n"
66 | by (metis "2" even_mult_iff of_int_eq_iff of_int_mult of_int_numeral power2_eq_square
67 | zdvd_mono zero_neq_numeral)
68 | then show False
69 | using \coprime m n\ \even m\ by auto
70 | qed
71 |
72 | subsection \Material for a later post, about descriptions\
73 |
74 |
75 | lemma
76 | fixes \ :: "'a::metric_space set set" and L :: "nat list set"
77 | assumes "\ \ {ball x r | x r. r>0}" and "L \ {}"
78 | shows "P \ L"
79 | proof -
80 | have "\B. B \ \ \ \x. \r>0. B = ball x r"
81 | using assms by blast
82 | then obtain centre rad where rad: "\B. B \ \ \ rad B > 0"
83 | and centre: "\B. B \ \ \ B = ball (centre B) (rad B)"
84 | by metis
85 | define infrad where "infrad \ Inf (rad ` \)"
86 | have "infrad \ rad B" if "B \ \" for B
87 | by (smt (verit, best) bdd_below.I cINF_lower image_iff infrad_def rad that)
88 |
89 | have "\B \ \. rad B = infrad" if "finite \" "\ \ {}"
90 | by (smt (verit) empty_is_image finite_imageI finite_less_Inf_iff imageE infrad_def that)
91 |
92 | define minl where "minl = Inf (length ` L)"
93 | obtain l0 where "l0 \ L" "length l0 = minl"
94 | by (metis Inf_nat_def1 empty_is_image imageE minl_def \L \ {}\)
95 | then have "length l0 \ length l" if "l \ L" for l
96 | by (simp add: cINF_lower minl_def that)
97 |
98 | show ?thesis
99 | sorry
100 | qed
101 |
102 |
103 |
104 |
105 | end
106 |
--------------------------------------------------------------------------------
/Isabelle-Examples/Binary_Euclidean_Algorithm.thy:
--------------------------------------------------------------------------------
1 | theory Binary_Euclidean_Algorithm
2 | imports "HOL-Computational_Algebra.Primes"
3 | begin
4 |
5 | subsection \The binary GCD algorithm\
6 |
7 | inductive_set bgcd :: "(nat \ nat \ nat) set" where
8 | bgcdZero: "(u, 0, u) \ bgcd"
9 | | bgcdEven: "\ (u, v, g) \ bgcd \ \ (2*u, 2*v, 2*g) \ bgcd"
10 | | bgcdOdd: "\ (u, v, g) \ bgcd; \ 2 dvd v \ \ (2*u, v, g) \ bgcd"
11 | | bgcdStep: "\ (u - v, v, g) \ bgcd; v \ u \ \ (u, v, g) \ bgcd"
12 | | bgcdSwap: "\ (v, u, g) \ bgcd \ \ (u, v, g) \ bgcd"
13 |
14 | subsection \Proving that the algorithm is correct\
15 |
16 | text \Show that the bgcd of @{text x} und @{text y} is
17 | really a divisor of both numbers\
18 | lemma bgcd_divides: "(x,y,g) \ bgcd \ g dvd x \ g dvd y"
19 | proof (induct rule: bgcd.induct)
20 | case (bgcdStep u v g)
21 | with dvd_diffD show ?case
22 | by blast
23 | qed auto
24 |
25 | text \The bgcd of @{text x} und @{text y} really is the greatest common divisor
26 | of both numbers, with respect to the divides relation.\
27 | lemma bgcd_greatest:
28 | "(x,y,g) \ bgcd \ d dvd x \ d dvd y \ d dvd g"
29 | proof (induct arbitrary: d rule: bgcd.induct)
30 | case (bgcdEven u v g d)
31 | show ?case
32 | proof (cases "2 dvd d")
33 | case True thus ?thesis using bgcdEven by (force simp add: dvd_def)
34 | next
35 | case False
36 | thus ?thesis using bgcdEven
37 | by (simp add: coprime_dvd_mult_right_iff)
38 | qed
39 | next
40 | case (bgcdOdd u v g d)
41 | hence "coprime d 2"
42 | by fastforce
43 | thus ?case using bgcdOdd
44 | by (simp add: coprime_dvd_mult_right_iff)
45 | qed auto
46 |
47 | subsection \Proving uniqueness and existence\
48 |
49 | text \despite its apparent non-determinism, the relation @{text bgcd} is deterministic
50 | and therefore defines a function\
51 | lemma bgcd_unique:
52 | "(x,y,g) \ bgcd \ (x,y,g') \ bgcd \ g = g'"
53 | by (meson bgcd_divides bgcd_greatest gcd_nat.strict_iff_not)
54 |
55 | lemma bgcd_defined_aux: "a+b \ n \ \g. (a, b, g) \ bgcd"
56 | proof (induction n arbitrary: a b rule: less_induct)
57 | case (less n a b)
58 | show ?case
59 | proof (cases b)
60 | case 0
61 | thus ?thesis by (metis bgcdZero)
62 | next
63 | case (Suc b')
64 | then have *: "a + b' < n"
65 | using Suc_le_eq add_Suc_right less.prems by presburger
66 | show ?thesis
67 | proof (cases "b \ a")
68 | case True
69 | thus ?thesis
70 | by (metis bgcd.simps le_add1 le_add_diff_inverse less.IH [OF *])
71 | next
72 | case False
73 | then show ?thesis
74 | by (metis less.IH [OF *] Suc Suc_leI bgcd.simps le_add_diff_inverse
75 | less_add_same_cancel2 nle_le zero_less_iff_neq_zero)
76 | qed
77 | qed
78 | qed
79 |
80 | theorem bgcd_defined: "\!g. (a, b, g) \ bgcd"
81 | using bgcd_defined_aux bgcd_unique by auto
82 |
83 | text \Alternative proof suggested by YawarRaza7349\
84 | lemma bgcd_defined_aux': "a+b = n \ \g. (a, b, g) \ bgcd"
85 | proof (induction n arbitrary: a b rule: less_induct)
86 | case (less n a b)
87 | then show ?case
88 | proof (cases "b \ a")
89 | case True
90 | with less obtain g where "(a-b, b, g) \ bgcd"
91 | by (metis add_cancel_right_right bgcd.simps le_add1 le_add_diff_inverse nat_less_le)
92 | thus ?thesis
93 | using True bgcd.bgcdStep by blast
94 | next
95 | case False
96 | with less show ?thesis
97 | by (metis bgcd.simps le_add_diff_inverse less_add_same_cancel2 nle_le zero_less_iff_neq_zero)
98 | qed
99 | qed
100 |
101 | end
102 |
103 |
--------------------------------------------------------------------------------
/Isabelle-Examples/Binomial_Coeffs.thy:
--------------------------------------------------------------------------------
1 | theory Binomial_Coeffs
2 | imports Complex_Main "HOL-Number_Theory.Fib"
3 | begin
4 |
5 | lemma choose_row_sum: "(\k\n. n choose k) = 2^n"
6 | using binomial [of 1 1 n] by (simp add: numeral_2_eq_2)
7 |
8 | text\sums of binomial coefficients.\
9 | lemma sum_choose_lower:
10 | "(\k\n. (r+k) choose k) = Suc (r+n) choose n"
11 | by (induction n) auto
12 |
13 | lemma sum_choose_upper:
14 | "(\k\n. k choose m) = Suc n choose Suc m"
15 | by (induction n) auto
16 |
17 | lemma sum_choose_diagonal:
18 | assumes "m\n"
19 | shows "(\k\m. (n-k) choose (m-k)) = Suc n choose m"
20 | proof -
21 | have "(\k\m. (n-k) choose (m-k)) = (\k\m. (n-m+k) choose k)"
22 | using sum.atLeastAtMost_rev [of "\k. (n - k) choose (m - k)" 0 m]
23 | by (simp add: atMost_atLeast0 \m\n\)
24 | also have "\ = Suc (n-m+m) choose m"
25 | by (rule sum_choose_lower)
26 | also have "\ = Suc n choose m" using assms
27 | by simp
28 | finally show ?thesis .
29 | qed
30 |
31 | lemma choose_mult_lemma:
32 | "((m+r+k) choose (m+k)) * ((m+k) choose k) = ((m+r+k) choose k) * ((m+r) choose m)"
33 | (is "?lhs = _")
34 | proof -
35 | have "?lhs =
36 | fact(m+r+k) div (fact(m+k) * fact(m+r-m)) * (fact(m+k) div (fact k * fact m))"
37 | by (simp add: binomial_altdef_nat)
38 | also have "\ = fact(m+r+k) * fact(m+k) div
39 | (fact(m+k) * fact(m+r-m) * (fact k * fact m))"
40 | by (metis add_implies_diff add_le_mono1 choose_dvd diff_cancel2 div_mult_div_if_dvd
41 | le_add1 le_add2)
42 | also have "\ = fact(m+r+k) div (fact r * (fact k * fact m))"
43 | by (auto simp: algebra_simps fact_fact_dvd_fact)
44 | also have "\ = (fact(m+r+k) * fact(m+r)) div (fact r * (fact k * fact m) * fact(m+r))"
45 | by simp
46 | also have "\ =
47 | (fact(m+r+k) div (fact k * fact(m+r)) * (fact(m+r) div (fact r * fact m)))"
48 | by (smt (verit) fact_fact_dvd_fact div_mult_div_if_dvd mult.assoc mult.commute)
49 | finally show ?thesis
50 | by (simp add: binomial_altdef_nat mult.commute)
51 | qed
52 |
53 | text \The "Subset of a Subset" identity.\
54 | lemma choose_mult:
55 | "k \ m \ m \ n \ (n choose m) * (m choose k) = (n choose k) * ((n - k) choose (m - k))"
56 | using choose_mult_lemma [of "m-k" "n-m" k] by simp
57 |
58 |
59 | text \Concrete Mathematics, 5.18: "this formula is easily verified by induction on m"\
60 | lemma choose_row_sum_weighted:
61 | "(\k\m. (r choose k) * (r/2 - k)) = (Suc m)/2 * (r choose (Suc m))"
62 | proof (induction m)
63 | case 0 show ?case by simp
64 | next
65 | case (Suc m)
66 | have "(\k\Suc m. real (r choose k) * (r/2 - k))
67 | = ((r choose Suc m) * (r/2 - (Suc m))) + (Suc m) / 2 * (r choose Suc m)"
68 | by (simp add: Suc)
69 | also have "\ = (r choose Suc m) * (real r - (Suc m)) / 2"
70 | by (simp add: field_simps)
71 | also have "\ = Suc (Suc m) / 2 * (r choose Suc (Suc m))"
72 | proof (cases "r \ Suc m")
73 | case True with binomial_absorb_comp[of r "Suc m"] show ?thesis
74 | by (metis binomial_absorption mult.commute of_nat_diff of_nat_mult times_divide_eq_left)
75 | qed (simp add: binomial_eq_0)
76 | finally show ?case .
77 | qed
78 |
79 |
80 | lemma sum_drop_zero: "(\k\Suc n. if 0j\n. f j)"
81 | by (induction n) auto
82 |
83 | lemma sum_choose_drop_zero:
84 | "(\k\Suc n. if k = 0 then 0 else (Suc n - k) choose (k - 1)) =
85 | (\j\n. (n-j) choose j)"
86 | by (rule trans [OF sum.cong sum_drop_zero]) auto
87 |
88 | lemma ne_diagonal_fib:
89 | "(\k\n. (n-k) choose k) = fib (Suc n)"
90 | proof (induction n rule: fib.induct)
91 | case 1 show ?case by simp
92 | next
93 | case 2 show ?case by simp
94 | next
95 | case (3 n)
96 | have "(\k\Suc n. Suc (Suc n) - k choose k) =
97 | (\k\Suc n. (Suc n - k choose k) + (if k=0 then 0 else (Suc n - k choose (k - 1))))"
98 | by (rule sum.cong) (simp_all add: choose_reduce_nat)
99 | also have "\ = (\k\Suc n. Suc n - k choose k) +
100 | (\k\Suc n. if k=0 then 0 else (Suc n - k choose (k - 1)))"
101 | by (simp add: sum.distrib)
102 | also have "\ = (\k\Suc n. Suc n - k choose k) + (\j\n. n - j choose j)"
103 | by (metis sum_choose_drop_zero)
104 | finally show ?case using 3
105 | by simp
106 | qed
107 |
108 | end
109 |
--------------------------------------------------------------------------------
/Isabelle-Examples/CTT_Examples.thy:
--------------------------------------------------------------------------------
1 | (*Run with
2 | isabelle jedit -l CTT CTT_Examples.thy
3 | *)
4 | theory CTT_Examples
5 | imports "CTT.CTT"
6 | begin
7 |
8 | schematic_goal "?A type"
9 | apply (rule form_rls)
10 | back
11 | apply (rule form_rls)
12 | apply (rule form_rls)
13 | done
14 |
15 | schematic_goal "<0, succ(0)> : ?A"
16 | apply (rule intr_rls)
17 | apply (rule intr_rls)
18 | apply (rule intr_rls)
19 | apply (rule intr_rls)
20 | done
21 |
22 | lemma "<0, succ(0)> : N \ N"
23 | by (rule intr_rls)+
24 |
25 | text "typechecking the addition function"
26 |
27 | schematic_goal "\<^bold>\n. \<^bold>\m. rec(n, m, \x y. succ(y)) : ?A"
28 | apply (rule intr_rls form_rls elim_rls | assumption)+
29 | done
30 |
31 |
32 | text "This finds the functions fst and snd!"
33 |
34 | schematic_goal "A type \ ?a : (A \ A) \ A"
35 | apply (rule intr_rls form_rls | erule elim_rls | assumption)+
36 | back
37 | done
38 |
39 | text "Double negation of the Excluded Middle"
40 | schematic_goal "A type \ ?a : ((A + (A\F)) \ F) \ F"
41 | apply intr
42 | apply (rule ProdE)
43 | apply assumption
44 | apply pc
45 | done
46 |
47 | (*Experiment: the proof above in Isar*)
48 | lemma
49 | assumes "A type" shows "(\<^bold>\f. f ` inr(\<^bold>\y. f ` inl(y))) : ((A + (A\F)) \ F) \ F"
50 | proof intr
51 | fix f
52 | assume f: "f : A + (A \ F) \ F"
53 | with assms have "inr(\<^bold>\y. f ` inl(y)) : A + (A \ F)"
54 | by pc
55 | then show "f ` inr(\<^bold>\y. f ` inl(y)) : F"
56 | by (rule ProdE [OF f])
57 | qed (rule assms)+
58 |
59 | text "Binary sums and products"
60 | schematic_goal "\A type; B type; C type\ \ ?a : (A + B \ C) \ (A \ C) \ (B \ C)"
61 | apply pc
62 | done
63 |
64 | (*A distributive law*)
65 | schematic_goal
66 | assumes "A type"
67 | and "\x. x:A \ B(x) type"
68 | and "\x. x:A \ C(x) type"
69 | shows "?a : (\x:A. B(x) + C(x)) \ (\x:A. B(x)) + (\x:A. C(x))"
70 | apply (pc assms)
71 | done
72 |
73 | text "Construction of the currying functional"
74 | schematic_goal
75 | assumes "A type"
76 | and "\x. x:A \ B(x) type"
77 | and "\z. z: (\x:A. B(x)) \ C(z) type"
78 | shows "?a : \f: (\z : (\x:A . B(x)) . C(z)).
79 | (\x:A . \y:B(x) . C())"
80 | apply (pc assms)
81 | done
82 |
83 | text "Martin-Löf (1984), page 48: axiom of sum-elimination (uncurry)"
84 | schematic_goal
85 | assumes "A type"
86 | and "\