Merge pull request #4 from diogogithub/add_polynomial

Implement add_polynomial
This commit is contained in:
Diogo Cordeiro 2018-11-22 23:43:09 +00:00 committed by GitHub
commit 63473ec912
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

View File

@ -581,3 +581,17 @@ scale_polynomial(P, C, S) :-
%% Tests:
%% ?- scale_polynomial(3*x^2, 2, S).
%@ S = 2*3*x^2.
%% add_polynomial(+P1:polynomial,+P2:polynomial,-S:polynomial) is det
%
% S = P1 + P2
%
add_polynomial(P1, P2, S) :-
polynomial_to_list(P1, L1),
polynomial_to_list(P2, L2),
append(L1, L2, LA),
join_like_terms(LA,LJ),
list_to_polynomial(LJ, P),
simplify_polynomial(P, S).
%% Tests:
%