From b00566901740c297d9d6088caa18ce89b258fb7b Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Thu, 22 Nov 2018 23:13:32 +0000 Subject: [PATCH] Add support for - in list_to_polynomial --- polimani.pl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/polimani.pl b/polimani.pl index cdd7054..f63c06e 100644 --- a/polimani.pl +++ b/polimani.pl @@ -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 ),