Small UI cleanup
This commit is contained in:
		
							
								
								
									
										28
									
								
								polymani.pl
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								polymani.pl
									
									
									
									
									
								
							@@ -71,11 +71,15 @@ simpoly(P, S) :-
 | 
				
			|||||||
    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.
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
scalepoly(P1, P2, S) :-
 | 
					scalepoly(P1, C, S) :-
 | 
				
			||||||
    is_polynomial_valid_in_predicate(P1, "scalepoly"),
 | 
					    is_polynomial_valid_in_predicate(P1, "scalepoly"),
 | 
				
			||||||
    is_polynomial_valid_in_predicate(P2, "scalepoly"),
 | 
					    is_number_in_predicate(C, "scalepoly"),
 | 
				
			||||||
    scale_polynomial(P1, P2, S),
 | 
					    scale_polynomial(P1, C, S),
 | 
				
			||||||
    !.
 | 
					    !.
 | 
				
			||||||
 | 
					%% Tests:
 | 
				
			||||||
 | 
					%% ?- scalepoly(3*x*z+2*z, 4, S).
 | 
				
			||||||
 | 
					%@ S = 12*x*z+8*z.
 | 
				
			||||||
 | 
					%% ?- scalepoly(3*x*z+2*z, 2, S).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
    addpoly/3 adds two polynomials as expressions resulting in a
 | 
					    addpoly/3 adds two polynomials as expressions resulting in a
 | 
				
			||||||
@@ -102,7 +106,7 @@ is_polynomial_valid_in_predicate(P, _) :-
 | 
				
			|||||||
    polynomial(P),
 | 
					    polynomial(P),
 | 
				
			||||||
    !.
 | 
					    !.
 | 
				
			||||||
is_polynomial_valid_in_predicate(P, F) :-
 | 
					is_polynomial_valid_in_predicate(P, F) :-
 | 
				
			||||||
    %% Writes the polynomial and fails otherwise
 | 
					    %% Otherwise, write the polynomial and fails
 | 
				
			||||||
    write("Invalid polynomial in "),
 | 
					    write("Invalid polynomial in "),
 | 
				
			||||||
    write(F),
 | 
					    write(F),
 | 
				
			||||||
    write(": "),
 | 
					    write(": "),
 | 
				
			||||||
@@ -133,6 +137,20 @@ is_polynomial_as_list_valid_in_predicate(L, F) :-
 | 
				
			|||||||
%@ Invalid polynomial in Test: a*4+0*x
 | 
					%@ Invalid polynomial in Test: a*4+0*x
 | 
				
			||||||
%@ false.
 | 
					%@ false.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%% is_number_in_predicate(+C:number, +F:string) is det
 | 
				
			||||||
 | 
					%
 | 
				
			||||||
 | 
					%  Validates that C is a number or prints F and it then it
 | 
				
			||||||
 | 
					%
 | 
				
			||||||
 | 
					is_number_in_predicate(C, _) :-
 | 
				
			||||||
 | 
					    number(C),
 | 
				
			||||||
 | 
					    !.
 | 
				
			||||||
 | 
					is_number_in_predicate(C, F) :-
 | 
				
			||||||
 | 
					    %% Writes the argument and fails
 | 
				
			||||||
 | 
					    write("Invalid number in "),
 | 
				
			||||||
 | 
					    write(F),
 | 
				
			||||||
 | 
					    write(": "),
 | 
				
			||||||
 | 
					    write(C),
 | 
				
			||||||
 | 
					    fail.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                 /*******************************
 | 
					                 /*******************************
 | 
				
			||||||
                 *            BACKEND           *
 | 
					                 *            BACKEND           *
 | 
				
			||||||
@@ -775,6 +793,8 @@ polynomial_to_list(T, [T]) :-
 | 
				
			|||||||
%@ S = [-2*y, 5, 2*x^2].
 | 
					%@ S = [-2*y, 5, 2*x^2].
 | 
				
			||||||
%% ?- polynomial_to_list(2*x^2-5-y*2, S).
 | 
					%% ?- polynomial_to_list(2*x^2-5-y*2, S).
 | 
				
			||||||
%@ S = [-2*y, -5, 2*x^2].
 | 
					%@ S = [-2*y, -5, 2*x^2].
 | 
				
			||||||
 | 
					%% ?- polynomial_to_list(P, [-2*y, -5, 2*x^2]).
 | 
				
			||||||
 | 
					%@ ERROR: Unhandled exception: type_error(_527068=_527074*_527076,2,'a real number',_527074*_527076)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
%% list_to_polynomial(+L:List, -P:Polynomial) is det
 | 
					%% list_to_polynomial(+L:List, -P:Polynomial) is det
 | 
				
			||||||
%
 | 
					%
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user