How I predict how some formula will behave with integers?

59 Views Asked by At

I am making some software that need to work with integers. Also I need to apply some formula to those integers, repeatedly over time (example, do x/=z several times in a row for a indefinite amount).

All tools, algorithms and formulas I could think or find, or don't work with integers at all, or work as approximations at best.

For example the x/=z several times in a row for example, you can theoretically calculate what x will be in the 10th time by doing x = x/(z^10), but that will be wrong if the result is fractional, you can use floor(x/(z^10)), but the result will STILL be wrong.

Plotting software that I found also don't have integers at all, or has "floor()/ceil()" functions support, at best, and still the result would fall in the problem of the previous paragraph.

So how I do it?

1

There are 1 best solutions below

0
On

Here's something to get you going for the iteration of x/=z:

enter image description here (that should have ended in "all three terms are 0 with regard to integer division")

Now if x or z are negative, you can try and see whether this still holds; I did not invest the time to make the necessary case distinctions, but they should be fairly analogous.


As Karoly Horvath mentions in a comment, without a clear specification of the kinds of functions for which you would like to find a shortcut to replace iterative evaluation, helping you out won't be possible since there are uncountably many functions over the integers, and the same approach won't work for all of them.