IndProp

Slide 0

Good afternoon!

Slide 1

For the previous lectures, we have seen many ways to define propositions like equations, implications, AND, OR, FORALL and EXISTS.
Today, we are going to define propositions in a more general way, called inductive definition.

Slide 2

We have seen two ways to say a number n is even:

  • by showing that evenb n is true, or
  • by showing that n is the double of some number k.
    We can also define the evenness of numbers inductively.
    The base case says that 0 is even.
    The induction case says that if n is even, then n+2 is also even.

Slide 3

We can write the definition in another way:
There is a bar which is annotated by the name of the rule.
The propositions above the bar are the hypothesis.
Those below are the conclusions.
We can read it like this:
ev_0 takes no hypothesis, and infers that 0 is even.
ev_SS takes the evidence that n is even, and infers that n+2 is even.
We can take the conclusion of one inference to satisfy the hypothesis of another inference.
By joining these inferences, we can construct proofs in a tree structure.
Here is how we prove that 4 is even:
By ev_0, we know that 0 is even.
We take the evenness of 0 to satisfy the hypothesis of ev_SS, and infer that 2 is even.
We do it again, so 4 is even. QED.

Slide 4

Let's see how to write it in Coq.
We are using Inductive again, just like how we define inductive data types like natural numbers.
Remember we define nat with two constructors, O and S.
It says, O is a nat, and S takes a nat and to construct another nat.
For ev, it is a proposition that takes a natural number.
You can also read it as a property of natural numbers.
The two constructors are, ev_0 that constructs the evidence for ev 0, and ev_SS that takes the evidence that n is even and constructs the evidence n+2 as even.
As we define this inductive proposition, we also get two "primitive theorems".
If you look at the two constructors ev_0 and ev_SS, their type is actually a theorem.
We will cover more about the relation between types and theorems in our next chapter, called ProofObjects, so for now,

Slide 5

Let's see how to use these "constructor theorems" to prove something else.
(Proof General)
We want to show that 4 is even.
From the proof tree we just seen, we know that the evenness of 4 is based on the evenness of 2 and the theorem ev_SS.
Let's check the type of ev_SS.
It is forall n, ev n -> ev (n+2).
Remember what apply tactic does?
When you do apply ev_SS. our target changes to the evenness of 2.
We apply ev_SS again, and now we need to show that 0 is even.
This comes from ev_0.
Thus, Qed.
We can also treat the constructor theorems as functions, and simply apply this stuff.
Let's try another one.
We hope to show that for all n, if n is even, then 4+n is even.
We first do intros and simpl.
Apply ev_SS twice.
Now we need to show that n is even, which comes from the hypothesis.
If you draw the proof tree, it will be ev n at the top, then ev (n+2) by using inference rule ev_SS, and then ev (n+4) by using ev_SS again.
Any questions?
Let's try some exercises.

Slide 6

ev 0
Answer: One

Slide 7

ev 1
Answer: Zero

Slide 8

ev 2
Answer: One

Slide 9

ev n
Answer: At most one

Slide 10

Add ev_PP
Answer: Finite or infinitely many
For example, in order to show that 0 is even, we can either use ev_0 directly, or apply ev_PP to some evidence that 2 is even.
To show that 2 is even, we can use either apply ev_SS to some evidence that 0 is even, or apply ev_PP to some evidence that 4 is even.
Similarly, for all even numbers, you always have two approaches to prove it, and each approach, except for ev_0, is based on some evidence that another number is even.
Therefore, for all even numbers, there are infinite many proofs for its evenness.
For odd numbers, we still cannot construct a proof for its evenness.
Therefore, adding this rule does not change the semantics of our definition.

Slide 11

Remove ev_0
Answer: Zero
The reason is that we don't have a base case.
In order to prove some natural number is even, we can only apply the remaining two constructors to some evidence that another natural number is even, thus leads to an infinite loop.

Slide 12

Remove ev_0
forall n, ev n -> ev (4 + n)
Answer: Infinitely many
The reason is that our proof does not require ev_0.

Slide 13

So much for the exercises.
We have learnt how to construct a proof that shows a natural number is even.
Let's try to prove some more interesting theorems that have inductive propositions like evenness.
The inductive definition of evenness tells us how to build evidence that some number is even.
It also tells us that the two constructors ev_0 and ev_SS are the only ways to build evidence that numbers of even in the sense of ev.

Slide 14

So once we have an evidence E that says n is even, we know that E must have one of the two shapes:

  1. E is ev_0 and n is 0, or
  2. E is ev_SS applied to n-2 and some evidence that n-2 is even.
    Remember that we could do induction and case analysis for natural numbers and lists.
    Now we can do the same on evenness.

Slide 15

When we do inversion on a natural number n, we get two cases, n is constructed by either O or S applied to some n'.
When we do inversion on the evidence that n is even, we also get two cases: the evidence is constructed by either ev_0, which tells us that n is 0, or ev_SS applied to n-2, which tells us that n-2 is even.

Slide 16

Let's prove this theorem that if n is even, then n-2 is even.
(Proof General)
In the previous chapter, we have proven the equivalence of evenness in terms of evenb n = true and n is equal to the double some k.
Let's try to show that the ev property is semantically equivalent to our previous definitions.

Slide 17

(Proof General)

Slide 18

Let's try the proof again and see what would happen if we do induction on E.
(Proof General)

Slide 19

Evenness is a single-argument proposition, in other words, a property of natural numbers.
We can also define propositions that take multiple arguments, also known as relations.
For instance, we can define "the less than or equal to" relation with two constructors:

  • le_n says that any natural number is less than or equal to itself
  • le_S says that if we have evidence that n is less than or equal to m, then we know that n is less than or equal to m+1
    The notation for it is the same as many programming languages like C and Java.

Slide 20

Let's do some sanity checks for the relation we defined to see if it makes sense.
(Proof General)

Slide 21

Once we defined "less than or equal to", we can define "less than" easily.
n is less than m if n+1 is less than or equal to m.
Here are some more examples of relation on numbers, that define a number is the square of another, a number is the next nat of another, and a number is the next even number of another.
As you can see, for these relations, we can also write a function that takes the two numbers and returns a Boolean that says whether they have such relation.
These two styles of defining relations are both used in practice.
The functional definition is decidable, and we can run checking on it.
The inductive definition is usually easier for reasoning and writing proofs.
In order to utilize the benefit of both styles of definitions, we can write them both, and prove that they are equivalent.
So whenever we need to prove one style of definition, we can prove it in the other style instead, and use the equivalence to transform the definition.
Any questions?
So this is a good point for us to wrap up.
For the next lecture, we are going to discuss regular expressions.
If you don't know what regular expressions are, I would suggest that you fill yourself with these knowledge.
See you next week.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,921评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,635评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,393评论 0 338
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,836评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,833评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,685评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,043评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,694评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 42,671评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,670评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,779评论 1 332
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,424评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,027评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,984评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,214评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,108评论 2 351
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,517评论 2 343

推荐阅读更多精彩内容