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