0

I'm trying to implement an algorithm to solve conversion of base, and I'm stuck.

I want to express value in this form: $ v = a×b^e$ . How can I solve this problem? If a $\epsilon \ I_{\ne 0}\ , e \ \epsilon \ I$ and v and b are given.

An example:

$v = 0.02 ;\ b = 10;$

Which smallest value of a and e must have to meet the conditions?

Foreword, I apologize if there's misunderstood, it's my first time posting here in MathStackExchange.

  • Are you asking how to generalize scientific notation ($m \times 10^n$) to bases other than ten? – Dan Apr 28 '22 at 22:10
  • what does $ N_{\ne 0}$ mean? Do $a$ and $e$ need to be positive integers? – WW1 Apr 28 '22 at 22:13
  • @Dan, no, any base can be used, not only 10. – Novatto Apr 29 '22 at 10:45
  • @WW1, $N_{\ne 0}$ means natural numbers without zero. Yes, I made a contradiction in conditions. In example given, e has value of -2 when you transform to base 10, so would be impossible to solve the example to require conditions. I'll edit my post, thanks for the comment. – Novatto Apr 29 '22 at 10:53
  • What does $I$ mean? – Gerry Myerson Apr 29 '22 at 11:26
  • Also, $0.02=2\times10^{-2}=20\times10^{-3}=200\times10^{-4}=\cdots$, so without further conditions there could be many solutions. It's also $1\times50^{-1}$ and $18\times30^{-2}$ and lots of other things. – Gerry Myerson Apr 29 '22 at 11:30
  • @GerryMyerson $I$ means integer numbers. You are right about that, the value can be express in many ways, so this problem could be undetermined. The ideal is to find the smallest combination about two values because of computational purpose(less storage). For example, $ 0.02 = 2\times10^{-2} = 20 \times10^{-3}$..., the preference would be $ 2\times10^{-2} $ than $ 20 \times10^{-3} $. I'll edit my post, thanks for the question. – Novatto Apr 29 '22 at 13:25
  • 1
    I don't think you can simultaneously minimize both $a$ and $e$. What combination of the two do you want to minimize? Please [edit] the question to clarify, and include several solved examples. (Don't carry on an extended discussion in comments.) – Ethan Bolker Apr 29 '22 at 13:49

1 Answers1

0

I Assume that $I$ is supposed to the integers. (Commonly we denote the integers by $\Bbb Z$ - when I is used to represent a set of numbers, most commonly that set will be $[0,1]$, all numbers $\ge 0$ and $\le 1$. But there is no standard meaning for $I$. If you do not already know - for certain - that some notation you are using is a widely practiced standard, it is best to define/explain the notation instead of just assuming everyone will understand.)

There are two cases you have to consider:

  • $v$ has a terminating expansion in base $b$. Equivalently, there is some integer $n$ such that $b^n v$ is an integer. Then the $e$ you want will be the lowest such $n$. A simple-minded algorithm to find $e$ and $a$ would be:
    • If $v$ is integer, keep dividing by $b$ until the result is no longer integer. $e$ will be the number of times you divided and got an integer result. $a$ is the last integer result you got.
    • If $v$ is not integer, keep multiplying by $b$ until you get an integer result. $e$ will be the opposite of the number of times you multiplied by $b$ to get that integer result. $a$ will be the integer result.
  • $v$ does not have a terminating expression in base $b$. Equivalently, for every integer $n, b^nv$ is not integer. In this case the problem cannot be solved. Such numbers (which include almost all numbers) cannot be expressed as $a\times b^e$ for any integers $a$ and $b$.

Even when you restrict to numbers representable on a computer, unless $b$ is even, the vast majority of representable numbers will not have a terminating base $b$ expansion. I.e., they cannot be expressed as $a\times b^e$ for integer $a, e$.

Paul Sinclair
  • 43,643
  • Thanks for warning about integers. Your answer was perfect, I learn a lot by it. I was thinking that the problem is impossible and you create cases about it. I'm trying to solve this issue in Github(link) and my idea was to implement a base conversion like description problem. You'll receive credits there too. Thanks! – Novatto May 02 '22 at 11:41