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

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

问题描述

我读了一篇关于 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天全站免登陆