我想創建一個函數,它將命題轉換爲析取範式。haskell:一個析取範式函數
type Valuation = [(Variable, Bool)] -- Valuation of variables to truth values
和使用這些:
它會通過讀取評估列表爲此
findBool :: (Variable, Bool)->Bool
findBool (_,x) = x
findVar :: (Variable, Bool)->Variable
findVar (x,_) = x
而且命題是:
data Prop = Falsum -- a contradiction, or
| Var Variable -- a variable, or
| Not Prop -- a negation of a formula, or
| Or Prop Prop -- a disjunction of two formulae, or
| And Prop Prop -- a conjunction of two formulae, or
| Imp Prop Prop -- a conditional of two formulae.
deriving (Eq, Show)
我覺得我有什麼到目前爲止是非常穩固的,但我不知道該怎麼辦空箱子。 這是我到目前爲止有:
minterm :: Valuation -> Prop
minterm [] = ?
minterm (x:xs) = if (findBool x) then (And (findVar x) (minterm xs)) else (And (Not(findVar x) (minterm xs))
我的目標是:minterm [("p",True),("q",False)]
返回:And (Var "p") (Not (Var "q"))
編輯: 不Falsum工作,但如果它不返回任何東西我喜歡。反正我有可以排除它會被退回,所以我可以得到這樣的情況:
minterm [("p",True),("q",False)]
== And (Var "p") (Not (Var "q"))
怎麼樣'不Falsum' – Ingo