• Post Reply Bookmark Topic Watch Topic
  • New Topic

x = (int) Math.ceil[ x/2 ] + Math.floor[ x/2 ]  RSS feed

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a program which assumes that:

It seems to work most of the time.
Is there a definite mathematical proof for this; akin to proofs for
factorisation of integers, prime factors etc.. ?

Thanks

Pho
 
Pat Farrell
Rancher
Posts: 4686
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pho Tek:

It seems to work most of the time.


What do you mean? Does it work all the time you've tested it? or only most of the time? if just "most" then does that mean it does not work always?
If it fails just once, there is no proof, you have a counter example.

Assuming it has always worked in your tests, how many tests did you do?

What kind of proof do you expect? I'd probably do it by induction, but only once I was confident it held.
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Way too much meaning for a post in the Meaningless Drivel forum.

Moving this to the Java In General (Intermediate) forum.

Mark
 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't a "mathematical" proof because you aren't asking about a mathematical concept, you're asking about how Java implements things.

However there's a logical proof which would parallel the mathematical proof of that question. Assuming your "x" is an integer, there are four possibilities: x can be odd or even, and it can be negative or non-negative. Consider each of them and show that your equation is true when Java executes it.
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,

I finally found an axiom stating that it is true;
from wikipedia's entry on Floor function.

Pho
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!