繁体   English   中英

如何编写序言程序和查询

[英]How to write prolog program and queries

编写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? 

请帮我。

  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

由于这看起来像是一项作业,因此我故意在各处使用错误的名称。 您将不得不更正那些。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM