2013-03-08 126 views

回答

1

短篇小說:使用find_consts

長篇:

這是一個如何,要征服這樣的問題。

Main,有List.dropWhile

List.dropWhile :: "('a => bool) => 'a list => 'a list" 

然而,只有從一開始就刪除。這可能不是預期的功能。

value "List.dropWhile (λ x. x = ''c'') [''c'', ''c'', ''d'']" 
"[''d'']" 

value "List.dropWhile (λ x. x = ''c'') [''d'', ''c'', ''c'']" 
"[''d'', ''c'', ''c'']" 

手動方法

我們可以寫一個函數自己從而消除所有出現

fun dropAll :: "('a => bool) => 'a list => 'a list" where 
    "dropAll P [] = []" 
    | "dropAll P (x # xs) = (if P x then dropAll P xs else x # (dropAll P xs))" 

搜索庫

但是,此功能相當於與過濾¬ P

我們如何找到這樣的庫函數?

如果我們知道了我們想要做的簽名,我們可以使用find_consts

find_consts "('a ⇒ bool) ⇒ 'a list ⇒ 'a list" 

它從主返回3個功能,與簽名:List.dropWhileList.filterList.takeWhile

現在,讓我們表明我們不需要dropAll,但可以使用filter

lemma "dropAll P l = filter (λ x. ¬ P x) l" 
    apply(induction l) 
    by simp_all 

建議您不要實施之類的東西dropAll自己而使用的過濾器。因此,所有經證實可用於filter的詞條都是可用的。

提示

提示:我們可以使用便捷的列表理解語法來寫例如過濾器表達式

lemma "filter (λ x. ¬ P x) l = [x ← l. ¬ P x]" by simp 
+1

'find_consts'應該是搜索現有函數時的第一步(大部分時間您對簽名和/或可能的名稱有一個比較特殊的概念)。這在你的長篇博覽會上有點失落。如何將提示移到'find_consts'到最頂端? – chris 2013-03-15 06:02:56

1

一個辦法,找出你所期望存在的功能是從伊莎貝爾文檔文件What's in Main。它簡要概述了Isabelle/HOL的理論Main提供的主要類型,功能和語法。

如果您查看該文檔中的列表部分,您會發現功能似乎具有正確類型的功能filter