Something I fail to prove ......

Pre

I had thought I understand how to prove progress in Coq for some simple semantic ..... until I saw one of our QE question

Link is here
https://eng-cs.syr.edu/wp-content/uploads/2018/10/CISE-QE-1-January-8-2018.pdf

Semantic

operational semantic

It looks quite straight forward. Interesting part of this semantic is raise and handle. if exception in raise body is not handled, language will run into the case of a direct raise γ which very similar to a abort. And looks quite easy to formalize it in Coq.

Inductive expr : Type :=
| Tru
| Fls
| If (e0 : expr) (e1 : expr) (e2 : expr)
| Raise (γ : string)
| Handle (e1 : expr) (γ : string) (e2 : expr).

(* bool is the only type here *)
Inductive ty : Type :=
| TBool : ty.

Inductive eval : expr -> expr -> Prop :=
| E_If_t : forall e2 e3, eval (If Tru e2 e3) e2
| E_If_f : forall e2 e3, eval (If Fls e2 e3) e3
| E_If_g : forall e1 e1' e2 e3,
    eval e1 e1' ->
    eval (If e1 e2 e3) (If e1' e2 e3)
| E_If_r : forall e2 e3 γ,
    eval (If (Raise γ) e2 e3) (Raise γ)
| E_handle_t : forall γ e2, eval (Handle Tru γ e2) Tru
| E_handle_f : forall γ e2, eval (Handle Fls γ e2) Fls
| E_handle_r : forall γ e2, eval (Handle (Raise γ) γ e2) e2
| E_handle_e : forall e1 e1' γ e2,
    eval e1 e1' ->
    eval (Handle e1 γ e2) (Handle e1' γ e2)
| E_handle_h : forall γ γ' e2,
    γ <> γ' ->
    eval (Handle (Raise γ) γ' e2) (Raise γ).

in order to make sure of every raise is handled, we also has following typing rule:

Typing

Inductive value : expr -> Prop :=
| v_t : value Tru
| v_f : value Fls.

Inductive has_type : context -> expr -> ty -> Prop :=
| T_Tru : forall Γ, has_type Γ Tru TBool
| T_Fls : forall Γ, has_type Γ Fls TBool
| T_Raise : forall Γ γ, (Γ γ) = 1 -> has_type Γ (Raise γ) TBool
| T_If : forall Γ e1 e2 e3,
    has_type Γ e1 TBool ->
    has_type Γ e2 TBool ->
    has_type Γ e3 TBool ->
    has_type Γ (If e1 e2 e3) TBool
| T_Handle : forall Γ γ e1 e2,
    (Γ γ) = 0 ->
    has_type (γ !-> 1 ; Γ) e1 TBool ->
    has_type Γ e2 TBool ->
    has_type Γ (Handle e1 γ e2) TBool.

My Coq knowledge is very limited, so I use a total map to simulate set, since the core of this this problem is not proving properties of set. So my plan is just leave and use addmited on that part of proof. (TvT)/

Progress

finally this QE question ask me to prove progress properties of above semantic. However, since we also has raise here. So this language can finally run into either a value or a raise.

Theorem e_progress : forall e T Γ,
    has_type Γ e T ->
    value e \/ (exists γ, (Γ γ) = 1 -> e = Raise γ) \/ exists e', eval e e'.
Proof with eauto.
  intros.
  induction H...
  - right. right.
    destruct IHhas_type1.
    inversion H2; subst...
    destruct H2.
    inversion H; subst... 
    (* stuck *)

My proof start from induction on type relation, True, False and Raise case is trivial. First interesting case is If case. If e1 e2 e3 of course should step to something. But the second clause of my inductive hypothesis really annoy me, a or case. It is easy to see value If ... of course is impossible and can be eliminated, but second clause which is an exists one can't be discriminated! My proof context looks like this:

H2 looks like an impossible case, because If of course can't equal to a Raise. But if I want to get that \bot , I need to show γ in set of Γ ! this is not in any of context.... and my proof stuck....

....

my failure code is here....
https://github.com/StarGazerM/my-foolish-code/blob/master/qe/pl2018.v

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子吟吝,更是在濱河造成了極大的恐慌砸烦,老刑警劉巖渠牲,帶你破解...
    沈念sama閱讀 211,194評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件乳丰,死亡現(xiàn)場離奇詭異散址,居然都是意外死亡喉镰,警方通過查閱死者的電腦和手機(jī)旅择,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,058評論 2 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來侣姆,“玉大人生真,你說我怎么就攤上這事∞嘧冢” “怎么了柱蟀?”我有些...
    開封第一講書人閱讀 156,780評論 0 346
  • 文/不壞的土叔 我叫張陵,是天一觀的道長蚜厉。 經(jīng)常有香客問我长已,道長,這世上最難降的妖魔是什么昼牛? 我笑而不...
    開封第一講書人閱讀 56,388評論 1 283
  • 正文 為了忘掉前任术瓮,我火速辦了婚禮,結(jié)果婚禮上贰健,老公的妹妹穿的比我還像新娘胞四。我一直安慰自己,他們只是感情好伶椿,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,430評論 5 384
  • 文/花漫 我一把揭開白布辜伟。 她就那樣靜靜地躺著氓侧,像睡著了一般。 火紅的嫁衣襯著肌膚如雪游昼。 梳的紋絲不亂的頭發(fā)上甘苍,一...
    開封第一講書人閱讀 49,764評論 1 290
  • 那天,我揣著相機(jī)與錄音烘豌,去河邊找鬼载庭。 笑死,一個(gè)胖子當(dāng)著我的面吹牛廊佩,可吹牛的內(nèi)容都是我干的囚聚。 我是一名探鬼主播,決...
    沈念sama閱讀 38,907評論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼标锄,長吁一口氣:“原來是場噩夢啊……” “哼顽铸!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起料皇,我...
    開封第一講書人閱讀 37,679評論 0 266
  • 序言:老撾萬榮一對情侶失蹤谓松,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后践剂,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體鬼譬,經(jīng)...
    沈念sama閱讀 44,122評論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,459評論 2 325
  • 正文 我和宋清朗相戀三年逊脯,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了优质。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,605評論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡军洼,死狀恐怖巩螃,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情匕争,我是刑警寧澤避乏,帶...
    沈念sama閱讀 34,270評論 4 329
  • 正文 年R本政府宣布,位于F島的核電站甘桑,受9級特大地震影響拍皮,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜扇住,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,867評論 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望盗胀。 院中可真熱鬧艘蹋,春花似錦、人聲如沸票灰。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,734評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至浸策,卻和暖如春冯键,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背庸汗。 一陣腳步聲響...
    開封第一講書人閱讀 31,961評論 1 265
  • 我被黑心中介騙來泰國打工惫确, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人蚯舱。 一個(gè)月前我還...
    沈念sama閱讀 46,297評論 2 360
  • 正文 我出身青樓改化,卻偏偏與公主長得像,于是被迫代替她去往敵國和親枉昏。 傳聞我的和親對象是個(gè)殘疾皇子陈肛,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,472評論 2 348

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