# How to find a number that multiplied to a list, returns an all-integer list

I do not know how to code the following.

Suppose you have a list lst={x1,...,xn}and you need to find a number $$Z$$, to a given digits precision such that

Z * lst={y1,..,yn}


in which all $$y_i$$ are integers. I am clueless.

Edit: To be more precise, given a list of numbers lst={x1,...,xn}and a parameter $$\varepsilon>0$$ I want to find the smallest real number $$Z$$ such that for each $$i \leq n$$ we have $$\mid Z\cdot x_i-\text{Round}(z\cdot x_i) \mid<\varepsilon$$. Here Round$$(x)$$ denotes the closest integer to $$x$$.

• Are your X floating point or rational? Mar 16, 2020 at 23:02
• the $x$ values are the result of a rational list times $\pi/180$ Mar 16, 2020 at 23:09
• So you don't want an all integer list, you want an all "almost integer" list where they are all with $\varepsilon$ of an integer, correct? You want to find the minimum $Z$ that satisfies it? Mar 17, 2020 at 2:47
• Yes, precisely. That is what I am looking for Mar 17, 2020 at 13:52

Here is a list of rationals:

n=20; listRats = RandomInteger[{1, 10}, n]/RandomInteger[{1, 10}, n];


You can find your integer the Least Common Multiple of all the denominators of the rationals, so that

LCM @@ Denominator[listRats]*listRats


is the desired list of integers.

• What if my list is not made up of rationals, but I wanted some degree precision, namely 10 digits. How could I transform my list into a list of rationals? so that I can use this Mar 16, 2020 at 23:20
• You said your list was composed of rational numbers times $\pi$/180, so multiply by 180/$\pi$. Otherwise you can rationalize the list using Rationalize[list, inc]. Mar 16, 2020 at 23:27
• Thanks, I did so. But my result is always an integer, which is not always the case for the minimum $z$ that works Mar 16, 2020 at 23:32
• If it is not working, please show an example of how it fails. But really, look at the help for Rationalize, this is the function you want. Mar 17, 2020 at 0:51
• It does work, but is not quite the answer to the problem. This is because this solution will only return the smallest integer $z$ such that z * lst is a integer list, what I need is the smallest positive real $z$. Mar 17, 2020 at 1:05
qlst = Table[RandomInteger[{1, 10}]/RandomInteger[{1, 10}], 20]
z = Apply[LCM, qlst]
nlst = z*qlst
d = Apply[GCD, nlst]
lst = nlst/d


Not a full answer, just a clear statement of the problem. It is actually pretty interesting.

Create a set of integer denominators (what really matters) in a 2D space.

SeedRandom; den = Table[RandomInteger[{5, 25}], {2}];
1/den
(* {1/6, 1/25} *)


Find the least common multiplier lcm, which is also your value of $$Z$$ when $$\varepsilon=0$$

lcm = LCM @@ den
(* 150 *)


Plot $$Z$$ as you vary it over the range {0, lcm}

ParametricPlot[z/den, {z, 0, lcm}, Frame -> True,
GridLines -> {Range[0, (lcm/den)[]],
Range[0, (lcm/den)[]]
}] You can see that it almost hits the {4,1} grid coord and others. We can plot that. Set $$\varepsilon=0.1$$

eps = 0.1;
Plot[Norm[z/den - Round[z/den], Infinity],
{z, 0, lcm},
Epilog -> Line[{{0, eps}, {lcm, eps}}]
] So $$Z$$ about 24 or so (eyeballing it) is your value.

Around each grid crossing is a $$D$$-dimensional cube centered on the crossing with side lengths $$\varepsilon$$. The problem is to find the first cube intersected by the vector, knowing that it is bounded by when the vector length = lcm.

It might be possible to brute force it, but lcm can explode as the number of terms increases. Again, interesting problem!