I have an arithmetic expression containing Var, and I need to match it to the following format:
Step * Var + Offset
If it can be represented in this form, I need to get Step and Offset values. If not, I need to know that too.
So far I tried matching expression trees, i. e.
Expression = ["+", ["*", Var, Step], Offset] % and other variations
and using CLP(FD):
78 ?- 2*Ind+3 #= Step*Ind+Offset, Ind in inf..sup.
Step*Ind#=_A,
2*Ind#=_B,
_B+3#=_C,
_A+Offset#=_C.
However, the first approach would require simplifying expressions (for example, Var+5-3) and handling multiple different cases, and the second does not work as I expected it to.
Am I missing something? Is there a simpler way, or is this problem too complex?