An algorithm for calculating $ax+b$ would take the stepsCalculate $a$ times $x$Calculate $b$ plus the result of previous line.But if the values of $a$ and $b$ are known, can we create a more efficient algorithm for the task?Of course, when $a = 1$, I can optimize the previous algorithm by simply skipping the first step, and when $b = 0$, an optimization would be to skip step 2. But is there always an optimization that I can do?More formallyLet $originalAlgorithm$ be the two-step algorithm above. What I want is a meta-algorithm, $M$ that $$M(a,b) = optimizedAlgorithm$$and, of course,$$optimizedAlgorithm(x) = originalAlgorithm(x) = ax+b$$but $optimizedAlgorithm$ is more time-efficient than $originalAlgorithm$.
Is it possible to optimize the calculation of $ax+b$ once I know $a$ and $b$?
cc.complexity theory;ds.algorithms;optimization;time complexity