1

I am trying to solve ax^2+bx+c>0 type inequality question using prolog.

Can i use this coding for solving the problem. two

:-use_module(library(fd)).

compute(L=R, X) :-
        term_variables(L, [X]),
        L #= R.
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
ict
  • 95
  • 1
  • 5
  • How do you instantiate it, why do you use finite domains, what are the domains? `fd` is not even a library as far as I know. – Willem Van Onsem Aug 25 '14 at 19:13
  • http://stackoverflow.com/questions/9209058/how-to-do-arithmetic-expression-evaluation-in-prolog from the above link i got to know it.Also I want to know how to insert a library into a .pl file.The # sign doen;t support at all.Even in the above program. – ict Aug 25 '14 at 19:32
  • as already mentioned, the `fd` library is unknown to me. You probably should use `clpfd`... – Willem Van Onsem Aug 26 '14 at 06:58
  • The `fd` library is from ECLiPSe Prolog. – Mark Brown Oct 07 '14 at 13:07

1 Answers1

0

First library(clpfd) (not fd) is - as far as I know - a finite domain solver. So you need to provide the finite domains.

Secondly, you provide an equality constraint, you should provide an inequality constraint.

Example:

:- use_module(library(clpfd)).

compute(L>R,X,Low,High) :-
    term_variables(L, [X]),
    X in Low..High,
    L #> R,
    label([X]).

Or when no domains are given:

compute(L>R,X) :-
    term_variables(L,[X]),
    L #> R.

And then instantiate:

?- compute(5*X*X-2*X+7>0,X).
2*X#=_G1114,
_G1128*X#=_G1126,
5*X#=_G1128,
_G1152+_G1114#=_G1126,
_G1152 in -6..sup,
_G1152+7#=_G1174,
_G1174 in 1..sup.
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
  • 1
    What is the purpose of term_variables/2 – false Aug 25 '14 at 19:37
  • I think @ict is interested in generating some kind expression like `X > 5`, thus in order to retrieve the variable... – Willem Van Onsem Aug 25 '14 at 19:42
  • var(L), L = X would be the same. But why at all – false Aug 25 '14 at 19:44
  • But it's not guaranteed `L` is a simple variable... I think the aim is to extract the `X` in `5*X*X-2*X+7` – Willem Van Onsem Aug 25 '14 at 19:47
  • But why?? If X is X in Low..High it cannot be just anything – false Aug 25 '14 at 19:51
  • @false: What if one queries `compute(5*R*R-2*R+7=0,X)`. with `R` not really given (but asked)? – Willem Van Onsem Aug 25 '14 at 19:53
  • True. But then consider the same query with R = 1+S, now, the range is shifted. But the query is the same... – false Aug 25 '14 at 20:16
  • 1
    @false, I totally agree on that point, I would drop that part as well, but the question is still very unclear. ict should elaborate on this... Sidenote: funny that a user named false says true. ;) – Willem Van Onsem Aug 25 '14 at 20:30
  • thnks all.But @ CommuSoft ,the coding didin't work.when consult the .pl file it says "Syntax error:operator_expected." Actually what I am doing is solving inequality questions using prolog.I have identified 3 parts under inequalities.They are 1)linear ineq.2)quadratic inequalities 3)absolute inequalities. Quadratic inequalities structure is ax^2+bx+c.I want to solve this type of inequality using SWI-Prolog.help me.thanks. – ict Aug 26 '14 at 15:58
  • Wouldn't it be legit to have compute(L>R,X) head instead of compute(L=R,X) ? –  Feb 16 '21 at 18:42
  • @MostowskiCollapse: Yes, I probably made some typo''s... Although it has been a long time ago, so I don't know that for sure :). – Willem Van Onsem Feb 16 '21 at 18:46