Prolog集差异关系
在 Prolog 中定义集合减法关系:
difference( Set 1, Set 2, SetDifference)
其中所有三个集合都表示为列表。例如:
difference( [a,b,c,d], [b,d,e,f], [a,c])
谢谢!
Define the set subtraction relation in Prolog:
difference( Set 1, Set 2, SetDifference)
where all the three sets are represented as lists. For example:
difference( [a,b,c,d], [b,d,e,f], [a,c])
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Prolog系统中一般都包含这样的功能。这让我觉得这是一个任意的家庭作业,我想知道规则是什么。大概你不能调用set_difference。可以用member/2吗?列表是否已排序?该函数是否应该在所有模式(+++、++-、-++、++)下工作,并回溯以产生替代答案?
如果从头开始做这样的功能,最好的办法就是用英语思考,归纳思考。
如何回答最简单的情况:两个空列表之间的区别是一个空列表。不同之处([],[],[])。
如果您添加到其中一个列表怎么办?给另一个?每个答案都有一个子句。
除此之外,答案取决于作业规则。
Such a function is generally included in Prolog systems. This makes me think it's an arbitrary homework assignment, and I wonder what the rules are. Presumably you can't call set_difference. Can you use member/2? Are the lists sorted or not? Should the function work in all modes (+++, ++-, -++, +-+), and backtrack to produce alternative answers?
If doing such a function from scratch, the best approach is to think in English, and think inductively.
How do you answer the simplest case: The difference between two empty lists is an empty list. difference([],[],[]).
What if you add to one of the lists? To the other? Each answer gets a clause.
Beyond that, the answer depends on the rules of the assignment.