Author Topic: Collatz Conjecture  (Read 5417 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Collatz Conjecture
« Reply #15 on: July 08, 2020, 12:43:38 pm »
OK last night and this morning I been working on a rule change to Collatz:

When the number is odd do this: (3*N + 1)/2 because with the bare 3*N + 1 your next step IS ALWAYS to divide by 2 because an Odd + 1 ALWAYS makes an Even number, automatically dividing by 2 saves a step and more importantly to computer programs keeps the highest working number (it's working with) considerably lower! (so you don't hit the Type limit so soon).

Because this is how you could work an equivalent expression:

(((N + 1) / 2) * 3) - 1 = (3*N + 1) / 2 and the computer math on the left expression never exceeds ~~ 1.5 * N (+/-) as opposed to 3 * N + 1


If the number is odd then add 1 (makes the odd number even) so you can divide by 2 (and stay an Integer) then multiply by 3 (this gives us a higher limit we can go with our number Type, nearly doubling it!) now you subtract 1 because when adding 1 before dividing by 2 you are really adding 2.

Before limit for Integers is 32XXX/ 3, with rule change that gets equivalent results limit for Integers is (32XXX / 3) * 2. So you've effectively doubled the numbers you can work with a given Type.

« Last Edit: July 08, 2020, 02:32:21 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Collatz Conjecture
« Reply #16 on: July 09, 2020, 02:30:17 am »
Code: QB64: [Select]
  1. ' 2020-07-09 Write up  from reply I left at QB64 forum yesterday
  2. ' ref: https://www.qb64.org/forum/index.php?topic=2789.msg120521#msg120521
  3. ' here is essence  (((N + 1) / 2) * 3) - 1 = (3*N + 1) / 2   is New Rule for Odd
  4. ' here is new limit (32766 / 3) * 2
  5.  
  6. _TITLE "Collatz Array Program revist 2020-07-09"
  7. CONST topLimit = (32766 / 3) * 2 'just integers today
  8. REDIM cSeq$(0)
  9.     PRINT "The highest number Interger Type can handle is"; topLimit; ","
  10.     PRINT "If our test number wanders up there we must cut the run short."
  11.     PRINT "Go ahead try 20,000 it is over 1/3 of Integer Type Limit!"
  12.     INPUT "(0 quits) Enter a number to try New Collatz Sequencer "; n
  13.     IF n = 0 THEN EXIT DO
  14.     done = 0: odd = 0: even = 0: l = 1
  15.     WHILE n <> 1 OR done
  16.         s$ = STR$(l) + ":" + STR$(n)
  17.         IF n MOD 2 THEN 'odd
  18.             IF n < topLimit THEN s$ = s$ + " odd": l = l + 1 ELSE s$ = s$ + " hit limit, end of run.": done = 1
  19.             n = (((n + 1) / 2) * 3) - 1: odd = odd + 1
  20.         ELSE
  21.             s$ = s$ + " even": l = l + 1
  22.             n = n \ 2: even = even + 1
  23.         END IF
  24.         sAppend cSeq$(), s$
  25.     WEND
  26.     IF done = 0 THEN
  27.         s$ = STR$(l) + ":" + STR$(n)
  28.         sAppend cSeq$(), s$
  29.         even = even + 1
  30.     END IF
  31.     s$ = STR$(odd) + " times the odd rule was applied.": sAppend cSeq$(), s$
  32.     s$ = STR$(even) + " times the even  rule was applied.": sAppend cSeq$(), s$
  33.     s$ = STR$(odd + even) + " steps were taken to create this sequence.": sAppend cSeq$(), s$
  34.     display cSeq$()
  35.     REDIM cSeq$(0)
  36.     CLS
  37. PRINT: PRINT "0 tells me to say, goodbye!"
  38.  
  39. SUB sAppend (arr() AS STRING, addItem$)
  40.     REDIM _PRESERVE arr(LBOUND(arr) TO UBOUND(arr) + 1) AS STRING
  41.     arr(UBOUND(arr)) = addItem$
  42.  
  43. SUB display (arr() AS STRING)
  44.     lb = LBOUND(arr): ub = UBOUND(arr)
  45.     IF ub - lb + 1 < 21 THEN top = ub ELSE top = lb + 19
  46.     CLS: PRINT "press any key to quit scroller..."
  47.     LOCATE 3, 1
  48.     FOR i = lb TO top
  49.         PRINT arr(i)
  50.     NEXT
  51.     DO
  52.         IF ub - lb + 1 > 20 THEN
  53.             DO WHILE _MOUSEINPUT
  54.                 IF row >= lb THEN row = row + _MOUSEWHEEL ELSE row = lb 'prevent under scrolling
  55.                 IF row > ub - 19 THEN row = ub - 19 'prevent over scrolling
  56.                 IF prevrow <> row THEN 'look for a change in row value
  57.                     IF row >= lb AND row <= ub - 19 THEN
  58.                         CLS: PRINT "press any key to quit scroller..."
  59.                         LOCATE 3, 1
  60.                         FOR n = row TO row + 19
  61.                             PRINT arr(n)
  62.                         NEXT
  63.                     END IF
  64.                 END IF
  65.                 prevrow = row 'store previous row value
  66.             LOOP
  67.         END IF
  68.     LOOP UNTIL INKEY$ > ""
  69.  
  70.  
  71.  

So what? I just made the Odd Rule Odder! ;-))
« Last Edit: July 09, 2020, 02:34:49 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Collatz Conjecture
« Reply #17 on: July 09, 2020, 02:40:13 pm »
Collatz Collapse, reducing Collatz Sequence to it's essential sequence of odd integers by removing all the Even Step fluff:

Code: QB64: [Select]
  1. ' 2020-07-09 Write up  from reply I left at QB64 forum yesterday
  2. ' ref: https://www.qb64.org/forum/index.php?topic=2789.msg120521#msg120521
  3. ' here is essence  (((N + 1) / 2) * 3) - 1 = (3*N + 1) / 2   is New Rule for Odd
  4. ' here is new limit (32766 / 3) * 2
  5.  
  6. ' 2020-07-09 A dream I had this morning to change 2 rules into 1 (almost) in order to simplify
  7. ' the Collatz sequence into the significant sequence of ascending odd numbers.
  8. ' What do they look like in terms of prime numbers?
  9.  
  10.  
  11. _TITLE "Collatz Collapse 2020-07-09"
  12. CONST topLimit = (32766 / 3) * 2 'just integers today
  13. REDIM cSeq$(0)
  14.    1 PRINT "The highest number Interger Type can handle is"; topLimit; ","
  15.     PRINT "If our test number wanders up there we must cut the run short."
  16.     PRINT "Go ahead try 20,000 it is over 1/3 of Integer Type Limit!"
  17.     INPUT "(0 quits) Enter a number to try New Collatz Sequencer "; n
  18.     IF n = 0 THEN EXIT DO
  19.     IF n > topLimit THEN GOTO 1
  20.     done = 0: odd = 0: even = 0: l = 1
  21.     sAppend cSeq$(), "Starting number is" + STR$(n)
  22.     WHILE n MOD 2 = 0 'drop down and give me an odd number of pushups
  23.         n = n \ 2
  24.     WEND
  25.     WHILE n <> 1 OR done
  26.         s$ = STR$(l) + ":" + STR$(n)
  27.         IF n MOD 2 THEN 'odd
  28.             IF n < topLimit THEN
  29.                 s$ = s$ + " odd": l = l + 1
  30.                 n = (((n + 1) / 2) * 3) - 1
  31.                 odd = odd + 1
  32.             ELSE
  33.                 s$ = s$ + " hit limit, end of run.": done = 1
  34.             END IF
  35.         ELSE
  36.             s$ = s$ + " even": l = l + 1
  37.             n = n \ 2: even = even + 1
  38.         END IF
  39.         WHILE n MOD 2 = 0 'drop down and give me an odd number of pushups
  40.             n = n \ 2
  41.         WEND
  42.         sAppend cSeq$(), s$
  43.     WEND
  44.     IF done = 0 THEN
  45.         s$ = STR$(l) + ":" + STR$(n)
  46.         sAppend cSeq$(), s$
  47.         even = even + 1
  48.     END IF
  49.     sAppend cSeq$(), "------------------------------------------------------------------"
  50.     s$ = STR$(odd) + " odd steps were taken to create this sequence.": sAppend cSeq$(), s$
  51.     display cSeq$()
  52.     REDIM cSeq$(0)
  53.     CLS
  54. PRINT: PRINT "0 tells me to say, goodbye!"
  55.  
  56. SUB sAppend (arr() AS STRING, addItem$)
  57.     REDIM _PRESERVE arr(LBOUND(arr) TO UBOUND(arr) + 1) AS STRING
  58.     arr(UBOUND(arr)) = addItem$
  59.  
  60. SUB display (arr() AS STRING)
  61.     lb = LBOUND(arr): ub = UBOUND(arr)
  62.     IF ub - lb + 1 < 21 THEN top = ub ELSE top = lb + 19
  63.     CLS: PRINT "press any key to quit scroller..."
  64.     LOCATE 3, 1
  65.     FOR i = lb TO top
  66.         PRINT arr(i)
  67.     NEXT
  68.     DO
  69.         IF ub - lb + 1 > 20 THEN
  70.             DO WHILE _MOUSEINPUT
  71.                 IF row >= lb THEN row = row + _MOUSEWHEEL ELSE row = lb 'prevent under scrolling
  72.                 IF row > ub - 19 THEN row = ub - 19 'prevent over scrolling
  73.                 IF prevrow <> row THEN 'look for a change in row value
  74.                     IF row >= lb AND row <= ub - 19 THEN
  75.                         CLS: PRINT "press any key to quit scroller..."
  76.                         LOCATE 3, 1
  77.                         FOR n = row TO row + 19
  78.                             PRINT arr(n)
  79.                         NEXT
  80.                     END IF
  81.                 END IF
  82.                 prevrow = row 'store previous row value
  83.             LOOP
  84.         END IF
  85.     LOOP UNTIL INKEY$ > ""
  86.  
  87.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Collatz Conjecture
« Reply #18 on: July 10, 2020, 11:59:41 am »
Quote
@bplus: Why you don't use the type _UNSIGNED _INTEGER, your upper limit is much higher,
as I have used it in my old program?

A reasonable question from those impressed by big numbers.

If I can't discover the essence of what makes Collatz tick in the Integer range then I am not so interested in the problem. I do know I have the option to go the way you suggest, if I have to, as yet I am not so compelled. With number there is no end to going bigger, it's an essential part of the proof process if something happens for small number it will also happen with big. "As above, so below." or is it the other way around? Well if it's universal, it is the same above and below.

« Last Edit: July 10, 2020, 12:02:32 pm by bplus »