C Board  

Go Back   C Board > Community Boards > Contests Board

Reply
 
LinkBack Thread Tools Display Modes
Old 07-18-2007, 04:54 PM   #1
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,927
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.
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet
abachler is offline   Reply With Quote
Old 07-18-2007, 05:46 PM   #2
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,381
Quote:
Originally Posted by abachler View Post
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));
}
brewbuck is offline   Reply With Quote
Old 07-19-2007, 12:46 AM   #3
Registered User
 
Join Date: Sep 2001
Posts: 752
implementing log and exp without addition seems... non-trivial.
__________________
Callou collei we'll code the way
Of prime numbers and pings!
QuestionC is offline   Reply With Quote
Old 07-19-2007, 07:43 AM   #4
Anti-Poster
 
Join Date: Feb 2002
Posts: 1,212
Quote:
Originally Posted by abachler View Post
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?
__________________
Rule #1: Every rule has exceptions

Traveller's Dilemma Contest Site - Results posted!
pianorain is offline   Reply With Quote
Old 07-19-2007, 08:51 AM   #5
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,927
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.
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet

Last edited by abachler; 07-19-2007 at 09:01 AM.
abachler is offline   Reply With Quote
Old 07-19-2007, 09:38 AM   #6
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,927
Quote:
Originally Posted by pianorain View Post
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.
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet
abachler is offline   Reply With Quote
Old 07-19-2007, 10:04 AM   #7
Anti-Poster
 
Join Date: Feb 2002
Posts: 1,212
Quote:
Originally Posted by abachler View Post
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 View Post
The limits of the inputs are
+/- 100000.0 The entry must work with all numbers in that range.
However, your PM made it more clear.
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 / ?
__________________
Rule #1: Every rule has exceptions

Traveller's Dilemma Contest Site - Results posted!

Last edited by pianorain; 07-19-2007 at 10:07 AM.
pianorain is offline   Reply With Quote
Old 07-19-2007, 10:14 AM   #8
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,927
Thats pretty much it, multiply and divide only. Sort of a twist on the old implement multiply or divide using only additon and subtraction.
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet
abachler is offline   Reply With Quote
Old 07-19-2007, 03:52 PM   #9
Anti-Poster
 
Join Date: Feb 2002
Posts: 1,212
I've designed a solution, but it requires the comparison and assignment operators. Are those allowable?
__________________
Rule #1: Every rule has exceptions

Traveller's Dilemma Contest Site - Results posted!
pianorain is offline   Reply With Quote
Old 07-19-2007, 06:47 PM   #10
aoeuhtns
 
Join Date: Jul 2005
Posts: 581
And.... what decides the winner?
__________________
There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.
Rashakil Fol is offline   Reply With Quote
Old 07-19-2007, 08:31 PM   #11
Anti-Poster
 
Join Date: Feb 2002
Posts: 1,212
Quote:
Originally Posted by Rashakil Fol View Post
And.... what decides the winner?
Oh Rashakil...next you'll be asking what languages are valid for a submission.
__________________
Rule #1: Every rule has exceptions

Traveller's Dilemma Contest Site - Results posted!
pianorain is offline   Reply With Quote
Old 07-19-2007, 11:27 PM   #12
aoeuhtns
 
Join Date: Jul 2005
Posts: 581
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?
__________________
There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.

Last edited by Rashakil Fol; 07-19-2007 at 11:31 PM.
Rashakil Fol is offline   Reply With Quote
Old 07-19-2007, 11:51 PM   #13
Registered Abuser
 
Join Date: Jun 2006
Location: Toronto
Posts: 572
just a guess, but usually these types of problems are geared towards a solution that uses some sort of bitwise manipulations.
@nthony is offline   Reply With Quote
Old 07-20-2007, 05:55 AM   #14
Anti-Poster
 
Join Date: Feb 2002
Posts: 1,212
Quote:
Originally Posted by @nthony View Post
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.
__________________
Rule #1: Every rule has exceptions

Traveller's Dilemma Contest Site - Results posted!
pianorain is offline   Reply With Quote
Old 07-20-2007, 09:41 AM   #15
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,927
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.
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet

Last edited by abachler; 07-20-2007 at 09:47 AM.
abachler is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Faster way to divide numbers scwizzo C++ Programming 3 04-29-2009 11:45 AM
Overflow and range checking for mul/div Elysia C++ Programming 28 06-06-2008 02:09 PM
working with rotation matrices hannibar Game Programming 23 03-30-2005 01:10 PM
How to multiply and Divide Huge int numbers Dewayne C++ Programming 3 10-21-2004 08:41 PM
calculator in c++ gamer C++ Programming 11 02-19-2003 10:46 AM


All times are GMT -6. The time now is 06:22 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22