表示 X 的特定子集在 core.logic 中具有属性 Y
我想:
- 描述有关一类对象的子集的事实。
- 声明一个对象具有由其他属性组成的属性。
举个例子:
Red robotic birds are only composed of buttons, cheese, and wire.
我想表达一类鸟,红色的机器鸟,有一个属性。 这个属性是它们仅由纽扣、奶酪和金属丝组成。对钢丝奶酪或纽扣的类型没有限制。因此,应该推断不存在由纸组成的红色机器鸟。此外,这些鸟可以由按钮、奶酪和电线的子集组成。
在 clojure/core.logic.prelude 中,有使用 defrel
和 fact
的关系和事实。 然而,我无法想出一个组合来解释这个事实。
I want to:
- Describe a fact about a subset of a class of objects.
- Declare that an object has a property that consists of other properties.
Take the following as an example:
Red robotic birds are only composed of buttons, cheese, and wire.
I want to express that a class of birds, birds that are red and robotic, have a property.
This property is that they are composed only of buttons, cheese, and wire. There are no restrictions on the type of wire cheese or buttons. Also as a result, it should be deducible that there are no red robotic birds that are composed of paper. Also, these birds can be composed of a subset of the items buttons, cheese, and wire.
In clojure/core.logic.prelude, there are relations and facts using defrel
and fact
.
However, I can't come up with a combination to explain this fact.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Prolog 中,事实和目标之间没有像 miniKanren 那样的区别。我将来可能会解决这个问题。
顺便说一句,我不确定这是否完全回答了您的问题 - 听到您希望运行什么类型的查询会很有帮助。
这是经过测试的代码(针对 Clojure 1.3.0-beta1),因为我使用的是 ^:index 技巧,如果您将其替换为 ^{,此代码将在 1.2.0 中正常运行:index true}:
尝试一下。
In Prolog there is no distinction between facts and goals as there are in miniKanren. I might address this in the future.
BTW, I'm not sure that this completely answers your question - it would be helpful to hear what types of queries you wish to run.
This is tested code (for Clojure 1.3.0-beta1) since I'm using the ^:index trick, this code will run fine in 1.2.0 if you swap it for ^{:index true}:
Trying it out.
不完全确定这是否是您所需要的,但是您可以通过创建事实的图形结构轻松地表达一个类具有一组属性(请参阅下面的属性事实列表以及在一组中查找属性的规则)。
然后,为了表达该组属性的组合,您需要另一组组合事实和规则,以发现该类的任何子属性以及其可以组成的结果。
我在下面还给出了一个代码示例来帮助解释。
示例查询
Prolog 规则简介。
规则本质上只是事实(例如
animal(cat)。
),其条件是其他规则或事实为真。规则由头部和主体组成(head :- body.
)。主体是最常以合取范式 (A /\ B /\ C) 表达的逻辑证明。 prolog中的and运算符是,
,or运算符是;
(但在规则中不鼓励使用) ,句点 (.
) 表示规则或事实的结束。请注意,如果主体中后面的规则或事实失败,则 prolog 将回溯并从先前的规则或事实中请求替代答案,然后重试。考虑下面这个有些人为的例子。
share_same_colour(FruitA, FruitB) :-
颜色(颜色,水果A),
颜色(颜色,FruitB)。
如果我们执行查询
share_same_colour(apple, Strawberry).
,则colour(Colour, apple).
可能会返回 Color 作为绿色。然而,没有绿色的草莓,所以序言将回溯并询问苹果还有哪些其他颜色。下一个答案可能是红色,此时第二个颜色语句将成功,整个规则为真。Not entirely sure if this is what you need, but you can easily express that a class has a set of properties by creating a graph structure of facts (see the list of properties facts below and the rule for finding the properties within a set).
Then to express the composition of that set of properties you need another set of composition facts and rule that discovers any sub-properties of the class and as a result things it can be composed of.
I've given a code example below as well to help explain.
example queries
Prolog rules in brief.
Rules are essentially just facts (eg.
animal(cat).
) that are conditional on other rules or facts being true. A rule is made up a head and a body (head :- body.
). A body is a logical proof most commonly expressed in conjunctive normal form (A /\ B /\ C). The and operator in prolog is,
, the or operator is;
(but its use is discouraged in rules), and the period (.
) denotes the end of a rule or fact.Note that if a later rule or fact in the body fails then prolog will backtrack and ask for an alternative answer from a previous rule or fact and then try again. Consider the somewhat contrived example below.
share_same_colour(FruitA, FruitB) :-
colour(Colour, FruitA),
colour(Colour, FruitB).
If we execute the query
share_same_colour(apple, strawberry).
thencolour(Colour, apple).
might return Colour as being green. However, there no green strawberries, so prolog will backtrack and ask what other colours do apples come in. The next answer might be red, upon which the second colour statement would succeed and the whole rule be true.