Merge branch 'master' of github.com:diogogithub/polynomialmani.pl

This commit is contained in:
Hugo Sales 2018-11-25 18:38:19 +00:00
commit e75e67559e

View File

@ -680,7 +680,6 @@ term_to_canon(L, [N | L2]) :-
%
term_to_canon_with_coefficient(N, [N2 | TS], TS2) :-
number(N2),
%% {N2 >= 0; N2 < 0},
term_to_canon_with_coefficient(N3, TS, TS2),
N is N2 * N3,
!.
@ -750,7 +749,7 @@ add_terms([NL | TL], [NR | TR], [N2 | TL2]) :-
%% have a number in front, so it can be added
term_to_canon([NL | TL], [NL2 | TL2]),
term_to_canon([NR | TR], [NR2 | TR2]),
%% If they rest of the term is the same
%% If the rest of the term is the same
TL2 == TR2,
%% Add the coeficients
N2 is NL2 + NR2.
@ -876,13 +875,16 @@ scale_polynomial(P, C, S) :-
polynomial_to_list(P, L),
%% Convert each term to a list
maplist(term_to_list, L, L2),
%% Canonize terms
maplist(term_to_canon, L2, L3),
%% Append C to the start of each sublist
maplist(cons(C), L2, L3),
%% Convert back
maplist(term_to_list, L4, L3),
maplist(cons(C), L3, L4),
%% Convert to a list of terms
maplist(term_to_list, L5, L4),
%% Simplify the resulting polynomial
simplify_polynomial_as_list(L4, L5),
list_to_polynomial(L5, S),
simplify_polynomial_as_list(L5, L6),
%% Return as a simplified polynomial
list_to_polynomial(L6, S),
!.
%% Tests:
%% ?- scale_polynomial(3*x^2, 2, S).
@ -894,7 +896,7 @@ scale_polynomial(P, C, S) :-
%
cons(C, L, [C | L]).
%% Tests:
%% It just trivially works.
%% No need for tests as it is trivially correct.
%% add_polynomial(+P1:polynomial,+P2:polynomial,-S:polynomial) is det
%