So i have an expression definition language. besides that come rules in pattern matching manner like:
<a> * <x> + <a> * <y> => <a> * (<x> + <y>)
Upon stating a starting set of expressions all rules are matched against that set and against themselves to enrich starting set with new expressions. I would call that as deduction.
The problem is with rules like
<x:Number> => <x> + 1
When resulting right side is reconsidered with the left side of the same rule, a new statement is produced, but that statement also matches left side which goes to infinity. Something like:
<x> + 1 + 1 + 1 + ...
I would like to detect rules like this one and report them as errors, as they should be rewritten nonrecursively like:
<x:Number> => <x> + 1 [N times]
with right side of type "function of N"
When left side is consisted only of one variable, all I have to do is to match right side against left side to detect unwanted behavior, but I don't know if there are other cases that lead to infinite calculation.
Are there other cases or this is it? Maybe someone already encountered the same problem? Do U have any idea on how to resolve this?
If so, I would like to hear Ur thoughts.