Algebraic expression of a python function

45 Views Asked by At

I created a python function, which finds the input number's 5% minimum value and 5% maximum value. From there, it creates a list that consists of all the integers between those values.

def RangeForNumber(number):

    # I had to use rounding because the main function requires floats
    roundingNumber = round(number, 6) * 1000000
    # Finding the 5 percent of the input number
    Numb5perc = int(roundingNumber * 0.05)
    # Finding the minimum and maximum values value
    minnumber = int(roundingNumber) - Numb5perc
    maxnumber = int(roundingNumber) + Numb5perc
    return list(range(minnumber, maxnumber + 1))

So for example if my input is 100, then it returns 95 as the minimum value and 105 as the maximum value, and the list consists of values 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105.

Is it possible to express it in an algebraic way?

1

There are 1 best solutions below

0
On BEST ANSWER

Given any positive real input $x>0$ the set you are constructing might be written as $$ \mathbb Z \cap [0.95x, 1.05x] $$ or without using intersections and intervals as $$ \left\{\ k\in\mathbb Z \mid0.95x \le k \le 1.05x\ \right\}. $$ Here $\mathbb Z$ denotes the set of integers, $\cap$ denotes intersection of sets, $[a,b]$ denotes a closed interval and the second expression is written in set-builder notation