使用 AND、NOT 和 > 的逻辑编程如何获得最高价值

How does getting the highest value work with Logic Programming with AND, NOT and >

这是关于逻辑程序设计,来自计算机程序的结构和解释

理解如何获得最大值是一个简单的问题。

这是一个示例数据库:

((is-student Anna)
(is-student  Bart)
(is-student  Charlie)
(is-student  David)
(is-student  Eddy)
(is-student  Fanny)

(has-points Anna    73)
(has-points Bart    84)
(has-points Charlie 65)
(has-points David   34)
(has-points Eddy    85)
(has-points Fanny   70))

我理解以下代码是对学生的总结和他们的观点:

;;; Query input:
(and (is-student ?student1)
       (has-points ?student1 ?points1))

;;; Query results:
(and (is-student fanny) (has-points fanny 70))
(and (is-student eddy) (has-points eddy 85))
(and (is-student david) (has-points david 34))
(and (is-student charlie) (has-points charlie 65))
(and (is-student bart) (has-points bart 84))
(and (is-student anna) (has-points anna 73))

同理,AND & OR 的组合也很好理解。它主要是计算组合并过滤出结果。

我很难理解下面的代码获得最高分的学生。看起来很简单,但是我不明白 AND & NOT & "> points2 points1" 的组合如何提供最大的值(points)?

这是我 运行 它(在 DrRacket 中)让学生获得最高分时得到的结果:

;;; Query input:
(and (is-student ?student1)
       (has-points ?student1 ?points1)
       (not (and (is-student ?student2)
                 (has-points ?student2 ?points2)
                 (lisp-value > ?points2 ?points1))))

;;; Query results:
(and (is-student eddy) 
     (has-points eddy 85) 
     (not (and (is-student ?student2) 
               (has-points ?student2 ?points2) 
               (lisp-value > ?points2 85))))

比较第二个列表的否定与第一个列表的否定如何工作? 第一个结果中的每个 answer/line 是否与第二个 AND 的每一行进行比较? 我不知道如何 read/interpret 代码以及为什么这给出了我们正在搜索的内容?

如果您能帮助我们理解这是如何给出最高价值的,我们将不胜感激!

谢谢

PS:我的母语不是英语,对于任何语法或拼写错误,我深表歉意

在我看来,我可以对此做出解释:我有一个 student1 有一个点 point1 and 那里 not存在这样一种情况,即存在一个student2,其点为point2point2大于point1。 粗体 and, not 与代码完美匹配。 希望这对你有帮助,我也不是英语母语者:)