Added some elementary missing functionalities and minor bug fixes
Added multiply, add, etc. to process_input Memory is now properly working (store, forget and access storage) Command concatenation is now properly working (as is sophisticated numbers [bug fix])
This commit is contained in:
parent
b984b0efd4
commit
04199f670f
56
polymani.pl
56
polymani.pl
@ -68,13 +68,19 @@ polyplay :-
|
|||||||
),
|
),
|
||||||
!.
|
!.
|
||||||
|
|
||||||
process_input(show(P, void)) :-
|
%process_input(show(P, void)) :-
|
||||||
P \== void,
|
% P \== void,
|
||||||
polynomial_store(P, T),
|
% polynomial_store(P, T),
|
||||||
write(P),
|
% write(P),
|
||||||
write(" = "),
|
% write(" = "),
|
||||||
print_polynomial_tree(T),
|
% print_polynomial_tree(T),
|
||||||
nl.
|
% nl.
|
||||||
|
process_input(command(C1, C2)) :-
|
||||||
|
process_input(C1),
|
||||||
|
process_input(C2).
|
||||||
|
process_input(show_stored_polynomials) :-
|
||||||
|
findall(nm(X,Y), polynomial_store(X,Y),D),
|
||||||
|
nlp_print_memory(D).
|
||||||
process_input(show(P, T)) :-
|
process_input(show(P, T)) :-
|
||||||
P \== void,
|
P \== void,
|
||||||
T \== void,
|
T \== void,
|
||||||
@ -88,12 +94,19 @@ process_input(show(void, T)) :-
|
|||||||
nl.
|
nl.
|
||||||
process_input(store(P, T)) :-
|
process_input(store(P, T)) :-
|
||||||
assertz(polynomial_store(P, T)),
|
assertz(polynomial_store(P, T)),
|
||||||
|
write(P),
|
||||||
|
write(" = "),
|
||||||
|
print_polynomial_tree(T),
|
||||||
nl.
|
nl.
|
||||||
|
process_input(forget(P)) :-
|
||||||
|
retract(polynomial_store(P,_)).
|
||||||
process_input(simplify(P)) :-
|
process_input(simplify(P)) :-
|
||||||
polynomial_tree_to_polynomial(P, PP),
|
polynomial_tree_to_polynomial(P, PP),
|
||||||
simpoly(PP, SP),
|
simpoly(PP, SP),
|
||||||
write(SP),
|
write(SP),
|
||||||
nl.
|
nl.
|
||||||
|
process_input(op(Op, TL, TR)) :-
|
||||||
|
process_input(simplify(op(Op, TL, TR))).
|
||||||
|
|
||||||
print_polynomial_tree(op(Op, TL, TR)) :-
|
print_polynomial_tree(op(Op, TL, TR)) :-
|
||||||
write(TL),
|
write(TL),
|
||||||
@ -190,7 +203,9 @@ parse_number_explicit(_, T, T, [], []) :-
|
|||||||
!.
|
!.
|
||||||
|
|
||||||
parse_number(T, SL, NC) :-
|
parse_number(T, SL, NC) :-
|
||||||
parse_number_explicit(void, void, T, SL, NC).
|
parse_number_explicit(void, void, T1, SL, NC),
|
||||||
|
polynomial_tree_to_polynomial(T1, PP),
|
||||||
|
simpoly(PP, T).
|
||||||
%% Tests:
|
%% Tests:
|
||||||
%% ?- parse_number(T, [two], _).
|
%% ?- parse_number(T, [two], _).
|
||||||
%@ T = 2.
|
%@ T = 2.
|
||||||
@ -319,20 +334,22 @@ parse_polynomial_explicit(void-_, T) -->
|
|||||||
%% ?- parse_polynomial(T, [two, plus, two, plus, one, times, y], _).
|
%% ?- parse_polynomial(T, [two, plus, two, plus, one, times, y], _).
|
||||||
%@ T = op(+, op(+, 2, 2), op(*, 1, y)).
|
%@ T = op(+, op(+, 2, 2), op(*, 1, y)).
|
||||||
|
|
||||||
|
parse_command(show_stored_polynomials) -->
|
||||||
parse_command(show(void, T)) --> %% NOTE Probably easier if the tree is always binary
|
[show, stored, polynomials].
|
||||||
[show],
|
parse_command(store(P, T)) -->
|
||||||
parse_polynomial(T).
|
|
||||||
parse_command(show(P, T)) -->
|
|
||||||
[show],
|
[show],
|
||||||
parse_polynomial(T),
|
parse_polynomial(T),
|
||||||
[as],
|
[as],
|
||||||
[P].
|
[P].
|
||||||
|
parse_command(forget(P)) -->
|
||||||
|
[forget],
|
||||||
|
[P].
|
||||||
|
parse_command(show(void, T)) --> %% NOTE Probably easier if the tree is always binary
|
||||||
|
[show],
|
||||||
|
parse_polynomial(T).
|
||||||
parse_command(show(P, void)) -->
|
parse_command(show(P, void)) -->
|
||||||
[show],
|
[show],
|
||||||
[P].
|
[P].
|
||||||
parse_command(show_all) -->
|
|
||||||
[show, stored, polynomials].
|
|
||||||
parse_command(store(P, T)) -->
|
parse_command(store(P, T)) -->
|
||||||
[let],
|
[let],
|
||||||
[P],
|
[P],
|
||||||
@ -351,6 +368,12 @@ parse_command(op(*, TN, TP)) -->
|
|||||||
parse_number(TN),
|
parse_number(TN),
|
||||||
[by],
|
[by],
|
||||||
parse_polynomial(TP).
|
parse_polynomial(TP).
|
||||||
|
parse_command(op(+, TN, TP)) -->
|
||||||
|
[add],
|
||||||
|
parse_polynomial(TN),
|
||||||
|
[with],
|
||||||
|
parse_polynomial(TP).
|
||||||
|
|
||||||
parse_input(command(TCL, TCR)) -->
|
parse_input(command(TCL, TCR)) -->
|
||||||
parse_command(TCL),
|
parse_command(TCL),
|
||||||
[and],
|
[and],
|
||||||
@ -368,7 +391,8 @@ parse_input(void, [], _).
|
|||||||
nlp_print_memory([nm(X,Y)|T]) :-
|
nlp_print_memory([nm(X,Y)|T]) :-
|
||||||
write(X),
|
write(X),
|
||||||
write(" = "),
|
write(" = "),
|
||||||
writeln(Y),
|
print_polynomial_tree(Y),
|
||||||
|
nl,
|
||||||
nlp_print_memory(T).
|
nlp_print_memory(T).
|
||||||
nlp_print_memory([]).
|
nlp_print_memory([]).
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user