You are on page 1of 3

restart;interface(imaginaryunit=JZ):

Mset := {A, B, C, P, R, S, a, b, c, ha, hb, hc};


Fset := {
[{A, B}, C, A = 180-B-C],
[{A, C}, B, A = 180-B-C],
[{A, R}, a, R = a/(2*sin(A))],
[{A, a}, R, R = a/(2*sin(A))],
[{B, C}, A, A = 180-B-C],
[{B, R}, b, R = b/(2*sin(B))],
[{B, b}, R, R = b/(2*sin(B))],
[{C, R}, c, R = c/(2*sin(C))],
[{C, c}, R, R = c/(2*sin(C))],
[{R, a}, A, R = a/(2*sin(A))],
[{R, b}, B, R = b/(2*sin(B))],
[{R, c}, C, R = c/(2*sin(C))],
[{S, a}, ha, S = (1/2)*a*ha],
[{S, b}, hb, S = (1/2)*b*hb],
[{S, c}, hc, S = (1/2)*c*hc],
[{S, ha}, a, S = (1/2)*a*ha],
[{S, hb}, b, S = (1/2)*b*hb],
[{S, hc}, c, S = (1/2)*c*hc],
[{a, ha}, S, S = (1/2)*a*ha],
[{b, hb}, S, S = (1/2)*b*hb],
[{c, hc}, S, S = (1/2)*c*hc],
[{A, B, a}, b, b = a*sin(B)/sin(A)],
[{A, B, b}, a, b = a*sin(B)/sin(A)],
[{A, C, a}, c, c = a*sin(C)/sin(A)],
[{A, C, c}, a, c = a*sin(C)/sin(A)],
[{A, a, b}, B, b = a*sin(B)/sin(A)],
[{A, a, c}, C, c = a*sin(C)/sin(A)],
[{B, C, b}, c, b = c*sin(B)/sin(C)],
[{B, C, c}, b, b = c*sin(B)/sin(C)],
[{B, a, b}, A, b = a*sin(B)/sin(A)],
[{B, b, c}, C, b = c*sin(B)/sin(C)],
[{C, S, a}, b, S = (1/2)*a*b*sin(C)],
[{C, S, b}, a, S = (1/2)*a*b*sin(C)],
[{C, a, b}, S, S = (1/2)*a*b*sin(C)],
[{C, a, c}, A, c = a*sin(C)/sin(A)],
[{C, b, c}, B, b = c*sin(B)/sin(C)],
[{P, a, b}, c, P = (a+b+c)*(1/2)],
[{P, a, c}, b, P = (a+b+c)*(1/2)],
[{P, b, c}, a, P = (a+b+c)*(1/2)],
[{S, a, b}, C, S = (1/2)*a*b*sin(C)],
[{a, b, c}, P, P = (a+b+c)*(1/2)],
[{P, S, a, b}, c, S = sqrt(P*(P-a)*(P-b)*(P-c))],
[{P, S, a, c}, b, S = sqrt(P*(P-a)*(P-b)*(P-c))],
[{P, S, b, c}, a, S = sqrt(P*(P-a)*(P-b)*(P-c))],
[{P, a, b, c}, S, S = sqrt(P*(P-a)*(P-b)*(P-c))],
[{S, a, b, c}, P, S = sqrt(P*(P-a)*(P-b)*(P-c))]}:
FindSolution := proc (GT, goal)
local Findr, Findhas, r, LoaiThua, SimplifyValues, SimplifySolution;
global Solution, Vknown, Values;
Values := GT;
Vknown := indets(GT);
Solution := [];
Findhas := [];
Findr := proc ()
local r;
for r in Fset do

if nops(`minus`(indets(r[1]), Vknown)) = 0 and nops(`min


us`(indets(r[2]), Vknown)) = 1 then
return r ;
end if;
end do;
return false;
end proc;
while not `subset`(goal, Vknown) do
r := Findr();
if r = false then
return 0;
end if;
Values := `union`(Values, solve(subs(Values, r[3]), {r[2]}));
Vknown := `union`(Vknown, {r[2]}); Findhas := [op(Findhas), r];
Solution := [op(Solution), solve(r[3], {r[2]})]
end do;
LoaiThua := proc (newVknown)
local i, Vknowntemp;
Vknowntemp := newVknown;
for i to nops(Findhas) do
if not Findhas[i] = null then
if `in`(Findhas[i][2], Vknowntemp) then
Vknowntemp := `union`(Vknowntemp, Findha
s[i][1]);
Findhas[i] := null;
Vknowntemp := LoaiThua(Vknowntemp);
end if;
end if;
end do;
return Vknowntemp;
end proc;
SimplifyValues := proc ()
local tamValues, k;
tamValues := {};
for k in Values do
if `subset`(indets(k), Vknown) then
tamValues := [op(tamValues), k]
end if;
end do;
return tamValues;
end proc;
SimplifySolution := proc ()
local newSol, temp;
newSol := [];
for temp in Solution do
if `in`(lhs(op(temp)), Vknown) then
newSol := [op(newSol), temp]
end if;
end do;
return newSol;
end proc;
if not Findhas = [] then
Vknown := `union`(LoaiThua(Findhas[nops(Findhas)][1]), {Findhas[
nops(Findhas)][2]});
Values := SimplifyValues();
Solution := SimplifySolution();
return 1;

end if;
return 2;
end proc:
BaiGiai := proc (GT, goal)
local kt, i, s, v;
kt := FindSolution(GT, goal);
if kt = 1 then Solution[1];
for s in Solution do
printf("ta c %a", op(s));
for v in Values do
if lhs(v) = lhs(op(s)) then
printf(" => %a", v);
printf("\n");
break;
end if;
end do;
end do;
end if;
if kt = 2 then
print("Kt qu nm trong đp n");
end if;
if kt = 0 then
print("khng gii đ?c6"")
end if;
end proc:

You might also like