window_brush(_, rgb(0,0,255)),
edit( G_S1, 1, fail(_), "", 10, 10,200, 25),
edit( G_S2, 1, fail(_), "", 10, 45,200, 25),
button(_,_,b7_func(_),"7",10,80,35,35),
button(_,_,b8_func(_),"8",50,80,35,35),
button(_,_,b9_func(_),"9",90,80,35,35),
button(_,_,b4_func(_),"4",10,120,35,35),
button(_,_,b5_func(_),"5",50,120,35,35),
button(_,_,b6_func(_),"6",90,120,35,35),
button(_,_,b1_func(_),"1",10,160,35,35),
button(_,_,b2_func(_),"2",50,160,35,35),
button(_,_,b3_func(_),"3",90,160,35,35),
button(_,_,b0_func(_),"0",10,200,35,35),
button(_,_,point_func(_),".",50,200,35,35),
button(_,_,back_func(_),"<-",90,200,35,35),
button(_,_,plus_func(_),"+",140,160,35,75),
button(_,_,ravno_func(_),"=",180,200,35,35),
button(_,_,mult_func(_),"*",180,160,35,35),
button(_,_,minus_func(_),"-",140,120,35,35),
button(_,_,div_func(_),"/",180,120,35,35),
button(_,_,onc_func(_),"on/c",140,80,75,35),
button(_,_,lskoba_func(_),"(",220,200,35,35),
button(_,_,dskoba_func(_),")",260,200,35,35),
button(_,_,sin_func(_),"sin",220,80,35,35),
button(_,_,cos_func(_),"cos",220,120,35,35),
button(_,_,tg_func(_),"tg",220,160,35,35),
button(_,_,arcsin_func(_),"arcs",260,80,35,35),
button(_,_,arccos_func(_),"arcc",260,120,35,35),
button(_,_,arctg_func(_),"arct",260,160,35,35),
button(_,_,sqr_func(_),"sqr",300,80,35,35),
button(_,_,exp_func(_),"exp",300,120,35,35),
button(_,_,nlog_func(_),"nlog",300,160,35,35),
button(_,_,dlog_func(_),"dlog",300,200,35,35),
button(_,_,b_func(_),"b",260,45,35,30),
button(_,_,x_func(_),"x",300,10,35,30),
button(_,_,pow_func(_),"pow",300,45,35,30),
button(_,_,a_func(_),"a",220,45,35,30),
button(_,_,dx_func(_),"dx",220,10,75,30).
% this clause is corrected by LEE, Chung-Woo
% from Korean Republic
menu_extend(press) :-
size(_,X, _),
X > 360, !.
menu_extend(press) :-
repeat,
size(_,X, Y),
X1 is X + 1,
size(_,X1, Y),
X1>360.
menu_normal(press) :-
size(_,232,300).
b0_func(press) :- add_text(G_S1, "0").
b1_func(press) :- add_text(G_S1, "1").
b2_func(press) :- add_text(G_S1, "2").
b3_func(press) :- add_text(G_S1, "3").
b4_func(press) :- add_text(G_S1, "4").
b5_func(press) :- add_text(G_S1, "5").
b6_func(press) :- add_text(G_S1, "6").
b7_func(press) :- add_text(G_S1, "7").
b8_func(press) :- add_text(G_S1, "8").
b9_func(press) :- add_text(G_S1, "9").
plus_func(press) :-add_text(G_S1, "+").
minus_func(press) :-add_text(G_S1, "- ").
mult_func(press) :-add_text(G_S1, "*").
div_func(press) :-add_text(G_S1, "/").
point_func(press) :-add_text(G_S1, ".").
lskoba_func(press) :-add_text(G_S1, " (").
dskoba_func(press) :-add_text(G_S1, ")").
sin_func(press) :-add_text(G_S1, "sin(").
arcsin_func(press) :-add_text(G_S1, "arcsin(").
cos_func(press) :-add_text(G_S1, "cos(").
arccos_func(press) :-add_text(G_S1, "arccos(").
tg_func(press) :-add_text(G_S1, "tg(").
arctg_func(press) :-add_text(G_S1, "arctg(").
sqr_func(press) :-add_text(G_S1, "sqrt(").
exp_func(press) :-add_text(G_S1, "exp(").
nlog_func(press) :-add_text(G_S1, "log(").
dlog_func(press) :-add_text(G_S1, "log10(").
a_func(press) :-add_text(G_S1, "a").
b_func(press) :-add_text(G_S1, "b").
x_func(press) :-add_text(G_S1, "x").
pow_func(press) :-add_text(G_S1, "**").
ravno_func(press):-
T is scan(get_text(G_S1)),
Result is T,
set_text(print(Result),G_S2).
onc_func(press) :-
set_text("",G_S1),
set_text("",G_S2).
back_func(press) :-
S is get_text(G_S1),
L is str_length(S),
sub_string(S2, S, 0, L- 1),
set_text(S2,G_S1).
dx_func(press) :-
T is scan(get_text(G_S1)),
d( T, x, Result),
simplify(Result,Result2),
set_text(printq(Result2),G_S2).
% For dx
atomic(X) :- not(X=..P).
d(X,X,1) :- !.
d(C,_,0) :- atomic(C).
%d(~U,X,~A) :- d(U,X,A).
d(U+V,X,A+B) :- d(U,X,A),d(V,X,B).
d(U-V,X,A-B) :- d(U,X,A),d(V,X,B).
d(C*U,X,C*A) :- atomic(C), C\=X,d(U,X,A),!.
d(U*V,X,B*U+A*V) :- d(U,X,A), d(V,X,B).
%d(U/V,X,A) :- d( V^V(~1), X, P).
simplify(E,F) :-
E = Op(L, R),
simplify(L,X),
simplify(R,Y),
s(Op,X,Y,F).
simplify(E,E).
s('+',X,Y,Z) :- number(X),number(Y), Z is X+Y.
s('+',X,0,X).
s('+',0,X,X).
s('+',X,X,R):-simplify(2*X,R).
s('+',X*Z,Y*Z,R*Z) :-number(X),number(Y), R is X+Y.
s('+',X,Y,Y+X) :- number(X).
s('+',X+Y,Z,X+W) :-number(Y),number(Z),W is Y+Z.
s('+',X+Y,Z,X+Z+Y) :- number(Y).
s('+',X,Y,X+Y).
s('*',X,Y,Z) :- number(X),number(Y), Z is X*Y.
s('*',_,0,0).
s('*',0,_,0).
s('*',1,X,X).
s('*',X,1,X).
s('*',X,Y,Y*X) :- number(Y).
s('*',X*Y,W,Z*Y) :-number(X),number(W),Z is X*W.
s('*',X,Y*Z,R*Z) :- number(X),number(Y), R is X*Y.
s('*',X,Y*Z,Y*X*Z) :- number(Y).
s('*',X,Y,X*Y).
edit( G_S1, 1, fail(_), "", 10, 10,200, 25),
edit( G_S2, 1, fail(_), "", 10, 45,200, 25),
button(_,_,b7_func(_),"7",10,80,35,35),
button(_,_,b8_func(_),"8",50,80,35,35),
button(_,_,b9_func(_),"9",90,80,35,35),
button(_,_,b4_func(_),"4",10,120,35,35),
button(_,_,b5_func(_),"5",50,120,35,35),
button(_,_,b6_func(_),"6",90,120,35,35),
button(_,_,b1_func(_),"1",10,160,35,35),
button(_,_,b2_func(_),"2",50,160,35,35),
button(_,_,b3_func(_),"3",90,160,35,35),
button(_,_,b0_func(_),"0",10,200,35,35),
button(_,_,point_func(_),".",50,200,35,35),
button(_,_,back_func(_),"<-",90,200,35,35),
button(_,_,plus_func(_),"+",140,160,35,75),
button(_,_,ravno_func(_),"=",180,200,35,35),
button(_,_,mult_func(_),"*",180,160,35,35),
button(_,_,minus_func(_),"-",140,120,35,35),
button(_,_,div_func(_),"/",180,120,35,35),
button(_,_,onc_func(_),"on/c",140,80,75,35),
button(_,_,lskoba_func(_),"(",220,200,35,35),
button(_,_,dskoba_func(_),")",260,200,35,35),
button(_,_,sin_func(_),"sin",220,80,35,35),
button(_,_,cos_func(_),"cos",220,120,35,35),
button(_,_,tg_func(_),"tg",220,160,35,35),
button(_,_,arcsin_func(_),"arcs",260,80,35,35),
button(_,_,arccos_func(_),"arcc",260,120,35,35),
button(_,_,arctg_func(_),"arct",260,160,35,35),
button(_,_,sqr_func(_),"sqr",300,80,35,35),
button(_,_,exp_func(_),"exp",300,120,35,35),
button(_,_,nlog_func(_),"nlog",300,160,35,35),
button(_,_,dlog_func(_),"dlog",300,200,35,35),
button(_,_,b_func(_),"b",260,45,35,30),
button(_,_,x_func(_),"x",300,10,35,30),
button(_,_,pow_func(_),"pow",300,45,35,30),
button(_,_,a_func(_),"a",220,45,35,30),
button(_,_,dx_func(_),"dx",220,10,75,30).
% this clause is corrected by LEE, Chung-Woo
% from Korean Republic
menu_extend(press) :-
size(_,X, _),
X > 360, !.
menu_extend(press) :-
repeat,
size(_,X, Y),
X1 is X + 1,
size(_,X1, Y),
X1>360.
menu_normal(press) :-
size(_,232,300).
b0_func(press) :- add_text(G_S1, "0").
b1_func(press) :- add_text(G_S1, "1").
b2_func(press) :- add_text(G_S1, "2").
b3_func(press) :- add_text(G_S1, "3").
b4_func(press) :- add_text(G_S1, "4").
b5_func(press) :- add_text(G_S1, "5").
b6_func(press) :- add_text(G_S1, "6").
b7_func(press) :- add_text(G_S1, "7").
b8_func(press) :- add_text(G_S1, "8").
b9_func(press) :- add_text(G_S1, "9").
plus_func(press) :-add_text(G_S1, "+").
minus_func(press) :-add_text(G_S1, "- ").
mult_func(press) :-add_text(G_S1, "*").
div_func(press) :-add_text(G_S1, "/").
point_func(press) :-add_text(G_S1, ".").
lskoba_func(press) :-add_text(G_S1, " (").
dskoba_func(press) :-add_text(G_S1, ")").
sin_func(press) :-add_text(G_S1, "sin(").
arcsin_func(press) :-add_text(G_S1, "arcsin(").
cos_func(press) :-add_text(G_S1, "cos(").
arccos_func(press) :-add_text(G_S1, "arccos(").
tg_func(press) :-add_text(G_S1, "tg(").
arctg_func(press) :-add_text(G_S1, "arctg(").
sqr_func(press) :-add_text(G_S1, "sqrt(").
exp_func(press) :-add_text(G_S1, "exp(").
nlog_func(press) :-add_text(G_S1, "log(").
dlog_func(press) :-add_text(G_S1, "log10(").
a_func(press) :-add_text(G_S1, "a").
b_func(press) :-add_text(G_S1, "b").
x_func(press) :-add_text(G_S1, "x").
pow_func(press) :-add_text(G_S1, "**").
ravno_func(press):-
T is scan(get_text(G_S1)),
Result is T,
set_text(print(Result),G_S2).
onc_func(press) :-
set_text("",G_S1),
set_text("",G_S2).
back_func(press) :-
S is get_text(G_S1),
L is str_length(S),
sub_string(S2, S, 0, L- 1),
set_text(S2,G_S1).
dx_func(press) :-
T is scan(get_text(G_S1)),
d( T, x, Result),
simplify(Result,Result2),
set_text(printq(Result2),G_S2).
% For dx
atomic(X) :- not(X=..P).
d(X,X,1) :- !.
d(C,_,0) :- atomic(C).
%d(~U,X,~A) :- d(U,X,A).
d(U+V,X,A+B) :- d(U,X,A),d(V,X,B).
d(U-V,X,A-B) :- d(U,X,A),d(V,X,B).
d(C*U,X,C*A) :- atomic(C), C\=X,d(U,X,A),!.
d(U*V,X,B*U+A*V) :- d(U,X,A), d(V,X,B).
%d(U/V,X,A) :- d( V^V(~1), X, P).
simplify(E,F) :-
E = Op(L, R),
simplify(L,X),
simplify(R,Y),
s(Op,X,Y,F).
simplify(E,E).
s('+',X,Y,Z) :- number(X),number(Y), Z is X+Y.
s('+',X,0,X).
s('+',0,X,X).
s('+',X,X,R):-simplify(2*X,R).
s('+',X*Z,Y*Z,R*Z) :-number(X),number(Y), R is X+Y.
s('+',X,Y,Y+X) :- number(X).
s('+',X+Y,Z,X+W) :-number(Y),number(Z),W is Y+Z.
s('+',X+Y,Z,X+Z+Y) :- number(Y).
s('+',X,Y,X+Y).
s('*',X,Y,Z) :- number(X),number(Y), Z is X*Y.
s('*',_,0,0).
s('*',0,_,0).
s('*',1,X,X).
s('*',X,1,X).
s('*',X,Y,Y*X) :- number(Y).
s('*',X*Y,W,Z*Y) :-number(X),number(W),Z is X*W.
s('*',X,Y*Z,R*Z) :- number(X),number(Y), R is X*Y.
s('*',X,Y*Z,Y*X*Z) :- number(Y).
s('*',X,Y,X*Y).