Re: Программы на прологе
predicates
sum(integer,real)
member(integer,real)
sum(real,real,real,real)
clauses
member(Y,R):-A=2*Y,B=A+1,R=A/B.
sum(N,R):-sum(N,R,N,1).
sum(N,R,0,R):-!.
sum(N,R,L,P):-member(L,R1),
L1=L-1,
P1=P*R1,
sum(N,R,L1,P1).
goal
sum(2,R1).
Re: Программы на прологе
predicates
sum(integer,real)
cosinus(integer,real)
sum(real,real,real,real)
clauses
cosinus(Y,R):-A=ln(1),B=Y*A,St=exp(B),R=cos(St).
sum(N,R):-sum(N,R,1,0).
sum(N,R,N,R):-!.
sum(N,R,L,P):-cosinus(L,R1),L1=L+1,
P1=P+R1,
sum(N,R,L1,P1).
goal
sum(5,R1).
Re: Программы на прологе
predicates
max_1(integer,integer).
max(integer,integer,integer).
clauses
max_1 (X,Y):- X>Y,! .
max_1 (Y,X):- Y>X.
max (X,Y,Z):- max_1(X,Y),max_1(X,Z), write ("Максимальное число = ",X,"\n"), ! .
max (X,Y,Z):- max_1(Y,X),max_1(Y,Z), write ("Максимальное число = ",Y,"\n"), ! .
max (X,Y,Z):- max_1(Z,Y),max_1(Z,X), write ("Максимальное число = ",Z,"\n").
GOAL: random(100,A), random(100,B), random(1000,C),
max( A, B, C).
Re: Программы на прологе
predicates
max_1(integer,integer).
max(integer,integer,integer).
clauses
max_1 (X,Y):- X>Y,! .
max_1 (Y,X):- Y>X.
max (X,Y,Z):- max_1(X,Y),max_1(X,Z), write ("Максимальное число = ",X,"\n"), ! .
max (X,Y,Z):- max_1(Y,X),max_1(Y,Z), write ("Максимальное число = ",Y,"\n"), ! .
max (X,Y,Z):- max_1(Z,Y),max_1(Z,X), write ("Максимальное число = ",Z,"\n").
GOAL: random(100,A), random(100,B), random(1000,C),
max( A, B, C).
Re: Программы на прологе
predicates
mesto(integer)
name(symbol)
shymaher(symbol,integer)
alezi(symbol,integer)
hill(symbol,integer)
kylxard(symbol,integer)
clauses
mesto(1).
mesto(2).
mesto(3).
mesto(4).
name(shymaher).
name(hill).
name(alezi).
name(kylxard).
shymaher(shymaher,X):- mesto(X), not(X=4), not(X=2), not(X=3).
hill(hill,Y):- mesto(Y), shymaher(shymaher,X), not(Y=X), not(Y=2), not(Y=4).
kylxard(kylxard,X):- mesto(X), shymaher(shymaher,Y), hill(hill,Z), not(X=Y), not(X=Z), not(X=4).
alezi(alezi,X):- mesto(X),shymaher(shymaher,Y), hill(hill,Z), kylxard(kylxard,V), not(X=Z), not(X=V).
goal
shymaher(X1,Y1),hill(X2,Y2),kylxard(X3,Y3),alezi(X4,Y4).
Re: Программы на прологе
predicates
r(unsigned, real, unsigned, real)
r(unsigned, real)
do
clauses
r(N, Proiz):-
r(N, Proiz, 0, 1).
r(N, Proiz, N, Proiz):-!.
r(N, Proiz, I, P):-
NewI=I+1,
NewP=P*((NewI+1)),
r(N, Proiz, NewI, NewP).
do:-
write("Введите число: "), readint(N), X=2*N, r(X, Sum), write("Произведение ряда = ",Sum,"\n").
goal
do.
Re: Программы на прологе
predicates
ryad(unsigned, real)
do
clauses
ryad(2, 0.66667):-!.
ryad(N, Proiz):-
NewN=N-2,
ryad(NewN, NewProiz),
Proiz=NewProiz*N/(N+1).
do:-
write("Введите число:"),
readint(X),
N=2*X,
ryad(N,Proiz),
write("\nПроизведение ряда = ",Proiz,"\n").
goal
do.
Re: Программы на прологе
predicates
r(long)
%r(unsigned, long,unsigned, long)
do
clauses
%r(N, NewPr):- r(N, NewPr,1,1).
%r(N, NewPr,N, NewPr):- !.
r(X):- X>100,write("\nNO\n"),!.
r(X):- X=81,write("\nYES\n"),!.
r(X):- NewX=X*X,%write(NewX),
r(NewX).
do:-write("Ввведите "), readint(X), r(X). %write("Сумма=", Pr,"\n").
goal
do.
Re: Программы на прологе
predicates
r(unsigned, long)
do
clauses
r(2, 2):-!.
r(N, Pr):-
NewN=N-2,
r(NewN, NewPr),
Pr=NewPr*N.
do:-write("Ввведите членов "), readint(X), N=2*X, r(N,Pr), write("Сумма=", Pr,"\n").
goal
do.
Re: Программы на прологе
domains
treetype = tree (string, treetype, treetype); empty ()
predicates
%all_elemeprint_nts (treetype)
find_tap(treetype,string)
clauses
find_tap (empty,A).
find_tap (tree (X, Y, Z),A):-
write (X), nl,A<>X,
find_tap(Y,A),
find_tap (Z,A).
goal
find_tap (tree ("Katea",
tree ("Misha",
tree ("Vova", empty, empty),
tree ("Lida", empty, empty)),
tree ("Lyda",
tree ("Zina", empty, empty),
tree ("Petea", empty, empty))),"Petea"),nl,fail;true.
Re: Программы на прологе
domains
inttree = tree(integer,inttree,inttree); end
predicates
nondeterm do(inttree)
action(integer,inttree,inttree)
create_tree(inttree,inttree)
insert(integer,inttree,inttree)
write_tree(inttree)
sumtree(inttree,integer)
nondeterm repeat
clauses
do(Tree):-
repeat,nl,
write("*******************************************************"),nl,
write("Введите 1 для изменения дерева\n"),
write("Введите 2 для вывода дерева\n"),
write("Введите 3 для вывода суммы\n"),
write("Введите 999 для выхода из программы\n"),
write("*******************************************************"),nl,
write("Enter number - "),
readint(X),nl,
action(X, Tree, NewTree),
do(NewTree).
action(1,Tree,NewTree):-
write("Введите 999 для окончания ввода\n"),
create_Tree(Tree, NewTree).
action(2,Tree,Tree):-
write_Tree(Tree),
write("\nPress a key to continue"),
readint(_),nl.
action(3,Tree,Tree):-
sumtree(Tree, Sum),
write("Сумма вершин дерева равна ", Sum, "\n"),
write("\nPress a key to continue").
action(999, _, end):-
exit.
create_Tree(Tree, NewTree):-
readint(C),
C<>999,!,
insert(C, Tree, TempTree),
create_Tree(TempTree, NewTree).
create_Tree(Tree, Tree).
insert(New,end,tree(New,end,end)):-!.
insert(New,tree(Element,Left,Right),tree(Element,NewLeft,Right)):-
New<Element,!,
insert(New,Left,NewLeft).
insert(New,tree(Element,Left,Right),tree(Element,Left,NewRight)):-
insert(New,Right,NewRight).
write_Tree(end).
write_Tree(tree(Item,Left,Right)):-
write_Tree(Left),
write(Item, " "),
write_Tree(Right).
repeat.
repeat:-repeat.
sumtree(end,Sum):-Sum=0.
sumtree(tree(Element, Left, Right), Sum):-
sumtree(Left,Sum1),
sumtree(Right,Sum2),
Sum=Sum1+Sum2+Element.
goal
write("*************** Отсортированное дерево *******************"),nl,
do(end).
Re: Программы на прологе
DOMAINS
treetype = tree (integer, treetype, treetype); empty
PREDICATES
max(treetype)
max(treetype,integer)
compare(integer,integer,integer)
CLAUSES
max(tree(X,Y,Z)):-compare(X,0,R),max(tree(X,Y,Z),R).
max(empty,M):-write("MAX - ",M,"\n"),!.
max(tree(X,Y,Z),M):-
compare(X,M,Rez),
max(Y,Rez),
max(Z,Rez).
compare(X,Y,Z):-X>=Y,!,Z=X.
compare(_,Y,Z):-Z=Y.
GOAL
%clearwindow,
max(tree(10,
tree(5,
tree(3,empty,empty),
tree(7,empty,empty)),
tree(15,
tree(16,empty,empty),
tree(17,empty,empty)))).
Re: Программы на прологе
predicates
sum(integer,real)
member(integer,real)
sum(real,real,real,real)
clauses
member(Y,R):-A=2*Y,B=A+1,R=A/B.
sum(N,R):-sum(N,R,N,1).
sum(N,R,0,R):-!.
sum(N,R,L,P):-member(L,R1),
L1=L-1,
P1=P*R1,
sum(N,R,L1,P1).
goal
sum(2,R1).
Re: Программы на прологе
predicates
ryad (integer, real)
ryad(integer, real, real)
clauses
ryad(N, Zn):-ryad(N, Zn,Sin),!.
ryad(1, X, Z ):- X=1/sin(1), Z=sin(1),!.
ryad(N, Zn, Sin):-
NewN=N-1,
ryad( NewN, NewZn, NewSin),
Sin=NewSin+sin(N),
Zn=NewZn+(1/Sin).
GOAL: write ("Enter a number.\n"),readint(X), ryad(X, Y).
Re: Программы на прологе
predicates
ryad (integer, real)
ryad(integer, real, real)
ryad(integer, real,real, integer, real,real)
clauses
ryad(N, Zn):-ryad(N, Zn,Sin),!.
ryad(N, Zn, Sin):-ryad(N, Zn, Sin, 1, 1.188395106,0.8414709).
ryad(N, Zn,Sin, N, Zn,Sin):- !.
ryad(N, Zn,Sin, I, Z, S):-
NewI=I+1,
NewSin=S+sin(NewI),
NewZn=Z+1/NewSin,
ryad(N, Zn,Sin, NewI, NewZn, NewSin).
GOAL: write ("Enter a number.\n"),readint(X),ryad(X, Y).
Re: Программы на прологе
predicates
ryad (integer, real)
ryad(integer, real, real, real)
clauses
ryad(N, Zn):-ryad(N, Zn, Cos, Sin),!.
ryad(1, X, Y, Z ):- X=cos(1)/sin(1), Y=cos(1), Z=sin(1),!.
ryad(N, Zn, Cos, Sin):-
NewN=N-1,
ryad( NewN, NewZn, NewCos, NewSin),
Cos=NewCos+cos(N),
Sin=NewSin+sin(N),
Zn=NewZn*Cos/Sin.
GOAL: write ("Enter a number.\n"),readint(X), ryad(X, Y).
Re: Программы на прологе
predicates
ryad (integer, real)
ryad(integer, real, real, real)
clauses
ryad(N, Zn):-ryad(N, Zn, Cos, Sin),!.
ryad(1, X, Y, Z ):- X=cos(1)/sin(1), Y=cos(1), Z=sin(1),!.
ryad(N, Zn, Cos, Sin):-
NewN=N-1,
ryad( NewN, NewZn, NewCos, NewSin),
Cos=NewCos+cos(N),
Sin=NewSin+sin(N),
Zn=NewZn*Cos/Sin.
GOAL: write ("Enter a number.\n"),readint(X), ryad(X, Y).
Re: Программы на прологе
predicates
ryad (integer, real)
ryad(integer, real, real, real)
ryad(integer, real, real, real, integer, real, real, real)
clauses
ryad(N, Zn):-ryad(N, Zn, Cos, Sin),!.
ryad(N, Zn, Cos, Sin):-ryad(N, Zn, Cos, Sin, 1, 0.6420926, 0.5403023,0.8414709).
ryad(N, Zn, Cos, Sin, N, Zn, Cos, Sin):- !.
ryad(N, Zn, Cos, Sin, I, Z, C, S):-
NewI=I+1,
NewCos=C+cos(NewI),
NewSin=S+sin(NewI),
NewZn=Z*NewCos/NewSin,
ryad(N, Zn, Cos, Sin, NewI, NewZn, NewCos, NewSin).
GOAL: write ("Enter a number.\n"),readint(X),ryad(X, Y).
Re: Программы на прологе
predicates
ryad(real, real)
clauses
ryad(1, C):-C=sin(1),!.
ryad(X, Zn):-
Y=X-1,
ryad (Y, Z),
Zn=Z+sin(1+X/10).
GOAL: X=11, ryad(X-9, Y).
Re: Программы на прологе
predicates
ryad(integer, real)
ryad(integer, real, integer, real)
clauses
ryad(N, Zn):-
X=N+1,ryad(X,Zn,1,0.841470985).
ryad(N,Zn,N,Zn):-!.
ryad(N, Zn, I, Z) :-
NewI=I+1,
NewZ=sin(1+I/10)+Z,
ryad(N, Zn, NewI, NewZ).
GOAL: X=10, ryad(X, Y).