作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是序言新手,正在尝试编写一个程序,以格式良好的命题公式返回原子
。例如,查询 ats(and(q, imp(or(p, q), neg(p))), As).
应返回 [p,q]
对于作为
。下面是我的代码,它将公式返回为 As
。我不知道如何分割F1
中的ats
中的单个F
和中的
所以 F2
wffwff/2
永远不会被调用。请我需要帮助才能从这里继续。谢谢。
代码
logical_atom( A ) :-
atom( A ),
atom_codes( A, [AH|_] ),
AH >= 97,
AH =< 122.
wff(A):- ground(A),
logical_atom(A).
wff(neg(A)) :- ground(A),wff(A).
wff(or(F1,F2)) :-
wff(F1),
wff(F2).
wff(and(F1,F2)) :-
wff(F1),
wff(F2).
wff(imp(F1,F2)) :-
wff(F1),
wff(F2).
ats(F, As):- wff(F), setof(F, logical_atom(F), As).
最佳答案
首先,考虑使用更清晰的表示形式:目前,您无法通过公共(public)仿函数来区分原子。因此,将它们包装在 a(Atom)
中。
其次,使用 DCG 来描述格式良好的公式与其原子列表之间的关系,例如:
wff_atoms(a(A)) --> [A].
wff_atoms(neg(F)) --> wff_atoms(F).
wff_atoms(or(F1,F2)) --> wff_atoms(F1), wff_atoms(F2).
wff_atoms(and(F1,F2)) --> wff_atoms(F1), wff_atoms(F2).
wff_atoms(imp(F1,F2)) --> wff_atoms(F1), wff_atoms(F2).
示例查询及其结果:
?- phrase(wff_atoms(and(a(q), imp(or(a(p), a(q)), neg(a(p))))), As).
As = [q, p, q, p].
关于Prolog 程序返回命题公式中的原子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26544693/
前言请注意,这是一项作业。第一个问题已经问了一个问题。所以我们有数据类型: data BoolProp : ??? where ptrue : BoolProp true pfalse :
我是依赖类型的新手,有 Haskell 经验,正在慢慢学习 Idris。作为练习,我想编写霍夫曼编码。目前我正在尝试编写一个证明,证明代码树的“扁平化”会产生一个前缀代码,但被量词卡住了。 我有一个简
我是一名优秀的程序员,十分优秀!