我有一組真實的語句和一階邏輯中的條件語句,我想用prolog來解決。但是,我無法高雅地表達我的事實和條件。Prolog的邏輯推導和轉換
例如,假設我想表達以下幾點:
He drinks tea.
she does not drink tea if he does not drink tea.
either she likes soda or tea but not both
if she likes soda then he does not like tea.
以上是一個愚蠢的例子,我注意到感興趣的邏輯推演。我有興趣直接翻譯成序言,以便我們可以開始推斷。這是我的嘗試:
Drink_Tea(He).
/* I can't seem to find a not operator, so I'll use !*/
!Drink_Tea(She) :- !Drink_Tea(He).
likes(Soda, She) ; likes(tea, She) , !likes(Soda, She) , !likes(Tea, She).
!likes(Tea, He) :- likes(Soda, She).
所有幫助非常感謝!如果您需要更多信息,請與我們聯繫。
編輯: 在序言文件,那爲什麼我不能寫「事實」,如not(p) ; not(q)
變量p
和q
?
「不」操作符是'\ +'。所以你會有,例如'\ +喜歡(蘇打,她)'。 – lurker
請注意Prolog'(\ +)/ 1'謂詞的意思是否定爲失敗而不是邏輯否定(請參閱http://en.wikipedia.org/wiki/Negation_as_failure)。 –
@PauloMoura是的,好點。 – lurker