我很好奇逻辑程序是否可以代数 [英] I'm curious if Logic Programs can do algebra

查看:89
本文介绍了我很好奇逻辑程序是否可以代数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了有关Prolog和逻辑编程的简短文章.我很好奇逻辑程序是否可以代数.就像您能够问等式5 + X = 7中X的变量是什么,得到-2的答案一样?

I read a brief article about Prolog and Logic Programming. I'm curious if Logic Programs can do algebra. Like would you be able to ask what the Variable of X is in the equation 5+X = 7 and get an answer of -2?

推荐答案

所有严肃的Prolog系统都在有限域(简称CLP(FD))上提供约束逻辑编程,您可以轻松地求解许多这样的方程.例如,使用SICStus Prolog,SWI和Yap:

All serious Prolog systems provide constraint logic programming over finite domains, called CLP(FD) for short, with which you can solve many such equations easily. For example, with SICStus Prolog, SWI and Yap:

?- use_module(library(clpfd)).
true.

?- 5+X #= 7.
X = 2.

显然,答案是2而不是-2.还要检查其他领域的约束逻辑编程,例如带有library(clpq)的推理.

Apparently, the answer is 2 instead of -2. Also check out constraint logic programming over other domains, like the rationals with library(clpq).

这篇关于我很好奇逻辑程序是否可以代数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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