Looking to substitute to make fewer multiplication calls

TonyHudson

New member
Joined
Sep 11, 2006
Messages
1
The object is to simplify the calculations below to make the
fewest number of multiplication calls as possible.

Given
x = ab-cc+bd
and
y = bb-cc+ad.

"My instructor insists that it can be done using 3 or 4 substitutions and then
3 multiplications."

I can do it with 4 multiplications.

first I make x = bb * (a+d) - cc

let cc = temp1
let bb = temp2
let ad = temp3

so x= temp2*(a+d) - temp1
and y = temp2 - temp1 + temp3

Is there some deep magic I don't get here?
 
Obviously, you were not there when they wrote the deep magic. :wink:

With a little sleight of hand, 3 is possible. I'm not seeing 2.

x = b*(a+d) - c*c

That's two multiplications.

This is just algebra. don't code it.
x - y = ab - bb + bd - ad = b*(a-b) - d*(a-b) = (b-d)*(a-b)

OK, then more coding.

y = x - (b-d)*(a-b)

That's three multiplications.

Note: Do not forget your algebra. It will save you.
Note: Why are we scrimping on multiplications? CPU cycles are cheap these days.
Note: I would HATE to debug what I just showed. I would have to wonder, "What evil spirit possessed the programmer to write this?"
 
Note: Why are we scrimping on multiplications? CPU cycles are cheap these days.

If the code had to be executed a hundred-trillion times, it would definetly make a difference. Even moreso if these numbers had a few hundred digits a peice.
 
Try this on your instructor (you never know, he may have a hangover...!):

x = b*(a + d) - c^2

y = a*d + b^2 - c^2

All he'll see is 2 multiplication signs :idea:
 
Top