# Thread: Generating a list of irrational numbers

1. ## Generating a list of irrational numbers

Greetings to everyone

I've been doodling on my assignment for OOP C++, my main idea is to create a fully featured C++ program that represents the real
number system,(Real,rational,irrational....etc), I would to know how is it possible to create a function that can generate a certain number of irrational numbers, The code below is a small snippet from my program that generates a list of rational numbers.

Code:
``` void RationalNumbers::displayRationalNumbers(double P_p,double P_q)  //
{
cout<<"How many rational numbers do you want to generate from your given values?"<<endl;
cin>>EndUserRequest;

cout<<"\n\nRational numbers division starting \nwith numerator as "<<P_p<<" and denominator as "<<P_q<<endl;
for(int i=0; i<=EndUserRequest; i++)
{
resultOfRational = P_p/P_q;
cout<<resultOfRational<<" at "<<i<<endl;
P_p++;  // postfix increment operator used to increment given values for numerator and denominator
P_q++;
}

system("pause");
}```
Code:
```   void RationalNumbers::readRationalNumberInfo()
{
double p1,q1;
cout<<"Please enter a value for each of the following to generate Rational numbers"<<endl;
cout<<"\nThe following calculation will be in the form of p/q where p and q are integers and q cannot be zero"<<endl;
cout<<"P: "<<endl;
cin>>p1;
cout<<"Q: "<<endl;
cin>>q1;

if(p1 >=1 && q1 >=1)
displayRationalNumbers(p1,q1); // passes arguments to member function parameters
else
{
cout<<"Please enter valid values for each of the following! "<<endl;
}

}```

Yours sincerely

Thanks,
Last edited by HamadMMX; 04-06-2013 at 10:31 PM.  Reply With Quote

2. It's not clear what you mean by 'list of irrational numbers'. From your initial code I suspect that what you intended to do might be to output all numbers starting from a certain starting point until you have output a fixed amount of numbers.

Mathematically, this does not make much sense. Given a specific real number N it is unclear what the 'next' real number would be. For every N+Epsilon you pick, I can come up with a smaller Epsilon such that my number is 'nexter' to N than yours.

In computer science however, we don't have real numbers. Instead we have a binary representation with a fixed precision. Therefore, it is completely possible given a specific float value f to determine the 'next' float value. You simply need to decompose the float into its mantissa, exponent and sign components and increment the mantissa by 1. Dealing with overflow issues is a bit more tricky and can be done in a second step.

If you have further questions regarding the issue, feel free to ask. If this is completely unrelated to what you're trying to do, please give some more info on what your actual goal is.  Reply With Quote

3. Registered User Join Date
Dec 2004
Posts
184

## Relatively Prime

I think I understand what you are trying to do. I am a beginning programmer so have patience.

You were looking for a way to always find a rational numbers. Just add a whole number.

You are dividing p/q and testing to see if it is a decimal.

If you are looking to find rational numbers by comparing if they are < 1 that is easy. Trying to find a pattern that will create a series that is always irrational is extremely more difficult.

I would say where the mod > 0. Off the top of my head with no in-depth inspection I would say it is possible. I would try adding a number that is relatively Prime to the last irrational number in the series. You may discover that a series is possible.
Because it really isn’t a problem just testing for irrational numbers; I don’t know if this will work. It may lead you to a very difficult problem on choosing relatively Prime numbers.

I don’t know why you are diving P by Q? Is that to create the irrational? If you can determine a relatively Prime number you can divide by it and always get an irrational. However, this may prove very challenging.

This is how I would approach the problem if I understand what you are saying. It seems beyond the scope of a standard C++ class assignment. But this may inspire a good idea.  Reply With Quote

4. Originally Posted by trurl_ I don’t know why you are diving P by Q? Is that to create the irrational? If you can determine a relatively Prime number you can divide by it and always get an irrational. However, this may prove very challenging.
No. A number obtained by dividing two integers P and Q is, by definition, never an irrational number.

Furthermore, there is no logically sound representation of irrational numbers in the numerically-oriented arithmetic model of C++. There are numeric approximations of irrational numbers (e.q. the number returned by std::sqrt(2)), but all of the numbers representable by the floating point datatypes are again, by definition, rational numbers.

