All together now!

This commit is contained in:
Diogo Cordeiro 2018-11-23 00:09:07 +00:00
parent 0aafcc327f
commit 58f5a5562a
1 changed files with 26 additions and 26 deletions

View File

@ -14,12 +14,10 @@
* Hugo David Cordeiro Sales
* up201704178@fc.up.pt
*
*********************************************
* Follows 'Coding guidelines for Prolog' *
* https://doi.org/10.1017/S1471068411000391 *
*********************************************
*/
*********************************************/
/* Import the Constraint Logic Programming over Finite Domains library
* Essentially, this library improves the way Prolog deals with integers,
@ -33,10 +31,11 @@
/*******************************
* USER INTERFACE *
*******************************/
/*
poly2list/2 transforms a list representing a polynomial (second
argument) into a polynomial represented as an expression (first argu-
ment) and vice-versa.
argument) into a polynomial represented as an expression (first
argument) and vice-versa.
*/
poly2list(P, L) :-
polynomial_to_list(P, L).
@ -100,12 +99,12 @@ polynomial_variable(X) :-
% Returns true if X is a power term, false otherwise.
%
power(P^N) :-
(
zcompare((<), 0, N),
polynomial_variable(P)
;
fail
).
(
zcompare((<), 0, N),
polynomial_variable(P)
;
fail
).
power(X) :-
polynomial_variable(X).
%% Tests:
@ -136,13 +135,13 @@ power(X) :-
%
term(N) :-
number(N).
%% N in inf..sup.
%% N in inf..sup.
term(X) :-
power(X).
term(L * R) :-
term(L),
term(R).
%% append_two_atoms_with_star(L, R, T).
%% append_two_atoms_with_star(L, R, T).
%% Tests:
%% ?- term(2*x^3).
%@ true .
@ -271,19 +270,20 @@ term_to_list(P, [P2]) :-
simplify_term(Term_In, Term_Out) :-
term_to_list(Term_In, L),
sort(0, @=<, L, L2),
(
member(0, L2),
Term_Out = 0
;
(
length(L2, 1),
Term_Out = Term_In
);
exclude(==(1), L2, L3),
join_similar_parts_of_term(L3, L4),
sort(0, @>=, L4, L5),
term_to_list(Term_Out, L5)
),
(
member(0, L2),
Term_Out = 0
;
(
length(L2, 1),
Term_Out = Term_In
;
exclude(==(1), L2, L3),
join_similar_parts_of_term(L3, L4),
sort(0, @>=, L4, L5),
term_to_list(Term_Out, L5)
)
),
% First result is always the most simplified form.
!.
%% Tests: