
Algebra PreAlgebra and Basic Algebra Math Forum 
 LinkBack  Thread Tools  Display Modes 
June 16th, 2017, 03:37 PM  #1 
Member Joined: Oct 2015 From: Greece Posts: 33 Thanks: 0  Custom function help!
Hello! Say I have a number x. I want to make a function which will take this number and add some value to it in order to make it power of two (the closest value that is a power of two). f(x) > (power of two) x can be any integer number. For example, if I have x = 1, then I must add to it 1 in order to make it power of two because (1+1 = 2). If x = 9, I must add 7 (9+7 = 16). I tried, but I can't think of any mathematical way of doing it. So my point is, how can I find which number I must add to x in order to create a new number that is gonna be power of two? Thank you! Last edited by skipjack; June 17th, 2017 at 03:18 AM. 
June 16th, 2017, 03:52 PM  #2 
Senior Member Joined: Aug 2012 Posts: 1,679 Thanks: 436 
How can we find the next largest power of $2$? Given $x$, its exact power of $2$ is $\log_2 x$ and the next integer power of $2$ is $2^{\lceil \log_2 x \rceil}$ where $\lceil \cdot \rceil$ is the ceiling function, by definition the integer greater than or equal to a given real number. Then the difference function is $2^{\lceil \log_2 x \rceil}  x$. For example with $x = 9$ we have: * $\log_2 9 \approx 3.1699 \dots$ [Wolfram Alpha] * $\lceil 3.1699 \dots \rceil = 4$ * $2^4 = 16$ * $16  9 = 7$ This method works for any positive real number, not just positive integers. However we have problems if $x$ is negative. For example what's the smallest power of $2$ greater than or equal to $5$? Is it $\frac{1}{2}$, or $\frac{1}{4}$, or $\frac{1}{8}$? There is no "next" power of $2$ greater than $5$. I'm too lazy at the moment to sort this out in terms of complex logs but if we stick to real numbers, then $x$ has to be strictly positive. Last edited by Maschke; June 16th, 2017 at 04:13 PM. 
June 16th, 2017, 04:08 PM  #3 
Math Team Joined: Jul 2013 From: काठमाडौं, नेपाल Posts: 876 Thanks: 60 Math Focus: सामान्य गणित 
$\displaystyle f(x)=\left \lceil \sqrt{x} \right \rceil^{2}$ for a positive number 'x' if you take the square root of 'x' and again square it will give the same value. If you square a value less than the square root of 'x' it will give lesser value than 'x' and if you square a value greater than the square root of 'x' it will give greater value than 'x' so, if you square a whole number just greater than the square root of 'x' you will get the desired value. for example: if $\displaystyle x = 98 $ $\displaystyle f(x)=\left \lceil \sqrt{98} \right \rceil^{2}$ $\displaystyle f(x)=\left \lceil 9.8994949.......\right \rceil^{2}$ $\displaystyle f(x)=10^{2}$ $\displaystyle \therefore f(x)=100$ 
June 16th, 2017, 04:11 PM  #4 
Member Joined: Oct 2015 From: Greece Posts: 33 Thanks: 0 
Thank you guys so much! That was easy but i don't know much about logarithms so this is why i couldn't think about it myself.

June 16th, 2017, 04:12 PM  #5 
Math Team Joined: Jul 2013 From: काठमाडौं, नेपाल Posts: 876 Thanks: 60 Math Focus: सामान्य गणित 
Seems like I misunderstood the question .......
Last edited by skipjack; June 17th, 2017 at 03:19 AM. 

Tags 
custom, function 
Thread Tools  
Display Modes  

Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
guessing the base function of a real function that meets certain requirements  vlekje5  PreCalculus  11  March 27th, 2017 01:58 PM 
Inverting the Riemann Zeta Function with the Mobius Function  neelmodi  Number Theory  0  February 4th, 2015 10:52 AM 
Derivation of tau function, sigma, euler and mobius function  msgelyn  Number Theory  2  January 12th, 2014 04:13 AM 
Find all linear function given a function equals its inverse  deSitter  Algebra  4  April 10th, 2013 02:17 PM 