How to get rid of large numbers in a function?

83 Views Asked by At

I study mathematics, and I have a question:

I have this math function:

f(x) = floor(x^99999 / 10^(floor(log10(x^99999+0.1)) + 1 - 5))

(floor() is rounding down)

It gets x, increases it highly and outputs it's first 5 left digits.

For greater simplicity, my function can be written like this:

f(x) = floor(Increase(x) / 10^(Length(x) - 5))

where:

Length(x) = floor(log10(x+0.1)) + 1

  • is function outputs length (num of digits) of given x.

and

Increase(x) = x^99999

  • is function increases given x.

The problem is that I insert small numbers into this function (x is up to 1000), and it also produces small numbers (5-digit), but when it works, it has to internally generate very large numbers, the number of characters in which is so large that my computer cannot cope with calculation of the result.

Understanding that there can only be small numbers at the input and output leads me to believe that huge numbers are not needed when calculating the result. This comes from the fact that, for example, such a function f() can be rewritten as:

f(x) = IsEqual(x; 2)*y2 + IsEqual(x; 3)*y3 + IsEqual(x; 4)*y4 + ... + IsEqual(x; 1000)*y1000

where IsEqual() outputs 1 if its two arguments are equal or otherwise 0, and y1, y2, y3 and others are 5-digit hypothetical outputs of function f().

This example shows the possibility of getting rid of too large numbers in functions when calculating them. Yes, the function itself turns out to be quite cumbersome, but at least it is not as demanding in terms of performance as it was originally.

At its core, my question can be reduced to the problem of getting rid of large powers, but the problem may not necessarily lie in the powers, because raising to a power is not the only mathematical way to greatly increase a number (there are also, for example, sums of series, products, multiplication and other)

Question: how can I mathematically simplify/transform such functions so that they do not have such large numbers inside?

EDIT: in my exampme-function f() argument x is an integer greater than 1. Thanks @gnasher729 for this.

1

There are 1 best solutions below

1
On

This function will usually return the highest five digits of $x^{99999}$, and in exceedingly rare cases it returns 9999 instead of 99999. Actually, for x slightly larger than 1 if $9.9 \le x^{99999} < 10$ the result will be ten times too small in a rather large range, and it gets worse for x < 1.

So if you want the exact function, you’ll need the large exponent.