Post Reply 
Goldbach Conjecture 
03-15-2015, 04:45 PM (This post was last modified: 03-19-2015 10:27 AM by DrD.)
Post: #1
Goldbach Conjecture 
Here's a short program to display both the number of Goldbach partitions, and a list containing them:

For additional "fun" points, can you graph the number of resulting partitions vs. an even number (greater than 4) that produces a composition of twin prime summands?

Code:
 
//============================================
//  Goldbach Conjecture, June 7,1742         =
//                                           =
//  Lists the number of Goldbach twin-prime  =
//  summand pairs,                           =
//  Enter an even number greater than 4      =
//  Displays Number of, and List of          =
//           Goldbach Partitions.            =
//                                           =
// ===========================================

EXPORT Gold(n)
BEGIN
local a:=0, i ;    
    L1:={};
    print();
    for i from 3 to n  do 
        if isprime(i) and isprime(n-i) then  
            L1:=concat(L1,{{i,(n-i)}}); //  Full Goldbach Composition
            a:= a+1 ;  //  Total number of Goldbach elements
        end; 
    end; 
    print("Goldbach Partitions " + a/2);  //  Number of distinct Goldbach partitions
    print(L1({1,size(L1)/2})); //  Goldbach partition listing
END;
Find all posts by this user
Quote this message in a reply
03-16-2015, 01:10 PM
Post: #2
RE:   former rainy day
I did not know about Goldbachs conjecture. Thanks for sharing the idea. This is DrDs frame with some changes. Have not found out yet how to plot with the prime so this has to wait. [/quote]
Code:

EXPORT Goldbach(n)
//  Goldbach conjecture (June 7, 1742):  Positive even integers greater than 2 are the sum of two prime numbers.
BEGIN
  local a:=2, maxn:= n/2, pp:={};         
  print();
         
// Make list of prime number pairs
 REPEAT
    IFTE(isPrime(n-a), pp:=concat(pp,{{a,n-a}}))));   
    a:=nextprime(a);
 UNTIL a>maxn;  //end calc
 
  print(pp);  // prime pairs
  print("Goldbach Partitions = " + SIZE(pp));   //number of pairs 
END;  // Ends program
Find all posts by this user
Quote this message in a reply
03-18-2015, 04:07 PM
Post: #3
RE: Goldbach Conjecture 
Thanks for your ideas, Theresa. I had to edit my opening post, as something went crazy with the text there.

I've also included a different approach, of many I'm sure, that builds the Goldbach composition and partitions. Graphing the composition of twin prime summands vs. an even number (greater than 4) used to generate them, should result in the famous Goldbach's Comet plot.

I struggled with the makelist() command, using an IFTE() construct, but I got stuck on the "else" clause, thinking I wanted to add any twin primes, to the list, but nothing otherwise. No success there.

-Dale-
Find all posts by this user
Quote this message in a reply
03-22-2015, 10:32 AM (This post was last modified: 03-22-2015 02:32 PM by DrD.)
Post: #4
RE: Goldbach Conjecture 
The code below is an attempt to plot the Goldbach "Comet," which is a plot of the number of twin prime summands, for each positive even integer, (up to a users specified number, and within calculator limitations). The plotted cometary tail gets more interesting for large numbers, (like 500), taking a correspondingly longer time to present, naturally.

I'm sure there are better ways to produce this plot, but readers may find interesting tidbits in the programming details useful for your own future projects, which is my primary purpose in sharing this program. I found the subject matter interesting, and fun, getting built to this point. Perhaps you will, too.

Seems to run ok on r6975 release firmware. If it locks up the calc, try: On + Symb, and re-run the program. The virtual calc does better.

-Dale-
Code:

//====================================================
//                                                                                                                      =
//                                         Gold(n)                                                              =
//                                                                                                                      =
//   Input:  Positive EVEN integer greater than 2                                =
//   Output:  Goldbach's Comet plot                                                     =
//                                                                                                                      =
//   Descr: The composite number of twin prime summands     =
//                 is plotted vs the positive even number >2   input.       =
//                                                                                                                      =
//====================================================

