Mathematics_in_Lean
Mathematics in lean :基于mathlib库,建造复杂表达式的方式:1.自己写,2.提供instruction 指导如何构建
Theorem Proving in Lean: 侧重底层逻辑框架和Lean的核心语法
Log
Linear algebra写法
2 basic
1 | -- le_div_iff₀这个theorem,以及rm[] |
3.1 Impication and the Universal Quantifier
In lean,in a sequence of implications there are implicit parentheses grouped to the right.
it is common in Lean to use curly brackets to make quantified variables implicit when they can be inferred from subsequent hypotheses.So we can just do lemma to the hypothese without mentioning the objects.即用{}括起来的在调用时不需要显示指出。
5.2 Induction and Recursion
1 | -- 归纳 |
6.1 Defining Structures
structure
can specify not only data types but also constraints that the data must satisfy(In lean,these are represented as fields of type Prop
).def
可以用来定义structure实例subtype
类型({x: alpha // p x}表示for all a in alpha,p x is true) construction combines a piece of data with a property.
structure的好处:But even though we can use products, subtypes, and Sigma types instead of structures, using structures has a number of advantages. Defining a structure abstracts away the underlying representation and provides custom names for the functions that access the components. This makes proofs more robust: proofs that rely only on the interface to a structure will generally continue to work when we change the definition, as long as we redefine the old accessors in terms of the new definition. Moreover, as we are about to see, Lean provides support for weaving structures together into a rich, interconnected hierarchy, and for managing the interactions between them.
1 | structure structure_name where |
annotation when define a structure:
structure
can bundle together data,so as the and符号
1 | -- 此注解表示自动生成定理: 当结构体的两个实例组成部分对应相同时,这两个实例相等 |
define particular instances of structure
1 | def inst_name : struc_name where |
definations and theorems
about namespace: when namespace not open, can use anonymous projection notation,which allows us to write a.add b instead of namespace_name.add a b.
protected keyword
1 | -- so that the theorem name is Point.add_comm,even when the namespace is open |
6.2 Algebraic Structures
abelian or commutative group : set A, operation •,假设a b ∈ A,则需要满足Closure (a · b ∈ A),Associativity(结合律),Identity element (必存在e∈A就是元 使得a · e = e · a = a),Inverse element(对任意a,都有a · b = b · a = e),Commutativity(交换律)
lattice : 带有join和meet(leat upper bound 和greatest lower bound)偏序集合
ring : 加法abelian group和an associative multiplication operation *,和identity 1,且multiplication distributes over addition.如果乘法是交换的则环是交换的
Lean theorem
multiple arrows:隐式右结合(associate to the right)
Lean使用快捷键
Ctrl-Shift-P : get access to the Lean 4:show all abbreviations
Ctrl-Space : completion in the editior to guess the theorem name
写法
运算的特殊写法
- divisibility relation整除关系 |
提示写法
“apply?”可以在右边得到suggestions
重复证明过程的写法
1 | --1. 使用hypothesis :任意 |
name_of_theorem
A_of_B_of_C: established something of the form A from hypothese of the form B and C,where A,B,C approximate the way we might read the goals out loud,e.g. x+y<… probably start with add_lt.
example use by & not use by
1 | example (a b : R) : a - b = a + -b :=by |
语法记录
Command
1 | -- |
rfl is short for “reflexivity”.
calc先定义阶段目标再填写过程
1 | example:(a+b)*(a+b) = a*a+2*a*b +b*b: |
have 先提出假设h进行证明,之后可以使用h推断goal
1 | theorem zero_mul(a: R):0*a =0 := by |
rw[…,…,…]替换
- 变量
定理
左箭头表示a=b:用a替换b
1 | nth_rw <第几个>[]替换 |
<⬅>mul_assoc
mul_comm <v1,v2>
tactic:ring
automation for that follow purely from the ring axioms
1 | example: c*b*a = b*(a*c):= by |
a ring consists of a collection of
objects,
R,(R with + is an abelian group,with 0 as the additive identity , with negation as inverse)
operations + *,and (multiplication is associative with identity 1,and multiplication distributes over addition)
constants 0 and 1,and
an operation x->-x
Lean is good not only for proving things about concrete mathematical structures like the natural numbers and the integers, but also for proving things about abstract structures, characterized axiomatically, like rings. Moreover, Lean supports generic reasoning about both abstract and concrete structures, and can be trained to recognize appropriate instances.