Minor changes to comments and to scale_polynomial

This commit is contained in:
Hugo Sales 2018-11-22 18:55:37 +00:00
parent 3471f6a328
commit 202f57ef9d

View File

@ -13,26 +13,26 @@
* *
* 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 lybrary
Import the Constraint Logic Programming over Finite Domains lybrary * Essentially, this library improves the way Prolog deals with integers,
Essentially, this library improves the way Prolog deals with integers, * allowing more predicates to be reversible.
allowing more predicates to be reversible. * For instance, number(N) is always false, which prevents the
For instance, number(N) is always false, which prevents the * reversing of a predicate.
reversing of a predicate.
*/ */
:- use_module(library(clpfd)). :- use_module(library(clpfd)).
/******************************* /*******************************
* 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 argu-
@ -56,7 +56,7 @@ simpoly(P, S) :-
simplify_polynomial(P, S). simplify_polynomial(P, S).
/* /*
scalepoly/3 multiplies one polynomial as expression by a scalar scalepoly/3 multiplies a polynomial represented as an expression by a scalar
resulting in a second polynomial. The two first arguments are assumed to resulting in a second polynomial. The two first arguments are assumed to
be ground. The polynomial resulting from the sum is in simplified form. be ground. The polynomial resulting from the sum is in simplified form.
*/ */
@ -71,6 +71,7 @@ scalepoly(P1, P2, S) :-
addpoly(P1, P2, S) :- addpoly(P1, P2, S) :-
add_polynomial(P1, P2, S). add_polynomial(P1, P2, S).
/******************************* /*******************************
* BACKEND * * BACKEND *
*******************************/ *******************************/
@ -474,14 +475,12 @@ append_two_atoms_with_star(V1, V2, R) :-
scale_polynomial(P, C, S) :- scale_polynomial(P, C, S) :-
polynomial_to_list(P, L), polynomial_to_list(P, L),
maplist(append_two_atoms_with_star(C), L, L2), maplist(append_two_atoms_with_star(C), L, L2),
list_to_polynomial(L2, S). polynomial_to_list(S, L2),
%simplify_polynomial(S1, S). simplify_polynomial(S, S1),
!.
%% Tests: %% Tests:
%% ?- scale_polynomial(3*x^2, 2, S). %% ?- scale_polynomial(3*x^2, 2, S).
%@ S = 2*3*x^2. %@ S = 2*3*x^2.
%@ S = 2*(3*x^2).