How to process the formula with a prologue?

If a

a+b+c=1
a^2+b^2+c^2=2
a^3+b^3+c^3=3

then

a^4+b^4+c^4=?

I know the result is 25/6, but how to calculate it as a prologue?

I tried this but could not:

[1] 5 ?- A+B+C=:=1,A**2+B**2+C**2=:=2,A**3+B**3+C**3=:=3.
ERROR: Unhandled exception: =:=/2: Arguments are not sufficiently instantiated
+3
source share
6 answers

Unfortunately, using Prolog as a numerical solver is not trivial.

?- X is 1 + 2*X.

will raise the same mistake, while the answer will seem perfectly obvious.

While Prolog is able to drill its knowledge base to magically solve a logical problem, it simply cannot do the same with numbers. The problem is not only the infinity of most common sets of numbers, but also continuity (i.e., what number comes after 1.1234567890123456789?).

, : , , Prolog.

, Prolog (. ).

+5

, , :

Prolog!

, . ( , , Undefined procedure: :-/2). , , , ():

:- use_module(library(clpr)). 
run(A, B, C) :- {A+B+C=1, A*A+B*B+C*C=2}.

consult/1 ( "consult" ). Prolog , . ( , "" ).

run(A,B,C) . , .

, Prolog, - SO, , .

+2

:

a+b+c=1
a^2+b^2+c^2=2
a^3+b^3+c^3=3
a^4+b^4+c^4=?

. () .

[EDIT] Prolog , , ...

.... :

a+b+c=1
a^2+b^2+c^2 = ( a + b + c )^2 - 2ab - 2ac - 2bc = 2
a^3+b^3+c^3 = ( a + b + c )*(a^2 + b^2 + c^2 - ab - ab - bc ) + 3abc = 3
.
.
.

!!! ( Prolog, ...)

+1

Prolog, ISO Prolog, , , . :

SWI-Prolog . , :

:- use_module(library(clpr)).
run(A, B, C) :- {A+B+C=1, A*A+B*B+C*C=2}.

. A.8 SWI-Prolog.

SICStus Prolog CHR ( ).

GNU Prolog , .

+1

, . , Prolog , :

expt (var, 0): - 1, expt (var, n): - var * expt (var, n-1)

, ( , , 20 , ).

0

. , - :

number(1).
number(N) :- number(N-1).

rational(X) :- number(A), number(B), X is A/B.

A, B, C, :

?- rational(A), rational(B), rational(C), A+B+C=:=1,A**2+B**2+C**2=:=2,A**3+B**3+C**3=:=3.

However, I suspect that the search order for the set of rational numbers will hit infinity for A before the second value for B is used. A workaround / cheat (assuming some knowledge of the solution) would only determine numbers less than (say) 100 to limit the search space.

number(1).
number(N) :- N <= 100, number(N-1).

Sorry if my syntax is a bit off. I have not used Prolog for a long time.

0
source

Source: https://habr.com/ru/post/1727026/


All Articles