Add support for - in list_to_polynomial

This commit is contained in:
Diogo Cordeiro 2018-11-22 23:13:32 +00:00
parent ad892c9711
commit b005669017
1 changed files with 10 additions and 4 deletions

View File

@ -272,7 +272,6 @@ join_similar_parts_of_term([], []).
%% simplify_polynomial(+P:atom, -P2:atom) is det
%
% Simplifies a polynomial.
% TODO: not everything is a +, there are -
%
simplify_polynomial(0, 0) :-
!.
@ -399,7 +398,6 @@ simplify_polynomial_list(L, L2) :-
%% polynomial_to_list(+P:polynomial, -L:List)
%
% Converts a polynomial in a list.
% TODO: not everything is a +, there are -
%
polynomial_to_list(L - T, [T2 | LS]) :-
term(T),
@ -435,13 +433,21 @@ polynomial_to_list(T, [T]) :-
%% list_to_polynomial(+P:polynomial, -L:List)
%
% Converts a list in a polynomial.
% TODO: not everything is a +, there are -
%
list_to_polynomial([T1|T2], P) :-
list_to_polynomial(T2, L1),
(
not(L1 = []),
P = L1+T1
(
term_string(T1, S1),
string_chars(S1, [First|_]),
First = -,
term_string(L1, S2),
string_concat(S2,S1,S3),
term_string(P, S3)
;
P = L1+T1
)
;
P = T1
),