Post Reply 
Goldbach Conjecture 
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 


Messages In This Thread
Goldbach Conjecture  - DrD - 03-15-2015, 04:45 PM
RE:   former rainy day - Teresa - 03-16-2015, 01:10 PM
RE: Goldbach Conjecture  - DrD - 03-18-2015, 04:07 PM
RE: Goldbach Conjecture  - DrD - 03-22-2015 10:32 AM



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