为给定日期之前的消息编写 Prolog 规则 [英] Writing a Prolog rule for messages before a given date

查看:51
本文介绍了为给定日期之前的消息编写 Prolog 规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何编写一个 Prolog 规则,让两个人测试在给定日期之前他们之间是否有以任一方向发送的消息?

How do I write a Prolog rule that given two people, tests if there has been a message sent in either direction between them before a given date?

到目前为止我有:

?- MBefore(x,y) :- message(x,y,d1), message(y,x,d1), d1@<Date.

推荐答案

mbefore(X,Y,D) :- message(X,Y,D1), D >D1;消息(Y,X,D1),D >D1.

这里',' 表示和"';' 表示或"."or" 组合的两种选择都被独立尝试.首先,系统尝试证明第一个备选方案(在 ; 的左侧),然后搜索回溯,将任何逻辑变量恢复到以前的状态,然后是第二个备选方案(在 '; 的右侧).') 进行了尝试.这就是为什么我们可以在 "or" 组合的两种替代方案中使用相同的 logvar D1.

Here ',' means "and", ';' means "or". Both alternatives of the "or" combination are tried, independently. First the system attempts to prove the first alternative (to the left of ;), then the search backtracks, any logical variables are restored to their previous states, and the second alternative (to the right of ';') is tried. That's why we can use the same logvar D1 in both alternatives of the "or"-combination.

此外,':-' 的意思是成立,如果以下可以证明".

如果以上任何内容对您来说都是新的,您真的应该通过一些教程或教科书来学习该语言的基础知识.《序言的艺术》是一本优秀的入门书.

If any of the above is new for you, you really should study the basics of the language through some tutorials or textbooks. "The Art of Prolog" is an excellent introductory book.

这篇关于为给定日期之前的消息编写 Prolog 规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