dec2bin: Write a predicate dec2bin(N, L) that takes a positive integer N and returns a list L that is the binary representation of N. For instance:
dec2bin(1,L) should succeed with L=[1] and dec2bin(2,L) should succeed with L=[1,0]
dec2bin(26,L) should succeed with L=[1,1,0,1,0]
eval: Consider expression trees represented as a Prolog data structure, as discussed in class (Sep 20). Write a predicate eval(E, V) that takes an expression tree E and returns in V the value of the expression. For instance:
eval(plus(num(4), num(2)), V) succeeds with V=6
eval(star(plus(num(4), num(2)),minus(num(3), num(1))), V) succeeds with V=12
You may assume that the first argument is always a valid expression tree.
comp: This question also deals with expression trees. Write a predicate traverse(E, L) that takes an expression tree E and returns in L the list of stack machine instructions that evaluate E. The relevant instructions for this exercise are:
ildc(n) which pushes a given integer n on the stack;
iadd, isub, imul and idiv that add, subtract, multiply or divide the top two elements of the stack.
For instance:
comp(plus(num(4), num(2)), C) succeeds with C=[ildc(4), ildc(2), iadd]
comp(minus(num(4), num(2)), C) succeeds with C=[ildc(4), ildc(2), isub]
comp(star(plus(num(4), num(2)),minus(num(3), num(1))), C) succeeds with C=[ildc(4), ildc(2), iadd, ildc(3), ildc(1), isub, imul]
You may assume that the first argument is always a valid expression tree.
Hi. I am good at functional programming. Check out my previous work where I did haskell assignments, also on functional programming. PM me if you want me to do this job. Also send me the source of the assignment. Thanks. Price is negotiable over chat. Cheers.