Representing irrational numbers requires a far more complex arithmetic model, since you need to include numbers that don't have an exact numeric representation. Take e.g. a look at interactive theorem provers to get an idea how one can solve this.  Reply With Quote

5. Registered User Join Date
Dec 2004
Posts
184
Good eye CSans. I couldn’t remember about irrational numbers definition. That was high school algebra. I should know this.

He made P and Q double not float. I really never studied that 2 integers divided will always produce a rational number. By definition rational is the ability to be written as a fraction.

But I want to throw something out there. What if both or one of P and Q was a fraction? You couldn’t program it as a double, but why not use float and decimals? I mean it is easy to see if 2 integers will eventually equal a fraction times the integer, but could you determine if 2 decimals P and Q divided equaled an irrational number. I can’t.

Mod would not work with decimals. And like you said computers cannot handle that precision.

I see a pattern in the division here. I cannot describe it, but in my last post of the mod to be used in cryptography I saw it also. I can’t explain it and it probably is nothing logical, but I will ask a question:

If you have 2 decimals that are relatively Prime will the Mod of these numbers never equal zero? If so you have just found a division of 2 decimals (or fractions) that is irrational.

How do you program this? I have no clue. Mod does not work on decimals. And I realize my math doesn’t seem logical. It just blows you mind and seems stupid. But I see something here. Does anyone see the value of this impossible problem?

In short CSans you are right he can’t program this as he is going. But I think the limitation on a list of irrational numbers is the limitation of the programming language and not the math.

But I’m probably completely wrong. But you can give Hamad better advice than me.  Reply With Quote

6. Originally Posted by trurl_ He made P and Q double not float.
Same thing with more bits. All limitations mentioned in my last post apply.

But I want to throw something out there. What if both or one of P and Q was a fraction? You couldn’t program it as a double, but why not use float and decimals? I mean it is easy to see if 2 integers will eventually equal a fraction times the integer, but could you determine if 2 decimals P and Q divided equaled an irrational number. I can’t.
You cannot get an irrational by dividing two rationals.
Proof: Let R1, R2 rationals. By definition, there exist natural numbers P1, P2, Q1, Q2 s.t. R1 = P1 / Q1 and R2 = P2 / Q2. Then R1 / R2 = P1*Q2 / P2*Q1, hence also a rational.

Mod would not work with decimals.
There is a reasonable definition for non-integer modulo, see fmod. Question is, why do you think modulo would help at all for the original problem? Make sure you understand the point of my last post: There is no way of representing irrational numbers in float arithmetic. Hence it is not possible to solve this proplem with the tools provided by said arithmetic.

But I think the limitation on a list of irrational numbers is the limitation of the programming language and not the math.
It is indeed in the math. As I laid out in my first post, there is no concept of a successor in the real numbers. Check out the concept of an uncountable set to get a feeling for some of the problems that you run into here. Any introductory textbook on set theory will cover this in great detail.

You should probably start reading some textbooks in general. Your thoughts seem not very structured, which makes it easy for you to fall for false conclusions. Grab some nice college-level introductory text to get a feeling on how to work with this stuff in a structured way.
Don't start chasing after assumptions you cannot prove, no matter how fascinating they seem. Otherwise, you'll be doing numerology and not mathematics.  Reply With Quote

7. Registered User Join Date
Dec 2004
Posts
184
I think my problem is I don’t know the true definition of irrational. I know the sqrt is irrational.

In my high school algebra II class we took the definition of irrational is that it cannot be written as a fraction. Then we moved on. I am not completely math illiterate. I have had 2 semesters of calculus. But those classes don’t really teach number theory. I mean we deal with series, but I am not a math major.

I tend to like impossible problems. When I read this post I knew I had one. What I wanted was to relate this exercise to my previous thread of finding where a fraction multiples until it reaches a whole number. I have benefited from this post on my ignorance, so please look at that thread.

I took the definition of irrational as being a nonterminating, nonrepeating decimal. In fact I believe you can find many nonterminating fractions; Or at least to approach infinity. Pi as you know is circumference/diameter and equals 3.14 and taken out to a billion and still no end or pattern.

So if I am able to find a fraction that doesn’t terminate, but can be written as a fraction is it irrational? That is why I said to use decimals in the fraction such as 1.247989/34.5783

