# Addition using only multiply and divide

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 07-18-2007
abachler
Addition using only multiply and divide
The goal is to perform the function A = B + C using only multiplication and division. Assume that A B and C are doubles. The limits of the inputs are
+/- 100000.0 The entry must work with all numbers in that range.

Rules -
1. I will disqualify any entry that I do not feel is in the spirit of the contest with or without an explanation. This decision is final.
2. Qualification is not commutative. Approximation of a qualifying function does not guarantee the approximation will qualify.
3. I reserve the right to change the specific or general nature of the contest at any time.
• 07-18-2007
brewbuck
Quote:

Originally Posted by abachler
The goal is to perform the function A = B + C using only multiplication and division. Assume that A B and C are doubles. The limits of the inputs are
+/- 100000.0 The entry must work with all numbers in that range.

Code:

```double sum(double b, double c) {     return log(exp(b) * exp(c)); }```
• 07-19-2007
QuestionC
implementing log and exp without addition seems... non-trivial.
• 07-19-2007
pianorain
Quote:

Originally Posted by abachler
1. I will disqualify any entry that I do not feel is in the spirit of the contest with or without an explanation. This decision is final.

Halloween has spirits. Contests shouldn't. Define the problem well enough and it's a non-issue.

To what precision should we expect the inputs? From the original statement, it appeared only to matter to the first decimal place.

Please define "the entry must work". Does this mean you will not accept any approximation?
• 07-19-2007
abachler
The contest is to implement it using only multiplication and addition, I dont think log or exp count as either of those. I was originally going to say to do it without using addition or subtraction, but I foresaw people trying to make entries using macros and functions that themselves use those, and then arguing that the rule was vague. So I nipped it in the bud and made it multiplication and division only.
• 07-19-2007
abachler
Quote:

Originally Posted by pianorain
To what precision should we expect the inputs? From the original statement, it appeared only to matter to the first decimal place.

Im nto really sure how you came up with that idea, it clearly states ALL values, you can safely assume that means ALL values that can fit into a double.

Quote:

Please define "the entry must work". Does this mean you will not accept any approximation?
Please define approximation and ill tell you if Ill accept it.
• 07-19-2007
pianorain
Quote:

Originally Posted by abachler
Im nto really sure how you came up with that idea, it clearly states ALL values, you can safely assume that means ALL values that can fit into a double.

Quote:

Originally Posted by abachler
The limits of the inputs are
+/- 100000.0 The entry must work with all numbers in that range.

Quote:

Originally Posted by abachler
I will not open the contest to approximations. The entry must produce the exact bit for bit result that the FPU on my computer will produce given the same inputs.

So sum(a,b) == a + b for all a,b where a and b are doubles in the range [-100000, 100000].

edit: I hope I'm missing something. The only operators we're allowed to use are * and / ?
• 07-19-2007
abachler
Thats pretty much it, multiply and divide only. Sort of a twist on the old implement multiply or divide using only additon and subtraction.
• 07-19-2007
pianorain
I've designed a solution, but it requires the comparison and assignment operators. Are those allowable?
• 07-19-2007
Rashakil Fol
And.... what decides the winner?
• 07-19-2007
pianorain
Quote:

Originally Posted by Rashakil Fol
And.... what decides the winner?

Oh Rashakil...next you'll be asking what languages are valid for a submission. ;)
• 07-19-2007
Rashakil Fol
Will the function be required to work on denormalized values?

Also, are arrays, and indexing thereof, allowed?

Edit: Also, what languages are valid for a submission? Seriously.

Edit 2: Can we use std::strings and concatenate them and then use size() to implement addition for positive integers as part of the algorithm?
• 07-19-2007
@nthony
just a guess, but usually these types of problems are geared towards a solution that uses some sort of bitwise manipulations.
• 07-20-2007
pianorain
Quote:

Originally Posted by @nthony
just a guess, but usually these types of problems are geared towards a solution that uses some sort of bitwise manipulations.

Indeed they are, but it's easier to implement addition using bit operations than it is to implement addition using multiplication.
Quote:

Originally Posted by Rashakil Fol
Edit 2: Can we use std::strings and concatenate them and then use size() to implement addition for positive integers as part of the algorithm?

Heh, that's a unique place to look for an accumulator. I bet yours will add faster than mine. ;)
• 07-20-2007
abachler
Again, you can only use multiply and divide. Since this is a C programming site, id say that C is the only acceptable language. Since I speak C and assembly Ill expand it to include assembly for the Xeon.

The impetus for this challenge is I have a GPU that for some reason is faster at multiply than it is at adds. The solution to this wont solve my problem with the GPU, it was just inspired by it. Our problem is the GPU doesnt properly parallelize the addition of all members of a vector. Its an implementation issue we are sure, but one thought we had was to switch it to multiplies. Turns otu its just that it executes operations across members of a vecvtor in series, which makes it run very slowly.
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last