//  Goldbach conjecture (June 7, 1742):  Positive even integers greater than 2 are the sum ot two prime numbers. 

Goldbach();
rescale();
EXPORT Gold(n)

BEGIN
  local a:=2,b,c,f,i,x,y;
  local white:=rgb(255,255,255),
            black:=rgb(0,0,0),
            red:=rgb(255,0,0),
            blue:=rgb(0,0,255),
            yellow:=rgb(255,255,0); 

Goldbach(n);  //  Determine  vertical scale Max G(E) twin prime summands
c:=3*size(L1);

// Display Title: Goldbach's Comet
  rect(0,20,320,214);
  rect_p(75,1,265,16,blue);
  textout_p("Goldbach's Comet",G0,110,4,2,yellow);

// Display plot screen
  rect_p(40,20,300,200,white,black);   //  Plot field rectangle 

  // Vertical Axis G(E) Goldbach partitions
  for a from 20 to 200 step 6 do
    IFTE((a mod 5) ==0, line_p(40,a,45,a,yellow), line_p(40,a,42,a,yellow));
    If (a mod 5) ==0 then
       HDigits:=0;
        b:=c-rescale(20,200,0,c,a);
        textout_p(b,G0,IFTE((b<10),32,35-5*trunc((1+LOG(b)))),a,1,black);  
       HDigits:=2;
    end; // end if
  end;   // Ends for: vert scale
 
  // Horiz Axis Goldbach number E
  for a from 40 to 300 step 26 do
    IFTE((a mod 5) ==0, line_p(a,200,a,195,yellow), line_p(a,200,a,197,yellow)); 
     If (a mod 5) ==0 then
       HDigits:=0;
        b:=rescale(40,300,0,n,a);
        textout_p(b,G0,a,201,1,black); 
       HDigits:=2;
    end; // end if   
  end;   // Ends for: Horiz scale

//  Composite G(E) for all positive even integers greater than 2 up to n
  f:=4;
 WHILE f <= n DO   
    Goldbach(f);  //  Get L1 (list of twin primes for each positive even integer greater than 2, up to n).
  
    // Plot Goldbach composite data from L1
  if size(L1) <>  0 then
    for i from 1 to size(L1) do
       x:=rescale(0,n,40,300,f);
       y:=rescale(0,c,200,20,size(L1));
      Case
       if ip(y mod 4) == 0 then pixon_P(G0,x,y,white);end; 
       if ip(y mod 4) == 1 then pixon_P(G0,x,y,yellow);end; 
       if ip(y mod 4) == 2 then pixon_P(G0,x,y,red);end; 
       pixon_P(G0,x,y,blue); 
      end;  // end case
    end;  // End for:  plot
  end;  //end if L1 !={}

   f:=f+2;
  END;  // ends while 
  wait(65535); 
END;  // Ends program

// ==========================  Subroutines  ==================================

//======================================
//                       Goldbach(n)                                      =  
//                                                                                     =
//   Input:    Current Positive Even Integer > 2   =
//  Output:  List of twin prime summands         =
//                                                                                     =
//=====================================
Goldbach(n)
BEGIN
local a:=0,i;

// Make list of twin-prime number pairs
  L1:={};
  for i from 3 to n  do 
        if isprime(i) and isprime(n-i) then  
            L1:=concat(L1,{{i,(n-i)}});    //  Full Goldbach Composition
            a:= a+1 ;                                   //  Total number of Goldbach elements
        end;  // end if
    end;   //  end for  
END;

// ============================================
//                                                                                                      =
//                                      Rescale                                                 =
//                                                                                                      =
//  Input:     Datapoint d in range (old min, old max)      =
// Returns:  Value in range (new min, new max)              =
//                                                                                                      =
// ============================================
rescale(omn,omx,nmn,nmx,d) 
BEGIN
   RETURN (((d-omn)*(nmx-nmn))/(omx-omn))+nmn; 
END;
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 3 Guest(s)