In doing so you start to get numbers that do not terminate; I did not use integers but multiple integer fractions divided by each other would result the same. Are you saying that because the number will eventually terminate when it approaches infinity it is rational? Would you argue that Pi is rational?

I know that I am grabbing you and beating your head against a brick wall with this problem, but you may get an idea in the dizzying daze.

What I meant by the mod is: Mod^5 or mod incremented into the original number

23/3 = 7 remainder 2

20/3 = 6 remainder 3

30/3 = 10

Compare to:
23/3 = 7 remainder 2

23 mod 2 = 1

23 mod 1 = 0

So divide 23 by 3 three times and the number is a 3 digit number. That is where it terminates.

Let’s discuss this further. If you see it as impossible we can end here. But if you have a racket ball we can bounce it against the brick wall.  Reply With Quote

8. Originally Posted by trurl_ I took the definition of irrational as being a nonterminating, nonrepeating decimal. In fact I believe you can find many nonterminating fractions; Or at least to approach infinity.
There are indeed many irrational numbers. Cantor showed that there are more irrational than rational numbers (which might seem strange at first, since there are already infinitely many rational numbers, but this is how set theory works ).

So if I am able to find a fraction that doesn’t terminate, but can be written as a fraction is it irrational? That is why I said to use decimals in the fraction such as 1.247989/34.5783
Don't do that. In fact, you should move away from decimals completely, as it's an unintuitive notation for most mathematical purposes and tends to obscure what's really going on. I already gave you the proof that a fraction of rationals is always a rational, so you should be able to see why your approach here won't work. Just remember the definition of the irrational numbers...

In doing so you start to get numbers that do not terminate; I did not use integers but multiple integer fractions divided by each other would result the same.
How do you know they don't terminate? Can you give a proof for that? How do you know it's really a non-repeating decimal and not just one with a very, very long period?

Are you saying that because the number will eventually terminate when it approaches infinity it is rational? Would you argue that Pi is rational?
Get your terminology straight. If it terminates, it's not irrational. There is no such thing as 'terminating when approaching infinity'. It either terminates, or not, it does not matter how long it takes. Don't toy around with abstract concepts like infinity if you're not sure what they actually mean.

What I meant by the mod is: Mod^5 or mod incremented into the original number

23/3 = 7 remainder 2

20/3 = 6 remainder 3

30/3 = 10

Compare to:
23/3 = 7 remainder 2

23 mod 2 = 1

23 mod 1 = 0

So divide 23 by 3 three times and the number is a 3 digit number. That is where it terminates.
Sorry, but you don't make any sense here. Step away from the numbers please and give some concrete formulae on what your method is.
This is exactly what I meant when I was mentioning numerology above. You are confusing random numerical patterns with actual mathematical reasoning.  Reply With Quote

9. Registered User Join Date
Dec 2004
Posts
184
I cannot win this debate. I think what the author of this thread thought was that he could use decimals and divide them to find irrational numbers. This got me too. But as you said it is possible to find infinitely many non-terminating numbers but the definition the irrational number is integers divided by integers. My original idea is to find a non-terminating decimal. But this breaks the rules of the definition.

But my numbers that wasn’t clear is not voodoo. I was just taking the mod of the original number by the remainder of the previous modulus. This will determine how many iterations it takes to completely factor the number. I may not be writing the modulus operation correct, but if you take the remained of the modulus and use it as a modulus into the original number.

23 / 3 = 7 remainder of 2

23/ (the previous remainder of 2) = 11 remainder of 1

23/ (the previous remainder of 1) = 23 remainder of 0

Since the remainder equals zero there number of iterations to divide or factor 23/3 is 3.

This may or may not be useful for determining where a decimal or fraction will end. I just thought it would be less steps and less computer intensive, since the computer language already has an operation for the modulus.

So I think the author of this post thought that he could uses decimals to find irrational numbers. This seems to work, but I understand by definition it is completely wrong. If so there would be infinitely many with no pattern or relationship to finding them.

Now for some numerology:

I believe that any terminating decimal multiplied by a number of iterations will eventually equal a whole number within infinitely iterations. The hard part is to find those iterations.

I think this would be a more worthy problem than the irrational number finding from decimals.  Reply With Quote

c++ 