Bug fix and added support for scaling a polynomial
This commit is contained in:
parent
05fcfcbcb2
commit
c057493d86
46
polymani.pl
46
polymani.pl
@ -117,6 +117,8 @@ do_process_input(show(void, T)) :-
|
|||||||
print_polynomial_tree(T),
|
print_polynomial_tree(T),
|
||||||
nl.
|
nl.
|
||||||
do_process_input(store(P, T)) :-
|
do_process_input(store(P, T)) :-
|
||||||
|
assertz(polynomial_store(P, T)).
|
||||||
|
do_process_input(show(store(P, T))) :-
|
||||||
assertz(polynomial_store(P, T)),
|
assertz(polynomial_store(P, T)),
|
||||||
write(P),
|
write(P),
|
||||||
write(" = "),
|
write(" = "),
|
||||||
@ -124,14 +126,18 @@ do_process_input(store(P, T)) :-
|
|||||||
nl.
|
nl.
|
||||||
do_process_input(forget(P)) :-
|
do_process_input(forget(P)) :-
|
||||||
retract(polynomial_store(P,_)).
|
retract(polynomial_store(P,_)).
|
||||||
do_process_input(simplify(P)) :-
|
do_process_input(simplify(PT)) :-
|
||||||
polynomial_tree_to_polynomial(P, PP),
|
polynomial_tree_to_polynomial(PT, P),
|
||||||
simpoly(PP, SP),
|
simpoly(P, SP),
|
||||||
|
write(SP),
|
||||||
|
nl.
|
||||||
|
do_process_input(multiply(TN, PT)) :-
|
||||||
|
polynomial_tree_to_polynomial(TN, N),
|
||||||
|
polynomial_tree_to_polynomial(PT, P),
|
||||||
|
scalepoly(N, P, P2),
|
||||||
|
simpoly(P2, SP),
|
||||||
write(SP),
|
write(SP),
|
||||||
nl.
|
nl.
|
||||||
%% do_process_input(T) :-
|
|
||||||
%% %% Empty command, assume simplfiy
|
|
||||||
%% do_process_input(simplify(T)).
|
|
||||||
|
|
||||||
print_polynomial_tree(op(Op, TL, TR)) :-
|
print_polynomial_tree(op(Op, TL, TR)) :-
|
||||||
!,
|
!,
|
||||||
@ -142,19 +148,19 @@ print_polynomial_tree(op(Op, TL, TR)) :-
|
|||||||
print_polynomial_tree(T) :-
|
print_polynomial_tree(T) :-
|
||||||
write(T).
|
write(T).
|
||||||
|
|
||||||
polynomial_tree_to_polynomial(A,B) :-
|
polynomial_tree_to_polynomial(op(Op, TL, TR), P) :-
|
||||||
polynomial_tree_to_atomic_polynomial(A,Pa),
|
!,
|
||||||
name(B, Pa).
|
polynomial_tree_to_polynomial(TL, PL),
|
||||||
|
polynomial_tree_to_polynomial(TR, PR),
|
||||||
polynomial_tree_to_atomic_polynomial(load(L), P) :-
|
term_to_atom(PL, TermL),
|
||||||
polynomial_store(L, P).
|
term_to_atom(PR, TermR),
|
||||||
polynomial_tree_to_atomic_polynomial(op(Op, TL, TR), P) :-
|
atom_concat(TermL, Op, Temp),
|
||||||
polynomial_tree_to_atomic_polynomial(TL,A),
|
atom_concat(Temp, TermR, PA),
|
||||||
polynomial_tree_to_atomic_polynomial(TR,B),
|
term_to_atom(P, PA).
|
||||||
atom_concat(A, Op, AOp),
|
polynomial_tree_to_polynomial(T, T).
|
||||||
atom_concat(AOp, B, P),
|
%% Tests:
|
||||||
!.
|
%% ?- polynomial_tree_to_polynomial(op(+, 2, op(+, 2, op(*, 1, y))), S).
|
||||||
polynomial_tree_to_atomic_polynomial(A,A).
|
%@ S = 2+2+1*y.
|
||||||
|
|
||||||
%% nlp_number(?W:Atom, ?D:Int) is det
|
%% nlp_number(?W:Atom, ?D:Int) is det
|
||||||
%
|
%
|
||||||
@ -420,7 +426,7 @@ parse_command(store(P, T)) -->
|
|||||||
parse_command(simplify(T)) -->
|
parse_command(simplify(T)) -->
|
||||||
[simplify],
|
[simplify],
|
||||||
parse_polynomial(T).
|
parse_polynomial(T).
|
||||||
parse_command(op(*, TN, TP)) -->
|
parse_command(multiply(TN, TP)) -->
|
||||||
[multiply],
|
[multiply],
|
||||||
parse_number(TN),
|
parse_number(TN),
|
||||||
[by],
|
[by],
|
||||||
|
Reference in New Issue
Block a user