我有一个标准的数据类型来表示谓词逻辑的公式。表示析取的自然演绎消除规则的函数可能如下所示:
d_el p q =
if p =: (Dis r s) && q =: (Neg r) then Just s else
if q =: (Dis r s) && p =: (Neg r) then Just s else
Nothing where r,s free
x =: y = (x =:= y) == success当统一失败时,该函数不会返回任何值,而是在PACKS中不返回任何解决方案
logic> d_el (Dis Bot Top) (Not Bot)
Result: Just Top
More Solutions? [Y(es)/n(o)/a(ll)] n
logic> d_el (Dis Bot Top) (Not Top)
No more solutions.我遗漏了什么,当统一失败时,为什么el不计算为Nothing?
发布于 2011-12-03 18:13:35
这似乎不是使用等式约束的最佳方式。当a =:= b失败时,complete function子句也会失败。
例如:
xx x = if (x =:= 5) == success then 1 else x
xx x = 3计算xx 7的结果是3 (而不是7),因为7 =:= 5完全终止了xx函数的第一个子句。
我认为代码应该是这样的:
d_el p q = case (p,q) of
(Dis a s, Neg b) -> if a == b then Just s else Nothing
(Neg a, Dis b s) -> if a == b then Just s else Nothing
_ -> Nothinghttps://stackoverflow.com/questions/7611426
复制相似问题