Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add(null,0).
- add(tree(R,LT,RT),S) :- add(LT,S1),add(RT,S2),S is R+S1+S2.
- count_leaves(null,0) :- !.
- count_leaves(tree(_,null,null),1) :- !.
- count_leaves(tree(_,LT,RT),Count) :- count_leaves(LT,Count1),count_leaves(RT,Count2),Count is Count1 +Count2.
- compute(tree(R,null,null),R).
- compute(tree(+,LT,RT),S) :-
- compute(LT,S1),
- compute(RT,S2),
- S is S1 + S2.
- compute(tree(-,LT,RT),S) :-
- compute(LT,S1),
- compute(RT,S2),
- S is S1 - S2.
- compute(tree(*,LT,RT),S) :-
- compute(LT,S1),
- compute(RT,S2),
- S is S1 * S2.
- compute(tree(/,LT,RT),S) :-
- compute(LT,S1),
- compute(RT,S2),
- S is S1 / S2.
- converting(A+B,tree(+,LT,RT)) :-
- converting(A,LT),
- converting(B,RT).
- converting(A-B,tree(-,LT,RT)) :-
- converting(A,LT),
- converting(B,RT).
- converting(A*B,tree(*,LT,RT)) :-
- converting(A,LT),
- converting(B,RT).
- converting(A/B,tree(/,LT,RT)) :-
- converting(A,LT),
- converting(B,RT).
- converting(E,tree(E,null,null)).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement