Author Topic: Collatz Conjecture  (Read 4718 times)

0 Members and 1 Guest are viewing this topic.

Offline Mathman1@comcast.net

  • Newbie
  • Posts: 3
    • View Profile
Collatz Conjecture
« on: July 07, 2020, 11:08:33 am »
I specifically downloaded QB64 to study (play with) Collatz Conjecture (Explained in Wikipedia). QB64 is very flexible and powerful. I wish QB64 had a scrollable output screen but applaud all its other capabilities. You enter the number under the unsigned integer max (18446744073709551615) (somewhat less or you will error immediately) and you will progress through the Collatz procedure. If the output page was scrollable, each operation would be printed on one line. Since it appears the scrollable feature is not available, I print out the operation number, the resulting number, and the resulting number length and some spaces. I do not know how to use the MOD function for the odd/even test so I divide and multiply by 2 and test for equivalency with the original number. If at any time the next result is going to go above the unsigned integer max, I print error and carriage return but still continue. I do 50 operations at a time and when the series finishes, I print end. My series completion number agrees with the Wikipedia example of maximum completion numbers. QB64 is cool!

Code: QB64: [Select]
  1. m~&& = 18446744073709551615 / 3
  2. 1 INPUT "number: ", a~&&: IF a~&& < 1 THEN 1
  3. n = 0: e = 0
  4. 2 PRINT a~&&; LEN(STR$(a~&&)) - 1;: IF e = 50 THEN INPUT s: e = 0
  5. b~&& = a~&& / 2
  6. c~&& = b~&& * 2
  7. IF a~&& >= m~&& AND c~&& <> a~&& THEN PRINT: PRINT "Error"
  8. IF c~&& = a~&& THEN PRINT " E, ";: a~&& = a~&& / 2: ELSE PRINT " O, ";: a~&& = a~&& * 3 + 1
  9. n = n + 1: e = e + 1: IF a~&& <> 1 THEN GOTO 2
  10. PRINT "1  1  END "; n: GOTO 1
« Last Edit: July 07, 2020, 11:27:42 am by Mathman1@comcast.net »

FellippeHeitor

  • Guest
Re: Collatz Conjecture
« Reply #1 on: July 07, 2020, 11:15:27 am »
Hi there. To add a code box, just paste your code between code tags:

[code=qb64]'your code here[/code]

And to get scrollable output, you can use the system's console. Add this to the beginning of your program:

Code: QB64: [Select]

Welcome aboard!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Collatz Conjecture
« Reply #2 on: July 07, 2020, 11:22:29 am »
@FellippeHeitor

Has he (Mathman1) been allowed access to Samples Gallery?

@Mathman1@comcast.net  code usually has to "cook" in Programs Board unless your real avatar name is @STxAxTIC  ;-))
« Last Edit: July 07, 2020, 11:51:24 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Collatz Conjecture
« Reply #3 on: July 07, 2020, 11:36:25 am »
@FellippeHeitor

I can remove this but I'd rather it be moved to Programs where we can discuss Collatz. ✨

Offline Mathman1@comcast.net

  • Newbie
  • Posts: 3
    • View Profile
Re: Collatz Conjecture
« Reply #4 on: July 07, 2020, 12:05:34 pm »
I am new here. I found this item in the book, The Secret Life of Numbers, Chapter 6 of 50 chapters so there may be more programming examples to come. Please move this to Programs if more appropriate.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Collatz Conjecture
« Reply #5 on: July 07, 2020, 12:37:18 pm »
@Mathman1@comcast.net

I would move it but I only have permissions for Samples Gallery, kinda curious how you have access but OK you're new :)

You could restart in Programs if you don't mind and I can remove the stuff here? (never done that)

FellippeHeitor

  • Guest
Re: Collatz Conjecture
« Reply #6 on: July 07, 2020, 12:56:41 pm »
Only now I noticed the board we're at. Let us pray odin moves it.

FellippeHeitor

  • Guest
Re: Collatz Conjecture
« Reply #7 on: July 07, 2020, 12:57:38 pm »
Done (amen).

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Collatz Conjecture
« Reply #8 on: July 07, 2020, 12:58:13 pm »
Yep, I'm with bplus.  How did this get in here? And with replies - not allowable in Library.  What is going on?

It's a conspiracy, though that would be mere Conjecture.

Later: well, it's not "here (Library)" any more.  We ought, I think, to look into how it could have got there in the first place.  Sorry mathman1, to be writing all over your post.

« Last Edit: July 07, 2020, 01:02:40 pm by Qwerkey »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Collatz Conjecture
« Reply #9 on: July 07, 2020, 12:59:10 pm »
Thanks Odin! 👍

@Mathman1@comcast.net

The Secret life of Numbers, I've heard of that. Who was author and year of Copy Right?

Not Ian Stewart by any chance? Or Clifford Pickover?

Update: Keep forgetting this is Internet Age and I can just look it up, so 2006 collection of math articles by George Szpiro.
« Last Edit: July 07, 2020, 01:28:09 pm by bplus »

Offline Mathman1@comcast.net

  • Newbie
  • Posts: 3
    • View Profile
Re: Collatz Conjecture
« Reply #10 on: July 07, 2020, 01:47:11 pm »
The book is The Secret Life of Numbers : 50 Easy Pieces on How Mathematicians Work and Think by George G. Szpiro, Copyright 2006. George Szpiro had a previous book Kempler's Conjecture as mention on the back cover.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Collatz Conjecture
« Reply #11 on: July 07, 2020, 02:48:02 pm »
I wrote a program that will write a program like this:
Code: QB64: [Select]
  1. PRINT "Testing number  9 " + CHR$(10): GOTO 9 '<<<<< 2-times plug-in number <= 10
  2.  
  3. 1 PRINT " 1! Collatz Conjecture Confirmed.": END
  4. 2 PRINT " 2 EVEN ": GOTO 1
  5. 3 PRINT " 3 ODD ": GOTO 10
  6. 4 PRINT " 4 EVEN ": GOTO 2
  7. 5 PRINT " 5 ODD ": GOTO 16
  8. 6 PRINT " 6 EVEN ": GOTO 3
  9. 7 PRINT " 7 ODD ": GOTO 22
  10. 8 PRINT " 8 EVEN ": GOTO 4
  11. 9 PRINT " 9 ODD ": GOTO 28
  12. 10 PRINT " 10 EVEN ": GOTO 5
  13. 11 PRINT " 11 ODD ": GOTO 34
  14. 13 PRINT " 13 ODD ": GOTO 40
  15. 14 PRINT " 14 EVEN ": GOTO 7
  16. 16 PRINT " 16 EVEN ": GOTO 8
  17. 17 PRINT " 17 ODD ": GOTO 52
  18. 20 PRINT " 20 EVEN ": GOTO 10
  19. 22 PRINT " 22 EVEN ": GOTO 11
  20. 26 PRINT " 26 EVEN ": GOTO 13
  21. 28 PRINT " 28 EVEN ": GOTO 14
  22. 34 PRINT " 34 EVEN ": GOTO 17
  23. 40 PRINT " 40 EVEN ": GOTO 20
  24. 52 PRINT " 52 EVEN ": GOTO 26
  25.  

Why?

(something about being a nerd)

Reminder if it's odd then  multply by 3 and add 1, 9 literally goes to 28

if it's even like 28 then it goes to half, 14 in the case of 28.

So on and so on and it always ends up at 1 according to Collatz Conjecture. Prove it and you can make some money I think.


Quote
I do not know how to use the MOD function for the odd/even test so I divide and multiply by 2 and test for equivalency with the original number.
@Mathman1@comcast.net

If N MOD 2 = 1 then N is Odd  else it's Even.

If N MOD M = 0 then N is divisible M.

Think of MOD as remainder If the remainder of N/M is 0 then N is divisible by M. MOD Comes in very handy for programming.
« Last Edit: July 07, 2020, 02:53:38 pm by bplus »

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Collatz Conjecture
« Reply #12 on: July 07, 2020, 09:22:48 pm »
I sometimes like to fantasize that there's an alien mathematics out there, completely unlike ours, where this problem is trivial

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Collatz Conjecture
« Reply #13 on: July 08, 2020, 03:34:18 am »
I sometimes like to fantasize ...

"Start with any positive integer n. Then each term is obtained from the previous term as follows: if the previous term is even, the next term is one half of the previous term. If the previous term is odd, the next term is 3 times the previous term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1."

Well it shows the type of people we are: fantasising over that!!!

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Collatz Conjecture
« Reply #14 on: July 08, 2020, 11:19:07 am »
"Start with any positive integer n. Then each term is obtained from the previous term as follows: if the previous term is even, the next term is one half of the previous term. If the previous term is odd, the next term is 3 times the previous term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1."

Completely self evident trivial case given the nature of difluranic branching operations on the field of dark integers