如何在 Prolog 中创建此规则? [英] How can I create this rule in Prolog?

查看:46
本文介绍了如何在 Prolog 中创建此规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助在 Prolog 中创建此规则.

I need a help for create this rule in Prolog.

问题来了:为 Prolog 创建事实和规则.

This is the question: Create fact and rule for Prolog.

  • 汉堡是一种食物.
  • 三明治是一种食物.
  • 披萨是一种食物.
  • 三明治是午餐.
  • 披萨是晚餐.
  • 每种食物都是一顿饭 OR 任何东西都是一顿饭,如果它是一种食物.

ps.这不是作业,是我自己的作业,我想知道如何正确创建此规则.

ps. it's not homework, it's myself assignment i want know how to create this rule correctly.

food(burger).
food(sandwich).
lunch(sandwich).

dinner(pizza).

meal(X) :- food(X) ; ...

推荐答案

首先,将英文句子翻译成一阶逻辑句.

First, translate the English sentences to first-order logic sentences.

every food is a meal
=> forall X (food(X) -> meal(X))

anything is a meal if it is a food
=> if it is a food, it is a meal
=> if X is a food, X is a meal
=> forall X (food(X) -> meal(X))

然后,将一阶逻辑语句翻译成 Prolog Horn 子句:

Then, translate the first-order logic sentences to Prolog Horn clauses:

meal(X) :- food(X).
meal(X) :- food(X).

这是多余的,只能写一次.

which is redundant and can be written just once instead.

这篇关于如何在 Prolog 中创建此规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