【问题标题】:How to write prolog program and queries如何编写 prolog 程序和查询
【发布时间】:2018-09-20 23:03:09
【问题描述】:

为后续编写 Prolog 程序。我写了所有的东西,我需要知道最后两个是不是我写的。

1. saman likes maths.
2. saman likes science.
3. udara likes maths.
4. fazal likes science.
5. fazal likes music.
6. geetha likes history.
7. geetha likes science.
8. geetha likes music.
9. those who like maths and science will follow engineering for advance level.
10. those who likes history or music will follow art for advance level.

这对最后两个正确吗?

student(X):- like(X,maths_and_science),follow(X,engineering).
student(X):- likes(X,history_or_music), follow(X,art).
  1. 我不知道如何编写 Prolog 查询以供关注。

    1) Does saman like maths or music?
    
    2) Who likes science and music?
    
    3) who will do engineering?
    

请帮帮我。

【问题讨论】:

  • 我认为你实现规则之前,首先需要定义predicatesfunctors对应的语义。但最后两个 - 据我所知 - 不正确。

标签: prolog


【解决方案1】:
  1. 那些喜欢数学和科学的人会跟随工程学进入高级水平。
  2. 那些喜欢历史或音乐的人会跟随艺术进阶。

这对最后两个正确吗?

没有。可能是:

will_follow(Student, engineering) :-
    likes(Student, maths),
    likes(Student, science).

will_follow(Student, art) :-
    likes(Student, history)  ;
    likes(Student, music).

1) 萨满喜欢数学还是音乐?

likes(saman, art) ; likes(saman, music).     % intentionally incorrect

2) 谁喜欢科学和音乐?

likes( Who, science) , likes( Who, maths).   % intentionally incorrect

3) 谁来做工程?

will_follow( Who, arts ).                    % intentionally incorrect

因为这看起来像是一项作业,所以我故意在这里和那里使用了错误的名称。你必须纠正这些。

【讨论】:

  • 感谢您的热心帮助。它对我以后的工作最有用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-06
  • 1970-01-01
  • 2020-10-02
  • 2022-11-12
相关资源
最近更新 更多