For example,
?- simp(0+a+b+0+0+1, Ans).
produces a solution
Ans = a+b+1
?- simp((0+a)+(0+0), Ans).
produces a solution
Ans = a
Extend this program so that it can deal with expressions containing '*' as well as '+'. Moreover, please make sure it can deal with the following two cases:
x*0 (or 0*x) should be simplified to 0
x*1 (or 1*x) should be simplified to x
Test your program by using the following queries:
?- simp(a+b+3*c+0+1*d+0+0, R). (answer should be a+b+3*c+d)
?- simp(1*(a+0)+0+d*1+c*0, R). (answer should be a+d)
?- simp((a+b)*(0+0*d), R). (answer should be 0)
?- simp(3+1*0+0+a*1*b*1, R). (answer should be 3+a*b)
Finally create three your own queries.
5 marks for the above work.