CTK Exchange
Front Page
Movie shortcuts
Personal info
Awards
Reciprocal links
Terms of use
Privacy Policy

Interactive Activities

Cut The Knot!
MSET99 Talk
Games & Puzzles
Arithmetic/Algebra
Geometry
Probability
Eye Opener
Analog Gadgets
Inventor's Paradox
Did you know?...
Proofs
Math as Language
Things Impossible
My Logo
Math Poll
Other Math sit's
Guest book
News sit's

Recommend this site

Manifesto: what CTK is about Search CTK Buying a book is a commitment to learning Table of content Things you can find on CTK Chronology of updates Email to Cut The Knot Recommend this page

CTK Exchange

Subject: "Rounding off of numbers"     Previous Topic | Next Topic
Printer-friendly copy     Email this topic to a friend    
Conferences The CTK Exchange This and that Topic #714
Reading Topic #714
frowdow
Member since May-25-06
May-25-06, 06:28 AM (EST)
Click to EMail frowdow Click to send private message to frowdow Click to view user profileClick to add this user to your buddy list  
"Rounding off of numbers"
 
   Most computer language compilers (the oft used ones anyway) round off
fractions to the floor value viz.

y/x = m , if y = mx+p, 0<=p<x ----- (1)

But the true (or desired value) in most cases is the ceiling function
viz.
y/x = m, if y = mx+p, p=0
= (m+1) if y = mx+p, 0<p<x ----- (2)

The usual thing to do in this case is to use the following function:

f(x) = (y+x-1)/x

Can i have a mathematical proof that this always produces the desired result (2), from first principles? That is, without merely substituting, y with (mx+p)?


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
mr_homm
Member since May-22-05
May-25-06, 10:21 AM (EST)
Click to EMail mr_homm Click to send private message to mr_homm Click to view user profileClick to add this user to your buddy list  
1. "RE: Rounding off of numbers"
In response to message #0
 
   You have:
>y/x = m , if y = mx+p, 0<=p<x ----- (1)

You want:
>y/x = m, if y = mx+p, p=0
> = (m+1) if y = mx+p, 0<p<x ----- (2)

You substitute:
>f(x) = (y+x-1)/x

>Can i have a mathematical proof that this always produces
>the desired result (2), from first principles? That is,
>without merely substituting, y with (mx+p)?

It looks like you have a built-in function that produces result (1) and you want to trick it into producing the desired result (2) by substituting a modified value y' = y+x-1. We need to check that this gives the desired result in all cases.

Applying the built-in function to y' gives
y'/x = m' if y' = m'x+p', 0<=p'<x

Now substitute the value of y' into the middle equation:
y'/x = m' if y+x-1 = m'x+p', 0<=p'<x

Rearrange the equation in the middle:
y'/x = m' if y = (m'-1)x+p'+1, 0<=p'<x

This is just a division with quotient m'-1 and remainder p'+1, except in the case where p'=x-1. In that case, p'+1 = x, so (m'-1)x + p'+1 = (m'-1)x + x = m'x, and the remainder is really p'=0. Therefore, the formula should be written as:
y'/x = m' if y = m'x + 0, p'=x-1
y'/x = m' if y = (m'-1)x+p'+1, 0<=p'<x-1

Let's clean these up by defining p" = p'+1 for 0<'p'<x-1 and p" = 0 for p' = x-1. Then the formulas become:
y'/x = m' if y = m'x + p", p"=0
y'/x = m' if y = (m'-1)x+p", 1<=p"<x

Now compare this to what you would get by plugging the original number y into the built-in function, which is your equation (1):
In the case 1<=p"<x, you know y=mx+p and also y=(m'-1)x+p", therefore m=m'-1 and p"=p, therefore m'=m+1, p=p", and in the case p"=0, you know y=mx+p and y=m'x+p", so m'=m and p=p". Substituting these relationships into the two formulas gives
y'/x = m if y=mx+p, p=0
y'/x = m+1 if y=mx+p, 1<p<x-1

This is exactly the output you desired from the function, so plugging y' = y+x-1 into the built-in function will produce the ceiling in every case.

Note that you still had to plug y=mx+p into the proof somewhere along the line, becasue the original function is your basis for comparison, and you would have no way to interpret what m' and p" were if you did not do this.

Hope this is what you wanted!

--Stuart Anderson


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
DWCantrell
guest
May-26-06, 09:16 AM (EST)
 
2. "RE: Rounding off of numbers"
In response to message #0
 
   >Most computer language compilers (the oft used ones anyway)
>round off fractions to the floor value viz.
>
>y/x = m , if y = mx+p, 0<=p<x ----- (1)
>
>But the true (or desired value) in most cases

Perhaps in what you're dealing with. But the floor function is, at least in my experience, used at least as much as the ceiling function.

> is the ceiling function
>viz.
>y/x = m, if y = mx+p, p=0
> = (m+1) if y = mx+p, 0<p<x ----- (2)
>
>The usual thing to do in this case is to use the following
>function:
>
>f(x) = (y+x-1)/x
>
>Can i have a mathematical proof that this always produces
>the desired result (2), from first principles? That is,
>without merely substituting, y with (mx+p)?

Here's a bit of information that might help, although it doesn't
answer your question.

If you already have an implementation of floor(x), then simply
define ceiling(x) = -floor(-x).

Cheers,
David


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
Graham C
Member since Feb-5-03
Jun-23-06, 01:51 PM (EST)
Click to EMail Graham%20C Click to send private message to Graham%20C Click to view user profileClick to add this user to your buddy list  
3. "RE: Rounding off of numbers"
In response to message #2
 
   >>Most computer language compilers (the oft used ones anyway)
>>round off fractions to the floor value viz.
>>
>>y/x = m , if y = mx+p, 0<=p<x ----- (1)
>>
>>But the true (or desired value) in most cases
>
>Perhaps in what you're dealing with. But the floor function
>is, at least in my experience, used at least as much as the
>ceiling function.
>
I'd have thought the most commonly wanted was the rounded function with round(x)=floor(x+0.5).


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top

Conferences | Forums | Topics | Previous Topic | Next Topic

You may be curious to have a look at the old CTK Exchange archive.
Please do not post there.

Copyright © 1996-2018 Alexander Bogomolny

Search:
Keywords:

Google
Web CTK