This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; P40 (**) Goldbach's conjecture. | |
;; Goldbach's conjecture says that every positive even number greater than 2 is the sum of two prime numbers. Example: 28 = 5 + 23. It is one of the most famous facts in number theory that has not been proved to be correct in the general case. It has been numerically confirmed up to very large numbers (much larger than we can go with our Prolog system). Write a predicate to find the two prime numbers that sum up to a given even integer. | |
;; Example: | |
;; * (goldbach 28) | |
;; (5 23) | |
#lang racket | |
(provide goldbach) | |
(require "p39.ss") | |
(define (goldbach n) | |
(and (> n 2) (even? n) | |
(let loop ((lst (eratosthenes n))) | |
(let ((i (car lst))) | |
(let ((j (- n i))) | |
(if (member j lst) | |
`(,i ,j) | |
(loop (cdr lst)))))))) | |