Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- simplify1(end):-!.
- simplify1(Exp+X):-
- ( (retract(v(X,N)),!, %% I put the retract in the "or" and changed the sides of the "or"
- N1 is N+1,
- assert(v(X,N1)))
- ;
- assert(v(X,1))
- ),
- simplify1(Exp).
- simplify1(X):-
- atomic(X), %% I add the atomic check
- simplify1(end+X).
- list_to_output([C/N|List],Sum,Out):-
- list_to_output(List,Sum1,Out1), %% I changed this line place
- ( atom(C),
- N>1,!,
- Out=Out1+C*N,
- Sum = Sum1 %% I added it
- ; atom(C),!,
- Out=Out1+C,
- Sum = Sum1 %% I added it
- ; integer(C),
- Sum is Sum1+(C*N),
- Out = Out1 % I added it
- ).
- list_to_output([],0,'').
- simplify(Expression,Out1):-
- simplify1(Expression),
- findall(C/N,v(C,N),List),
- list_to_output(List,Sum,Out),
- Out1 =Out+Sum.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement