Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
574 views
in Technique[技术] by (71.8m points)

prolog - I'm curious if Logic Programs can do algebra

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...