user52376
user52376

Reputation: 27

Prolog compact?

I have a problem, I need to compact a derivative result like this:

0*x*x + 2*(1*x + x*1) =====> example: 0+2*(2*x) =====> 0+2*4*x====>8*x

Is it possible? Thanks for your help.

Regards, Volter

Upvotes: 0

Views: 223

Answers (1)

Fred Foo
Fred Foo

Reputation: 363547

Yes, this is possible, it just takes some work. You'll need to write out atomic rules such as

rule(0*_, 0).
rule(_*0, 0).
rule(1*X, X).
rule(X*1, X).

and implement a fixpoint predicate (maybe a failure-driven loop) that applies rules until convergence.

Upvotes: 3

Related Questions