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.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末驾茴,一起剝皮案震驚了整個濱河市宿礁,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,376評論 6 491
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異航夺,居然都是意外死亡,警方通過查閱死者的電腦和手機崔涂,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,126評論 2 385
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來始衅,“玉大人冷蚂,你說我怎么就攤上這事缭保。” “怎么了蝙茶?”我有些...
    開封第一講書人閱讀 156,966評論 0 347
  • 文/不壞的土叔 我叫張陵艺骂,是天一觀的道長。 經(jīng)常有香客問我隆夯,道長钳恕,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,432評論 1 283
  • 正文 為了忘掉前任蹄衷,我火速辦了婚禮忧额,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘愧口。我一直安慰自己睦番,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 65,519評論 6 385
  • 文/花漫 我一把揭開白布耍属。 她就那樣靜靜地躺著托嚣,像睡著了一般。 火紅的嫁衣襯著肌膚如雪厚骗。 梳的紋絲不亂的頭發(fā)上示启,一...
    開封第一講書人閱讀 49,792評論 1 290
  • 那天,我揣著相機與錄音领舰,去河邊找鬼夫嗓。 笑死,一個胖子當(dāng)著我的面吹牛提揍,可吹牛的內(nèi)容都是我干的啤月。 我是一名探鬼主播,決...
    沈念sama閱讀 38,933評論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼劳跃,長吁一口氣:“原來是場噩夢啊……” “哼谎仲!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起刨仑,我...
    開封第一講書人閱讀 37,701評論 0 266
  • 序言:老撾萬榮一對情侶失蹤郑诺,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后杉武,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體辙诞,經(jīng)...
    沈念sama閱讀 44,143評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,488評論 2 327
  • 正文 我和宋清朗相戀三年轻抱,在試婚紗的時候發(fā)現(xiàn)自己被綠了飞涂。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 38,626評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖较店,靈堂內(nèi)的尸體忽然破棺而出士八,到底是詐尸還是另有隱情,我是刑警寧澤梁呈,帶...
    沈念sama閱讀 34,292評論 4 329
  • 正文 年R本政府宣布婚度,位于F島的核電站,受9級特大地震影響官卡,放射性物質(zhì)發(fā)生泄漏蝗茁。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,896評論 3 313
  • 文/蒙蒙 一寻咒、第九天 我趴在偏房一處隱蔽的房頂上張望哮翘。 院中可真熱鬧,春花似錦仔涩、人聲如沸忍坷。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,742評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽佩研。三九已至,卻和暖如春霞揉,著一層夾襖步出監(jiān)牢的瞬間旬薯,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,977評論 1 265
  • 我被黑心中介騙來泰國打工适秩, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留绊序,地道東北人。 一個月前我還...
    沈念sama閱讀 46,324評論 2 360
  • 正文 我出身青樓秽荞,卻偏偏與公主長得像骤公,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子扬跋,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,494評論 2 348

推薦閱讀更多精彩內(nèi)容