我正在复习我拿到的AI课本,我已经到了我的章节的最后一个家庭作业题:
“在您选择的任何语言中实现第69页中概述的统一算法。”
在第69页,您有以下统一算法的伪代码:
function unify(E1, E2);
begin
case
both E1 and E2 are constants or the empty list:
if E1 = E2 then return {}
else return FAIL;
E1 is a variable:
if E1 occurs in E2 then return FAIL
else return {E2/E1}
E2 is a variable
if E2 occurs in E1 then FAIL
else return {E1/E2}
either E1 or E2 are empty then return FAIL
otherwise:
begin
HE1 := first element of E1;
HE2 := first element of E2;
SUBS1 := unify(HE1, HE2);
if SUBS1 := FAIL then return FAIL;
TE1 := apply(SUBS1, rest of E1);
TE2 := apply(SUBS1, rest of E2);
SUBS2 := unify(TE1, TE2);
if SUBS2 = FAIL then return FAIL;
else return composition(SUBS1, SUBS2)
end
end
end
现在,我理解了统一的一般概念,但我完全不知道如何在Java或C#这样的语言中实现它。
我甚至不确定方法签名会是什么样子。它需要哪种类型的变量?我相当确定我需要返回列表来表示谓词演算的构造,但这只是一个猜测。
例如,当它说"E1是一个变量“时,如果我把它传递给Unify方法,它怎么可能不是呢?我可以检查null,但这是否与"empty list“不同?
有没有人可以帮我或者给我指个方向,让我在C#或Java中实现统一算法?
https://stackoverflow.com/questions/1396558
复制相似问题