├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── _static
└── favicon.ico
├── _templates
├── layout.html
└── navigation_without_header.html
├── axiomatic_foundations.rst
├── bussproofs.sty
├── classical_reasoning.rst
├── combinatorics.rst
├── conf.py
├── deploy.sh
├── elementary_number_theory.rst
├── exclude
├── algbraic_structures_in_lean.rst
├── algebraic_structures.rst
├── combinatorics_in_lean.rst
├── elementary_number_theory_in_lean.rst
├── probability.rst
├── probability_in_lean.rst
├── real_numbers_and_analysis_in_lean.rst
└── the_infinite_in_lean.rst
├── first_order_logic.rst
├── first_order_logic_in_lean.rst
├── functions.rst
├── functions_in_lean.rst
├── index.rst
├── inference_rules_for_first_order_logic.rst
├── inference_rules_for_propositional_logic.rst
├── introduction.rst
├── latex_images
├── Makefile
├── bussproofs.sty
├── classical_reasoning.1.tex
├── classical_reasoning.2.tex
├── classical_reasoning.3.tex
├── classical_reasoning.4.tex
├── classical_reasoning.5.tex
├── classical_reasoning.6.tex
├── classical_reasoning.6bis.tex
├── classical_reasoning.7.tex
├── classical_reasoning.8.tex
├── combinatorics.1.tex
├── first_order_logic.10.tex
├── first_order_logic.3.tex
├── first_order_logic.4.tex
├── first_order_logic.5.tex
├── first_order_logic.6.tex
├── first_order_logic.7.tex
├── first_order_logic.8.tex
├── first_order_logic_in_lean.1.tex
├── first_order_logic_in_lean.2.tex
├── introduction.1.tex
├── introduction.2.tex
├── introduction.3.tex
├── mylogic.sty
├── natural_deduction_for_first_order_logic.1.tex
├── natural_deduction_for_first_order_logic.10.tex
├── natural_deduction_for_first_order_logic.11.tex
├── natural_deduction_for_first_order_logic.12.tex
├── natural_deduction_for_first_order_logic.13.tex
├── natural_deduction_for_first_order_logic.13a.tex
├── natural_deduction_for_first_order_logic.14.tex
├── natural_deduction_for_first_order_logic.15.tex
├── natural_deduction_for_first_order_logic.16.tex
├── natural_deduction_for_first_order_logic.2.tex
├── natural_deduction_for_first_order_logic.3.tex
├── natural_deduction_for_first_order_logic.4.tex
├── natural_deduction_for_first_order_logic.5.tex
├── natural_deduction_for_first_order_logic.6.tex
├── natural_deduction_for_first_order_logic.7.tex
├── natural_deduction_for_first_order_logic.8.tex
├── natural_deduction_for_first_order_logic.9.tex
├── natural_deduction_for_propositional_logic.1.tex
├── natural_deduction_for_propositional_logic.10.tex
├── natural_deduction_for_propositional_logic.11.tex
├── natural_deduction_for_propositional_logic.12.tex
├── natural_deduction_for_propositional_logic.13.tex
├── natural_deduction_for_propositional_logic.14.tex
├── natural_deduction_for_propositional_logic.15.tex
├── natural_deduction_for_propositional_logic.16.tex
├── natural_deduction_for_propositional_logic.17.tex
├── natural_deduction_for_propositional_logic.18.tex
├── natural_deduction_for_propositional_logic.19.tex
├── natural_deduction_for_propositional_logic.2.tex
├── natural_deduction_for_propositional_logic.20.tex
├── natural_deduction_for_propositional_logic.21.tex
├── natural_deduction_for_propositional_logic.22.tex
├── natural_deduction_for_propositional_logic.23.tex
├── natural_deduction_for_propositional_logic.24.tex
├── natural_deduction_for_propositional_logic.25.tex
├── natural_deduction_for_propositional_logic.3.tex
├── natural_deduction_for_propositional_logic.4.tex
├── natural_deduction_for_propositional_logic.5.tex
├── natural_deduction_for_propositional_logic.6.tex
├── natural_deduction_for_propositional_logic.7.tex
├── natural_deduction_for_propositional_logic.8.tex
├── natural_deduction_for_propositional_logic.9.tex
├── propositional_logic.1.tex
├── propositional_logic.10.tex
├── propositional_logic.11.tex
├── propositional_logic.12.tex
├── propositional_logic.13.tex
├── propositional_logic.14.tex
├── propositional_logic.2.tex
├── propositional_logic.3.tex
├── propositional_logic.4.tex
├── propositional_logic.5.tex
├── propositional_logic.6.tex
├── propositional_logic.7.tex
├── propositional_logic.8.tex
├── propositional_logic.8b.tex
├── propositional_logic.9.tex
├── propositional_logic_in_lean.1.tex
├── propositional_logic_in_lean.2.tex
├── propositional_logic_in_lean.2b.tex
├── propositional_logic_in_lean.3.tex
├── propositional_logic_in_lean.4.tex
├── propositional_logic_in_lean.5.tex
├── propositional_logic_in_lean.tex
├── semantics_of_propositional_logic.1.tex
├── semantics_of_propositional_logic.2.tex
├── semantics_of_propositional_logic.3.tex
├── semantics_of_propositional_logic.4.tex
├── semantics_of_propositional_logic.5.tex
├── sets.1.tex
├── template.tex
└── the_natural_numbers_and_induction.1.tex
├── lean_sphinx.py
├── leanpkg.toml
├── mylogic.sty
├── natural_deduction_for_first_order_logic.rst
├── natural_deduction_for_propositional_logic.rst
├── nd_quickref.rst
├── png_images
├── card_diagram_1.png
├── card_diagram_2.png
├── card_diagram_3.png
├── card_diagram_4.png
└── card_diagram_5.png
├── propositional_logic.rst
├── propositional_logic_in_lean.rst
├── relations.rst
├── relations_in_lean.rst
├── semantics_of_first_order_logic.rst
├── semantics_of_propositional_logic.rst
├── sets.rst
├── sets_in_lean.rst
├── the_infinite.rst
├── the_natural_numbers_and_induction.rst
├── the_natural_numbers_and_induction_in_lean.rst
├── the_real_numbers.rst
└── unixode.sty
/.gitignore:
--------------------------------------------------------------------------------
1 | *.olean
2 | .venv/
3 | .vscode/
4 | /__pycache__
5 | /_build
6 | /_static
7 | /_target
8 | /leanpkg.path
9 | /latex_images
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # Minimal makefile for Sphinx documentation
2 | #
3 |
4 | # You can set these variables from the command line.
5 | SPHINXOPTS =
6 | SPHINXBUILD = python -msphinx
7 | SPHINXPROJ = logic_and_proof
8 | SOURCEDIR = .
9 | BUILDDIR = _build
10 |
11 | # Put it first so that "make" without argument is like "make help".
12 | help:
13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14 |
15 | VENVDIR := "$HOME/.pyenv/versions/environment3.5.4"
16 | export PATH := $(VENVDIR)/bin:$(PATH)
17 |
18 | install-deps:
19 | # test -f $(VENVDIR)/bin/pip || python3 -m venv $(VENVDIR)
20 | # pip install https://bitbucket.org/gebner/pygments-main/get/default.tar.gz#egg=Pygments
21 | # pip install 'wheel>=0.29' # needed for old ubuntu versions, https://github.com/pallets/markupsafe/issues/59
22 | # pip install sphinx
23 | .PHONY: help Makefile
24 |
25 | images:
26 | cd latex_images && make copy_images
27 |
28 | # Catch-all target: route all unknown targets to Sphinx using the new
29 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
30 | %: Makefile
31 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
32 |
33 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Logic and Proof
2 |
3 | This is a textbook for learning logic and proofs,
4 | as well as interactive theorem proving with `lean4`,
5 | written by Jeremy Avigad, Joseph Hua, Robert Y. Lewis, and Floris van Doorn.
6 | The web version is [available here](https://leanprover.github.io/logic_and_proof).
7 | It is based on the older version
8 | [available here](https://github.com/leanprover/logic_and_proof_lean3/tree/master),
9 | which uses `lean3`.
10 |
11 | # Installation
12 |
13 | ## Overview
14 |
15 | We need
16 | - an old version of `python` e.g. 3.5.4
17 | - the virtual environment for this version of `python`
18 | - `convert` from [imagemagick](https://imagemagick.org/)
19 | - `xelatex` and `latexmk`
20 |
21 | ## `imagemagick`/`convert`
22 | - follow [instructions for installing `imagemagick`](https://imagemagick.org/script/download.php)
23 |
24 | ## `latex`
25 | - there are many ways of installing `xelatex` and `latexmk`,
26 | we won't describe them here
27 | - note that `latexmk` might come under some other package such as `texlive-binextra`
28 |
29 | ## `pyenv` and `virtualenv`
30 | - install [`pyenv`](https://github.com/pyenv/pyenv)
31 | - install suitable version of python e.g. `python3.5.4` using `pyenv` by doing
32 | ```
33 | pyenv install 3.5.4
34 | ```
35 | - change global python version to `3.5.4` by doing
36 | ```
37 | pyenv global 3.5.4
38 | ```
39 | - check versions by doing
40 | ```
41 | pyenv versions
42 | ```
43 | - install [`pyenv-virtualenv`](https://github.com/pyenv/pyenv-virtualenv)
44 | - add the following to `~/.bashrc` (or equivalent)
45 | ```
46 | export PYENV_ROOT="$HOME/.pyenv"
47 | command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
48 | eval "$(pyenv init -)"
49 | eval "$(pyenv virtualenv-init -)"
50 | ```
51 | - close and reopen terminal for changes to take effect
52 |
53 | ## Make the virtual environment
54 | - make a virtual environment. We called it environment3.5.4
55 | ```
56 | pyenv virtualenv 3.5.4 environment3.5.4
57 | ```
58 | - you can activate the virtual environment by doing
59 | ```
60 | pyenv activate environment3.5.4
61 | ```
62 | - then install `sphinx` using `pip` inside virtual environment
63 | ```
64 | pip install --trusted-host pypi.python.org sphinx
65 | ```
66 | - `source deactivate` will deactivate the virtual environment
67 |
68 | ## Clone the sphinx project repository
69 | - clone the project into project directory `/logic_and_proof/`,
70 | ```
71 | git clone https://github.com/leanprover-community/logic_and_proof.git
72 | cd logic_and_proof
73 | ```
74 |
75 | - go to `MAKE` and make sure
76 | ```
77 | VENVDIR := "$HOME/.pyenv/versions/environment3.5.4"
78 | ```
79 | so that `make` will use the virtual environment we made.
80 | If you chose a different name for the virtual environment, change this line accordingly.
81 | - now in project directory, with the virtual environment active, we can do
82 | ```
83 | make images
84 | make html
85 | make latexpdf
86 | ```
87 | - The call to `make images` is also only required the first time, or if you add new latex source to `latex_images` after that.
88 | - note that the original
89 | ```
90 | make install-deps
91 | ```
92 | seems to no longer work because the link https://bitbucket.org/gebner/pygments-main/get/default.tar.gz#egg=Pygments is dead.
93 | This would give a bundled version of Sphinx and Pygments with improved syntax highlighting for Lean.
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 | # How to contribute
109 |
110 | Pull requests with corrections are welcome.
111 | Please follow our [commit conventions](https://github.com/leanprover/lean4/blob/master/doc/dev/commit_convention.md).
112 | If you have questions about whether a change will be considered helpful,
113 | please contact Jeremy Avigad, ``avigad@cmu.edu``.
114 |
--------------------------------------------------------------------------------
/_static/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/logic_and_proof/cb1efe705c5d6f901cedfce5bb46f67f98188096/_static/favicon.ico
--------------------------------------------------------------------------------
/_templates/layout.html:
--------------------------------------------------------------------------------
1 | {% extends "!layout.html" %}
2 | {% block extrahead %}
3 |
4 |
5 |
6 | {% endblock %}
7 |
--------------------------------------------------------------------------------
/_templates/navigation_without_header.html:
--------------------------------------------------------------------------------
1 |
2 | {{ toctree(includehidden=theme_sidebar_includehidden, collapse=theme_sidebar_collapse) }}
3 | {% if theme_extra_nav_links %}
4 |
5 |
6 | {% for text, uri in theme_extra_nav_links.items() %}
7 | - {{ text }}
8 | {% endfor %}
9 |
10 | {% endif %}
11 |
--------------------------------------------------------------------------------
/classical_reasoning.rst:
--------------------------------------------------------------------------------
1 | .. _classical_reasoning:
2 |
3 | Classical Reasoning
4 | ===================
5 |
6 | If we take all the rules of propositional logic we have seen so far and exclude *reductio ad absurdum*, or proof by contradiction, we have what is known as *intuitionistic logic*. In intuitionistic logic, it is possible to view proofs in computational terms: a proof of :math:`A \wedge B` is a proof of :math:`A` paired with a proof of :math:`B`, a proof of :math:`A \to B` is a procedure which transforms evidence for :math:`A` into evidence for :math:`B`, and a proof of :math:`A \vee B` is a proof of one or the other, tagged so that we know which is the case. The *ex falso* rule makes sense only because we expect that there is no proof of falsity; it is like the empty data type.
7 |
8 | Proof by contradiction does not fit in well with this world view: from a proof of a contradiction from :math:`\neg A`, we are supposed to magically produce a proof of :math:`A`. We will see that with proof by contradiction, we can prove the following law, known as the *law of the excluded middle*: :math:`\forall A, A \vee \neg A`. From a computational perspective, this says that for every :math:`A` we can decide whether or not :math:`A` is true.
9 |
10 | Classical reasoning does introduce a number of principles into logic, however, that can be used to simplify reasoning. In this chapter, we will consider these principles, and see how they follow from the basic rules.
11 |
12 | Proof by Contradiction
13 | ----------------------
14 |
15 | Remember that in natural deduction, proof by contradiction is expressed by the following pattern:
16 |
17 | .. raw:: html
18 |
19 |
20 |
21 | .. raw:: latex
22 |
23 | \begin{prooftree}
24 | \AXM{}
25 | \RLM{1}
26 | \UIM{\neg A}
27 | \noLine
28 | \UIM{\vdots}
29 | \noLine
30 | \UIM{\bot}
31 | \RLM{1}
32 | \UIM{A}
33 | \end{prooftree}
34 |
35 | The assumption :math:`\neg A` is canceled at the final inference.
36 |
37 | In Lean, the inference is named ``byContradiction``,
38 | and since it is a classical rule,
39 | we have to use the command ``open Classical`` before it is available.
40 | Once we do so, the pattern of inference is expressed as follows:
41 |
42 | .. code-block:: lean
43 |
44 | section
45 | open Classical
46 | variable (A : Prop)
47 |
48 | example : A :=
49 | byContradiction
50 | (fun h : ¬ A ↦ show False from sorry)
51 |
52 | end
53 |
54 | One of the most important consequences of this rule is a classical principle
55 | that we mentioned above,
56 | namely, the *law of the excluded middle*,
57 | which asserts that the following holds for all
58 | :math:`A`: :math:`A \vee \neg A`.
59 | In Lean we denote this law by ``em``.
60 | In mathematical arguments, one often splits a proof into two cases,
61 | assuming first :math:`A` and then :math:`\neg A`.
62 | Using the elimination rule for disjunction,
63 | this is equivalent to using :math:`A \vee \neg A`,
64 | which is the excluded middle principle for this particular :math:`A`.
65 |
66 | Here is a proof of ``em``, in natural deduction, using proof by contradiction:
67 |
68 | .. raw:: html
69 |
70 |
71 |
72 | .. raw:: latex
73 |
74 | \begin{center}
75 | \AXM{}
76 | \RLM{2}
77 | \UIM{\neg (A \vee \neg A)}
78 | \AXM{}
79 | \RLM{2}
80 | \UIM{\neg (A \vee \neg A)}
81 | \AXM{}
82 | \RLM{1}
83 | \UIM{A}
84 | \UIM{A \vee \neg A}
85 | \BIM{\bot}
86 | \RLM{1}
87 | \UIM{\neg A}
88 | \UIM{A \vee \neg A}
89 | \BIM{\bot}
90 | \RLM{2}
91 | \UIM{A \vee \neg A}
92 | \DP
93 | \end{center}
94 |
95 | Here is the same proof rendered in Lean:
96 |
97 | .. code-block:: lean
98 |
99 | section
100 | open Classical
101 |
102 | example : A ∨ ¬ A := by
103 | apply byContradiction
104 | intro (h1 : ¬ (A ∨ ¬ A))
105 | have h2 : ¬ A := by
106 | intro (h3 : A)
107 | have h4 : A ∨ ¬ A := Or.inl h3
108 | show False
109 | exact h1 h4
110 | have h5 : A ∨ ¬ A := Or.inr h2
111 | show False
112 | exact h1 h5
113 |
114 | end
115 |
116 | The principle is known as the law of the excluded middle because it says that a proposition ``A`` is either true or false;
117 | there is no middle ground. As a result,
118 | the theorem is named ``em`` in the Lean library.
119 | For any proposition ``A``, ``em A`` denotes a proof of ``A ∨ ¬ A``,
120 | and you are free to use it any time ``Classical`` is open:
121 |
122 | .. code-block:: lean
123 |
124 | section
125 | open Classical
126 |
127 | example (A : Prop) : A ∨ ¬ A :=
128 | Or.elim (em A)
129 | (fun _ : A ↦ Or.inl ‹A›)
130 | (fun _ : ¬ A ↦ Or.inr ‹¬A›)
131 | end
132 |
133 | Or even more simply:
134 |
135 | .. code-block:: lean
136 |
137 | section
138 | open Classical
139 |
140 | example (A : Prop) : A ∨ ¬ A :=
141 | em A
142 |
143 | end
144 |
145 | In fact, we can go in the other direction,
146 | and use the law of the excluded middle to justify proof by contradiction.
147 | You are asked to do this in the exercises.
148 |
149 | Proof by contradiction is also equivalent to the principle
150 | :math:`\neg \neg A \leftrightarrow A`.
151 | The implication from right to left holds intuitionistically;
152 | the other implication is classical,
153 | and is known as *double-negation elimination*.
154 | Here is a proof in natural deduction:
155 |
156 | .. raw:: html
157 |
158 |
159 |
160 | .. raw:: latex
161 |
162 | \begin{center}
163 | \AXM{}
164 | \RLM{2}
165 | \UIM{\neg \neg A}
166 | \AXM{}
167 | \RLM{1}
168 | \UIM{\neg A}
169 | \BIM{\bot}
170 | \RLM{1}
171 | \UIM{A}
172 | \AXM{}
173 | \RLM{1}
174 | \UIM{\neg A}
175 | \AXM{}
176 | \RLM{2}
177 | \UIM{A}
178 | \BIM{\bot}
179 | \RLM{1}
180 | \UIM{\neg \neg A}
181 | \RLM{2}
182 | \BIM{\neg \neg A \leftrightarrow A}
183 | \DP
184 | \end{center}
185 |
186 | And here is the corresponding proof in Lean:
187 |
188 | .. code-block:: lean
189 |
190 | section
191 | open Classical
192 |
193 | example (A : Prop) : ¬ ¬ A ↔ A :=
194 | Iff.intro
195 | (fun h1 : ¬ ¬ A ↦
196 | show A from byContradiction
197 | (fun h2 : ¬ A ↦
198 | show False from h1 h2))
199 | (fun h1 : A ↦
200 | show ¬ ¬ A from fun h2 : ¬ A ↦ h2 h1)
201 |
202 | end
203 |
204 | In the next section, we will derive a number of classical rules and equivalences. These are tricky to prove. In general, to use classical reasoning in natural deduction, we need to extend the general heuristic presented in :numref:`forward_and_backward_reasoning` as follows:
205 |
206 | #. First, work backward from the conclusion, using the introduction rules.
207 | #. When you have run out things to do in the first step, use elimination rules to work forward.
208 | #. If all else fails, use a proof by contradiction.
209 |
210 | Sometimes a proof by contradiction is necessary, but when it isn't, it can be less informative than a direct proof. Suppose, for example, we want to prove :math:`A \wedge B \wedge C \to D`. In a direct proof, we assume :math:`A`, :math:`B`, and :math:`C`, and work towards :math:`D`. Along the way, we will derive other consequences of :math:`A`, :math:`B`, and :math:`C`, and these may be useful in other contexts. If we use proof by contradiction, on the other hand, we assume :math:`A`, :math:`B`, :math:`C`, and :math:`\neg D`, and try to prove :math:`\bot`. In that case, we are working in an inconsistent context; any auxiliary results we may obtain that way are subsumed by the fact that ultimately :math:`\bot` is a consequence of the hypotheses.
211 |
212 | Some Classical Principles
213 | -------------------------
214 |
215 | We have already seen that :math:`A \vee \neg A` and :math:`\neg \neg A \leftrightarrow A` are two important theorems of classical propositional logic. In this section we will provide some more theorems, rules, and equivalences. Some will be proved here, but most will be left to you in the exercises. In ordinary mathematics, these are generally used without comment. It is nice to know, however, that they can all be justified using the basic rules of classical natural deduction.
216 |
217 | If :math:`A \to B` is any implication, the assertion :math:`\neg B \to \neg A` is known as the *contrapositive*. Every implication implies its contrapositive, and the other direction is true classically:
218 |
219 | .. raw:: html
220 |
221 |
222 |
223 | .. raw:: latex
224 |
225 | \begin{center}
226 | \AXM{\neg B \to \neg A}
227 | \AXM{}
228 | \RLM{1}
229 | \UIM{\neg B}
230 | \BIM{\neg A}
231 | \AXM{}
232 | \RLM{2}
233 | \UIM{A}
234 | \BIM{\bot}
235 | \RLM{1}
236 | \UIM{B}
237 | \RLM{2}
238 | \UIM{A \to B}
239 | \DP
240 | \end{center}
241 |
242 | Here is another example. Intuitively, asserting "if A then B" is equivalent to saying that it cannot be the case that A is true and B is false. Classical reasoning is needed to get us from the second statement to the first.
243 |
244 | .. raw:: html
245 |
246 |
247 |
248 | .. raw:: latex
249 |
250 | \begin{center}
251 | \AXM{}
252 | \RLM{3}
253 | \UIM{\neg (A \wedge \neg B)}
254 | \AXM{}
255 | \RLM{2}
256 | \UIM{A}
257 | \AXM{}
258 | \RLM{1}
259 | \UIM{\neg B}
260 | \BIM{A \wedge \neg B}
261 | \BIM{\bot}
262 | \RLM{1}
263 | \UIM{B}
264 | \RLM{2}
265 | \UIM{A \to B}
266 | \RLM{3}
267 | \UIM{\neg (A \wedge \neg B) \to (A \to B)}
268 | \DP
269 | \end{center}
270 |
271 | Here are the same proofs, rendered in Lean:
272 |
273 | .. code-block:: lean
274 |
275 | section
276 | open Classical
277 | variable (A B : Prop)
278 |
279 | example (h : ¬ B → ¬ A) : A → B := by
280 | intro (h1 : A)
281 | show B
282 | apply byContradiction
283 | intro (h2 : ¬ B)
284 | have h3 : ¬ A := h h2
285 | show False
286 | exact h3 h1
287 |
288 | example (h : ¬ (A ∧ ¬ B)) : A → B := by
289 | intro (h1 : A)
290 | show B
291 | apply byContradiction
292 | intro
293 | have : A ∧ ¬ B := And.intro ‹A› ‹¬ B›
294 | show False
295 | exact h this
296 |
297 | end
298 |
299 | Notice that in the second example, we used an anonymous ``intro``
300 | and an anonymous ``have``.
301 | We used the brackets ``\f<`` and ``\f>`` to write ``‹A›`` and ``‹¬ B›``,
302 | referring back to the first assumption.
303 | The use of the word ``this`` refers back to the ``have``.
304 |
305 | Knowing that we can prove the law of the excluded middle,
306 | it is convenient to use it in classical proofs.
307 | Here is an example,
308 | with a proof of :math:`(A \to B) \vee (B \to A)`:
309 |
310 | .. raw:: html
311 |
312 |
313 |
314 | .. raw:: latex
315 |
316 | \begin{center}
317 | \AXM{}
318 | \UIM{B \vee \neg B}
319 | \AXM{}
320 | \RLM{1}
321 | \UIM{B}
322 | \UIM{A \to B}
323 | \UIM{(A \to B) \vee (B \to A)}
324 | \AXM{}
325 | \RLM{1}
326 | \UIM{\neg B}
327 | \AXM{}
328 | \RLM{2}
329 | \UIM{B}
330 | \BIM{\bot}
331 | \UIM{A}
332 | \RLM{2}
333 | \UIM{B \to A}
334 | \UIM{(A \to B) \vee (B \to A)}
335 | \RLM{1}
336 | \TIM{(A \to B) \vee (B \to A)}
337 | \DP
338 | \end{center}
339 |
340 | Here is the corresponding proof in Lean:
341 |
342 | .. code-block:: lean
343 |
344 | section
345 | open Classical
346 |
347 | variable (A B : Prop)
348 |
349 | example : (A → B) ∨ (B → A) :=
350 | Or.elim (em B)
351 | (fun h : B ↦
352 | have : A → B :=
353 | fun _ : A ↦ show B from h
354 | show (A → B) ∨ (B → A) from Or.inl this)
355 | (fun h : ¬ B ↦
356 | have : B → A :=
357 | fun _ : B ↦ have : False := h ‹B›
358 | show A from False.elim this
359 | show (A → B) ∨ (B → A) from Or.inr this)
360 |
361 | end
362 |
363 | Using classical reasoning, implication can be rewritten in terms of disjunction and negation:
364 |
365 | .. math::
366 |
367 | (A \to B) \leftrightarrow \neg A \vee B.
368 |
369 | The forward direction requires classical reasoning.
370 |
371 | The following equivalences are known as De Morgan's laws:
372 |
373 | - :math:`\neg (A \vee B) \leftrightarrow \neg A \wedge \neg B`
374 | - :math:`\neg (A \wedge B) \leftrightarrow \neg A \vee \neg B`
375 |
376 | The forward direction of the second of these requires classical reasoning.
377 |
378 | Using these identities, we can always push negations down to propositional variables. For example, we have
379 |
380 | .. raw:: html
381 |
382 |
383 |
384 | .. raw:: latex
385 |
386 | \begin{align*}
387 | \neg (\neg A \wedge B \to C)
388 | & \leftrightarrow \neg (\neg (\neg A \wedge B) \vee C) \\
389 | & \leftrightarrow \neg \neg (\neg A \wedge B) \wedge \neg C \\
390 | & \leftrightarrow \neg A \wedge B \wedge \neg C.
391 | \end{align*}
392 |
393 | A formula built up from :math:`\wedge`, :math:`\vee`, and :math:`\neg` in which negations only occur at variables is said to be in *negation normal form*.
394 |
395 | In fact, using distributivity laws, one can go on to ensure that all the disjunctions are on the outside, so that the formulas is a big or of and's of propositional variables and negated propositional variables. Such a formula is said to be in *disjunctive normal form*. Alternatively, all the and's can be brought to the outside. Such a formula is said to be in *conjunctive normal form*. An exercise below, however, shows that putting formulas in disjunctive or conjunctive normal form can make them much longer.
396 |
397 |
398 | The ``contradiction`` Tactic
399 | ----------------------------
400 |
401 | Once we reach a contradiction in our proof,
402 | i.e. by having ``h1 : A`` and ``h2 : ¬A``,
403 | we can apply the tactic ``contradiction``.
404 | This will search for a contradiction among the hypotheses,
405 | and complete the proof if it succeeds in finding one.
406 | Revisiting our previous example:
407 |
408 | .. code-block:: lean
409 |
410 | section
411 | open Classical
412 |
413 | example : A ∨ ¬ A := by
414 | apply byContradiction
415 | intro (h1 : ¬ (A ∨ ¬ A))
416 | have h2 : ¬ A := by
417 | intro (h3 : A)
418 | have h4 : A ∨ ¬ A := Or.inl h3
419 | show False
420 | exact h1 h4
421 | have h5 : A ∨ ¬ A := Or.inr h2
422 | show False
423 | exact h1 h5
424 |
425 | example : A ∨ ¬ A := by
426 | apply byContradiction
427 | intro (h1 : ¬ (A ∨ ¬ A))
428 | have h2 : ¬ A := by
429 | intro (h3 : A)
430 | have h4 : A ∨ ¬ A := Or.inl h3
431 | contradiction
432 | have h5 : A ∨ ¬ A := Or.inr h2
433 | contradiction
434 |
435 | end
436 |
437 | Since ``contradiction`` does not require the names of
438 | variables that form a contradiction
439 | we can even remove all of the names.
440 |
441 | .. code-block:: lean
442 |
443 | section
444 | open Classical
445 |
446 | example : A ∨ ¬ A := by
447 | apply byContradiction
448 | intro
449 | have : ¬ A := by
450 | intro
451 | have : A ∨ ¬ A := Or.inl ‹A›
452 | contradiction
453 | have : A ∨ ¬ A := Or.inr this
454 | contradiction
455 |
456 | end
457 |
458 |
459 | Exercises
460 | ---------
461 |
462 | #. Show how to derive the proof-by-contradiction rule from the law of the excluded middle, using the other rules of natural deduction. In other words, assume you have a proof of :math:`\bot` from :math:`\neg A`. Using :math:`A \vee \neg A` as a hypothesis, but *without* using the rule RAA, show how you can go on to derive :math:`A`.
463 |
464 | #. Give a natural deduction proof of :math:`\neg (A \wedge B)` from :math:`\neg A \vee \neg B`. (You do not need to use proof by contradiction.)
465 |
466 | #. Construct a natural deduction proof of :math:`\neg A \vee \neg B` from :math:`\neg (A \wedge B)`. You can do it as follows:
467 |
468 | #. First, prove :math:`\neg B`, and hence :math:`\neg A \vee \neg B`, from :math:`\neg (A \wedge B)` and :math:`A`.
469 |
470 | #. Use this to construct a proof of :math:`\neg A`, and hence :math:`\neg A \vee \neg B`, from :math:`\neg (A \wedge B)` and :math:`\neg (\neg A \vee \neg B)`.
471 |
472 | #. Use this to construct a proof of a contradiction from :math:`\neg (A \wedge B)` and :math:`\neg (\neg A \vee \neg B)`.
473 |
474 | #. Using proof by contradiction, this gives you a proof of :math:`\neg A \vee \neg B` from :math:`\neg (A \wedge B)`.
475 |
476 | #. Give a natural deduction proof of :math:`P` from :math:`\neg P \to (Q \vee R)`, :math:`\neg Q`, and :math:`\neg R`.
477 |
478 | #. Give a natural deduction proof of :math:`\neg A \vee B` from :math:`A \to B`. You may use the law of the excluded middle.
479 |
480 | #. Give a natural deduction proof of :math:`A \to ((A \wedge B) \vee (A \wedge \neg B))`. You may use the law of the excluded middle.
481 |
482 | #. Put :math:`(A \vee B) \wedge (C \vee D) \wedge (E \vee F)` in disjunctive normal form, that is, write it as a big "or" of multiple "and" expressions.
483 |
484 | #. Prove ``¬ (A ∧ B) → ¬ A ∨ ¬ B`` by replacing the sorry's below by proofs.
485 |
486 | .. code-block:: lean
487 |
488 | import Mathlib.Tactic
489 |
490 | section
491 |
492 | open Classical
493 | variable {A B C : Prop}
494 |
495 | -- Prove ¬ (A ∧ B) → ¬ A ∨ ¬ B by replacing the sorry's below
496 | -- by proofs.
497 |
498 | lemma step1 (h₁ : ¬ (A ∧ B)) (h₂ : A) : ¬ A ∨ ¬ B :=
499 | have : ¬ B := sorry
500 | show ¬ A ∨ ¬ B from Or.inr this
501 |
502 | lemma step2 (h₁ : ¬ (A ∧ B)) (h₂ : ¬ (¬ A ∨ ¬ B)) : False :=
503 | have : ¬ A :=
504 | fun _ : A ↦
505 | have : ¬ A ∨ ¬ B := step1 h₁ ‹A›
506 | show False from h₂ this
507 | show False from sorry
508 |
509 | theorem step3 (h : ¬ (A ∧ B)) : ¬ A ∨ ¬ B :=
510 | byContradiction
511 | (fun h' : ¬ (¬ A ∨ ¬ B) ↦
512 | show False from step2 h h')
513 |
514 | end
515 |
516 | #. Complete these proofs in tactic mode
517 |
518 | .. code-block:: lean
519 |
520 | section
521 | open Classical
522 | variable {A B C : Prop}
523 |
524 | example (h : ¬ B → ¬ A) : A → B := by
525 | sorry
526 |
527 | example (h : A → B) : ¬ A ∨ B := by
528 | sorry
529 |
530 | end
531 |
--------------------------------------------------------------------------------
/conf.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | # -*- coding: utf-8 -*-
3 | #
4 | # Logic and Proof documentation build configuration file, created by
5 | # sphinx-quickstart on Tue Aug 8 19:01:05 2017.
6 | #
7 | # This file is execfile()d with the current directory set to its
8 | # containing dir.
9 | #
10 | # Note that not all possible configuration values are present in this
11 | # autogenerated file.
12 | #
13 | # All configuration values have a default; values that are commented out
14 | # serve to show the default.
15 |
16 | # If extensions (or modules to document with autodoc) are in another directory,
17 | # add these directories to sys.path here. If the directory is relative to the
18 | # documentation root, use os.path.abspath to make it absolute, like shown here.
19 | #
20 | import os
21 | import sys
22 | sys.path.insert(0, os.path.abspath('.'))
23 |
24 | # -- General configuration ------------------------------------------------
25 |
26 | # If your documentation needs a minimal Sphinx version, state it here.
27 | #
28 | # needs_sphinx = '1.0'
29 |
30 | # Add any Sphinx extension module names here, as strings. They can be
31 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
32 | # ones.
33 | extensions = ['sphinx.ext.mathjax', 'sphinx.ext.githubpages', 'lean_sphinx']
34 |
35 | # Add any paths that contain templates here, relative to this directory.
36 | templates_path = ['_templates']
37 |
38 | # The suffix(es) of source filenames.
39 | # You can specify multiple suffix as a list of string:
40 | #
41 | # source_suffix = ['.rst', '.md']
42 | source_suffix = '.rst'
43 |
44 | # The master toctree document.
45 | master_doc = 'index'
46 |
47 | # General information about the project.
48 | project = u'Logic and Proof'
49 | copyright = u'2017, Jeremy Avigad, Joseph Hua, Robert Y. Lewis, and Floris van Doorn'
50 | author = u'Jeremy Avigad, Joseph Hua, Robert Y. Lewis, and Floris van Doorn'
51 |
52 | # The version info for the project you're documenting, acts as replacement for
53 | # |version| and |release|, also used in various other places throughout the
54 | # built documents.
55 | #
56 | # The short X.Y version.
57 | version = u'3.18.4'
58 | # The full version, including alpha/beta/rc tags.
59 | release = u'3.18.4'
60 |
61 | # The language for content autogenerated by Sphinx. Refer to documentation
62 | # for a list of supported languages.
63 | #
64 | # This is also used if you do content translation via gettext catalogs.
65 | # Usually you set "language" from the command line for these cases.
66 | language = None
67 |
68 | # List of patterns, relative to source directory, that match files and
69 | # directories to ignore when looking for source files.
70 | # This patterns also effect to html_static_path and html_extra_path
71 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.venv', 'exclude']
72 |
73 | # The name of the Pygments (syntax highlighting) style to use.
74 | pygments_style = 'sphinx'
75 |
76 | # If true, `todo` and `todoList` produce output, else they produce nothing.
77 | todo_include_todos = False
78 |
79 | source_parsers = {
80 | }
81 |
82 | # use numbering for section references with :numref:, e.g. 'Section 3.2'.
83 | numfig = True
84 |
85 |
86 | # -- Options for HTML output ----------------------------------------------
87 |
88 | # The theme to use for HTML and HTML Help pages. See the documentation for
89 | # a list of builtin themes.
90 | #
91 | html_theme = 'alabaster'
92 |
93 | # Theme options are theme-specific and customize the look and feel of a theme
94 | # further. For a list of options available for each theme, see the
95 | # documentation.
96 | #
97 | html_theme_options = {
98 | 'logo_name': True,
99 | 'font_family': 'Times New Roman, Times, serif',
100 | 'head_font_family': 'Times New Roman, Times, serif',
101 | 'code_bg': 'white',
102 | 'extra_nav_links': {'PDF version':'logic_and_proof.pdf',
103 | 'Lean Home':'https://leanprover.github.io/'},
104 | # 'sidebar_width' : '200px',
105 | # 'page_width' : '960px',
106 | # 'fixed_sidebar' : True
107 | }
108 |
109 | # Add any paths that contain custom static files (such as style sheets) here,
110 | # relative to this directory. They are copied after the builtin static files,
111 | # so a file named "default.css" will overwrite the builtin "default.css".
112 | html_static_path = ['_static']
113 |
114 | html_favicon = '_static/favicon.ico'
115 |
116 | html_output_encoding = 'ascii'
117 |
118 | # Custom sidebar templates, must be a dictionary that maps document names
119 | # to template names.
120 | #
121 | # This is required for the alabaster theme
122 | # refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
123 | html_sidebars = {
124 | '**': [
125 | 'about.html',
126 | 'navigation_without_header.html',
127 | #'relations.html', # needs 'show_related': True theme option to display
128 | 'searchbox.html',
129 | #'donate.html',
130 | ]
131 | }
132 |
133 |
134 | # -- Options for HTMLHelp output ------------------------------------------
135 |
136 | # Output file base name for HTML help builder.
137 | htmlhelp_basename = 'logic_and_proof'
138 |
139 |
140 | # -- Options for LaTeX output ---------------------------------------------
141 |
142 | latex_engine = 'xelatex'
143 |
144 | latex_additional_files = ['unixode.sty', 'bussproofs.sty', 'mylogic.sty']
145 |
146 | latex_elements = {
147 | # The paper size ('letterpaper' or 'a4paper').
148 | #
149 | # 'papersize': 'letterpaper',
150 |
151 | # The font size ('10pt', '11pt' or '12pt').
152 | #
153 | # 'pointsize': '10pt',
154 |
155 | # Additional stuff for the LaTeX preamble.
156 | # load packages and make box around code lighter
157 | 'preamble': r'''
158 | \usepackage{unixode}
159 | \usepackage{bussproofs}
160 | \usepackage{mylogic}
161 | \usepackage{amsmath}
162 | \definecolor{VerbatimBorderColor}{rgb}{0.7,0.7,0.7}
163 | ''',
164 |
165 | # Latex figure (float) alignment
166 | #
167 | # 'figure_align': 'htbp',
168 | }
169 |
170 | # Grouping the document tree into LaTeX files. List of tuples
171 | # (source start file, target name, title,
172 | # author, documentclass [howto, manual, or own class]).
173 | latex_documents = [
174 | (master_doc, 'logic_and_proof.tex', u'Logic and Proof',
175 | u'Jeremy Avigad, Joseph Hua, Robert Y. Lewis, and Floris van Doorn', 'manual'),
176 | ]
177 |
178 |
179 | # -- Options for manual page output ---------------------------------------
180 |
181 | # One entry per manual page. List of tuples
182 | # (source start file, name, description, authors, manual section).
183 | man_pages = [
184 | (master_doc, 'logicandproof', u'Logic and Proof',
185 | [author], 1)
186 | ]
187 |
188 |
189 | # -- Options for Texinfo output -------------------------------------------
190 |
191 | # Grouping the document tree into Texinfo files. List of tuples
192 | # (source start file, target name, title, author,
193 | # dir menu entry, description, category)
194 | texinfo_documents = [
195 | (master_doc, 'logic_and_proof', u'Logic and Proof',
196 | author, 'logic_and_proof', 'One line description of project.',
197 | 'Miscellaneous'),
198 | ]
199 |
--------------------------------------------------------------------------------
/deploy.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 | if [ "$#" -ne 2 ]; then
4 | echo "Usage example: $0 leanprover logic_and_proof"
5 | exit 1
6 | fi
7 |
8 | # Build
9 | make clean images html latexpdf
10 |
11 | # 3. Deploy
12 | rm -rf deploy
13 | mkdir deploy
14 | cd deploy
15 | git init
16 | cp -r ../_build/html/./ .
17 | cp ../_build/latex/logic_and_proof.pdf .
18 | git add .
19 | git commit -m "Update `date`"
20 | git push git@github.com:$1/$2 +HEAD:gh-pages
21 | cd ../
22 | rm -rf deploy
23 |
--------------------------------------------------------------------------------
/exclude/algbraic_structures_in_lean.rst:
--------------------------------------------------------------------------------
1 | Title: Logic and Proof
2 |
3 | Algebraic Structures in Lean
4 | ============================
5 |
6 | [Under construction.]
7 |
--------------------------------------------------------------------------------
/exclude/algebraic_structures.rst:
--------------------------------------------------------------------------------
1 | Title: Logic and Proof
2 |
3 | Algebraic Structures
4 | ====================
5 |
6 | [Under construction.]
7 |
--------------------------------------------------------------------------------
/exclude/combinatorics_in_lean.rst:
--------------------------------------------------------------------------------
1 | Title: Logic and Proof
2 |
3 | Combinatorics in Lean
4 | =====================
5 |
6 | [Under construction.]
7 |
--------------------------------------------------------------------------------
/exclude/elementary_number_theory_in_lean.rst:
--------------------------------------------------------------------------------
1 | Elementary Number Theory in Lean
2 | ================================
3 |
4 | [Under construction.]
5 |
--------------------------------------------------------------------------------
/exclude/probability.rst:
--------------------------------------------------------------------------------
1 | Probability
2 | ===========
3 |
4 | [Under construction.]
5 |
--------------------------------------------------------------------------------
/exclude/probability_in_lean.rst:
--------------------------------------------------------------------------------
1 | Title: Logic and Proof
2 |
3 | Probability in Lean
4 | ===================
5 |
6 | [Under construction.]
7 |
--------------------------------------------------------------------------------
/exclude/real_numbers_and_analysis_in_lean.rst:
--------------------------------------------------------------------------------
1 | The Real Numbers in Lean
2 | ========================
3 |
4 | [Under construction.]
5 |
--------------------------------------------------------------------------------
/exclude/the_infinite_in_lean.rst:
--------------------------------------------------------------------------------
1 | The Infinite in Lean
2 | ====================
3 |
--------------------------------------------------------------------------------
/index.rst:
--------------------------------------------------------------------------------
1 | Logic and Proof
2 | ===============
3 |
4 | .. toctree::
5 | :numbered:
6 | :maxdepth: 2
7 |
8 | introduction
9 | propositional_logic
10 | natural_deduction_for_propositional_logic
11 | propositional_logic_in_lean
12 | classical_reasoning
13 | semantics_of_propositional_logic
14 | first_order_logic
15 | natural_deduction_for_first_order_logic
16 | first_order_logic_in_lean
17 | semantics_of_first_order_logic
18 | sets
19 | sets_in_lean
20 | relations
21 | relations_in_lean
22 | functions
23 | functions_in_lean
24 | the_natural_numbers_and_induction
25 | the_natural_numbers_and_induction_in_lean
26 | elementary_number_theory
27 | combinatorics
28 | the_real_numbers
29 | the_infinite
30 | axiomatic_foundations
31 | nd_quickref
32 | .. elementary_number_theory_in_lean
33 | combinatorics_in_lean
34 | probability
35 | probability_in_lean
36 | algebraic_structures
37 | algebraic_structures_in_lean
38 | real_numbers_and_analysis_in_lean
39 | the_infinite_in_lean
40 |
41 | .. Indices and tables
42 | ==================
43 | * :ref:`genindex`
44 | * :ref:`modindex`
45 | * :ref:`search`
46 |
--------------------------------------------------------------------------------
/inference_rules_for_first_order_logic.rst:
--------------------------------------------------------------------------------
1 |
2 | *The universal quantifier:*
3 |
4 | .. raw:: html
5 |
6 |
7 |
8 | .. raw:: latex
9 |
10 | \begin{quote}
11 | \AXM{A(x)}
12 | \RLM{\mathord{\forall}\mathrm{I}}
13 | \UIM{\fa y A(y)}
14 | \DP
15 | \quad\quad
16 | \AXM{\fa x A(x)}
17 | \RLM{\mathord{\forall}\mathrm{E}}
18 | \UIM{A(t)}
19 | \DP
20 | \end{quote}
21 |
22 | In the introduction rule, :math:`x` should not be free in any uncanceled hypothesis. In the elimination rule, :math:`t` can be any term that does not clash with any of the bound variables in :math:`A`.
23 |
24 | *The existential quantifier:*
25 |
26 | .. raw:: html
27 |
28 |
29 |
30 | .. raw:: latex
31 |
32 | \begin{quote}
33 | \AXM{A(t)}
34 | \RLM{\mathord{\exists}\mathrm{I}}
35 | \UIM{\exists x A(x)}
36 | \DP
37 | \quad\quad
38 | \AXM{\exists x A(x)}
39 | \AXM{}
40 | \RLM{1}
41 | \UIM{A(y)}
42 | \noLine
43 | \UIM{\vdots}
44 | \noLine
45 | \UIM{B}
46 | \RLM{1 \;\; \mathord{\exists}\mathrm{E}}
47 | \BIM{B}
48 | \DP
49 | \end{quote}
50 |
51 | In the introduction rule, :math:`t` can be any term that does not clash with any of the bound variables in :math:`A`. In the elimination rule, :math:`y` should not be free in :math:`B` or any uncanceled hypothesis.
52 |
53 | *Equality:*
54 |
55 | .. raw:: html
56 |
57 |
58 |
59 | .. raw:: latex
60 |
61 | \begin{center}
62 | \AXM{}
63 | \RLM{\mathrm{refl}}
64 | \UIM{t = t}
65 | \DP
66 | \quad
67 | \AXM{s = t}
68 | \RLM{\mathrm{symm}}
69 | \UIM{t = s}
70 | \DP
71 | \quad
72 | \AXM{r = s}
73 | \AXM{s = t}
74 | \RLM{\mathrm{trans}}
75 | \BIM{r = t}
76 | \DP
77 | \\
78 | \ \\
79 | \AXM{s = t}
80 | \RLM{\mathrm{subst}}
81 | \UIM{r(s) = r(t)}
82 | \DP
83 | \quad
84 | \AXM{s = t}
85 | \RLM{\mathrm{subst}}
86 | \AXM{P(s)}
87 | \BIM{P(t)}
88 | \DP
89 | \end{center}
90 |
91 | Strictly speaking, only :math:`\mathrm{refl}` and the second substitution rule are necessary. The others can be derived from them.
92 |
--------------------------------------------------------------------------------
/inference_rules_for_propositional_logic.rst:
--------------------------------------------------------------------------------
1 |
2 | *Implication:*
3 |
4 | .. raw:: html
5 |
6 |
7 |
8 | .. raw:: latex
9 |
10 | \begin{quote}
11 | \AXM{}
12 | \RLM{1}
13 | \UIM{A}
14 | \noLine
15 | \UIM{\vdots}
16 | \noLine
17 | \UIM{B}
18 | \RLM{1 \;\; \mathord{\to}\mathrm{I}}
19 | \UIM{A \to B}
20 | \DP
21 | \quad\quad
22 | \AXM{A \to B}
23 | \AXM{A}
24 | \RLM{\mathord{\to}\mathrm{E}}
25 | \BIM{B}
26 | \DP
27 | \end{quote}
28 |
29 | *Conjunction:*
30 |
31 | .. raw:: html
32 |
33 |
34 |
35 | .. raw:: latex
36 |
37 | \begin{quote}
38 | \AXM{A}
39 | \AXM{B}
40 | \RLM{\mathord{\wedge}\mathrm{I}}
41 | \BIM{A \wedge B}
42 | \DP
43 | \quad\quad
44 | \AXM{A \wedge B}
45 | \RLM{\mathord{\wedge}\mathrm{E_l}}
46 | \UIM{A}
47 | \DP
48 | \quad\quad
49 | \AXM{A \wedge B}
50 | \RLM{\mathord{\wedge}\mathrm{E_r}}
51 | \UIM{B}
52 | \DP
53 | \end{quote}
54 |
55 | *Negation:*
56 |
57 | .. raw:: html
58 |
59 |
60 |
61 | .. raw:: latex
62 |
63 | \begin{quote}
64 | \AXM{}
65 | \RLM{1}
66 | \UIM{A}
67 | \noLine
68 | \UIM{\vdots}
69 | \noLine
70 | \UIM{\bot}
71 | \RLM{1 \;\; \neg \mathrm{I}}
72 | \UIM{\neg A}
73 | \DP
74 | \quad\quad
75 | \AXM{\neg A}
76 | \AXM{A}
77 | \RLM{\neg \mathrm{E}}
78 | \BIM{\bot}
79 | \DP
80 | \end{quote}
81 |
82 | *Disjunction:*
83 |
84 | .. raw:: html
85 |
86 |
87 |
88 | .. raw:: latex
89 |
90 | \begin{quote}
91 | \AXM{A}
92 | \RLM{\mathord{\vee}\mathrm{I_l}}
93 | \UIM{A \vee B}
94 | \DP
95 | \quad\quad
96 | \AXM{B}
97 | \RLM{\mathord{\vee}\mathrm{I_r}}
98 | \UIM{A \vee B}
99 | \DP
100 | \quad\quad
101 | \AXM{A \vee B}
102 | \AXM{}
103 | \RLM{1}
104 | \UIM{A}
105 | \noLine
106 | \UIM{\vdots}
107 | \noLine
108 | \UIM{C}
109 | \AXM{}
110 | \RLM{1}
111 | \UIM{B}
112 | \noLine
113 | \UIM{\vdots}
114 | \noLine
115 | \UIM{C}
116 | \RLM{1 \;\; \mathord{\vee}\mathrm{E}}
117 | \TIM{C}
118 | \DP
119 | \end{quote}
120 |
121 | *Truth and falsity:*
122 |
123 | .. raw:: html
124 |
125 |
126 |
127 | .. raw:: latex
128 |
129 | \begin{quote}
130 | \AXM{\bot}
131 | \RLM{\bot \mathrm{E}}
132 | \UIM{A}
133 | \DP
134 | \quad\quad
135 | \AXM{}
136 | \RLM{\top \mathrm{I}}
137 | \UIM{\top}
138 | \DP
139 | \end{quote}
140 |
141 | *Bi-implication:*
142 |
143 | .. raw:: html
144 |
145 |
146 |
147 | .. raw:: latex
148 |
149 | \begin{quote}
150 | \AXM{}
151 | \RLM{1}
152 | \UIM{A}
153 | \noLine
154 | \UIM{\vdots}
155 | \noLine
156 | \UIM{B}
157 | \AXM{}
158 | \RLM{1}
159 | \UIM{B}
160 | \noLine
161 | \UIM{\vdots}
162 | \noLine
163 | \UIM{A}
164 | \RLM{1 \;\; \mathord{\leftrightarrow}\mathrm{I}}
165 | \BIM{A \leftrightarrow B}
166 | \DP
167 | \AXM{A \leftrightarrow B}
168 | \AXM{A}
169 | \RLM{\mathord{\leftrightarrow}\mathrm{E}_l}
170 | \BIM{B}
171 | \DP
172 | \quad\quad
173 | \AXM{A \leftrightarrow B}
174 | \AXM{B}
175 | \RLM{\mathord{\leftrightarrow}\mathrm{E}_r}
176 | \BIM{A}
177 | \DP
178 | \end{quote}
179 |
180 | *Reductio ad absurdum (proof by contradiction):*
181 |
182 | .. raw:: html
183 |
184 |
185 |
186 | .. raw:: latex
187 |
188 | \begin{quote}
189 | \AXM{}
190 | \RLM{1}
191 | \UIM{\neg A}
192 | \noLine
193 | \UIM{\vdots}
194 | \noLine
195 | \UIM{\bot}
196 | \RLM{1 \;\; \mathrm{RAA}}
197 | \UIM{A}
198 | \DP
199 | \end{quote}
200 |
--------------------------------------------------------------------------------
/introduction.rst:
--------------------------------------------------------------------------------
1 | .. _introduction:
2 |
3 | Introduction
4 | ============
5 |
6 | Mathematical Proof
7 | ------------------
8 |
9 | Although there is written evidence of mathematical activity in Egypt as early as 3000 BC, many scholars locate the birth of mathematics proper in ancient Greece around the sixth century BC, when deductive proof was first introduced. Aristotle credited Thales of Miletus with recognizing the importance of not just what we know but how we know it, and finding grounds for knowledge in the deductive method. Around 300 BC, Euclid codified a deductive approach to geometry in his treatise, the *Elements*. Through the centuries, Euclid's axiomatic style was held as a paradigm of rigorous argumentation, not just in mathematics, but in philosophy and the sciences as well.
10 |
11 | Here is an example of an ordinary proof, in contemporary mathematical language. It establishes a fact that was known to the Pythagoreans.
12 |
13 | ----
14 |
15 | **Theorem.** :math:`\sqrt 2` is irrational, which is to say, it cannot be expressed as a fraction :math:`a / b`, where :math:`a` and :math:`b` are integers.
16 |
17 | **Proof.** Suppose :math:`\sqrt 2 = a / b` for some pair of integers :math:`a` and :math:`b`. By removing any common factors, we can assume :math:`a / b` is in lowest terms, so that :math:`a` and :math:`b` have no factor in common. Then we have :math:`a = \sqrt 2 b`, and squaring both sides, we have :math:`a^2 = 2 b^2`.
18 |
19 | The last equation implies that :math:`a^2` is even, and since the square of an odd number is odd, :math:`a` itself must be even as well. We therefore have :math:`a = 2c` for some integer :math:`c`. Substituting this into the equation :math:`a^2 = 2 b^2`, we have :math:`4 c^2 = 2 b^2`, and hence :math:`2 c^2 = b^2`. This means that :math:`b^2` is even, and so :math:`b` is even as well.
20 |
21 | The fact that :math:`a` and :math:`b` are both even contradicts the fact that :math:`a` and :math:`b` have no common factor. So the original assumption that :math:`\sqrt 2 = a / b` is false.
22 |
23 | ----
24 |
25 | In the next example, we focus on the natural numbers,
26 |
27 | .. math::
28 |
29 | \mathbb{N} = \{ 0, 1, 2, \ldots \}.
30 |
31 | A natural number :math:`n` greater than or equal to 2 is said to be *composite* if it can be written as a product :math:`n = m \cdot k` where neither :math:`m` nor :math:`k` is equal to :math:`1`, and *prime* otherwise. Notice that if :math:`n = m \cdot k` witnesses the fact that :math:`n` is composite, then :math:`m` and :math:`k` are both smaller than :math:`n`. Notice also that, by convention, 0 and 1 are considered neither prime nor composite.
32 |
33 | ----
34 |
35 | **Theorem.** Every natural number greater than or equal to 2 can be written as a product of primes.
36 |
37 | **Proof.** We proceed by induction on :math:`n`. Let :math:`n` be any natural number greater than 2. If :math:`n` is prime, we are done; we can consider :math:`n` itself as a product with one term. Otherwise, :math:`n` is composite, and we can write :math:`n = m \cdot k` where :math:`m` and :math:`k` are smaller than :math:`n` and greater than 1. By the inductive hypothesis, each of :math:`m` and :math:`k` can be written as a product of primes, say
38 | :math:`m = p_1 \cdot p_2 \cdot \ldots \cdot p_u` and :math:`k = q_1 \cdot q_2 \cdot \ldots \cdot q_v`. But then we have
39 |
40 | .. math::
41 |
42 | n = m \cdot k = p_1 \cdot p_2 \cdot \ldots \cdot p_u \cdot q_1 \cdot
43 | q_2 \cdot \ldots \cdot q_v,
44 |
45 | a product of primes, as required.
46 |
47 | ----
48 |
49 | Later, we will see that more is true: every natural number greater than 2 can be written as a product of primes in a unique way, a fact known as the *fundamental theorem of arithmetic*.
50 |
51 | The first goal of this course is to teach you to write clear, readable mathematical proofs. We will do this by considering a number of examples, but also by taking a reflective point of view: we will carefully study the components of mathematical language and the structure of mathematical proofs, in order to gain a better understanding of how they work.
52 |
53 | Symbolic Logic
54 | --------------
55 |
56 | Toward understanding how proofs work, it will be helpful to study a subject known as "symbolic logic," which provides an idealized model of mathematical language and proof. In the *Prior Analytics*, the ancient Greek philosopher set out to analyze patterns of reasoning, and developed the theory of the *syllogism*. Here is one instance of a syllogism:
57 |
58 | ----
59 |
60 | Every man is an animal.
61 |
62 | Every animal is mortal.
63 |
64 | Therefore every man is mortal.
65 |
66 | ----
67 |
68 | Aristotle observed that the correctness of this inference has nothing to do with the truth or falsity of the individual statements, but, rather, the general pattern:
69 |
70 | ----
71 |
72 | Every A is B.
73 |
74 | Every B is C.
75 |
76 | Therefore every A is C.
77 |
78 | ----
79 |
80 | We can substitute various properties for A, B, and C; try substituting the properties of being a fish, being a unicorn, being a swimming creature, being a mythical creature, etc. The various statements that result may come out true or false, but all the instantiations will have the following crucial feature: if the two hypotheses come out true, then the conclusion comes out true as well. We express this by saying that the inference is *valid*.
81 |
82 | Although the patterns of language addressed by Aristotle's theory of reasoning are limited, we have him to thank for a crucial insight: we can classify valid patterns of inference by their logical form, while abstracting away specific content. It is this fundamental observation that underlies the entire field of symbolic logic.
83 |
84 | In the seventeenth century, Leibniz proposed the design of a *characteristica universalis*, a universal symbolic language in which one would express any assertion in a precise way, and a *calculus ratiocinatur*, a "calculus of thought" which would express the precise rules of reasoning. Leibniz himself took some steps to develop such a language and calculus, but much greater strides were made in the nineteenth century, through the work of Boole, Frege, Peirce, Schroeder, and others. Early in the twentieth century, these efforts blossomed into the field of mathematical logic.
85 |
86 | If you consider the examples of proofs in the last section, you will notice that some terms and rules of inference are specific to the subject matter at hand, having to do with numbers and the properties of being prime, composite, even, odd, and so on. But there are other terms and rules of inference that are not domain specific, such as those related to the words "every," "some," "and," and "if ... then." The goal of symbolic logic is to identify these core elements of reasoning and argumentation and explain how they work, as well as to explain how more domain-specific notions are introduced and used.
87 |
88 | To that end, we will introduce symbols for key logical notions, including the following:
89 |
90 | - :math:`A \to B`, ":math:`\mbox{if $A$ then $B$}`"
91 | - :math:`A \wedge B`, ":math:`\mbox{$A$ and $B$}`"
92 | - :math:`A \vee B`, ":math:`\mbox{$A$ or $B$}`"
93 | - :math:`\neg A`, ":math:`\mbox{not $A$}`"
94 | - :math:`\forall x \; A`, ":math:`\mbox{for every $x$, $A$}`"
95 | - :math:`\exists x \; A`, ":math:`\mbox{for some $x$, $A$}`"
96 |
97 | We will then provide a formal proof system that will let us establish, deductively, that certain entailments between such statements are valid.
98 |
99 | The proof system we will use is a version of *natural deduction*, a type of proof system introduced by Gerhard Gentzen in the 1930s to model informal styles of argument. In this system, the fundamental unit of judgment is the assertion that a statement, :math:`A`, follows from a finite set of hypotheses, :math:`\Gamma`. This is written as :math:`\Gamma \vdash A`. If :math:`\Gamma` and :math:`\Delta` are two finite sets of hypotheses, we will write :math:`\Gamma, \Delta` for the *union* of these two sets, that is, the set consisting of all the hypotheses in each. With these conventions, the rule for the conjunction
100 | symbol can be expressed as follows:
101 |
102 | .. raw:: html
103 |
104 |
105 |
106 | .. raw:: latex
107 |
108 | \begin{prooftree}
109 | \def\fCenter{\ \vdash\ }
110 | \Axiom$\Gamma \fCenter A$
111 | \Axiom$\Delta \fCenter B$
112 | \BinaryInf$\Gamma, \Delta \fCenter A \wedge B$
113 | \end{prooftree}
114 |
115 | This should be interpreted as saying: assuming :math:`A` follows from the hypotheses :math:`\Gamma`, and :math:`B` follows from the hypotheses :math:`\Delta`, :math:`A \wedge B` follows from the hypotheses in both :math:`\Gamma` and :math:`\Delta`.
116 |
117 | We will see that one can write such proofs more compactly leaving the hypotheses implicit, so that the rule above is expressed as follows:
118 |
119 | .. raw:: html
120 |
121 |
122 |
123 | .. raw:: latex
124 |
125 | \begin{prooftree}
126 | \AxiomC{$A$}
127 | \AxiomC{$B$}
128 | \BinaryInfC{$A \wedge B$}
129 | \end{prooftree}
130 |
131 | In this format, a snippet of the first proof in the previous section might be rendered as follows:
132 |
133 | .. raw:: html
134 |
135 |
136 |
137 | .. raw:: latex
138 |
139 | \begin{prooftree}
140 | \AxiomC{}
141 | \UnaryInfC{$\neg \mathit{even}(b)$}
142 | \AxiomC{$\forall x \; (\neg \mathit{even}(x) \to \neg \mathit{even}(x^2))$}
143 | \UnaryInfC{$\neg \mathit{even}(b) \to \neg \mathit{even}(b^2)$}
144 | \BinaryInfC{$\neg \mathit{even}(b^2)$}
145 | \AxiomC{$\mathit{even}(b^2)$}
146 | \BinaryInfC{$\bot$}
147 | \UnaryInfC{$\mathit{even}(b)$}
148 | \end{prooftree}
149 |
150 | The complexity of such proofs can quickly grow out of hand, and complete proofs of even elementary mathematical facts can become quite long. Such systems are not designed for writing serious mathematics. Rather, they provide idealized models of mathematical inference, and insofar as they capture something of the structure of an informal proof, they enable us to study the properties of mathematical reasoning.
151 |
152 | The second goal of this course is to help you understand natural deduction, as an example of a formal deductive system.
153 |
154 | Interactive Theorem Proving
155 | ---------------------------
156 |
157 | Early work in mathematical logic aimed to show that ordinary mathematical arguments could be modeled in symbolic calculi, at least in principle. As noted above, complexity issues limit the range of what can be accomplished in practice; even elementary mathematical arguments require long derivations that are hard to write and hard to read, and do little to promote understanding of the underlying mathematics.
158 |
159 | Since the end of the twentieth century, however, the advent of computational proof assistants has begun to make complete formalization feasible. Working interactively with theorem proving software, users can construct formal derivations of complex theorems that can be stored and checked by computer. Automated methods can be used to fill in small gaps by hand, verify long calculations axiomatically, or fill in long chains of inferences deterministically. The reach of automation is currently fairly limited, however. The strategy used in interactive theorem proving is to ask users to provide just enough information for the system to be able to construct and check a formal derivation. This typically involves writing proofs in a sort of "programming language" that is designed with that purpose in mind. For example, here is a short proof in the *Lean* theorem prover:
160 |
161 | .. code-block:: lean
162 |
163 | section
164 | variable (P Q : Prop)
165 |
166 | theorem my_theorem : P ∧ Q → Q ∧ P := by
167 | rintro h : P ∧ Q
168 | apply And.intro
169 | . exact And.right h
170 | . exact And.left h
171 | end
172 |
173 | If you are reading the present text in online form, you will find a button above the formal "proof script" that says "try it!" Pressing the button opens the proof in an editor window and runs a version of Lean inside your browser to process the proof, turn it into an axiomatic derivation, and verify its correctness. You can experiment by varying the text in the editor; any errors will be noted in the window to the right.
174 |
175 | Proofs in Lean can access a library of prior mathematical results, all verified down to axiomatic foundations. A goal of the field of interactive theorem proving is to reach the point where any contemporary theorem can be verified in this way. For example, here is a formal proof that the square root of two is irrational, following the model of the informal proof presented above:
176 |
177 | .. code-block:: lean
178 |
179 | import Mathlib.Data.Nat.Prime.Basic
180 | open Nat
181 | open Prime
182 |
183 | section
184 |
185 | theorem sqrt_two_irrational {a b : ℕ} (co : gcd a b = 1) :
186 | a^2 ≠ 2 * b^2 := by
187 | rintro h : a^2 = 2 * b^2
188 | have : 2 ∣ a^2 := by
189 | simp [h]
190 | have : 2 ∣ a :=
191 | dvd_of_dvd_pow prime_two this
192 | apply Exists.elim this
193 | rintro c aeq
194 | have : 2 * (2 * c^2) = 2 * b^2 := by
195 | simp [Eq.symm h, aeq]
196 | simp [pow_succ' _, mul_comm, mul_assoc, mul_left_comm]
197 | have : 2 * c^2 = b^2 := by
198 | apply mul_left_cancel₀ _ this
199 | decide
200 | have : 2 ∣ b^2 := by
201 | simp [Eq.symm this]
202 | have : 2 ∣ b := by
203 | exact dvd_of_dvd_pow prime_two this
204 | have : 2 ∣ gcd a b := by
205 | apply dvd_gcd
206 | . assumption
207 | . assumption
208 | have _ : 2 ∣ (1 : ℕ) := by
209 | simp [co] at *
210 | contradiction
211 |
212 | end
213 |
214 | The third goal of this course is to teach you to write elementary proofs in Lean. The facts that we will ask you to prove in Lean will be more elementary than the informal proofs we will ask you to write, but our intent is that formal proofs will model and clarify the informal proof strategies we will teach you.
215 |
216 | The Semantic Point of View
217 | --------------------------
218 |
219 | As we have presented the subject here, the goal of symbolic logic is to specify a language and rules of inference that enable us to get at the truth in a reliable way. The idea is that the symbols we choose denote objects and concepts that have a fixed meaning, and the rules of inference we adopt enable us to draw true conclusions from true hypotheses.
220 |
221 | One can adopt another view of logic, however, as a system where some symbols have a fixed meaning, such as the symbols for "and," "or," and "not," and others have a meaning that is taken to vary. For example, the expression :math:`P \wedge (Q \vee R)`, read ":math:`P` and either :math:`Q` or :math:`R`," may be true or false *depending on the basic assertions that* :math:`P`, :math:`Q`, *and* :math:`R` *stand for*. More precisely, the truth of the compound expression depends only on whether the component symbols denote expressions that are true or false. For example, if :math:`P`, :math:`Q`, and :math:`R` stand for "seven is prime," "seven is even," and "seven is odd," respectively, then the expression is true. If we replace "seven" by "six," the statement is false. More generally, the expression comes out true whenever :math:`P` is true and at least one of :math:`Q` and :math:`R` is true, and false otherwise.
222 |
223 | From this perspective, logic is not so much a language for asserting truth, but a language for describing possible states of affairs. In other words, logic provides a specification language, with expressions that can be true or false depending on how we interpret the symbols that are allowed to vary. For example, if we fix the meaning of the basic predicates, the statement "there is a red block between two blue blocks" may be true or false of a given "world" of blocks, and we can take the expression to describe the set of worlds in which it is true. Such a view of logic is important in computer science, where we use logical expressions to select entries from a database matching certain criteria, to specify properties of hardware and software systems, or to assert constraints that we would like a constraint solver to satisfy.
224 |
225 | There are important connections between the syntactic / deductive point of view on the one hand, and the semantic / model-theoretic point of view on the other. We will explore some of these along the way. For example, we will see that it is possible to view the "valid" assertions as those that are true under all possible interpretations of the non-fixed symbols, and the "valid" inferences as those that maintain truth in all possible states and affairs. From this point of view, a deductive system should only allow us to derive valid assertions and entailments, a property known as *soundness*. If a deductive system is strong enough to allow us to verify *all* valid assertions and entailments, it is said to be *complete*.
226 |
227 | The fourth goal of this course is to convey the semantic view of logic, and to lead you to understand how logical expressions can be used to specify states of affairs.
228 |
229 | Goals Summarized
230 | ----------------
231 |
232 | To summarize, these are the goals of this course:
233 |
234 | - You should learn to write clear, "literate," mathematical proofs.
235 | - You should become comfortable with symbolic logic and the formal modeling of deductive proof.
236 | - You should learn how to use an interactive proof assistant.
237 | - You should understand how to use logic as a precise language for making claims about systems of objects and the relationships between them, and specifying certain states of affairs.
238 |
239 | Let us take a moment to consider the relationship between some of these goals. It is important not to confuse the first three. We are dealing with three kinds of mathematical language: ordinary mathematical language, the symbolic representations of mathematical logic, and computational implementations in interactive proof assistants. These are very different things!
240 |
241 | Symbolic logic is not meant to replace ordinary mathematical language, and you should not use symbols like :math:`\wedge` and :math:`\vee` in ordinary mathematical proofs any more than you would use them in place of the words "and" and "or" in letters home to your parents. Natural languages provide nuances of expression that can convey levels of meaning and understanding that go beyond pattern matching to verify correctness. At the same time, modeling mathematical language with symbolic expressions provides a level of precision that makes it possible to turn mathematical language itself into an object of study. Each has its place, and we hope to get you to appreciate the value of each without confusing the two.
242 |
243 | The proof languages used by interactive theorem provers lie somewhere between the two extremes. On the one hand, they have to be specified with enough precision for a computer to process them and act appropriately; on the other hand, they aim to capture some of the higher-level nuances and features of informal language in a way that enables us to write more complex arguments and proofs. Rooted in symbolic logic and designed with ordinary mathematical language in mind, they aim to bridge the gap between the two.
244 |
245 | This book also aims to show you how mathematics is built up from fundamental concepts. Logic provides the rules of the game, and then we work our way up from properties of sets, relations, functions, and the natural numbers to elementary number theory, combinatorics, and properties of the real numbers. The last chapter rounds out the story with a discussion of axiomatic foundations.
246 |
247 | About this Textbook
248 | -------------------
249 |
250 | Both this online textbook and the *Lean* theorem prover are ongoing projects.
251 | The original ``lean3`` version of this textbook
252 | is available `here `_.
253 | This version introduces ``lean4`` instead.
254 |
255 | You can learn more about Lean from its `project page `_,
256 | the Lean `community pages `_, and the online textbook,
257 | `Theorem Proving in Lean `_.
258 |
259 | The original textbook was written by Jeremy Avigad, Robert Y. Lewis, and Floris van Doorn.
260 | This was adapted to ``lean4`` by Joseph Hua.
261 | We are grateful for feedback and corrections from a number of people,
262 | including Bruno Cuconato, William DeMeo, Tobias Grosser, Lyle Kopnicky,
263 | Alexandre Rademaker, Matt Rice, and Jason Siefken.
264 |
--------------------------------------------------------------------------------
/latex_images/Makefile:
--------------------------------------------------------------------------------
1 | SRCS = $(wildcard *.tex)
2 | OBJS = $(patsubst %.tex,%.png,$(SRCS))
3 |
4 | images : $(OBJS) clean
5 |
6 | copy_images : images
7 | cp *.png ../_static/
8 |
9 | %.png : %.pdf
10 | convert -density 300 $< -quality 90 $@
11 |
12 | %.pdf : %.tex
13 | pdflatex $<
14 |
15 | clean :
16 | rm -f *.pdf *.log *.aux *.synctex.gz *.fls *.fdb_latexmk
17 |
18 | clean_all : clean
19 | rm -f *.png
--------------------------------------------------------------------------------
/latex_images/classical_reasoning.1.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{\neg A}
8 | \noLine
9 | \UIM{\vdots}
10 | \noLine
11 | \UIM{\bot}
12 | \RLM{1}
13 | \UIM{A}
14 | \end{prooftree}
15 | \end{document}
--------------------------------------------------------------------------------
/latex_images/classical_reasoning.2.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{2}
7 | \UIM{\neg (A \vee \neg A)}
8 | \AXM{}
9 | \RLM{1}
10 | \UIM{A}
11 | \UIM{A \vee \neg A}
12 | \BIM{\bot}
13 | \RLM{1}
14 | \UIM{\neg A}
15 | \UIM{A \vee \neg A}
16 | \AXM{}
17 | \RLM{1}
18 | \UIM{\neg (A \vee \neg A)}
19 | \BIM{\bot}
20 | \RLM{1}
21 | \UIM{A \vee \neg A}
22 | \DP
23 | \end{center}
24 | \end{document}
--------------------------------------------------------------------------------
/latex_images/classical_reasoning.3.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{2}
7 | \UIM{\neg (A \vee \neg A)}
8 | \AXM{}
9 | \RLM{2}
10 | \UIM{\neg (A \vee \neg A)}
11 | \AXM{}
12 | \RLM{1}
13 | \UIM{A}
14 | \UIM{A \vee \neg A}
15 | \BIM{\bot}
16 | \RLM{1}
17 | \UIM{\neg A}
18 | \UIM{A \vee \neg A}
19 | \BIM{\bot}
20 | \RLM{2}
21 | \UIM{A \vee \neg A}
22 | \DP
23 | \end{center}
24 | \end{document}
--------------------------------------------------------------------------------
/latex_images/classical_reasoning.4.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{2}
7 | \UIM{\neg \neg A}
8 | \AXM{}
9 | \RLM{1}
10 | \UIM{\neg A}
11 | \BIM{\bot}
12 | \RLM{1}
13 | \UIM{A}
14 | \AXM{}
15 | \RLM{1}
16 | \UIM{\neg A}
17 | \AXM{}
18 | \RLM{2}
19 | \UIM{A}
20 | \BIM{\bot}
21 | \RLM{1}
22 | \UIM{\neg \neg A}
23 | \RLM{2}
24 | \BIM{\neg \neg A \liff A}
25 | \DP
26 | \end{center}
27 | \end{document}
--------------------------------------------------------------------------------
/latex_images/classical_reasoning.5.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{\neg B \to \neg A}
6 | \AXM{}
7 | \RLM{1}
8 | \UIM{\neg B}
9 | \BIM{\neg A}
10 | \AXM{}
11 | \RLM{2}
12 | \UIM{A}
13 | \BIM{\bot}
14 | \RLM{1}
15 | \UIM{B}
16 | \RLM{2}
17 | \UIM{A \to B}
18 | \DP
19 | \end{center}
20 | \end{document}
--------------------------------------------------------------------------------
/latex_images/classical_reasoning.6.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{3}
7 | \UIM{\neg (A \wedge \neg B)}
8 | \AXM{}
9 | \RLM{2}
10 | \UIM{A}
11 | \AXM{}
12 | \RLM{1}
13 | \UIM{\neg B}
14 | \BIM{A \wedge \neg B}
15 | \BIM{\bot}
16 | \RLM{1}
17 | \UIM{B}
18 | \RLM{2}
19 | \UIM{A \to B}
20 | \RLM{3}
21 | \UIM{\neg (A \wedge \neg B) \to (A \to B)}
22 | \DP
23 | \end{center}
24 | \end{document}
--------------------------------------------------------------------------------
/latex_images/classical_reasoning.6bis.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \UIM{B \vee \neg B}
7 | \AXM{}
8 | \RLM{1}
9 | \UIM{B}
10 | \UIM{A \to B}
11 | \UIM{(A \to B) \vee (B \to A)}
12 | \AXM{}
13 | \RLM{1}
14 | \UIM{\neg B}
15 | \AXM{}
16 | \RLM{2}
17 | \UIM{B}
18 | \BIM{\bot}
19 | \UIM{A}
20 | \RLM{2}
21 | \UIM{B \to A}
22 | \UIM{(A \to B) \vee (B \to A)}
23 | \RLM{1}
24 | \TIM{(A \to B) \vee (B \to A)}
25 | \DP
26 | \end{center}
27 | \end{document}
--------------------------------------------------------------------------------
/latex_images/classical_reasoning.7.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic,amsmath}
3 | \begin{document}
4 | \begin{align*}
5 | \neg (A \vee B) & \leftrightarrow \neg A \wedge \neg B \\
6 | \neg (A \wedge B) & \leftrightarrow \neg A \vee \neg B
7 | \end{align*}
8 | \end{document}
--------------------------------------------------------------------------------
/latex_images/classical_reasoning.8.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic,amsmath}
3 | \begin{document}
4 | \begin{align*}
5 | \neg (\neg A \wedge B \to C)
6 | & \leftrightarrow \neg (\neg (\neg A \wedge B) \vee C) \\
7 | & \leftrightarrow \neg \neg (\neg A \wedge B) \wedge \neg C \\
8 | & \leftrightarrow \neg A \wedge B \wedge \neg C
9 | \end{align*}
10 | \end{document}
--------------------------------------------------------------------------------
/latex_images/combinatorics.1.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \begin{tabular}{rccccccccc}
6 | & & & & 1 \\\noalign{\smallskip\smallskip}
7 | & & & 1 & & 1 \\\noalign{\smallskip\smallskip}
8 | & & 1 & & 2 & & 1 \\\noalign{\smallskip\smallskip}
9 | & 1 & & 3 & & 3 & & 1 \\\noalign{\smallskip\smallskip}
10 | 1 & & 4 & & 6 & & 4 & & 1 \\\noalign{\smallskip\smallskip}
11 | \end{tabular}
12 | \end{center}
13 | \end{document}
--------------------------------------------------------------------------------
/latex_images/first_order_logic.10.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \UIM{t = t}
7 | \DP
8 | \quad
9 | \AXM{s = t}
10 | \UIM{t = s}
11 | \DP
12 | \quad
13 | \AXM{r = s}
14 | \AXM{s = t}
15 | \BIM{r = t}
16 | \DP
17 | \\
18 | \ \\
19 | \AXM{s = t}
20 | \UIM{r(s) = r(t)}
21 | \DP
22 | \quad
23 | \AXM{s = t}
24 | \AXM{P(s)}
25 | \BIM{P(t)}
26 | \DP
27 | \end{center}
28 | \end{document}
--------------------------------------------------------------------------------
/latex_images/first_order_logic.3.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{b \ne 0}
8 | \noLine
9 | \UIM{\vdots}
10 | \AXM{}
11 | \RLM{2}
12 | \UIM{a^2 = 2 \times b^2}
13 | \noLine
14 | \UIM{\vdots}
15 | \noLine
16 | \BIM{\bot}
17 | \RLM{2}
18 | \UIM{\neg (a^2 = 2 \times b^2)}
19 | \RLM{1}
20 | \UIM{b \ne 0 \to \neg (a^2 = 2 \times b^2)}
21 | \UIM{\forall b \; (b \ne 0 \to \neg (a^2 = 2 \times b^2))}
22 | \UIM{\forall a \; \forall b \; (b \ne 0 \to \neg (a^2 = 2 \times b^2))}
23 | \DP
24 | \end{center}
25 | \end{document}
--------------------------------------------------------------------------------
/latex_images/first_order_logic.4.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \AXM{A(x)}
6 | \UIM{\fa x A(x)}
7 | \end{prooftree}
8 | \end{document}
--------------------------------------------------------------------------------
/latex_images/first_order_logic.5.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \AXM{\forall x A(x)}
6 | \UIM{A(t)}
7 | \end{prooftree}
8 | \end{document}
--------------------------------------------------------------------------------
/latex_images/first_order_logic.6.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{\vdots}
6 | \noLine
7 | \UIM{\mathit{odd}(15)\wedge\mathit{composite}(15)}
8 | \UIM{\ex n(\mathit{odd}(n)\wedge\mathit{composite}(n))}
9 | \DP
10 | \end{center}
11 | \end{document}
--------------------------------------------------------------------------------
/latex_images/first_order_logic.7.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{A(t)}
6 | \UIM{\exists x A(x)}
7 | \DP
8 | \end{center}
9 | \end{document}
--------------------------------------------------------------------------------
/latex_images/first_order_logic.8.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \AXM{\exists x A(x)}
6 | \AXM{}
7 | \RLM{1}
8 | \UIM{A(y)}
9 | \noLine
10 | \UIM{\vdots}
11 | \noLine
12 | \UIM{B}
13 | \RLM{1}
14 | \BIM{B}
15 | \end{prooftree}
16 | \end{document}
--------------------------------------------------------------------------------
/latex_images/first_order_logic_in_lean.1.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{\fa x A(x)}
8 | \UIM{A(y)}
9 | \AXM{}
10 | \RLM{2}
11 | \UIM{\fa x B(x)}
12 | \UIM{B(y)}
13 | \BIM{A(y) \wedge B(y)}
14 | \UIM{\fa y (A(y) \wedge B(y))}
15 | \RLM{2}
16 | \UIM{\fa x B(x) \to \fa y (A(y) \wedge B(y))}
17 | \RLM{1}
18 | \UIM{\fa x A(x) \to (\fa x B(x) \to \fa y (A(y) \wedge B(y)))}
19 | \end{prooftree}
20 | \end{document}
--------------------------------------------------------------------------------
/latex_images/first_order_logic_in_lean.2.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \small
5 | \begin{prooftree}
6 | \AXM{}
7 | \RLM{2}
8 | \UIM{\ex x (A(x) \wedge B(x))}
9 | \AXM{}
10 | \RLM{1}
11 | \UIM{\fa x (A(x) \to \neg B(x))}
12 | \UIM{A(x) \to \neg B(x)}
13 | \AXM{}
14 | \RLM{3}
15 | \UIM{A(x) \wedge B(x)}
16 | \UIM{A(x)}
17 | \BIM{\neg B(x)}
18 | \AXM{}
19 | \RLM{3}
20 | \UIM{A(x) \wedge B(x)}
21 | \UIM{B(x)}
22 | \BIM{\bot}
23 | \RLM{3}
24 | \BIM{\bot}
25 | \RLM{2}
26 | \UIM{\neg\ex x(A(x) \wedge B(x))}
27 | \RLM{1}
28 | \UIM{\fa x (A(x) \to \neg B(x)) \to \neg \ex x (A(x) \wedge B(x))}
29 | \end{prooftree}
30 | \end{document}
--------------------------------------------------------------------------------
/latex_images/introduction.1.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs}
3 | \begin{document}
4 |
5 | \begin{prooftree}
6 | \def\fCenter{\ \vdash\ }
7 | \Axiom$\Gamma \fCenter A$
8 | \Axiom$\Delta \fCenter B$
9 | \BinaryInf$\Gamma, \Delta \fCenter A \wedge B$
10 | \end{prooftree}
11 |
12 | \end{document}
--------------------------------------------------------------------------------
/latex_images/introduction.2.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs}
3 | \begin{document}
4 | \begin{prooftree}
5 | \AxiomC{$A$}
6 | \AxiomC{$B$}
7 | \BinaryInfC{$A \wedge B$}
8 | \end{prooftree}
9 | \end{document}
--------------------------------------------------------------------------------
/latex_images/introduction.3.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs}
3 | \begin{document}
4 |
5 | \begin{prooftree}
6 | \AxiomC{}
7 | \UnaryInfC{$\neg \mathit{even}(b)$}
8 | \AxiomC{$\forall x \; (\neg \mathit{even}(x) \to \neg \mathit{even}(x^2))$}
9 | \UnaryInfC{$\neg \mathit{even}(b) \to \neg \mathit{even}(b^2))$}
10 | \BinaryInfC{$\neg \mathit{even}(b^2)$}
11 | \AxiomC{$\mathit{even}(b^2)$}
12 | \BinaryInfC{$\bot$}
13 | \UnaryInfC{$\mathit{even}(b)$}
14 | \end{prooftree}
15 |
16 | \end{document}
--------------------------------------------------------------------------------
/latex_images/mylogic.sty:
--------------------------------------------------------------------------------
1 |
2 | \newcommand{\horizontalrule}{\noindent \rule{\linewidth}{0.5pt}}
3 |
4 | % theorem environments
5 |
6 | \newtheorem{theorem}{Theorem}[section]
7 | \newtheorem{lemma}[theorem]{Lemma}
8 | \newtheorem{proposition}[theorem]{Proposition}
9 | \newtheorem{definition}[theorem]{Definition}
10 | \newtheorem{corollary}[theorem]{Corollary}
11 |
12 | % special fonts for theory names, functions, axioms, etc.
13 | \newcommand{\fn}[1]{\mathit{#1}} % function; e.g. successor
14 | \newcommand{\mdl}[1]{\frak{#1}} % model; e.g. M
15 |
16 | % logical connectives
17 | \newcommand{\liff}{\leftrightarrow}
18 | \newcommand{\ex}[1]{\exists #1 \;} % exists x ...
19 | \newcommand{\fa}[1]{\forall #1 \;} % forall x ...
20 | \newcommand{\lam}[1]{\lambda #1 \;} % forall x ...
21 | \newcommand{\exunique}[1]{\exists ! #1 \;}
22 |
23 | % useful symbols
24 | \newcommand{\proves}{\vdash}
25 | \newcommand{\nproves}{\nvdash}
26 | \newcommand{\forces}{\Vdash}
27 | \newcommand{\nforces}{\nVdash}
28 |
29 | \newcommand{\ph}{\varphi}
30 |
31 | \newcommand{\st}{\mid} % x such that ...
32 | \newcommand{\dash}{\mathord{\mbox{-}}}
33 |
34 | \newcommand{\inv}{^{-1}}
35 |
36 | % useful abbreviations
37 | \newcommand{\NN}{\mathbb{N}}
38 | \newcommand{\ZZ}{\mathbb{Z}}
39 | \newcommand{\QQ}{\mathbb{Q}}
40 | \newcommand{\RR}{\mathbb{R}}
41 | \newcommand{\CC}{\mathbb{C}}
42 | \newcommand{\lqt}{\mbox{`}}
43 | \newcommand{\rqt}{\mbox{'}}
44 | \newcommand{\true}{\mathbf{T}}
45 | \newcommand{\false}{\mathbf{F}}
46 | \newcommand{\MM}{\mathcal{M}}
47 |
48 | % BussProofs abbreviations
49 | \newcommand{\AXM}[1]{\AXC{$#1$}}
50 | \newcommand{\UIM}[1]{\UIC{$#1$}}
51 | \newcommand{\BIM}[1]{\BIC{$#1$}}
52 | \newcommand{\TIM}[1]{\TIC{$#1$}}
53 | \newcommand{\AXN}[1]{\AX$#1$}
54 | \newcommand{\BIN}[1]{\BI$#1$}
55 | \newcommand{\UIN}[1]{\UI$#1$}
56 | \newcommand{\TIN}[1]{\TI$#1$}
57 | % \newcommand{\RLM}[1]{\RL{$\mathrm{#1}$}}
58 | \newcommand{\RLM}[1]{\RL{$\scriptstyle #1$}}
59 |
60 | % common predicates and relations
61 | \newcommand{\even}{\ensuremath{\fn{even}}}
62 | \newcommand{\odd}{\ensuremath{\fn{odd}}}
63 | \newcommand{\primep}{\ensuremath{\fn{prime}}}
64 | \newcommand{\suc}{\ensuremath{\fn{succ}}}
65 | \newcommand{\tsub}{\mathbin{\mathchoice% truncated subtraction
66 | {\buildrel .\lower.6ex\hbox{\vphantom{.}} \over {\smash-}}%
67 | {\buildrel .\lower.6ex\hbox{\vphantom{.}} \over {\smash-}}%
68 | {\buildrel .\lower.4ex\hbox{\vphantom{.}} \over {\smash-}}%
69 | {\buildrel .\lower.3ex\hbox{\vphantom{.}} \over {\smash-}}}}
70 |
71 | \EnableBpAbbreviations
72 |
73 |
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_first_order_logic.1.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{quote}
5 | \AXM{A(x)}
6 | \RLM{\mathord{\forall}\mathrm{I}}
7 | \UIM{\fa y A(y)}
8 | \DP
9 | \quad\quad
10 | \AXM{\fa x A(x)}
11 | \RLM{\mathord{\forall}\mathrm{E}}
12 | \UIM{A(t)}
13 | \DP
14 | \end{quote}
15 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_first_order_logic.10.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \scriptsize
5 | \begin{prooftree}
6 | \AXM{}
7 | \RLM{2}
8 | \UIM{\ex x (A(x) \wedge B(x))}
9 | \AXM{}
10 | \RLM{1}
11 | \UIM{\fa x (A(x) \to \neg B(x))}
12 | \UIM{A(x) \to \neg B(x)}
13 | \AXM{}
14 | \RLM{3}
15 | \UIM{A(x) \wedge B(x)}
16 | \UIM{A(x)}
17 | \BIM{\neg B(x)}
18 | \AXM{}
19 | \RLM{3}
20 | \UIM{A(x) \wedge B(x)}
21 | \UIM{B(x)}
22 | \BIM{\bot}
23 | \RLM{3}
24 | \BIM{\bot}
25 | \RLM{2}
26 | \UIM{\neg\ex x(A(x) \wedge B(x))}
27 | \RLM{1}
28 | \UIM{\fa x (A(x) \to \neg B(x)) \to \neg\ex x(A(x) \wedge B(x))}
29 | \end{prooftree}
30 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_first_order_logic.11.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{\ex x P}
8 | \AXM{}
9 | \RLM{2}
10 | \UIM{P}
11 | \RLM{2}
12 | \BIM{P}
13 | \AXM{}
14 | \RLM{1}
15 | \UIM{P}
16 | \UIM{\ex x P}
17 | \RLM{1}
18 | \BIM{\ex x P \leftrightarrow P}
19 | \end{prooftree}
20 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_first_order_logic.12.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \UIM{t = t}
7 | \DP
8 | \quad
9 | \AXM{s = t}
10 | \UIM{t = s}
11 | \DP
12 | \quad
13 | \AXM{r = s}
14 | \AXM{s = t}
15 | \BIM{r = t}
16 | \DP
17 | \\
18 | \ \\
19 | \AXM{s = t}
20 | \UIM{r(s) = r(t)}
21 | \DP
22 | \quad
23 | \AXM{s = t}
24 | \AXM{P(s)}
25 | \BIM{P(t)}
26 | \DP
27 | \end{center}
28 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_first_order_logic.13.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{u + v = 0}
6 | \UIM{((u + v) + y) \times (z + 0) = (0 + y) \times (z + 0)}
7 | \DP
8 | \end{center}
9 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_first_order_logic.13a.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{u + v = 0}
6 | \AXM{x + (u + v) < y}
7 | \BIM{x + 0 < y}
8 | \DP
9 | \end{center}
10 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_first_order_logic.14.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{u + v = 0}
6 | \AXM{}
7 | \UIM{((u + v) + y) \times (z + 0) = ((u + v) + y) \times (z + 0)}
8 | \BIM{((u + v) + y) \times (z + 0) = (0 + y) \times (z + 0)}
9 | \DP
10 | \end{center}
11 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_first_order_logic.15.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \scriptsize
6 | \AXM{}
7 | \UIM{\mathsf{assoc}\strut}
8 | \UIM{(x + y) + z = x + (y + z)}
9 |
10 | \AXM{}
11 | \UIM{\mathsf{comm}\strut}
12 | \UIM{y + z = z + y}
13 | \UIM{x + (y + z) = x + (z + y)}
14 |
15 | \AXM{}
16 | \UIM{\mathsf{assoc}\strut}
17 | \UIM{(x + z) + y = x + (z + y)}
18 | \UIM{x + (z + y) = (x + z) + y}
19 |
20 | \BIM{x + (y + z) = (x + z) + y}
21 |
22 | \BIM{(x + y) + z = (x + z) + y}
23 | \UIM{\fa {x, y, z} ((x + y) + z = (x + z) + y)}
24 | \DP
25 | \end{center}
26 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_first_order_logic.16.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \scriptsize
6 | \AXM{}
7 | \RLM{1}
8 | \UIM{\neg\fa x A(x)}
9 | \AXM{}
10 | \RLM{4}
11 | \UIM{\neg(\ex x \neg A(x))}
12 | \AXM{}
13 | \RLM{5}
14 | \UIM{\neg A(x)}
15 | \UIM{\ex x \neg A(x)}
16 | \BIM{\bot}
17 | \RLM{5}
18 | \UIM{A(x)}
19 | \UIM{\fa x A(x)}
20 | \BIM{\bot}
21 | \RLM{4}
22 | \UIM{\ex x \neg A(x)}
23 | \AXM{}
24 | \RLM{1}
25 | \UIM{\ex x \neg A(x)}
26 | \AXM{}
27 | \RLM{3}
28 | \UIM{\neg A(y)}
29 | \AXM{}
30 | \RLM{2}
31 | \UIM{\fa x A(x)}
32 | \UIM{A(y)}
33 | \BIM{\bot}
34 | \RLM{3}
35 | \BIM{\bot}
36 | \RLM{2}
37 | \UIM{\neg\fa x A(x)}
38 | \RLM{1}
39 | \BIM{\neg\fa x A(x) \leftrightarrow \ex x \neg A(x)}
40 | \end{prooftree}
41 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_first_order_logic.2.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{quote}
5 | \AXM{A(t)}
6 | \RLM{\mathord{\exists}\mathrm{I}}
7 | \UIM{\ex x A(x)}
8 | \DP
9 | \quad\quad
10 | \AXM{\ex x A(x)}
11 | \AXM{}
12 | \RLM{1}
13 | \UIM{A(y)}
14 | \noLine
15 | \UIM{\vdots}
16 | \noLine
17 | \UIM{B}
18 | \RLM{1 \;\; \mathord{\exists}\mathrm{E}}
19 | \BIM{B}
20 | \DP
21 | \end{quote}
22 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_first_order_logic.3.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{\mathrm{refl}}
7 | \UIM{t = t}
8 | \DP
9 | \quad
10 | \AXM{s = t}
11 | \RLM{\mathrm{symm}}
12 | \UIM{t = s}
13 | \DP
14 | \quad
15 | \AXM{r = s}
16 | \AXM{s = t}
17 | \RLM{\mathrm{trans}}
18 | \BIM{r = t}
19 | \DP
20 | \\
21 | \ \\
22 | \AXM{s = t}
23 | \RLM{\mathrm{subst}}
24 | \UIM{r(s) = r(t)}
25 | \DP
26 | \quad
27 | \AXM{s = t}
28 | \RLM{\mathrm{subst}}
29 | \AXM{P(s)}
30 | \BIM{P(t)}
31 | \DP
32 | \end{center}
33 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_first_order_logic.4.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{\fa x A(x)}
8 | \UIM{A(y)}
9 | \AXM{}
10 | \RLM{2}
11 | \UIM{\fa x B(x)}
12 | \UIM{B(y)}
13 | \BIM{A(y) \wedge B(y)}
14 | \UIM{\fa y (A(y) \wedge B(y))}
15 | \RLM{2}
16 | \UIM{\fa x B(x) \to \fa y (A(y) \wedge B(y))}
17 | \RLM{1}
18 | \UIM{\fa x A(x) \to (\fa x B(x) \to \fa y (A(y) \wedge B(y)))}
19 | \end{prooftree}
20 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_first_order_logic.5.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{\fa x A(x)}
8 | \UIM{A(y)}
9 | \UIM{A(y) \vee B(y)}
10 | \UIM{\fa x (A(x) \vee B(x))}
11 | \RLM{1}
12 | \UIM{\fa x A(x) \to \fa x (A(x) \vee B(x))}
13 | \end{prooftree}
14 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_first_order_logic.6.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \scriptsize
5 | \begin{prooftree}
6 | \AXM{}
7 | \UIM{\even(n) \vee \neg \even(n)}
8 | \AXM{}
9 | \RLM{1}
10 | \UIM{\even(n)}
11 | \UIM{\even(n) \vee \odd(n)}
12 | \AXM{}
13 | \UIM{\fa n (\neg \even(n) \to \odd(n))}
14 | \UIM{\neg \even (n) \to \odd(n)}
15 | \AXM{}
16 | \RLM{1}
17 | \UIM{\neg \even(n)}
18 | \BIM{\odd(n)}
19 | \UIM{\even(n) \vee \odd(n)}
20 | \RLM{1}
21 | \TIM{\even(n) \vee \odd(n)}
22 | \UIM{\fa n (\even (n) \vee \odd(n))}
23 | \end{prooftree}
24 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_first_order_logic.7.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \scriptsize
5 | \begin{prooftree}
6 | \AXM{}
7 | \UIM{\odd(n) \to \neg \even(n)}
8 | \AXM{}
9 | \RLM{H}
10 | \UIM{\even(n) \wedge \odd(n)}
11 | \UIM{\odd(n)}
12 | \BIM{\neg \even(n)}
13 | \AXM{}
14 | \RLM{H}
15 | \UIM{\even(n) \wedge \odd(n)}
16 | \UIM{\even(n)}
17 | \BIM{\bot}
18 | \RLM{H}
19 | \UIM{\neg (\even(n) \wedge \odd(n))}
20 | \UIM{\fa n \neg (\even(n) \wedge \odd(n))}
21 | \end{prooftree}
22 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_first_order_logic.8.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{\exists x (A(x) \wedge B(x))}
8 | \AXM{}
9 | \RLM{2}
10 | \UIM{A(y) \wedge B(y)}
11 | \UIM{A(y)}
12 | \UIM{\exists x A(x)}
13 | \RLM{2}
14 | \BIM{\exists x A(x)}
15 | \RLM{1}
16 | \UIM{\exists x (A(x) \wedge B(x)) \to \exists x A(x)}
17 | \end{prooftree}
18 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_first_order_logic.9.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \scriptsize
5 | \begin{prooftree}
6 | \AXM{}
7 | \RLM{1}
8 | \UIM{\ex x (A(x) \vee B(x))}
9 | \AXM{}
10 | \RLM{2}
11 | \UIM{A(y) \vee B(y)}
12 | \AXM{}
13 | \RLM{3}
14 | \UIM{A(y)}
15 | \UIM{\ex x A(x)}
16 | \UIM{\ex x A(x) \vee \ex x B(x)}
17 | \AXM{}
18 | \RLM{3}
19 | \UIM{B(y)}
20 | \UIM{\ex x B(x)}
21 | \UIM{\ex x A(x) \vee \ex x B(x)}
22 | \RLM{3}
23 | \TIM{\ex x A(x) \vee \ex x B(x)}
24 | \RLM{2}
25 | \BIM{\ex x A(x) \vee \ex x B(x)}
26 | \RLM{1}
27 | \UIM{\ex x (A(x) \vee B(x)) \to \ex x A(x) \vee \ex x B(x))}
28 | \end{prooftree}
29 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.1.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{A}
6 | \AXM{B}
7 | \BIM{A \wedge B}
8 | \DP
9 | \end{center}
10 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.10.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{quote}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{A}
8 | \noLine
9 | \UIM{\vdots}
10 | \noLine
11 | \UIM{\bot}
12 | \RLM{1 \;\; \neg \mathrm{I}}
13 | \UIM{\neg A}
14 | \DP
15 | \quad\quad
16 | \AXM{\neg A}
17 | \AXM{A}
18 | \RLM{\neg \mathrm{E}}
19 | \BIM{\bot}
20 | \DP
21 | \end{quote}
22 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.11.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{quote}
5 | \AXM{A}
6 | \RLM{\mathord{\vee}\mathrm{I_l}}
7 | \UIM{A \vee B}
8 | \DP
9 | \quad\quad
10 | \AXM{B}
11 | \RLM{\mathord{\vee}\mathrm{I_r}}
12 | \UIM{A \vee B}
13 | \DP
14 | \quad\quad
15 | \AXM{A \vee B}
16 | \AXM{}
17 | \RLM{1}
18 | \UIM{A}
19 | \noLine
20 | \UIM{\vdots}
21 | \noLine
22 | \UIM{C}
23 | \AXM{}
24 | \RLM{1}
25 | \UIM{B}
26 | \noLine
27 | \UIM{\vdots}
28 | \noLine
29 | \UIM{C}
30 | \RLM{1 \;\; \mathord{\vee}\mathrm{E}}
31 | \TIM{C}
32 | \DP
33 | \end{quote}
34 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.12.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{quote}
5 | \AXM{\bot}
6 | \RLM{\bot \mathrm{E}}
7 | \UIM{A}
8 | \DP
9 | \quad\quad
10 | \AXM{}
11 | \RLM{\top \mathrm{I}}
12 | \UIM{\top}
13 | \DP
14 | \end{quote}
15 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.13.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{quote}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{A}
8 | \noLine
9 | \UIM{\vdots}
10 | \noLine
11 | \UIM{B}
12 | \AXM{}
13 | \RLM{1}
14 | \UIM{B}
15 | \noLine
16 | \UIM{\vdots}
17 | \noLine
18 | \UIM{A}
19 | \RLM{1 \;\; \mathord{\liff}\mathrm{I}}
20 | \BIM{A \liff B}
21 | \DP
22 | \AXM{A \liff B}
23 | \AXM{A}
24 | \RLM{\mathord{\liff}\mathrm{E}_l}
25 | \BIM{B}
26 | \DP
27 | \quad\quad
28 | \AXM{A \liff B}
29 | \AXM{B}
30 | \RLM{\mathord{\liff}\mathrm{E}_r}
31 | \BIM{A}
32 | \DP
33 | \end{quote}
34 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.14.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{quote}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{\neg A}
8 | \noLine
9 | \UIM{\vdots}
10 | \noLine
11 | \UIM{\bot}
12 | \RLM{1 \;\; \mathrm{RAA}}
13 | \UIM{A}
14 | \DP
15 | \end{quote}
16 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.15.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{A}
8 | \AXM{A \to B}
9 | \BIM{B}
10 | \AXM{B \to C}
11 | \BIM{C}
12 | \RLM{1}
13 | \UIM{A \to C}
14 | \DP
15 | \end{center}
16 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.16.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{A}
8 | \AXM{}
9 | \RLM{2}
10 | \UIM{(A \to B) \wedge (B \to C)}
11 | \UIM{A \to B}
12 | \BIM{B}
13 | \AXM{}
14 | \RLM{2}
15 | \UIM{(A \to B) \wedge (B \to C)}
16 | \UIM{B \to C}
17 | \BIM{C}
18 | \RLM{1}
19 | \UIM{A \to C}
20 | \RLM{2}
21 | \UIM{(A \to B) \wedge (B \to C) \to (A \to C)}
22 | \DP
23 | \end{center}
24 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.17.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{2}
7 | \UIM{A \to (B \to C)}
8 | \AXM{}
9 | \RLM{1}
10 | \UIM{A \wedge B}
11 | \UIM{A}
12 | \BIM{B \to C}
13 | \AXM{}
14 | \RLM{1}
15 | \UIM{A \wedge B}
16 | \UIM{B}
17 | \BIM{C}
18 | \RLM{1}
19 | \UIM{A \wedge B \to C}
20 | \RLM{2}
21 | \UIM{(A \to (B \to C)) \to
22 | (A \wedge B \to C)}
23 | \DP
24 | \end{center}
25 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.18.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{2}
7 | \UIM{A \wedge (B \vee C)}
8 | \UIM{B \vee C}
9 | \AXM{}
10 | \RLM{2}
11 | \UIM{A \wedge (B \vee C)}
12 | \UIM{A}
13 | \AXM{}
14 | \RLM{1}
15 | \UIM{B}
16 | \BIM{A \wedge B}
17 | \UIM{(A \wedge B) \vee (A \wedge C)}
18 | \AXM{}
19 | \RLM{2}
20 | \UIM{A \wedge (B \vee C)}
21 | \UIM{A}
22 | \AXM{}
23 | \RLM{1}
24 | \UIM{C}
25 | \BIM{A \wedge C}
26 | \UIM{(A \wedge B) \vee (A \wedge C)}
27 | \RLM{1}
28 | \TIM{(A \wedge B) \vee (A \wedge C)}
29 | \RLM{2}
30 | \UIM{(A \wedge (B \vee C)) \to ((A \wedge B) \vee (A \wedge C))}
31 | \DP
32 | \end{center}
33 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.19.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{3}
7 | \UIM{\neg (A \vee B)}
8 | \AXM{}
9 | \RLM{1}
10 | \UIM{A}
11 | \UIM{A \vee B}
12 | \BIM{\bot}
13 | \RLM{1}
14 | \UIM{\neg A}
15 | \AXM{}
16 | \RLM{3}
17 | \UIM{\neg (A \vee B)}
18 | \AXM{}
19 | \RLM{2}
20 | \UIM{B}
21 | \UIM{A \vee B}
22 | \BIM{\bot}
23 | \RLM{2}
24 | \UIM{\neg B}
25 | \BIM{\neg A \wedge \neg B}
26 | \RLM{3}
27 | \UIM{\neg (A \vee B) \to \neg A \wedge \neg B}
28 | \DP
29 | \end{center}
30 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.2.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{A}
6 | \AXM{B}
7 | \BIM{A \wedge B}
8 | \AXM{A}
9 | \AXM{C}
10 | \BIM{A \wedge C}
11 | \BIM{(A \wedge B) \wedge (A \wedge C)}
12 | \DP
13 | \end{center}
14 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.20.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{\neg A}
6 | \AXM{A}
7 | \BIM{\bot}
8 | \UIM{B}
9 | \DP
10 | \end{center}
11 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.21.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{\neg A \vee B}
6 | \AXM{}
7 | \RLM{1}
8 | \UIM{\neg A}
9 | \AXM{A}
10 | \BIM{\bot}
11 | \UIM{B}
12 | \AXM{}
13 | \RLM{1}
14 | \UIM{B}
15 | \RLM{1}
16 | \TIM{B}
17 | \DP
18 | \end{center}
19 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.22.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{A \wedge B}
6 | \UIM{B}
7 | \DP
8 | \quad\quad
9 | \AXM{A \wedge B}
10 | \UIM{A}
11 | \DP
12 | \end{center}
13 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.23.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{A \wedge B}
6 | \UIM{B}
7 | \AXM{A \wedge B}
8 | \UIM{A}
9 | \BIM{B \wedge A}
10 | \DP
11 | \end{center}
12 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.24.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{A \wedge B}
8 | \UIM{B}
9 | \AXM{}
10 | \RLM{1}
11 | \UIM{A \wedge B}
12 | \UIM{A}
13 | \BIM{B \wedge A}
14 | \RLM{1}
15 | \UIM{A \wedge B \to B \wedge A}
16 | \DP
17 | \end{center}
18 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.25.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{A \vee B}
6 | \AXM{A \to C}
7 | \AXM{}
8 | \RLM{1}
9 | \UIM{A}
10 | \BIM{C}
11 | \UIM{C \vee D}
12 | \AXM{B \to D}
13 | \AXM{}
14 | \RLM{1}
15 | \UIM{B}
16 | \BIM{D}
17 | \UIM{C \vee D}
18 | \RLM{1}
19 | \TIM{C \vee D}
20 | \DP
21 | \end{center}
22 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.3.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{A}
6 | \AXM{}
7 | \RLM{1}
8 | \UIM{B}
9 | \BIM{A \wedge B}
10 | \AXM{A}
11 | \AXM{C}
12 | \BIM{A \wedge C}
13 | \BIM{(A \wedge B) \wedge (A \wedge C)}
14 | \RLM{1}
15 | \UIM{B \to (A \wedge B) \wedge (A \wedge C)}
16 | \DP
17 | \end{center}
18 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.4.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{2}
7 | \UIM{A}
8 | \AXM{}
9 | \RLM{1}
10 | \UIM{B}
11 | \BIM{A \wedge B}
12 | \AXM{}
13 | \RLM{2}
14 | \UIM{A}
15 | \AXM{C}
16 | \BIM{A \wedge C}
17 | \BIM{(A \wedge B) \wedge (A \wedge C)}
18 | \RLM{1}
19 | \UIM{B \to (A \wedge B) \wedge (A \wedge C)}
20 | \RLM{2}
21 | \UIM{A \to (B \to (A \wedge B) \wedge (A \wedge C))}
22 | \DP
23 | \end{center}
24 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.5.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{2}
7 | \UIM{A}
8 | \AXM{}
9 | \RLM{1}
10 | \UIM{B}
11 | \BIM{A \wedge B}
12 | \AXM{}
13 | \RLM{2}
14 | \UIM{A}
15 | \AXM{}
16 | \RLM{3}
17 | \UIM{C}
18 | \BIM{A \wedge C}
19 | \BIM{(A \wedge B) \wedge (A \wedge C)}
20 | \RLM{1}
21 | \UIM{B \to (A \wedge B) \wedge (A \wedge C)}
22 | \RLM{2}
23 | \UIM{A \to (B \to (A \wedge B) \wedge (A \wedge C))}
24 | \RLM{3}
25 | \UIM{C \to (A \to (B \to (A \wedge B) \wedge (A \wedge C)))}
26 | \DP
27 | \end{center}
28 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.6.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{B}
6 | \UIM{A \to B}
7 | \DP
8 | \end{center}
9 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.7.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{A}
6 | \DP
7 | \end{center}
8 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.8.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{quote}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{A}
8 | \noLine
9 | \UIM{\vdots}
10 | \noLine
11 | \UIM{B}
12 | \RLM{1 \;\; \mathord{\to}\mathrm{I}}
13 | \UIM{A \to B}
14 | \DP
15 | \quad\quad
16 | \AXM{A \to B}
17 | \AXM{A}
18 | \RLM{\mathord{\to}\mathrm{E}}
19 | \BIM{B}
20 | \DP
21 | \end{quote}
22 | \end{document}
--------------------------------------------------------------------------------
/latex_images/natural_deduction_for_propositional_logic.9.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{quote}
5 | \AXM{A}
6 | \AXM{B}
7 | \RLM{\mathord{\wedge}\mathrm{I}}
8 | \BIM{A \wedge B}
9 | \DP
10 | \quad\quad
11 | \AXM{A \wedge B}
12 | \RLM{\mathord{\wedge}\mathrm{E_l}}
13 | \UIM{A}
14 | \DP
15 | \quad\quad
16 | \AXM{A \wedge B}
17 | \RLM{\mathord{\wedge}\mathrm{E_r}}
18 | \UIM{B}
19 | \DP
20 | \end{quote}
21 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic.1.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{A}
6 | \AXM{B}
7 | \BIM{C}
8 | \DP
9 | \end{center}
10 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic.10.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{A \vee B}
6 | \AXM{}
7 | \RLM{1}
8 | \UIM{A}
9 | \noLine
10 | \UIM{\vdots}
11 | \noLine
12 | \UIM{C}
13 | \AXM{}
14 | \RLM{1}
15 | \UIM{B}
16 | \noLine
17 | \UIM{\vdots}
18 | \noLine
19 | \UIM{C}
20 | \RLM{1 \; \; \mathord{\vee}\mathrm{E}}
21 | \TIM{C}
22 | \DP
23 | \end{center}
24 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic.11.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{A \vee B}
6 | \AXM{\neg A}
7 | \BIM{B}
8 | \DP
9 | \end{center}
10 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic.12.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{A}
8 | \noLine
9 | \UIM{\vdots}
10 | \noLine
11 | \UIM{B}
12 | \AXM{}
13 | \RLM{1}
14 | \UIM{B}
15 | \noLine
16 | \UIM{\vdots}
17 | \noLine
18 | \UIM{A}
19 | \RLM{1 \; \; \liff \mathrm{I}}
20 | \BIM{A \liff B}
21 | \DP
22 | \end{center}
23 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic.13.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{A \liff B}
6 | \AXM{A}
7 | \RLM{\liff \mathrm{E}_l}
8 | \BIM{B}
9 | \DP
10 | \quad
11 | \AXM{A \liff B}
12 | \AXM{B}
13 | \RLM{\liff \mathrm{E}_r}
14 | \BIM{A}
15 | \DP
16 | \end{center}
17 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic.14.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{\neg A}
8 | \noLine
9 | \UIM{\vdots}
10 | \noLine
11 | \UIM{\bot}
12 | \RLM{\mathrm{RAA}, 1}
13 | \UIM{A}
14 | \end{prooftree}
15 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic.2.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{A \to B}
6 | \AXM{A}
7 | \RLM{\mathord{\to}\mathrm{E}}
8 | \BIM{B}
9 | \DP
10 | \end{center}
11 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic.3.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{A}
8 | \noLine
9 | \UIM{\vdots}
10 | \noLine
11 | \UIM{B}
12 | \RLM{1 \; \; \mathord{\to}\mathrm{I}}
13 | \UIM{A \to B}
14 | \DP
15 | \end{center}
16 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic.4.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{A}
6 | \AXM{B}
7 | \RLM{\mathord{\wedge}\mathrm{I}}
8 | \BIM{A \wedge B}
9 | \DP
10 | \end{center}
11 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic.5.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{A \wedge B}
6 | \RLM{\mathord{\wedge}\mathrm{E_l}}
7 | \UIM{A}
8 | \DP
9 | \quad
10 | \AXM{A \wedge B}
11 | \RLM{\mathord{\wedge}\mathrm{E_r}}
12 | \UIM{B}
13 | \DP
14 | \end{center}
15 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic.6.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{A}
8 | \noLine
9 | \UIM{\vdots}
10 | \noLine
11 | \UIM{\bot}
12 | \RLM{1 \; \; \neg \mathrm{I}}
13 | \UIM{\neg A}
14 | \DP
15 | \end{center}
16 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic.7.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{\neg A}
6 | \AXM{A}
7 | \RLM{\neg \mathrm{E}}
8 | \BIM{\bot}
9 | \DP
10 | \end{center}
11 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic.8.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{\bot}
6 | \RLM{\bot \mathrm{E}}
7 | \UIM{A}
8 | \DP
9 | \end{center}
10 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic.8b.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \AXM{}
6 | \UIM{\top}
7 | \end{prooftree}
8 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic.9.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{A}
6 | \RLM{\mathord{\vee}\mathrm{I_l}}
7 | \UIM{A \vee B}
8 | \DP
9 | \quad
10 | \AXM{B}
11 | \RLM{\mathord{\vee}\mathrm{I_r}}
12 | \UIM{A \vee B}
13 | \DP
14 | \end{center}
15 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic_in_lean.1.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{\vdots}
6 | \noLine
7 | \UIM{P}
8 | \noLine
9 | \UIM{\vdots}
10 | \noLine
11 | \UIM{A \wedge B}
12 | \UIM{A}
13 | \DP
14 | \end{center}
15 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic_in_lean.2.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{h}
7 | \UIM{A \wedge \neg B}
8 | \UIM{A}
9 | \DP
10 | \quad\quad
11 | \AXM{}
12 | \RLM{h}
13 | \UIM{A \wedge \neg B}
14 | \UIM{\neg B}
15 | \DP
16 | \end{center}
17 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic_in_lean.2b.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{h}
7 | \UIM{A \wedge \neg B}
8 | \UIM{\neg B}
9 | \AXM{}
10 | \RLM{h}
11 | \UIM{A \wedge \neg B}
12 | \UIM{A}
13 | \BIM{\neg B \wedge A}
14 | \DP
15 | \end{center}
16 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic_in_lean.3.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{1}
7 | \UIM{A}
8 | \AXM{A \to B}
9 | \BIM{B}
10 | \AXM{B \to C}
11 | \BIM{C}
12 | \RLM{1}
13 | \UIM{A \to C}
14 | \DP
15 | \end{center}
16 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic_in_lean.4.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{2}
7 | \UIM{A \to (B \to C)}
8 | \AXM{}
9 | \RLM{1}
10 | \UIM{A \wedge B}
11 | \UIM{A}
12 | \BIM{B \to C}
13 | \AXM{}
14 | \RLM{1}
15 | \UIM{A \wedge B}
16 | \UIM{B}
17 | \BIM{C}
18 | \RLM{1}
19 | \UIM{A \wedge B \to C}
20 | \RLM{2}
21 | \UIM{(A \to (B \to C)) \to (A \wedge B \to C)}
22 | \DP
23 | \end{center}
24 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic_in_lean.5.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \AXM{}
6 | \RLM{2}
7 | \UIM{A \wedge (B \vee C)}
8 | \UIM{B \vee C}
9 | \AXM{}
10 | \RLM{2}
11 | \UIM{A \wedge (B \vee C)}
12 | \UIM{A}
13 | \AXM{}
14 | \RLM{1}
15 | \UIM{B}
16 | \BIM{A \wedge B}
17 | \UIM{(A \wedge B) \vee (A \wedge C)}
18 | \AXM{}
19 | \RLM{2}
20 | \UIM{A \wedge (B \vee C)}
21 | \UIM{A}
22 | \AXM{}
23 | \RLM{1}
24 | \UIM{C}
25 | \BIM{A \wedge C}
26 | \UIM{(A \wedge B) \vee (A \wedge C)}
27 | \RLM{1}
28 | \TIM{(A \wedge B) \vee (A \wedge C)}
29 | \RLM{2}
30 | \UIM{(A \wedge (B \vee C)) \to ((A \wedge B) \vee
31 | (A \wedge C))}
32 | \DP
33 | \end{center}
34 | \end{document}
--------------------------------------------------------------------------------
/latex_images/propositional_logic_in_lean.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \def\fCenter{\ \vdash\ }
6 | \Axiom$\Gamma \fCenter A$
7 | \Axiom$\Delta \fCenter B$
8 | \BinaryInf$\Gamma, \Delta \fCenter A \wedge B$
9 | \end{prooftree}
10 | \end{document}
--------------------------------------------------------------------------------
/latex_images/semantics_of_propositional_logic.1.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \AXM{B}
6 | \UIM{A \to B}
7 | \end{prooftree}
8 | \end{document}
--------------------------------------------------------------------------------
/latex_images/semantics_of_propositional_logic.2.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \AXM{\neg A}
6 | \AXM{}
7 | \RLM{1}
8 | \UIM{A}
9 | \BIM{\bot}
10 | \RLM{1}
11 | \UIM{A \to B}
12 | \end{prooftree}
13 | \end{document}
--------------------------------------------------------------------------------
/latex_images/semantics_of_propositional_logic.3.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \AXM{\neg B}
6 | \AXM{}
7 | \RLM{1}
8 | \UIM{A \to B}
9 | \AXM{A}
10 | \BIM{B}
11 | \BIM{\bot}
12 | \RLM{1}
13 | \UIM{\neg (A \to B)}
14 | \end{prooftree}
15 | \end{document}
--------------------------------------------------------------------------------
/latex_images/semantics_of_propositional_logic.4.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \begin{tabular} {|c|c||c|}
6 | \hline
7 | $A$ & $B$ & $A \wedge B$ \\ \hline
8 | $\mathbf{T}$ & $\mathbf{T}$ & $\mathbf{T}$ \\ \hline
9 | $\mathbf{T}$ & $\mathbf{F}$ & $\mathbf{F}$ \\ \hline
10 | $\mathbf{F}$ & $\mathbf{T}$ & $\mathbf{F}$ \\ \hline
11 | $\mathbf{F}$ & $\mathbf{F}$ & $\mathbf{F}$ \\ \hline
12 | \end{tabular}
13 | \quad
14 | \begin{tabular} {|c|c||c|}
15 | \hline
16 | $A$ & $B$ & $A \vee B$ \\ \hline
17 | $\mathbf{T}$ & $\mathbf{T}$ & $\mathbf{T}$ \\ \hline
18 | $\mathbf{T}$ & $\mathbf{F}$ & $\mathbf{T}$ \\ \hline
19 | $\mathbf{F}$ & $\mathbf{T}$ & $\mathbf{T}$ \\ \hline
20 | $\mathbf{F}$ & $\mathbf{F}$ & $\mathbf{F}$ \\ \hline
21 | \end{tabular}
22 | \quad
23 | \begin{tabular} {|c|c||c|}
24 | \hline
25 | $A$ & $B$ & $A \to B$ \\ \hline
26 | $\mathbf{T}$ & $\mathbf{T}$ & $\mathbf{T}$ \\ \hline
27 | $\mathbf{T}$ & $\mathbf{F}$ & $\mathbf{F}$ \\ \hline
28 | $\mathbf{F}$ & $\mathbf{T}$ & $\mathbf{T}$ \\ \hline
29 | $\mathbf{F}$ & $\mathbf{F}$ & $\mathbf{T}$ \\ \hline
30 | \end{tabular}
31 | \end{center}
32 | \end{document}
--------------------------------------------------------------------------------
/latex_images/semantics_of_propositional_logic.5.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{center}
5 | \begin{tabular} {|c|c|c||c|c||c|}
6 | \hline
7 | $A$ & $B$ & $C$ & $A \to B$ & $B \to C$ & $(A \to B) \vee (B \to C)$ \\ \hline
8 | $\mathbf{T}$ & $\mathbf{T}$ & $\mathbf{T}$ & $\mathbf{T}$ & $\mathbf{T}$ & $\mathbf{T}$ \\ \hline
9 | $\mathbf{T}$ & $\mathbf{T}$ & $\mathbf{F}$ & $\mathbf{T}$ & $\mathbf{F}$ & $\mathbf{T}$ \\ \hline
10 | $\mathbf{T}$ & $\mathbf{F}$ & $\mathbf{T}$ & $\mathbf{F}$ & $\mathbf{T}$ & $\mathbf{T}$ \\ \hline
11 | $\mathbf{T}$ & $\mathbf{F}$ & $\mathbf{F}$ & $\mathbf{F}$ & $\mathbf{T}$ & $\mathbf{T}$ \\ \hline
12 | $\mathbf{F}$ & $\mathbf{T}$ & $\mathbf{T}$ & $\mathbf{T}$ & $\mathbf{T}$ & $\mathbf{T}$ \\ \hline
13 | $\mathbf{F}$ & $\mathbf{T}$ & $\mathbf{F}$ & $\mathbf{T}$ & $\mathbf{F}$ & $\mathbf{T}$ \\ \hline
14 | $\mathbf{F}$ & $\mathbf{F}$ & $\mathbf{T}$ & $\mathbf{T}$ & $\mathbf{T}$ & $\mathbf{T}$ \\ \hline
15 | $\mathbf{F}$ & $\mathbf{F}$ & $\mathbf{F}$ & $\mathbf{T}$ & $\mathbf{T}$ & $\mathbf{T}$ \\ \hline
16 | \end{tabular}
17 | \end{center}
18 | \end{document}
--------------------------------------------------------------------------------
/latex_images/sets.1.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \small
6 | \AXM{y \in A \cap (B \cup C)}
7 | \UIM{y \in B \cup C}
8 |
9 | \AXM{y \in A \cap (B \cup C)}
10 | \UIM{y \in A}
11 | \AXM{}
12 | \RLM{1}
13 | \UIM{y \in B}
14 | \BIM{y \in A \cap B}
15 | \UIM{y \in (A \cap B) \cup (A \cap C)}
16 |
17 | \AXM{y \in A \cap (B \cup C)}
18 | \UIM{y \in A}
19 | \AXM{}
20 | \RLM{1}
21 | \UIM{y \in C}
22 | \BIM{y \in A \cap C}
23 | \UIM{y \in (A \cap B) \cup (A \cap C)}
24 | \RLM{1}
25 | \TIM{y \in (A \cap B) \cup (A \cap C)}
26 | \end{prooftree}
27 | \end{document}
--------------------------------------------------------------------------------
/latex_images/template.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \def\fCenter{\ \vdash\ }
6 | \Axiom$\Gamma \fCenter A$
7 | \Axiom$\Delta \fCenter B$
8 | \BinaryInf$\Gamma, \Delta \fCenter A \wedge B$
9 | \end{prooftree}
10 | \end{document}
--------------------------------------------------------------------------------
/latex_images/the_natural_numbers_and_induction.1.tex:
--------------------------------------------------------------------------------
1 | \documentclass[preview]{standalone}
2 | \usepackage{bussproofs,mylogic}
3 | \begin{document}
4 | \begin{prooftree}
5 | \AXM{P(0)}
6 | \AXM{}
7 | \RLM{1}
8 | \UIM{P(n)}
9 | \noLine
10 | \UIM{\vdots}
11 | \noLine
12 | \UIM{P(n+1)}
13 | \BIM{\forall n \; P(n)}
14 | \end{prooftree}
15 | \end{document}
--------------------------------------------------------------------------------
/lean_sphinx.py:
--------------------------------------------------------------------------------
1 | from docutils import nodes
2 | from docutils.parsers.rst import Directive
3 | from sphinx.builders import Builder
4 | from sphinx.directives.code import CodeBlock
5 | from sphinx.errors import SphinxError
6 | import os, os.path, fnmatch, subprocess
7 | import codecs
8 | import urllib
9 | import re
10 |
11 | try:
12 | urlquote = urllib.parse.quote
13 | except:
14 | # Python 2
15 | def urlquote(s, safe='/'):
16 | return urllib.quote(s.encode('utf-8'), safe)
17 |
18 |
19 | # "Try it!" button
20 |
21 | class lean_code_goodies(nodes.General, nodes.Element): pass
22 |
23 | def mk_try_it_uri(code):
24 | uri = 'https://live.lean-lang.org/#code='
25 | uri += urlquote(code, safe='~()*!.\'')
26 | return uri
27 |
28 | def process_lean_nodes(app, doctree, fromdocname):
29 | env = app.builder.env
30 | for node in doctree.traverse(nodes.literal_block):
31 | if node['language'] != 'lean': continue
32 |
33 | new_node = lean_code_goodies()
34 | new_node['full_code'] = node.rawsource
35 | node.replace_self([new_node])
36 |
37 | code = node.rawsource
38 | m = re.search(r'--[^\n]*BEGIN[^\n]*\n(.*)--[^\n]*END', code, re.DOTALL)
39 | if m:
40 | node = nodes.literal_block(m.group(1), m.group(1))
41 | node['language'] = 'lean'
42 | new_node += node
43 |
44 | if app.builder.name.startswith('epub'):
45 | new_node.replace_self([node])
46 |
47 | def html_visit_lean_code_goodies(self, node):
48 | self.body.append(self.starttag(node, 'div', style='position: relative'))
49 | self.body.append("")
50 | self.body.append(self.starttag(node, 'a', target='_blank', href=mk_try_it_uri(node['full_code'])))
51 | self.body.append('try it!
')
52 |
53 | def html_depart_lean_code_goodies(self, node):
54 | self.body.append('')
55 |
56 | def latex_visit_lean_code_goodies(self, node):
57 | pass
58 |
59 | def latex_depart_lean_code_goodies(self, node):
60 | pass
61 |
62 | # Extract code snippets for testing.
63 |
64 | class LeanTestBuilder(Builder):
65 | '''
66 | Extract ``..code-block:: lean`` directives for testing.
67 | '''
68 | name = 'leantest'
69 |
70 | def init(self):
71 | self.written_files = set()
72 |
73 | def write_doc(self, docname, doctree):
74 | i = 0
75 | for node in doctree.traverse(lean_code_goodies):
76 | i += 1
77 | fn = os.path.join(self.outdir, '{0}_{1}.lean'.format(docname, i))
78 | self.written_files.add(fn)
79 | out = codecs.open(fn, 'w', encoding='utf-8')
80 | out.write(node['full_code'])
81 |
82 | def finish(self):
83 | for root, _, filenames in os.walk(self.outdir):
84 | for fn in fnmatch.filter(filenames, '*.lean'):
85 | fn = os.path.join(root, fn)
86 | if fn not in self.written_files:
87 | os.remove(fn)
88 |
89 | proc = subprocess.Popen(['lean', '--make', self.outdir], stdout=subprocess.PIPE)
90 | stdout, stderr = proc.communicate()
91 | errors = '\n'.join(l for l in stdout.decode('utf-8').split('\n') if ': error:' in l)
92 | if errors != '': raise SphinxError('\nlean exited with errors:\n{0}\n'.format(errors))
93 | retcode = proc.wait()
94 | if retcode: raise SphinxError('lean exited with error code {0}'.format(retcode))
95 |
96 | def prepare_writing(self, docnames): pass
97 |
98 | def get_target_uri(self, docname, typ=None):
99 | return ''
100 |
101 | def get_outdated_docs(self):
102 | return self.env.found_docs
103 |
104 | def setup(app):
105 | app.add_node(lean_code_goodies,
106 | html=(html_visit_lean_code_goodies, html_depart_lean_code_goodies),
107 | latex=(latex_visit_lean_code_goodies, latex_depart_lean_code_goodies))
108 | app.connect('doctree-resolved', process_lean_nodes)
109 |
110 | app.add_builder(LeanTestBuilder)
111 |
112 | return {'version': '0.1'}
113 |
--------------------------------------------------------------------------------
/leanpkg.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "logic_and_proof"
3 | version = "0.1"
4 | lean_version = "leanprover-community/lean:3.32.1"
5 | path = "src"
6 |
7 | [dependencies]
8 | mathlib = {git = "https://github.com/leanprover-community/mathlib", rev = "5dc8bc169bd8773735520e6b9680ce3b65b80bd7"}
9 |
--------------------------------------------------------------------------------
/mylogic.sty:
--------------------------------------------------------------------------------
1 |
2 | \newcommand{\horizontalrule}{\noindent \rule{\linewidth}{0.5pt}}
3 |
4 | % theorem environments
5 |
6 | \newtheorem{theorem}{Theorem}[section]
7 | \newtheorem{lemma}[theorem]{Lemma}
8 | \newtheorem{proposition}[theorem]{Proposition}
9 | \newtheorem{definition}[theorem]{Definition}
10 | \newtheorem{corollary}[theorem]{Corollary}
11 |
12 | % special fonts for theory names, functions, axioms, etc.
13 | \newcommand{\fn}[1]{\mathit{#1}} % function; e.g. successor
14 | \newcommand{\mdl}[1]{\frak{#1}} % model; e.g. M
15 |
16 | % logical connectives
17 | \newcommand{\liff}{\leftrightarrow}
18 | \newcommand{\ex}[1]{\exists #1 \;} % exists x ...
19 | \newcommand{\fa}[1]{\forall #1 \;} % forall x ...
20 | \newcommand{\lam}[1]{\lambda #1 \;} % forall x ...
21 | \newcommand{\exunique}[1]{\exists ! #1 \;}
22 |
23 | % useful symbols
24 | \newcommand{\proves}{\vdash}
25 | \newcommand{\nproves}{\nvdash}
26 | \newcommand{\forces}{\Vdash}
27 | \newcommand{\nforces}{\nVdash}
28 |
29 | \newcommand{\ph}{\varphi}
30 |
31 | \newcommand{\st}{\mid} % x such that ...
32 | \newcommand{\dash}{\mathord{\mbox{-}}}
33 |
34 | \newcommand{\inv}{^{-1}}
35 |
36 | % useful abbreviations
37 | \newcommand{\NN}{\mathbb{N}}
38 | \newcommand{\ZZ}{\mathbb{Z}}
39 | \newcommand{\QQ}{\mathbb{Q}}
40 | \newcommand{\RR}{\mathbb{R}}
41 | \newcommand{\CC}{\mathbb{C}}
42 | \newcommand{\lqt}{\mbox{`}}
43 | \newcommand{\rqt}{\mbox{'}}
44 | \newcommand{\true}{\mathbf{T}}
45 | \newcommand{\false}{\mathbf{F}}
46 | \newcommand{\MM}{\mathcal{M}}
47 |
48 | % BussProofs abbreviations
49 | \newcommand{\AXM}[1]{\AXC{$#1$}}
50 | \newcommand{\UIM}[1]{\UIC{$#1$}}
51 | \newcommand{\BIM}[1]{\BIC{$#1$}}
52 | \newcommand{\TIM}[1]{\TIC{$#1$}}
53 | \newcommand{\AXN}[1]{\AX$#1$}
54 | \newcommand{\BIN}[1]{\BI$#1$}
55 | \newcommand{\UIN}[1]{\UI$#1$}
56 | \newcommand{\TIN}[1]{\TI$#1$}
57 | % \newcommand{\RLM}[1]{\RL{$\mathrm{#1}$}}
58 | \newcommand{\RLM}[1]{\RL{$\scriptstyle #1$}}
59 |
60 | % common predicates and relations
61 | \newcommand{\even}{\ensuremath{\fn{even}}}
62 | \newcommand{\odd}{\ensuremath{\fn{odd}}}
63 | \newcommand{\primep}{\ensuremath{\fn{prime}}}
64 | \newcommand{\suc}{\ensuremath{\fn{succ}}}
65 | \newcommand{\tsub}{\mathbin{\mathchoice% truncated subtraction
66 | {\buildrel .\lower.6ex\hbox{\vphantom{.}} \over {\smash-}}%
67 | {\buildrel .\lower.6ex\hbox{\vphantom{.}} \over {\smash-}}%
68 | {\buildrel .\lower.4ex\hbox{\vphantom{.}} \over {\smash-}}%
69 | {\buildrel .\lower.3ex\hbox{\vphantom{.}} \over {\smash-}}}}
70 |
71 | \EnableBpAbbreviations
72 |
73 |
--------------------------------------------------------------------------------
/nd_quickref.rst:
--------------------------------------------------------------------------------
1 | Appendix: Natural Deduction Rules
2 | =================================
3 |
4 | .. include:: inference_rules_for_propositional_logic.rst
5 | .. include:: inference_rules_for_first_order_logic.rst
6 |
--------------------------------------------------------------------------------
/png_images/card_diagram_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/logic_and_proof/cb1efe705c5d6f901cedfce5bb46f67f98188096/png_images/card_diagram_1.png
--------------------------------------------------------------------------------
/png_images/card_diagram_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/logic_and_proof/cb1efe705c5d6f901cedfce5bb46f67f98188096/png_images/card_diagram_2.png
--------------------------------------------------------------------------------
/png_images/card_diagram_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/logic_and_proof/cb1efe705c5d6f901cedfce5bb46f67f98188096/png_images/card_diagram_3.png
--------------------------------------------------------------------------------
/png_images/card_diagram_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/logic_and_proof/cb1efe705c5d6f901cedfce5bb46f67f98188096/png_images/card_diagram_4.png
--------------------------------------------------------------------------------
/png_images/card_diagram_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leanprover-community/logic_and_proof/cb1efe705c5d6f901cedfce5bb46f67f98188096/png_images/card_diagram_5.png
--------------------------------------------------------------------------------
/relations.rst:
--------------------------------------------------------------------------------
1 | .. _relations:
2 |
3 | Relations
4 | =========
5 |
6 | In :numref:`Chapter %s ` we discussed the notion of a *relation symbol* in first-order logic, and in :numref:`Chapter %s ` we saw how to interpret such a symbol in a model. In mathematics, we are generally interested in different sorts of relationships between mathematical objects, and so the notion of a relation is ubiquitous. In this chapter, we will consider some common kinds of relations.
7 |
8 | In some axiomatic foundations, the notion of a relation is taken to be primitive, but in axiomatic set theory, a relation is taken to be a set of tuples of the corresponding arity. For example, we can take a binary relation on :math:`A` to be a subset of :math:`A \times A`, where :math:`R(a, b)` means that :math:`(a, b) \in R`. The foundational definition is generally irrelevant to everyday mathematical practice; what is important is simply that we can write expressions like :math:`R(a, b)`, and that they are true or false, depending on the values of :math:`a` and :math:`b`. In mathematics, we often use *infix* notation, writing :math:`a \mathrel{R} b` instead of :math:`R(a, b)`.
9 |
10 | .. _order_relations:
11 |
12 | Order Relations
13 | ---------------
14 |
15 | We will start with a class of important binary relations in mathematics, namely, *partial orders*.
16 |
17 | ----
18 |
19 | **Definition.** A binary relation :math:`\leq` on a domain :math:`A` is a *partial order* if it has the following three properties:
20 |
21 | - *reflexivity*: :math:`a \leq a`, for every :math:`a` in :math:`A`
22 | - *transitivity*: if :math:`a \leq b` and :math:`b \leq c`, then :math:`a \leq c`, for every :math:`a`, :math:`b`, and :math:`c` in :math:`A`
23 | - *antisymmetry*: if :math:`a \leq b` and :math:`b \leq a` then :math:`a = b`, for every :math:`a` and :math:`b` in :math:`A`
24 |
25 | ----
26 |
27 | Notice the compact way of introducing the symbol :math:`\leq` in the statement of the definition, and the fact that :math:`\leq` is written as an infix symbol. Notice also that even though the relation is written with the symbol :math:`\leq`, it is the only symbol occurring in the definition; mathematical practice favors natural language to describe its properties.
28 |
29 | You now know enough, however, to recognize the universal quantifiers that are present in the three clauses. In symbolic logic, we would write them as follows:
30 |
31 | - :math:`\forall a \; (a \leq a)`
32 | - :math:`\forall a, b, c \; (a \leq b \wedge b \leq c \to a \leq c)`
33 | - :math:`\forall a, b \; (a \leq b \wedge b \leq a \to a = b)`
34 |
35 | Here the variables :math:`a`, :math:`b`, and :math:`c` implicitly range over the domain :math:`A`.
36 |
37 | The use of the symbol :math:`\leq` is meant to be suggestive, and, indeed, the following are all examples of partial orders:
38 |
39 | - :math:`\leq` on the natural numbers
40 | - :math:`\leq` on the integers
41 | - :math:`\leq` on the rational numbers
42 | - :math:`\leq` on the real numbers
43 |
44 | But keep in mind that :math:`\leq` is only a symbol; it can have unexpected interpretations as well. For example, the :math:`\geq` relation on any of these domains is also a partial order, and can interpret the :math:`\leq` symbol just as well.
45 |
46 | These are not fully representative of the class of partial orders, in that they all have an additional property:
47 |
48 | ----
49 |
50 | **Definition.** A partial order :math:`\leq` on a domain :math:`A` is a *total order* (also called a *linear order*) if it also has the following property:
51 |
52 | - for every :math:`a` and :math:`b` in :math:`A`, either :math:`a \leq b` or :math:`b \leq a`
53 |
54 | ----
55 |
56 | You can check these these are two examples of partial orders that are not total orders:
57 |
58 | - the divides relation, :math:`x \mid y`, on the integers
59 | - the subset relation, :math:`x \subseteq y`, on sets of elements of some domain :math:`A`
60 |
61 | On the integers, we also have the strict order relation, :math:`<`, which is not a partial order, since it is not reflexive. It is, rather, an instance of a *strict partial order*:
62 |
63 | ----
64 |
65 | **Definition.** A binary relation :math:`<` on a domain :math:`A` is a *strict partial order* if it satisfies the following:
66 |
67 | - *irreflexivity*: :math:`a \nless a` for every :math:`a` in :math:`A`
68 | - *transitivity*: :math:`a < b` and :math:`b < c` implies :math:`a < c`, for every :math:`a`, :math:`b`, and :math:`c` in :math:`A`
69 |
70 | A strict partial order is a *strict total order* (or *strict linear order*) if, in addition, we have the following property:
71 |
72 | - *trichotomy*: :math:`a < b`, :math:`a = b`, or :math:`a > b` for every :math:`a` and :math:`b` in :math:`A`
73 |
74 | ----
75 |
76 | Here, :math:`b \nless a` means, of course, that it is not the case that :math:`a < b`, and :math:`a > b` is alternative notation for :math:`b < a`. To distinguish an ordinary partial order from a strict one, an ordinary partial order is sometimes called a *weak* partial order.
77 |
78 | ----
79 |
80 | **Proposition**. A strict partial order :math:`<` on :math:`A` is *asymmetric*: for every :math:`a` and :math:`b`, :math:`a < b` implies :math:`b \nless a`.
81 |
82 | **Proof**. Suppose :math:`a < b` and :math:`b < a`. Then, by transitivity, :math:`a < a`, contradicting irreflexivity.
83 |
84 | ----
85 |
86 | On the integers, there are precise relationships between :math:`<` and :math:`\leq`: :math:`x \leq y` if and only if :math:`x < y` or :math:`x = y`, and :math:`x < y` if and only if :math:`x \leq y` and :math:`x \neq y`. This illustrates a more general phenomenon.
87 |
88 | ----
89 |
90 | **Theorem.** Suppose :math:`\leq` is a partial order on a domain :math:`A`. Define :math:`a < b` to mean that :math:`a \leq b` and :math:`a \neq b`. Then :math:`<` is a strict partial order. Moreover, if :math:`\leq` is total, so is :math:`<`.
91 |
92 | **Theorem.** Suppose :math:`<` is a strict partial order on a domain :math:`A`. Define :math:`a \leq b` to mean :math:`a < b` or :math:`a = b`. Then :math:`\leq` is a partial order. Moreover, if :math:`<` is total, so is :math:`\leq`.
93 |
94 | ----
95 |
96 | We will prove the first here, and leave the second as an exercise. This proof is a nice illustration of how universal quantification, equality, and propositional reasoning are combined in a mathematical argument.
97 |
98 | ----
99 |
100 | **Proof**. Suppose :math:`\leq` is a partial order on :math:`A`, and :math:`<` be defined as in the statement of the theorem. Irreflexivity is immediate, since :math:`a < a` implies :math:`a \neq a`, which is a contradiction.
101 |
102 | To show transitivity, suppose :math:`a < b` and :math:`b < c`. Then we have :math:`a \leq b`, :math:`b \leq c`, :math:`a \neq b`, and :math:`b \neq c`. By the transitivity of :math:`\leq`, we have :math:`a \leq c`. To show :math:`a < c`, we only have to show :math:`a \neq c`. So suppose :math:`a = c`. then, from the hypotheses, we have :math:`c < b` and :math:`b < c`. From the definition of :math:`<`, we have :math:`c \leq b`, :math:`b \leq c`, and :math:`c \neq b`. But the first two imply :math:`c = b`, a contradiction. So :math:`a \neq c`, as required.
103 |
104 | To establish the last claim in the theorem, suppose :math:`\leq` is total, and let :math:`a` and :math:`b` be any elements of :math:`A`. We need to show that :math:`a < b`, :math:`a = b`, or :math:`a > b`. If :math:`a = b`, we are done, so we can assume :math:`a \neq b`. Since :math:`\leq` is total, we have :math:`a \leq b` or :math:`b \leq a`. Since :math:`a \neq b`, in the first case we have :math:`a < b`, and in the second case, we have :math:`a > b`.
105 |
106 | ----
107 |
108 | More on Orderings
109 | -----------------
110 |
111 | Let :math:`\leq` be a partial order on a domain, :math:`A`, and let :math:`<` be the associated strict order, as defined in the last section. It is possible to show that if we go in the other direction, and define :math:`\leq'` to be the partial order associated to :math:`<`, then :math:`\leq` and :math:`\leq'` are the same, which is to say, for every :math:`a` and :math:`b` in :math:`A`, :math:`a \leq b` if and only if :math:`a \leq' b`. So we can think of every partial order as really being a pair, consisting of a weak partial order and an associated strict one. In other words, we can assume that :math:`x < y` holds if and only if :math:`x \leq y` and :math:`x \neq y`, and we can assume :math:`x \leq y` holds if and only if :math:`x < y` or :math:`x = y`.
112 |
113 | We will henceforth adopt this convention. Given a partial order :math:`\leq` and the associated strict order :math:`<`, we leave it to you to show that if :math:`x \leq y` and :math:`y < z`, then :math:`x < z`, and, similarly, if :math:`x < y` and :math:`y \leq z`, then :math:`x < z`.
114 |
115 | Consider the natural numbers with the less-than-or-equal relation. It has a least element, :math:`0`. We can express the fact that :math:`0` is the least element in at least two ways:
116 |
117 | - :math:`0` is less than or equal to every natural number.
118 | - There is no natural number that is less than :math:`0`.
119 |
120 | In symbolic logic, we could formalize these statements as follows:
121 |
122 | - :math:`\forall x \; (0 \leq x)`
123 | - :math:`\forall x \; (x \nless 0)`
124 |
125 | Using the existential quantifier, we could render the second statement more faithfully as follows:
126 |
127 | - :math:`\neg \exists x \; (x < 0)`
128 |
129 | Notice that this more faithful statement is equivalent to the original, using deMorgan's laws for quantifiers.
130 |
131 | Are the two statements above equivalent? Say an element :math:`y` is *minimum* for a partial order if it is less than or equal to any other element, that is, if it takes the place of 0 in the first statement. Say that an element :math:`y` is *minimal* for a partial order if no element is less than it, that is, if it takes the place of 0 in the second statement. Two facts are immediate.
132 |
133 | ----
134 |
135 | **Theorem.** Any minimum element is minimal.
136 |
137 | **Proof.** Suppose :math:`x` is minimum for :math:`\leq`. We need to show that :math:`x` is minimal, that is, for every :math:`y`, it is not the case that :math:`y < x`. Suppose :math:`y < x`. Since :math:`x` is minimum, we have :math:`x \leq y`. From :math:`y < x` and :math:`x \leq y`, we have :math:`y < y`, contradicting the irreflexivity of :math:`<`.
138 |
139 | **Theorem.** If a partial order :math:`\leq` has a minimum element, it is unique.
140 |
141 | **Proof.** Suppose :math:`x_1` and :math:`x_2` are both minimum. Then :math:`x_1 \leq x_2` and :math:`x_2 \leq x_1`. By antisymmetry, :math:`x_1 = x_2`.
142 |
143 | ----
144 |
145 | Notice that we have interpreted the second theorem as the statement that if :math:`x_1` and :math:`x_2` are both minimum, then :math:`x_1 = x_2`. Indeed, this is exactly what we mean when we say that something is "unique." When a partial order has a minimum element :math:`x`, uniqueness is what justifies calling :math:`x` *the* minimum element. Such an :math:`x` is also called the *least* element or the *smallest* element, and the terms are generally interchangeable.
146 |
147 | The converse to the first theorem -- that is, the statement that every minimal element is minimum -- is false. As an example, consider the nonempty subsets of the set :math:`\{ 1, 2 \}` with the subset relation. In other words, consider the collection of sets :math:`\{ 1 \}`, :math:`\{ 2 \}`, and :math:`\{1, 2\}`, where :math:`\{ 1 \} \subseteq \{1, 2\}`, :math:`\{ 2 \} \subseteq \{1, 2\}`, and, of course, every element is a subset of itself. Then you can check that :math:`\{1\}` and :math:`\{2\}` are each minimal, but neither is minimum. (One can also exhibit such a partial order by drawing a diagram, with dots labeled :math:`a`, :math:`b`, :math:`c`, etc., and upwards edges between elements to indicate that one is less than or equal to the other.)
148 |
149 | Notice that the statement "a minimal element of a partial order is not necessarily minimum" makes an "existential" assertion: it says that there is a partial order :math:`\leq`, and an element :math:`x` of the domain, such that :math:`x` is minimal but not minimum. For a fixed partial order :math:`\leq`, we can express the assertion that such an :math:`x` exists as follows:
150 |
151 | .. math::
152 |
153 | \exists x \; (\forall y \; (y \nless x) \wedge \neg \forall y \; (x \leq y)).
154 |
155 | The assertion that there exists a domain :math:`A`, and a partial order :math:`\leq` on that domain :math:`A`, is more dramatic: it is a "higher order" existential assertion. But symbolic logic provides us with the means to make assertions like these as well, as we will see later on.
156 |
157 | We can consider other properties of orders. An order is said to be *dense* if between any two distinct elements, there is another element. More precisely, an order is dense if, whenever :math:`x < y`, there is an element :math:`z` satisfying :math:`x < z` and :math:`z < y`. For example, the rational numbers are dense with the usual :math:`\leq` ordering, but not the integers. Saying that an order is dense is another example of an implicit use of existential quantification.
158 |
159 | .. _equivalence_relations_and_equality:
160 |
161 | Equivalence Relations and Equality
162 | ----------------------------------
163 |
164 | In ordinary mathematical language, an *equivalence relation* is defined as follows.
165 |
166 | ----
167 |
168 | **Definition**. A binary relation :math:`\equiv` on some domain :math:`A` is said to be an *equivalence relation* if it is reflexive, symmetric, and transitive. In other words, :math:`\equiv` is an equivalent relation if it satisfies these three properties:
169 |
170 | - *reflexivity*: :math:`a \equiv a`, for every :math:`a` in :math:`A`
171 | - *symmetry*: if :math:`a \equiv b`, then :math:`b \equiv a`, for every :math:`a` and :math:`b` in :math:`A`
172 | - *transitivity*: if :math:`a \equiv b` and :math:`b \equiv c`, then :math:`a \equiv c`, for every :math:`a`, :math:`b`, and :math:`c` in :math:`A`
173 |
174 | ----
175 |
176 | We leave it to you to think about how you could write these statements in first-order logic. (Note the similarity to the rules for a partial order.) We will also leave you with an exercise: by a careful choice of how to instantiate the quantifiers, you can actually prove the three properties above from the following two:
177 |
178 | - :math:`\forall a \; (a \equiv a)`
179 | - :math:`\forall {a, b, c} \; (a \equiv b \wedge c \equiv b \to a \equiv c)`
180 |
181 | Try to verify this using natural deduction or Lean.
182 |
183 | These three properties alone are not strong enough to characterize equality. You should check that the following informal examples are all instances of equivalence relations:
184 |
185 | - the relation on days on the calendar, given by ":math:`x` and :math:`y` fall on the same day of the week"
186 | - the relation on people currently alive on the planet, given by ":math:`x` and :math:`y` have the same age"
187 | - the relation on people currently alive on the planet, given by ":math:`x` and :math:`y` have the same birthday"
188 | - the relation on cities in the United States, given by ":math:`x` and :math:`y` are in the same state"
189 |
190 | Here are two common mathematical examples:
191 |
192 | - the relation on lines in a plane, given by ":math:`x` and :math:`y` are parallel"
193 | - for any fixed natural number :math:`m \geq 0`, the relation on natural numbers, given by ":math:`x` is congruent to :math:`y` modulo :math:`m`" (see :numref:`Chapter %s `)
194 |
195 | Here, we say that :math:`x` is congruent to :math:`y` modulo :math:`m` if they leave the same remainder when divided by :math:`m`. Soon, you will be able to prove rigorously that this is equivalent to saying that :math:`x - y` is divisible by :math:`m`.
196 |
197 | Consider the equivalence relation on citizens of the United States, given by ":math:`x` and :math:`y` have the same age." There are some properties that respect that equivalence. For example, suppose I tell you that John and Susan have the same age, and I also tell you that John is old enough to vote. Then you can rightly infer that Susan is old enough to vote. On the other hand, if I tell you nothing more than the facts that John and Susan have the same age and John lives in South Dakota, you cannot infer that Susan lives in South Dakota. This little example illustrates what is special about the *equality* relation: if two things are equal, then they have exactly the same properties.
198 |
199 | Let :math:`A` be a set and let :math:`\equiv` be an equivalence relation on :math:`A`. There is an important mathematical construction known as forming the *quotient* of :math:`A` under the equivalence relation. For every element :math:`a` in :math:`A`, let :math:`[a]` be the set of elements :math:`\{ c \mid c \equiv a \}`, that is, the set of elements of :math:`A` that are equivalent to :math:`a`. We call :math:`[a]` the equivalence class of :math:`A`. The set :math:`A / \mathord{\equiv}`, the *quotient of* :math:`A` *by* :math:`\equiv`, is defined to be the set :math:`\{ [a] : a \in A \}`, that is, the set of all the equivalence classes of elements in :math:`A`. The exercises below as you to show that if :math:`[a]` and :math:`[b]` are elements of such a quotient, then :math:`[a] = [b]` if and only if :math:`a \equiv b`.
200 |
201 | The motivation is as follows. Equivalence tries to capture a weak notion of equality: if two elements of :math:`A` are equivalent, they are not necessarily the same, but they are similar in some way. Equivalence classes collect similar objects together, essentially glomming them into new objects. Thus :math:`A / \mathord{\equiv}` is a version of the set :math:`A` where similar elements have been compressed into a single element. For example, given the equivalence relation :math:`\equiv` of congruence modulo 5 on the integers, :math:`\mathbb{N} / \mathord{\equiv}` is the set :math:`\{ [0], [1], [2], [3], [4] \}`, where, for example, :math:`[0]` is the set of all multiples of 5.
202 |
203 | Exercises
204 | ---------
205 |
206 | #. Suppose :math:`<` is a strict partial order on a domain :math:`A`, and define :math:`a \leq b` to mean that :math:`a < b` or :math:`a = b`.
207 |
208 | - Show that :math:`\leq` is a partial order.
209 | - Show that if :math:`<` is moreover a strict total order, then :math:`\leq` is a total order.
210 |
211 | (Above we proved the analogous theorem going in the other direction.)
212 |
213 | #. Suppose :math:`<` is a strict partial order on a domain :math:`A`. (In other words, it is transitive and asymmetric.) Suppose that :math:`\leq` is defined so that :math:`a \leq b` if and only if :math:`a < b` or :math:`a = b`. We saw in class that :math:`\leq` is a partial order on a domain :math:`A`, i.e.~it is reflexive, transitive, and antisymmetric.
214 |
215 | Prove that for every :math:`a` and :math:`b` in :math:`A`, we have :math:`a < b` iff :math:`a \leq b` and :math:`a \neq b`, using the facts above.
216 |
217 | #. An *ordered graph* is a collection of vertices (points), along with a collection of arrows between vertices. For each pair of vertices, there is at most one arrow between them: in other words, every pair of vertices is either unconnected, or one vertex is "directed" toward the other. Note that it is possible to have an arrow from a vertex to itself.
218 |
219 | Define a relation :math:`\leq` on the set of vertices, such that for two vertices :math:`a` and :math:`b`, :math:`a \leq b` means that there is an arrow from :math:`a` pointing to :math:`b`.
220 |
221 | On an arbitrary graph, is :math:`\leq` a partial order, a strict partial order, a total order, a strict total order, or none of the above? If possible, give examples of graphs where :math:`\leq` fails to have these properties.
222 |
223 | #. Let :math:`\equiv` be an equivalence relation on a set :math:`A`. For every element :math:`a` in :math:`A`, let :math:`[a]` be the equivalence class of :math:`a`: that is, the set of elements :math:`\{ c \mid c \equiv a \}`. Show that for every :math:`a` and :math:`b`, :math:`[a] = [b]` if and only if :math:`a \equiv b`.
224 |
225 | (Hints and notes:
226 |
227 | - Remember that since you are proving an \`\`if and only if'' statement, there are two directions to prove.
228 | - Since that :math:`[a]` and :math:`[b]` are sets, :math:`[a] = [b]` means that for every element :math:`c`, :math:`c` is in :math:`[a]` if and only if :math:`c` is in :math:`[b]`.
229 | - By definition, an element :math:`c` is in :math:`[a]` if and only if :math:`c \equiv a`. In particular, :math:`a` is in :math:`[a]`.)
230 |
231 | #. Let the relation :math:`\sim` on the natural numbers :math:`\mathbb{N}` be defined as follows: if :math:`n` is even, then :math:`n \sim n+1`, and if :math:`n` is odd, then :math:`n \sim n-1`. Furthermore, for every :math:`n`, :math:`n \sim n`. Show that :math:`\sim` is an equivalence relation. What is the equivalence class of the number 5? Describe the set of equivalence classes :math:`\{ [n] \mid n \in \mathbb{N} \}`.
232 |
233 | #. Show that the relation on lines in the plane, given by ":math:`l_1` and :math:`l_2` are parallel," is an equivalence relation. What is the equivalence class of the x-axis? Describe the set of equivalence classes :math:`\{ [l] \mid l\text{ is a line in the plane} \}`.
234 |
235 | #. A binary relation :math:`\leq` on a domain :math:`A` is said to be a *preorder* it is is reflexive and transitive. This is weaker than saying it is a partial order; we have removed the requirement that the relation is asymmetric. An example is the ordering on people currently alive on the planet defined by setting :math:`x \leq y` if and only if :math:`x` 's birth date is earlier than :math:`y` 's. Asymmetry fails, because different people can be born on the same day. But, prove that the following theorem holds:
236 |
237 | .. TODO: set off
238 |
239 | **Theorem.** Let :math:`\leq` be a preorder on a domain :math:`A`. Define the relation :math:`\equiv`, where :math:`x \equiv y` holds if and only if :math:`x \leq y` and :math:`y \leq x`. Then :math:`\equiv` is an equivalence relation on :math:`A`.
240 |
--------------------------------------------------------------------------------
/relations_in_lean.rst:
--------------------------------------------------------------------------------
1 | Relations in Lean
2 | =================
3 |
4 | In the last chapter, we noted that set theorists think of a binary relation
5 | :math:`R` on a set :math:`A` as a set of ordered pairs,
6 | so that :math:`R(a, b)` really means :math:`(a, b) \in R`.
7 | An alternative is to think of :math:`R` as a function which,
8 | when applied to :math:`a` and :math:`b`,
9 | returns the proposition that :math:`R(a, b)` holds.
10 | This is the viewpoint adopted by Lean:
11 | a binary relation on a type ``A`` is a function ``A → A → Prop``.
12 | Remember that the arrows associate to the right,
13 | so ``A → A → Prop`` really means ``A → (A → Prop)``.
14 | So, given ``a : A``,
15 | ``R a`` is a predicate (the property of being related to ``A``),
16 | and given ``a b : A``, ``R a b`` is a proposition.
17 |
18 |
19 | Order Relations
20 | ---------------
21 |
22 | With first-order logic,
23 | we can say what it means for a relation to be reflexive,
24 | symmetric, transitive, antisymmetric, and so on:
25 |
26 | .. code-block:: lean
27 |
28 | namespace hidden
29 |
30 | variable {A : Type}
31 |
32 | def Reflexive (R : A → A → Prop) : Prop :=
33 | ∀ x, R x x
34 |
35 | def Symmetric (R : A → A → Prop) : Prop :=
36 | ∀ x y, R x y → R y x
37 |
38 | def Transitive (R : A → A → Prop) : Prop :=
39 | ∀ x y z, R x y → R y z → R x z
40 |
41 | def AntiSymmetric (R : A → A → Prop) : Prop :=
42 | ∀ x y, R x y → R y x → x = y
43 |
44 | def Irreflexive (R : A → A → Prop) : Prop :=
45 | ∀ x, ¬ R x x
46 |
47 | def Total (R : A → A → Prop) : Prop :=
48 | ∀ x y, R x y ∨ R y x
49 |
50 | end hidden
51 |
52 | Notice that Lean will unfold the definitions when necessary,
53 | for example, treating ``Reflexive R`` as ``∀ x, R x x``.
54 |
55 | .. code-block:: lean
56 |
57 | namespace hidden
58 |
59 | variable {A : Type}
60 |
61 | def Reflexive (R : A → A → Prop) : Prop :=
62 | ∀ x, R x x
63 |
64 | def Symmetric (R : A → A → Prop) : Prop :=
65 | ∀ x y, R x y → R y x
66 |
67 | def Transitive (R : A → A → Prop) : Prop :=
68 | ∀ x y z, R x y → R y z → R x z
69 |
70 | def AntiSymmetric (R : A → A → Prop) : Prop :=
71 | ∀ x y, R x y → R y x → x = y
72 |
73 | -- BEGIN
74 | variable (R : A → A → Prop)
75 |
76 | example (h : Reflexive R) (x : A) : R x x := h x
77 |
78 | example (h : Symmetric R) (x y : A) (h1 : R x y) : R y x :=
79 | h x y h1
80 |
81 | example (h : Transitive R) (x y z : A) (h1 : R x y) (h2 : R y z) :
82 | R x z :=
83 | h x y z h1 h2
84 |
85 | example (h : AntiSymmetric R) (x y : A) (h1 : R x y)
86 | (h2 : R y x) :
87 | x = y :=
88 | h x y h1 h2
89 | -- END
90 |
91 | end hidden
92 |
93 | In the command ``variable {A : Type}``,
94 | we put curly braces around ``A`` to indicate that it is an *implicit* argument,
95 | which is to say, you do not have to write it explicitly;
96 | Lean can infer it from the argument ``R``.
97 | That is why we can write ``Reflexive R`` rather than ``Reflexive A R``:
98 | Lean knows that ``R`` is a binary relation on ``A``,
99 | so it can infer that we mean reflexivity for binary relations on ``A``.
100 |
101 | Given ``h : Transitive R``, ``h1 : R x y``, and ``h2 : R y z``,
102 | it is annoying to have to write ``h x y z h1 h2`` to prove ``R x z``.
103 | After all,
104 | Lean should be able to infer that we are talking about transitivity at
105 | ``x``, ``y``, and ``z``,
106 | from the fact that ``h1`` is ``R x y`` and ``h2`` is ``R y z``.
107 | Indeed, we can replace that information by underscores:
108 |
109 | .. code-block:: lean
110 |
111 | namespace hidden
112 |
113 | variable {A : Type}
114 |
115 | def Transitive (R : A → A → Prop) : Prop :=
116 | ∀ x y z, R x y → R y z → R x z
117 |
118 | -- BEGIN
119 | variable (R : A → A → Prop)
120 |
121 | example (h : Transitive R) (x y z : A) (h1 : R x y)
122 | (h2 : R y z) :
123 | R x z :=
124 | h _ _ _ h1 h2
125 | -- END
126 |
127 | end hidden
128 |
129 | But typing underscores is annoying, too.
130 | The best solution is to declare the arguments ``x y z``
131 | to a transitivity hypothesis to be implicit as well.
132 | We can do this by introducing curly braces around the
133 | variables in the definition.
134 |
135 | .. code-block:: lean
136 |
137 | namespace hidden
138 |
139 | variable {A : Type}
140 |
141 | -- BEGIN
142 | def Transitive' (R : A → A → Prop) : Prop :=
143 | ∀ {x} {y} {z}, R x y → R y z → R x z
144 |
145 | def Transitive (R : A → A → Prop) : Prop :=
146 | ∀ {x y z}, R x y → R y z → R x z
147 |
148 | variable (R : A → A → Prop)
149 |
150 | example (h : Transitive R) (x y z : A) (h1 : R x y)
151 | (h2 : R y z) :
152 | R x z :=
153 | h h1 h2
154 | -- END
155 |
156 | end hidden
157 |
158 | In fact, the notions
159 | ``Reflexive``, ``Symmetric``, ``Transitive``,
160 | and so on are defined in Mathlib in exactly this way,
161 | so we are free to use them by doing ``import Mathlib.Init.Logic``
162 | at the top of the file.
163 |
164 | .. code:: lean
165 |
166 | import Mathlib.Init.Logic
167 |
168 | #check Reflexive
169 | #check Symmetric
170 | #check Transitive
171 | #check AntiSymmetric
172 | #check Irreflexive
173 |
174 | We put our temporary definitions of in a namespace ``hidden``;
175 | that means that the full name of our version of ``Reflexive`` is
176 | ``hidden.Reflexive``,
177 | which would not conflict with the one defined in the library
178 | were we to import that module.
179 |
180 | In :numref:`order_relations` we showed that a strict partial order -
181 | that is, a binary relation that is transitive and irreflexive -
182 | is also asymmetric. Here is a proof of that fact in Lean.
183 |
184 | .. code-block:: lean
185 |
186 | import Mathlib.Init.Logic
187 |
188 | variable (A : Type)
189 | variable (R : A → A → Prop)
190 |
191 | -- BEGIN
192 | example (h1 : Irreflexive R) (h2 : Transitive R) :
193 | ∀ x y, R x y → ¬ R y x := by
194 | intro x y
195 | intro (h3 : R x y)
196 | intro (h4 : R y x)
197 | have h5 : R x x := h2 h3 h4
198 | have h6 : ¬ R x x := h1 x
199 | show False
200 | exact h6 h5
201 | variable A : Type
202 | variable R : A → A → Prop
203 | -- END
204 |
205 | In mathematics,
206 | it is common to use infix notation and a symbol like ``≼``
207 | to denote a partial order,
208 | which you can input by typing ``\preceq``.
209 | Lean supports this practice:
210 |
211 | .. code-block:: lean
212 |
213 | import Mathlib.Init.Logic
214 |
215 | -- BEGIN
216 | section
217 | variable (A : Type)
218 | variable (R : A → A → Prop)
219 |
220 | -- type \preceq for the symbol ≼
221 | local infix:50 " ≼ " => R
222 |
223 | example (h1 : Irreflexive R) (h2 : Transitive R) :
224 | ∀ x y, x ≼ y → ¬ y ≼ x := by
225 | intro x y
226 | intro (h3 : x ≼ y)
227 | intro (h4 : y ≼ x)
228 | have h5 : x ≼ x := h2 h3 h4
229 | have h6 : ¬ x ≼ x := h1 x
230 | show False
231 | exact h6 h5
232 |
233 | end
234 | -- END
235 |
236 | The structure of a partial order consists of a type ``A``
237 | (traditionally a set ``A``)
238 | with a binary relation ``le : A → A → Prop``
239 | (short for "lesser or equal")
240 | on it that is reflexive,
241 | transitive, and antisymmetric.
242 | We can package this structure as a "class" in Lean.
243 |
244 | .. code-block:: lean
245 |
246 | import Mathlib.Order.Basic
247 |
248 | namespace hidden
249 |
250 | -- BEGIN
251 | class PartialOrder (A : Type u) where
252 | le : A → A → Prop
253 | refl : Reflexive le
254 | trans : Transitive le
255 | antisymm : ∀ {a b : A}, le a b → le b a → a = b
256 |
257 | -- type \preceq for the symbol ≼
258 | local infix:50 " ≼ " => PartialOrder.le
259 | -- END
260 |
261 | end hidden
262 |
263 | Assuming we have a type ``A`` that is a partial order,
264 | we can define the corresponding strict partial order ``lt : A → A → Prop``
265 | (short for "lesser than")
266 | and prove that it is,
267 | indeed, a strict order.
268 | We also introduce notation ``≺`` for ``le``,
269 | which you can write by typing ``\prec``.
270 |
271 | .. code-block:: lean
272 |
273 | import Mathlib.Tactic.Basic
274 | import Mathlib.Order.Basic
275 |
276 | namespace hidden
277 |
278 | class PartialOrder (A : Type u) where
279 | le : A → A → Prop
280 | refl : Reflexive le
281 | trans : Transitive le
282 | antisymm : ∀ {a b : A}, le a b → le b a → a = b
283 |
284 | -- type \preceq for the symbol ≼
285 | local infix:50 " ≼ " => PartialOrder.le
286 |
287 | -- BEGIN
288 | namespace PartialOrder
289 | variable {A : Type} [PartialOrder A]
290 |
291 | def lt (a b : A) : Prop := a ≼ b ∧ a ≠ b
292 |
293 | -- type \prec for the symbol ≺
294 | local infix:50 " ≺ " => lt
295 |
296 | theorem irrefl_lt (a : A) : ¬ (a ≺ a) := by
297 | intro (h : a ≺ a)
298 | have : a ≠ a := And.right h
299 | have : a = a := rfl
300 | contradiction
301 |
302 | theorem trans_lt {a b c : A} (h₁ : a ≺ b) (h₂ : b ≺ c) : a ≺ c :=
303 | have : a ≼ b := And.left h₁
304 | have : a ≠ b := And.right h₁
305 | have : b ≼ c := And.left h₂
306 | have : b ≠ c := And.right h₂
307 | have : a ≼ c := trans ‹a ≼ b› ‹b ≼ c›
308 | have : a ≠ c :=
309 | fun hac : a = c ↦
310 | have : c ≼ b := by rw [← hac]; assumption
311 | have : b = c := antisymm ‹b ≼ c› ‹c ≼ b›
312 | show False from ‹b ≠ c› ‹b = c›
313 | show a ≺ c from And.intro ‹a ≼ c› ‹a ≠ c›
314 |
315 | end PartialOrder
316 | -- END
317 | end hidden
318 |
319 | The variable declaration ``[PartialOrder A]`` can be read as
320 | "assume ``A`` is a partial order".
321 | Then Lean will use this "instance" of the class ``PartialOrder``
322 | to figure out what ``le`` and ``lt`` are referring to.
323 |
324 | The proofs use anonymous ``have``,
325 | referring back to them with the French quotes, ```\f<`` and ``\f>``,
326 | or ``assumption`` (in tactic mode).
327 | The proof of transitivity switches from term mode to tactic mode,
328 | to use ``rewrite`` to replace ``c`` for ``a`` in ``a ≤ b``.
329 | Recall that ``contradiction`` instructs Lean to find
330 | a hypothesis and its negation in the context, and hence complete the proof.
331 |
332 | We could even define the class ``StrictPartialOrder`` in a similar manner,
333 | then use the above theorems to show that any (weak) ``PartialOrder`` is also a
334 | ``StrictPartialOrder``.
335 |
336 | .. code-block:: lean
337 |
338 | import Mathlib.Tactic.Basic
339 | import Mathlib.Order.Basic
340 |
341 | namespace hidden
342 |
343 | class PartialOrder (A : Type u) where
344 | le : A → A → Prop
345 | refl : Reflexive le
346 | trans : Transitive le
347 | antisymm : ∀ {a b : A}, le a b → le b a → a = b
348 |
349 | -- type \preceq for the symbol ≼
350 | local infix:50 " ≼ " => PartialOrder.le
351 |
352 | namespace PartialOrder
353 | variable {A : Type} [PartialOrder A]
354 |
355 | def lt (a b : A) : Prop := a ≼ b ∧ a ≠ b
356 |
357 | -- type \prec for the symbol ≺
358 | local infix:50 " ≺ " => PartialOrder.lt
359 |
360 | theorem irrefl_lt (a : A) : ¬ (a ≺ a) := by
361 | intro (h : a ≺ a)
362 | have : a ≠ a := And.right h
363 | have : a = a := rfl
364 | contradiction
365 |
366 | theorem trans_lt {a b c : A} (h₁ : a ≺ b) (h₂ : b ≺ c) : a ≺ c :=
367 | have : a ≼ b := And.left h₁
368 | have : a ≠ b := And.right h₁
369 | have : b ≼ c := And.left h₂
370 | have : b ≠ c := And.right h₂
371 | have : a ≼ c := trans ‹a ≼ b› ‹b ≼ c›
372 | have : a ≠ c :=
373 | fun hac : a = c ↦
374 | have : c ≼ b := by rw [← hac]; assumption
375 | have : b = c := antisymm ‹b ≼ c› ‹c ≼ b›
376 | show False from ‹b ≠ c› ‹b = c›
377 | show a ≺ c from And.intro ‹a ≼ c› ‹a ≠ c›
378 |
379 | end PartialOrder
380 |
381 | -- BEGIN
382 | class StrictPartialOrder (A : Type u) where
383 | lt : A → A → Prop
384 | irrefl : Irreflexive lt
385 | trans : Transitive lt
386 |
387 | -- type \prec for the symbol ≺
388 | local infix:50 " ≺ " => StrictPartialOrder.lt
389 |
390 | instance {A : Type} [PartialOrder A] : StrictPartialOrder A where
391 | lt := PartialOrder.lt
392 | irrefl := PartialOrder.irrefl_lt
393 | trans _ _ _ := PartialOrder.trans_lt
394 |
395 | example (a : A) [PartialOrder A] : ¬ a ≺ a :=
396 | StrictPartialOrder.irrefl a
397 | -- END
398 |
399 | end hidden
400 |
401 | Once we have shown this instance, we would be able to use the inherited
402 | ``≺`` (not the one we defined in the ``PartialOrder`` namespace!)
403 | and facts about ``StrictPartialOrder`` on any partial order.
404 |
405 | In Section :numref:`order_relations`,
406 | we also noted that you can define a (weak) partial order from a strict one.
407 | We ask you to do this formally in the exercises below.
408 |
409 | Mathlib defines ``PartialOrder`` in roughly the same way as we have,
410 | which is why we enclosed our definitions in the ``hidden`` namespace,
411 | so that our definition is called ``hidden.PartialOrder``
412 | rather than just ``PartialOrder`` outside the namespace.
413 | There is no ``StrictPartialOrder`` definition,
414 | but we can refer to the strict partial order, given a partial order.
415 | The notation used by Mathlib is the more common ``≤``
416 | (input ``\le``) and ``<``.
417 |
418 | Here is one more example. Suppose ``R`` is a binary relation on a type ``A``, and we define ``S x y`` to mean that both ``R x y`` and ``R y x`` holds. Below we show that the resulting relation is reflexive and symmetric.
419 |
420 | .. code-block:: lean
421 |
422 | section
423 | axiom A : Type
424 | axiom R : A → A → Prop
425 |
426 | variable (h1 : Transitive R)
427 | variable (h2 : Reflexive R)
428 |
429 | def S (x y : A) := R x y ∧ R y x
430 |
431 | example : Reflexive S :=
432 | fun x ↦
433 | have : R x x := h2 x
434 | show S x x from And.intro this this
435 |
436 | example : Symmetric S :=
437 | fun x y ↦
438 | fun h : S x y ↦
439 | have h1 : R x y := h.left
440 | have h2 : R y x := h.right
441 | show S y x from ⟨h2, h1⟩
442 |
443 | end
444 |
445 | In the exercises below, we ask you to show that ``S`` is transitive as well.
446 |
447 | In the first example,
448 | we use the anonymous ``have``,
449 | and then refer back to the ``have`` with the keyword ``this``.
450 | In the second example,
451 | we abbreviate ``And.left h`` and ``And.right h`` as ``h.left`` and ``h.right``,
452 | respectively.
453 | We also abbreviate ``And.intro h2 h1`` with an anonymous constructor,
454 | writing ``⟨h2, h1⟩``.
455 | Lean figures out that we are trying to prove a conjunction,
456 | and figures out that ``And.intro`` is the relevant introduction principle.
457 | You can type the corner brackets with ``\<`` and ``\>``, respectively.
458 |
459 | Orderings on Numbers
460 | --------------------
461 |
462 | Conveniently,
463 | Lean has the normal orderings on the natural numbers, integers,
464 | and so on defined already in Mathlib.
465 |
466 | .. code-block:: lean
467 |
468 | import Mathlib.Data.Nat.Defs
469 |
470 | open Nat
471 | variable (n m : ℕ)
472 |
473 | #check 0 ≤ n
474 | #check n < n + 1
475 |
476 | example : 0 ≤ n := Nat.zero_le n
477 | example : n < n + 1 := lt_succ_self n
478 |
479 | example (h : n + 1 ≤ m) : n < m + 1 :=
480 | have h1 : n < n + 1 := lt_succ_self n
481 | have h2 : n < m := lt_of_lt_of_le h1 h
482 | have h3 : m < m + 1 := lt_succ_self m
483 | show n < m + 1 from lt_trans h2 h3
484 |
485 | There are many theorems in Lean that are useful for proving facts about inequality relations. We list some common ones here.
486 |
487 | .. code-block:: lean
488 |
489 | import Mathlib.Order.Basic
490 |
491 | variable (A : Type) [PartialOrder A]
492 | variable (a b c : A)
493 |
494 | #check (le_trans : a ≤ b → b ≤ c → a ≤ c)
495 | #check (lt_trans : a < b → b < c → a < c)
496 | #check (lt_of_lt_of_le : a < b → b ≤ c → a < c)
497 | #check (lt_of_le_of_lt : a ≤ b → b < c → a < c)
498 | #check (le_of_lt : a < b → a ≤ b)
499 |
500 | Notice that we assume an instance of ``PartialOrder`` on ``A``.
501 | There are also properties that are specific to some domains,
502 | like the natural numbers:
503 |
504 | .. code-block:: lean
505 |
506 | import Mathlib.Data.Nat.Defs
507 |
508 | variable (n : ℕ)
509 |
510 | #check (Nat.zero_le : ∀ n : ℕ, 0 ≤ n)
511 | #check (Nat.lt_succ_self : ∀ n : ℕ, n < n + 1)
512 | #check (Nat.le_succ : ∀ n : ℕ, n ≤ n + 1)
513 |
514 | .. TODO(Jeremy): add a section on equivalence relations
515 |
516 |
517 | Equivalence Relations
518 | ---------------------
519 |
520 | In :numref:`equivalence_relations_and_equality` we saw that an *equivalence relation* is a binary relation on some domain :math:`A` that is reflexive, symmetric, and transitive. We will see such relations in Lean in a moment, but first let's define another kind of relation called a *preorder*, which is a binary relation that is reflexive and transitive.
521 | Again, we use a ``class`` to capture this data.
522 |
523 | .. code-block:: lean
524 |
525 | import Mathlib.Order.Basic
526 |
527 | namespace hidden
528 |
529 | variable {A : Type}
530 |
531 | class Preorder (A : Type u) where
532 | le : A → A → Prop
533 | refl : Reflexive le
534 | trans : Transitive le
535 |
536 | end hidden
537 |
538 | Lean's library provides its own formulation of preorders.
539 | In order to use the same name, we have to put it in the ``hidden`` namespace.
540 | Lean's library defines other properties of relations, such as these:
541 |
542 | Building on our definition of a preorder,
543 | we can describe partial orders as antisymmetric preorders,
544 | and equivalences as symmetric preorders.
545 |
546 | .. code-block:: lean
547 |
548 | import Mathlib.Order.Basic
549 |
550 | namespace hidden
551 |
552 | variable {A : Type}
553 |
554 | class Preorder (A : Type u) where
555 | le : A → A → Prop
556 | refl : Reflexive le
557 | trans : Transitive le
558 |
559 | class PartialOrder (A : Type u) extends Preorder A where
560 | antisymm : AntiSymmetric le
561 |
562 | class Equivalence (A : Type u) extends Preorder A where
563 | symm : Symmetric le
564 |
565 | end hidden
566 |
567 | The ``extends Preorder A`` in this definition now makes
568 | ``PartialOrder`` a class that automatically
569 | inherits all the definitions and theorems from ``Preorder``.
570 | In particular ``le``, ``refl``, and ``trans`` become part of the data of
571 | ``PartialOrder``.
572 | Using classes in this way we can write very general proofs
573 | (for example proofs just about preorders)
574 | and apply them in contexts that are more specific
575 | (for example proofs about equivalence relations and partial orders).
576 |
577 | Note: we might *not* want to design the library in this way specifically.
578 | Since we might want to use ``≤`` as notation for a partial order,
579 | but for an equivalence relation.
580 | Indeed ``Mathlib`` does not define ``Equivalence`` as an extension of
581 | ``PartialOrder``.
582 |
583 | In :numref:`equivalence_relations_and_equality` we claimed that there is
584 | another way to define an equivalence relation,
585 | namely as a binary relation satisfying the following two properties:
586 |
587 | - :math:`\forall a \; (a \equiv a)`
588 | - :math:`\forall {a, b, c} \; (a \equiv b \wedge c \equiv b \to a \equiv c)`
589 |
590 | We derive the two definitions from each other in the following
591 |
592 | .. code-block:: lean
593 |
594 | import Mathlib.Order.Basic
595 |
596 | namespace hidden
597 |
598 | class Equivalence (A : Type u) where
599 | R : A → A → Prop
600 | refl : Reflexive R
601 | symm : Symmetric R
602 | trans : Transitive R
603 |
604 | local infix:50 " ~ " => Equivalence.R
605 |
606 | class Equivalence' (A : Type u) where
607 | R : A → A → Prop
608 | refl : Reflexive R
609 | trans' : ∀ {a b c}, R a b → R c b → R a c
610 |
611 | -- type ``≈`` as ``\~~``
612 | local infix:50 " ≈ " => Equivalence'.R
613 |
614 | section
615 | variable {A : Type u}
616 |
617 | theorem Equivalence.trans' [Equivalence A] {a b c : A} :
618 | a ~ b → c ~ b → a ~ c := by
619 | intro (hab : a ~ b)
620 | intro (hcb : c ~ b)
621 | apply trans hab
622 | show b ~ c
623 | exact symm hcb
624 |
625 | example [Equivalence A] : Equivalence' A where
626 | R := Equivalence.R
627 | refl := Equivalence.refl
628 | trans':= Equivalence.trans'
629 |
630 | theorem Equivalence'.symm [Equivalence' A] {a b : A} :
631 | a ≈ b → b ≈ a := by
632 | intro (hab : a ≈ b)
633 | have hbb : b ≈ b := Equivalence'.refl b
634 | show b ≈ a
635 | exact Equivalence'.trans' hbb hab
636 |
637 | theorem Equivalence'.trans [Equivalence' A] {a b c : A} :
638 | a ≈ b → b ≈ c → a ≈ c := by
639 | intro (hab : a ≈ b) (hbc : b ≈ c)
640 | have hcb : c ≈ b := Equivalence'.symm hbc
641 | show a ≈ c
642 | exact Equivalence'.trans' hab hcb
643 |
644 | example [Equivalence' A] : Equivalence A where
645 | R := Equivalence'.R
646 | refl := Equivalence'.refl
647 | symm _ _:= Equivalence'.symm
648 | trans _ _ _ := Equivalence'.trans
649 |
650 | end
651 | end hidden
652 |
653 | For one of the definitions we use the infix notation ``~`` and we use
654 | ``≈`` for the other. (You can type ``≈`` as ``\~~``.)
655 | We use ``example`` instead of ``instance`` so that we don't actually
656 | instantiate instances of the classes.
657 |
658 |
659 | Exercises
660 | ---------
661 |
662 | #. Replace the ``sorry`` commands in the following proofs to show that we can
663 | create a partial order ``R'`` out of a strict partial order ``R``.
664 |
665 | .. code-block:: lean
666 |
667 | import Mathlib.Order.Basic
668 |
669 | class StrictPartialOrder (A : Type u) where
670 | lt : A → A → Prop
671 | irrefl : Irreflexive lt
672 | trans : Transitive lt
673 |
674 | local infix:50 " ≺ " => StrictPartialOrder.lt
675 |
676 | section
677 | variable {A : Type u} [StrictPartialOrder A]
678 |
679 | def R' (a b : A) : Prop :=
680 | (a ≺ b) ∨ a = b
681 |
682 | local infix:50 " ≼ " => R'
683 |
684 | theorem reflR' (a : A) : a ≼ a := sorry
685 |
686 | theorem transR' {a b c : A} (h1 : a ≼ b) (h2 : b ≼ c) :
687 | a ≼ c :=
688 | sorry
689 |
690 | theorem antisymmR' {a b : A} (h1 : a ≼ b) (h2 : b ≼ a) :
691 | a = b :=
692 | sorry
693 |
694 | end
695 |
696 | #. Replace the ``sorry`` by a proof.
697 |
698 | .. code-block:: lean
699 |
700 | import Mathlib.Order.Basic
701 |
702 | namespace hidden
703 | class Preorder (A : Type u) where
704 | le : A → A → Prop
705 | refl : Reflexive le
706 | trans : Transitive le
707 |
708 | namespace Preorder
709 | def S (a b : A) [Preorder A] : Prop := le a b ∧ le b a
710 |
711 | example (A : Type u) [Preorder A] {x y z : A} :
712 | S x y → S y z → S x z :=
713 | sorry
714 |
715 | end Preorder
716 | end hidden
717 |
718 | #. Only one of the following two theorems is provable. Figure out which one is true, and replace the ``sorry`` command with a complete proof.
719 |
720 | .. code-block:: lean
721 |
722 | import Mathlib.Order.Basic
723 |
724 | axiom A : Type
725 | axiom a : A
726 | axiom b : A
727 | axiom c : A
728 | axiom R : A → A → Prop
729 | axiom Rab : R a b
730 | axiom Rbc : R b c
731 | axiom nRac : ¬ R a c
732 |
733 | -- Prove one of the following two theorems:
734 |
735 | theorem R_is_strict_partial_order :
736 | Irreflexive R ∧ Transitive R :=
737 | sorry
738 |
739 | theorem R_is_not_strict_partial_order :
740 | ¬(Irreflexive R ∧ Transitive R) :=
741 | sorry
742 |
743 | #. Complete the following proof. You may use results from Mathlib.
744 |
745 | .. code-block:: lean
746 |
747 | import Mathlib.Data.Nat.Defs
748 |
749 | section
750 | open Nat
751 | variable (n m : ℕ)
752 |
753 | example : 1 ≤ 4 :=
754 | sorry
755 |
756 | end
757 |
--------------------------------------------------------------------------------
/the_natural_numbers_and_induction_in_lean.rst:
--------------------------------------------------------------------------------
1 | .. _the_natural_numbers_and_induction_in_lean:
2 |
3 | The Natural Numbers and Induction in Lean
4 | =========================================
5 |
6 | Induction and Recursion in Lean
7 | -------------------------------
8 |
9 | Internally, in Lean, the natural numbers are defined as a type generated inductively from an axiomatically declared ``zero`` and ``succ`` operation:
10 |
11 | .. code-block:: lean
12 |
13 | namespace hidden
14 |
15 | open Nat
16 |
17 | -- BEGIN
18 | inductive Nat : Type
19 | | zero : Nat
20 | | succ : Nat → Nat
21 | -- END
22 | end hidden
23 |
24 | If you click the button that copies this text into the editor in the online version of this textbook, you will see that we wrap it with the phrases ``namespace hidden`` and ``end hidden``. This puts the definition into a new "namespace," so that the identifiers that are defined are ``hidden.Nat``, ``hidden.Nat.zero`` and ``hidden.Nat.succ``, to avoid conflicting with the one that is in the Lean library. Below, we will do that in a number of places where our examples duplicate objects defined in the library. The unicode symbol ``ℕ``, entered with ``\N`` or ``\nat``, is a synonym for ``Nat``.
25 |
26 | Declaring ``Nat`` as an inductively defined type means that we can define functions by recursion, and prove theorems by induction. For example, these are the first two recursive definitions presented in the last chapter:
27 |
28 | .. code-block:: lean
29 |
30 | import Mathlib.Data.Nat.Defs
31 |
32 | open Nat
33 |
34 | def two_pow : ℕ → ℕ
35 | | 0 => 1
36 | | (succ n) => 2 * two_pow n
37 |
38 | def fact : ℕ → ℕ
39 | | 0 => 1
40 | | (succ n) => (succ n) * fact n
41 |
42 | Addition and numerals are defined in such a way that Lean recognizes ``succ n`` and ``n + 1`` as essentially the same, so we could instead write these definitions as follows:
43 |
44 | .. code-block:: lean
45 |
46 | import Mathlib.Data.Nat.Defs
47 |
48 | open Nat
49 |
50 | -- BEGIN
51 | def two_pow : ℕ → ℕ
52 | | 0 => 1
53 | | (n + 1) => 2 * two_pow n
54 |
55 | def fact : ℕ → ℕ
56 | | 0 => 1
57 | | (n + 1) => (n + 1) * fact n
58 | -- END
59 |
60 | If we wanted to define the function ``m^n``, we would do that by fixing ``m``, and writing doing the recursion on the second argument:
61 |
62 | .. code-block:: lean
63 |
64 | import Mathlib.Data.Nat.Defs
65 |
66 | open Nat
67 |
68 | -- BEGIN
69 | def pow (m : ℕ) : ℕ → ℕ
70 | | 0 => 1
71 | | (n + 1) => (pow m n) * m
72 | -- END
73 |
74 | In fact, this is how the power function on the natural numbers,
75 | ``Nat.pow``, is defined in Lean's library.
76 |
77 | Lean is also smart enough to interpret more complicated forms of recursion, like this one:
78 |
79 | .. code-block:: lean
80 |
81 | import Mathlib.Data.Nat.Defs
82 |
83 | open Nat
84 |
85 | -- BEGIN
86 | def fib : ℕ → ℕ
87 | | 0 => 0
88 | | 1 => 1
89 | | (n + 2) => fib (n + 1) + fib n
90 |
91 | In addition to defining functions by recursion, we can prove theorems by induction. In Lean, each clause of a recursive definition results in a new identity. For example, the two clauses in the definition of ``pow`` above give rise to the following two theorems:
92 |
93 | .. code-block:: lean
94 |
95 | import Mathlib.Data.Nat.Defs
96 |
97 | open Nat
98 |
99 | -- BEGIN
100 | example (n : ℕ) : Nat.pow n 0 = 1 := rfl
101 | example (m n : ℕ) : Nat.pow m (n+1) = (Nat.pow m n) * m := rfl
102 | -- END
103 |
104 | Lean defines the usual notation for exponentiation:
105 |
106 | .. code-block:: lean
107 |
108 | import Mathlib.Data.Nat.Defs
109 |
110 | open Nat
111 |
112 | -- BEGIN
113 | example (n : ℕ) : n^0 = 1 := rfl
114 | example (m n : ℕ) : m^(n+1) = m^n * m := rfl
115 |
116 | #check @Nat.pow_zero
117 | #check @Nat.pow_succ
118 | -- END
119 |
120 | Notice that we could alternatively have used ``m * Nat.pow m n``
121 | in the second clause of the definition of ``Nat.pow``.
122 | Of course, we can prove that the two definitions are equivalent using the
123 | commutativity of multiplication, but,
124 | using a proof by induction,
125 | we can also prove it using only the associativity of multiplication,
126 | and the properties ``1 * m = m`` and ``m * 1 = m``.
127 | This is useful, because the power function is also often used in situations
128 | where multiplication is not commutative,
129 | such as with matrix multiplication.
130 | The theorem can be proved in Lean as follows:
131 |
132 | .. code-block:: lean
133 |
134 | import Mathlib.Data.Nat.Defs
135 |
136 | open Nat
137 |
138 | -- BEGIN
139 | example (m n : ℕ) : m^(succ n) = m * m^n := by
140 | induction n with
141 | | zero =>
142 | show m^(succ 0) = m * m^0
143 | calc
144 | m^(succ 0) = m^0 * m := by rw [Nat.pow_succ]
145 | _ = 1 * m := by rw [Nat.pow_zero]
146 | _ = m := by rw [Nat.one_mul]
147 | _ = m * 1 := by rw [Nat.mul_one]
148 | _ = m * m^0 := by rw [Nat.pow_zero]
149 | | succ n ih =>
150 | show m^(succ (succ n)) = m * m^(succ n)
151 | calc
152 | m^(succ (succ n)) = m^(succ n) * m := by rw [Nat.pow_succ]
153 | _ = (m * m^n) * m := by rw [ih]
154 | _ = m * (m^n * m) := by rw [Nat.mul_assoc]
155 | _ = m * m^(succ n) := by rw [Nat.pow_succ]
156 | -- END
157 |
158 | This is a typical proof by induction in Lean.
159 | It begins with the tactic ``induction n with``,
160 | which is like ``cases n with``,
161 | but also supplies the induction hypothesis ``ih``
162 | in the successor case.
163 | Here is a shorter proof:
164 |
165 | .. code-block:: lean
166 |
167 | import Mathlib.Data.Nat.Defs
168 |
169 | open Nat
170 |
171 | -- BEGIN
172 | example (m n : ℕ) : m^(succ n) = m * m^n := by
173 | induction n with
174 | | zero =>
175 | show m^(succ 0) = m * m^0
176 | rw [Nat.pow_succ, Nat.pow_zero, Nat.one_mul, Nat.mul_one]
177 | | succ n ih =>
178 | show m^(succ (succ n)) = m * m^(succ n)
179 | rw [Nat.pow_succ, Nat.pow_succ, ← Nat.mul_assoc, ← ih, Nat.pow_succ]
180 | -- END
181 |
182 | Remember that you can write a ``rewrite`` proof incrementally, checking the error messages to make sure things are working so far, and to see how far Lean got.
183 |
184 | As another example of a proof by induction, here is a proof of the identity ``m^(n + k) = m^n * m^k``.
185 |
186 | .. code-block:: lean
187 |
188 | import Mathlib.Data.Nat.Defs
189 |
190 | open Nat
191 |
192 | -- BEGIN
193 | example (m n k : ℕ) : m^(n + k) = m^n * m^k := by
194 | induction n with
195 | | zero =>
196 | show m^(0 + k) = m^0 * m^k
197 | calc m^(0 + k) = m^k := by rw [Nat.zero_add]
198 | _ = 1 * m^k := by rw [Nat.one_mul]
199 | _ = m^0 * m^k := by rw [Nat.pow_zero]
200 | | succ n ih =>
201 | show m^(succ n + k) = m^(succ n) * m^k
202 | calc
203 | m^(succ n + k) = m^(succ (n + k)) := by rw [Nat.succ_add]
204 | _ = m * m^(n + k) := by rw [Nat.pow_succ']
205 | _ = m * (m^n * m^k) := by rw [ih]
206 | _ = (m * m^n) * m^k := by rw [Nat.mul_assoc]
207 | _ = m^(succ n) * m^k := by rw [Nat.pow_succ']
208 | -- END
209 |
210 | Notice the same pattern.
211 | We do induction on ``n``,
212 | and the base case and inductive step are routine.
213 | The theorem is called ``pow_add`` in the library,
214 | and once again, with a bit of cleverness,
215 | we can shorten the proof with ``rewrite``:
216 |
217 | .. code-block:: lean
218 |
219 | import Mathlib.Data.Nat.Defs
220 |
221 | open Nat
222 |
223 | -- BEGIN
224 | example (m n k : ℕ) : m^(n + k) = m^n * m^k := by
225 | induction n with
226 | | zero =>
227 | show m^(0 + k) = m^0 * m^k
228 | rw [Nat.zero_add, Nat.pow_zero, Nat.one_mul]
229 | | succ n ih =>
230 | show m^(succ n + k) = m^(succ n) * m^k
231 | rw [Nat.succ_add, Nat.pow_succ', ih, ← Nat.mul_assoc, Nat.pow_succ']
232 | -- END
233 |
234 | You should not hesitate to use ``calc``,
235 | however, to make the proofs more explicit.
236 | Remember that you can also use ``calc`` and ``rewrite`` together,
237 | using ``calc`` to structure the calculational proof,
238 | and using ``rewrite`` to fill in each justification step.
239 |
240 | Defining the Arithmetic Operations in Lean
241 | ------------------------------------------
242 |
243 | In fact, addition and multiplication are defined in Lean essentially as described in :numref:`defining_arithmetic_operations`. The defining equations for addition hold by reflexivity, but they are also named ``add_zero`` and ``add_succ``:
244 |
245 | .. code-block:: lean
246 |
247 | import Mathlib.Data.Nat.Defs
248 |
249 | open Nat
250 |
251 | variable (m n : ℕ)
252 |
253 | -- BEGIN
254 | example : m + 0 = m := Nat.add_zero m
255 | example : m + succ n = succ (m + n) := Nat.add_succ m n
256 | -- END
257 |
258 | Similarly, we have the defining equations for the predecessor function
259 | and multiplication:
260 |
261 | .. code-block:: lean
262 |
263 | import Mathlib.Data.Nat.Defs
264 |
265 | -- BEGIN
266 | #check @Nat.pred_zero
267 | #check @Nat.pred_succ
268 | #check @Nat.mul_zero
269 | #check @Nat.mul_succ
270 | -- END
271 |
272 | Here are the five propositions proved in :numref:`defining_arithmetic_operations`.
273 |
274 | .. code-block:: lean
275 |
276 | import Mathlib.Data.Nat.Defs
277 |
278 | open Nat
279 |
280 | namespace hidden
281 |
282 | -- BEGIN
283 | theorem succ_pred (n : ℕ) : n ≠ 0 → succ (pred n) = n := by
284 | intro (hn : n ≠ 0)
285 | cases n with
286 | | zero => exact absurd rfl (hn : 0 ≠ 0)
287 | | succ n => rw [Nat.pred_succ]
288 | -- END
289 | end hidden
290 |
291 | Note that we don't need to use ``induction`` here, only ``cases``.
292 | We prove the next one in term mode instead:
293 |
294 | .. code-block:: lean
295 |
296 | import Mathlib.Data.Nat.Defs
297 |
298 | open Nat
299 |
300 | namespace hidden
301 |
302 | -- BEGIN
303 | theorem zero_add (n : Nat) : 0 + n = n :=
304 | match n with
305 | | zero => show 0 + 0 = 0 from rfl
306 | | succ n =>
307 | show 0 + succ n = succ n from calc
308 | 0 + succ n = succ (0 + n) := by rfl
309 | _ = succ n := by rw [zero_add n]
310 | -- END
311 |
312 | end hidden
313 |
314 | The ``match`` notation is very similar to ``induction``,
315 | except it does not let us provide a name like ``ih``
316 | for the induction hypothesis.
317 | Instead, we call ``zero_add n : 0 + n = n``,
318 | which is the induction hypothesis.
319 | Note that calling ``zero_add (succ n)`` in the same place would be circular,
320 | and if we did so Lean would throw an error.
321 |
322 | .. code-block:: lean
323 |
324 | import Mathlib.Data.Nat.Defs
325 |
326 | open Nat
327 |
328 | namespace hidden
329 |
330 | -- BEGIN
331 | theorem succ_add (m n : Nat) : succ m + n = succ (m + n) :=
332 | match n with
333 | | 0 => show succ m + 0 = succ (m + 0) from rfl
334 | | n + 1 =>
335 | show succ m + succ n = succ (m + succ n) from calc
336 | succ m + succ n = succ (succ m + n) := by rfl
337 | _ = succ (succ (m + n)) := by rw [succ_add m n]
338 | _ = succ (m + succ n) := by rfl
339 | -- END
340 |
341 | end hidden
342 |
343 | Note that this time we used ``0`` and ``n + 1`` in the ``match`` cases.
344 | Here are the final two:
345 |
346 | .. code-block:: lean
347 |
348 | import Mathlib.Data.Nat.Defs
349 |
350 | open Nat
351 |
352 | namespace hidden
353 |
354 | -- BEGIN
355 | theorem add_assoc (m n k : Nat) : m + n + k = m + (n + k) :=
356 | match k with
357 | | 0 => show m + n + 0 = m + (n + 0) from by
358 | rw [Nat.add_zero, Nat.add_zero]
359 | | k + 1 => show m + n + succ k = m + (n + (succ k)) from by
360 | rw [add_succ, add_assoc m n k, add_succ, add_succ]
361 |
362 | theorem add_comm (m n : Nat) : m + n = n + m :=
363 | match n with
364 | | 0 => show m + 0 = 0 + m from by rw [Nat.add_zero, Nat.zero_add]
365 | | n + 1 => show m + succ n = succ n + m from calc
366 | m + succ n = succ (m + n) := by rw [add_succ]
367 | _ = succ (n + m) := by rw [add_comm m n]
368 | _ = succ n + m := by rw [succ_add]
369 | -- END
370 |
371 | end hidden
372 |
373 |
374 |
375 | Exercises
376 | ---------
377 |
378 | #. Formalize as many of the identities from
379 | :numref:`defining_arithmetic_operations`
380 | as you can by replacing each `sorry` with a proof.
381 |
382 | .. code-block:: lean
383 |
384 | import Mathlib.Data.Nat.Defs
385 |
386 | open Nat
387 |
388 | --1.a.
389 | example : ∀ m n k : Nat, m * (n + k) = m * n + m * k := sorry
390 |
391 | --1.b.
392 | example : ∀ n : Nat, 0 * n = 0 := sorry
393 |
394 | --1.c.
395 | example : ∀ n : Nat, 1 * n = n := sorry
396 |
397 | --1.d.
398 | example : ∀ m n k : Nat, (m * n) * k = m * (n * k) := sorry
399 |
400 | --1.e.
401 | example : ∀ m n : Nat, m * n = n * m := sorry
402 |
403 | #. Formalize as many of the identities from :numref:`arithmetic_on_the_natural_numbers` as you can by replacing each `sorry` with a proof.
404 |
405 | .. code-block:: lean
406 |
407 | import Mathlib.Data.Nat.Defs
408 |
409 | open Nat
410 |
411 | --2.a.
412 | example : ∀ m n k : Nat, n ≤ m → n + k ≤ m + k := sorry
413 |
414 | --2.b.
415 | example : ∀ m n k : Nat, n + k ≤ m + k → n ≤ m := sorry
416 |
417 | --2.c.
418 | example : ∀ m n k : Nat, n ≤ m → n * k ≤ m * k := sorry
419 |
420 | --2.d.
421 | example : ∀ m n : Nat, m ≥ n → m = n ∨ m ≥ n+1 := sorry
422 |
423 | --2.e.
424 | example : ∀ n : Nat, 0 ≤ n := sorry
425 |
--------------------------------------------------------------------------------
/unixode.sty:
--------------------------------------------------------------------------------
1 | % ------------------------------------------------------------------------------
2 | % (C) 2012-2013 Olivier Verdier
3 | % Unixode Package
4 | % XeTeX Unicode character definitions
5 | % ------------------------------------------------------------------------------
6 | \NeedsTeXFormat{LaTeX2e}
7 | \ProvidesPackage{unixode}[2012/05/10]
8 |
9 | \RequirePackage{ifxetex}
10 |
11 | \ifxetex
12 | %\RequirePackage{mathspec}
13 | %\RequirePackage{fontspec}
14 | \defaultfontfeatures{Ligatures=TeX}
15 | \usepackage{newunicodechar}
16 | \newunicodechar{α}{\ensuremath{\mathrm{\alpha}}}
17 | \newunicodechar{β}{\ensuremath{\mathrm{\beta}}}
18 | \newunicodechar{γ}{\ensuremath{\mathrm{\gamma}}}
19 | \newunicodechar{δ}{\ensuremath{\mathrm{\delta}}}
20 | \newunicodechar{ε}{\ensuremath{\mathrm{\varepsilon}}}
21 | \newunicodechar{ζ}{\ensuremath{\mathrm{\zeta}}}
22 | \newunicodechar{η}{\ensuremath{\mathrm{\eta}}}
23 | \newunicodechar{θ}{\ensuremath{\mathrm{\theta}}}
24 | \newunicodechar{ι}{\ensuremath{\mathrm{\iota}}}
25 | \newunicodechar{κ}{\ensuremath{\mathrm{\kappa}}}
26 | \newunicodechar{λ}{\ensuremath{\mathrm{\lambda}}}
27 | \newunicodechar{μ}{\ensuremath{\mathrm{\mu}}}
28 | \newunicodechar{ν}{\ensuremath{\mathrm{\nu}}}
29 | \newunicodechar{ξ}{\ensuremath{\mathrm{\xi}}}
30 | \newunicodechar{π}{\ensuremath{\mathrm{\mathnormal{\pi}}}}
31 | \newunicodechar{ρ}{\ensuremath{\mathrm{\rho}}}
32 | \newunicodechar{σ}{\ensuremath{\mathrm{\sigma}}}
33 | \newunicodechar{τ}{\ensuremath{\mathrm{\tau}}}
34 | \newunicodechar{φ}{\ensuremath{\mathrm{\varphi}}}
35 | \newunicodechar{χ}{\ensuremath{\mathrm{\chi}}}
36 | \newunicodechar{ψ}{\ensuremath{\mathrm{\psi}}}
37 | \newunicodechar{ω}{\ensuremath{\mathrm{\omega}}}
38 |
39 | \newunicodechar{Γ}{\ensuremath{\mathrm{\Gamma}}}
40 | \newunicodechar{Δ}{\ensuremath{\mathrm{\Delta}}}
41 | \newunicodechar{Θ}{\ensuremath{\mathrm{\Theta}}}
42 | \newunicodechar{Λ}{\ensuremath{\mathrm{\Lambda}}}
43 | \newunicodechar{Σ}{\ensuremath{\mathrm{\Sigma}}}
44 | \newunicodechar{Φ}{\ensuremath{\mathrm{\Phi}}}
45 | \newunicodechar{Ξ}{\ensuremath{\mathrm{\Xi}}}
46 | \newunicodechar{Ψ}{\ensuremath{\mathrm{\Psi}}}
47 | \newunicodechar{Ω}{\ensuremath{\mathrm{\Omega}}}
48 |
49 | \newunicodechar{ℵ}{\ensuremath{\aleph}}
50 |
51 | \newunicodechar{≤}{\ensuremath{\leq}}
52 | \newunicodechar{≥}{\ensuremath{\geq}}
53 | \newunicodechar{≠}{\ensuremath{\neq}}
54 | \newunicodechar{≈}{\ensuremath{\approx}}
55 | \newunicodechar{≡}{\ensuremath{\equiv}}
56 | \newunicodechar{≃}{\ensuremath{\simeq}}
57 | \newunicodechar{≺}{\ensuremath{\prec}}
58 | \newunicodechar{≼}{\ensuremath{\preceq}}
59 |
60 | \newunicodechar{≤}{\ensuremath{\leq}}
61 | \newunicodechar{≥}{\ensuremath{\geq}}
62 |
63 | \newunicodechar{∂}{\ensuremath{\partial}}
64 | \newunicodechar{∆}{\ensuremath{\triangle}} % or \laplace?
65 |
66 | \newunicodechar{∫}{\ensuremath{\int}}
67 | \newunicodechar{∑}{\ensuremath{\mathrm{\Sigma}}}
68 | \newunicodechar{Π}{\ensuremath{\mathrm{\Pi}}}
69 |
70 | \newunicodechar{⊥}{\ensuremath{\perp}}
71 | \newunicodechar{∞}{\ensuremath{\infty}}
72 | \newunicodechar{∂}{\ensuremath{\partial}}
73 |
74 | \newunicodechar{∓}{\ensuremath{\mp}}
75 | \newunicodechar{±}{\ensuremath{\pm}}
76 | \newunicodechar{×}{\ensuremath{\times}}
77 |
78 | \newunicodechar{⊕}{\ensuremath{\oplus}}
79 | \newunicodechar{⊗}{\ensuremath{\otimes}}
80 | \newunicodechar{⊞}{\ensuremath{\boxplus}}
81 |
82 | \newunicodechar{∇}{\ensuremath{\nabla}}
83 | \newunicodechar{√}{\ensuremath{\sqrt}}
84 |
85 | \newunicodechar{⬝}{\ensuremath{\cdot}}
86 | \newunicodechar{•}{\ensuremath{\cdot}}
87 | \newunicodechar{∘}{\ensuremath{\circ}}
88 |
89 | \newunicodechar{⁻}{\ensuremath{^{\textup{\kern1pt\rule{2pt}{0.3pt}\kern-1pt}}}}
90 | \newunicodechar{▸}{\ensuremath{\blacktriangleright}}
91 |
92 | \newunicodechar{∧}{\ensuremath{\wedge}}
93 | \newunicodechar{∨}{\ensuremath{\vee}}
94 | \newunicodechar{¬}{\ensuremath{\neg}}
95 | \newunicodechar{⊢}{\ensuremath{\vdash}}
96 |
97 | %\newunicodechar{⟨}{\ensuremath{\left\langle}}
98 | %\newunicodechar{⟩}{\ensuremath{\right\rangle}}
99 | \newunicodechar{⟨}{\ensuremath{\langle}}
100 | \newunicodechar{⟩}{\ensuremath{\rangle}}
101 |
102 | \newunicodechar{∀}{\ensuremath{\forall}}
103 | \newunicodechar{∃}{\ensuremath{\exists}}
104 |
105 | \newunicodechar{↦}{\ensuremath{\mapsto}}
106 | \newunicodechar{→}{\ensuremath{\rightarrow}}
107 | \newunicodechar{↔}{\ensuremath{\leftrightarrow}}
108 | \newunicodechar{⇒}{\ensuremath{\Rightarrow}}
109 | \newunicodechar{⟹}{\ensuremath{\Longrightarrow}}
110 | \newunicodechar{⇐}{\ensuremath{\Leftarrow}}
111 | \newunicodechar{⟸}{\ensuremath{\Longleftarrow}}
112 |
113 | \newunicodechar{∩}{\ensuremath{\cap}}
114 | \newunicodechar{∪}{\ensuremath{\cup}}
115 | \newunicodechar{⋂}{\ensuremath{\bigcap}}
116 | \newunicodechar{⋃}{\ensuremath{\bigcup}}
117 | \newunicodechar{⊂}{\ensuremath{\subseteq}}
118 | \newunicodechar{⊆}{\ensuremath{\subseteq}}
119 | \newunicodechar{⊄}{\ensuremath{\nsubseteq}}
120 | \newunicodechar{⊈}{\ensuremath{\nsubseteq}}
121 | \newunicodechar{⊃}{\ensuremath{\supseteq}}
122 | \newunicodechar{⊇}{\ensuremath{\supseteq}}
123 | \newunicodechar{⊅}{\ensuremath{\nsupseteq}}
124 | \newunicodechar{⊉}{\ensuremath{\nsupseteq}}
125 | \newunicodechar{∈}{\ensuremath{\in}}
126 | \newunicodechar{∉}{\ensuremath{\notin}}
127 | \newunicodechar{∋}{\ensuremath{\ni}}
128 | \newunicodechar{∌}{\ensuremath{\notni}}
129 | \newunicodechar{∅}{\ensuremath{\emptyset}}
130 |
131 | \newunicodechar{∖}{\ensuremath{\setminus}}
132 | \newunicodechar{†}{\ensuremath{\dag}}
133 |
134 | \newunicodechar{ℕ}{\ensuremath{\mathbb{N}}}
135 | \newunicodechar{ℤ}{\ensuremath{\mathbb{Z}}}
136 | \newunicodechar{ℝ}{\ensuremath{\mathbb{R}}}
137 | \newunicodechar{ℚ}{\ensuremath{\mathbb{Q}}}
138 | \newunicodechar{ℂ}{\ensuremath{\mathbb{C}}}
139 | \newunicodechar{⌞}{\ensuremath{\llcorner}}
140 | \newunicodechar{⌟}{\ensuremath{\lrcorner}}
141 | \newunicodechar{⦃}{\ensuremath{\{\!|}}
142 | \newunicodechar{⦄}{\ensuremath{|\!\}}}
143 | \newunicodechar{∣}{\ensuremath{\mid}}
144 | \newunicodechar{∥}{\ensuremath{\parallel}}
145 |
146 | \newunicodechar{₁}{\ensuremath{_1}}
147 | \newunicodechar{₂}{\ensuremath{_2}}
148 | \newunicodechar{₃}{\ensuremath{_3}}
149 | \newunicodechar{₄}{\ensuremath{_4}}
150 | \newunicodechar{₅}{\ensuremath{_5}}
151 | \newunicodechar{₆}{\ensuremath{_6}}
152 | \newunicodechar{₇}{\ensuremath{_7}}
153 | \newunicodechar{₈}{\ensuremath{_8}}
154 | \newunicodechar{₉}{\ensuremath{_9}}
155 | \newunicodechar{₀}{\ensuremath{_0}}
156 | \newunicodechar{ᵢ}{\ensuremath{_i}}
157 | \newunicodechar{ⱼ}{\ensuremath{_j}}
158 | \newunicodechar{ₘ}{\ensuremath{_m}}
159 | \newunicodechar{ₙ}{\ensuremath{_n}}
160 | \newunicodechar{ᵤ}{\ensuremath{_u}}
161 | \newunicodechar{↑}{\ensuremath{\uparrow}}
162 | \newunicodechar{↓}{\ensuremath{\downarrow}}
163 | \else
164 | \usepackage[utf8x]{inputenc}
165 | \SetUnicodeOption{mathletters}
166 | \DeclareUnicodeCharacter{952}{\ensuremath{\theta}}
167 | \fi
168 |
--------------------------------------------------------------------------------