File: goldbach.mpi

package info (click to toggle)
mathpiper 0.81f%2Bsvn4469%2Bdfsg3-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 36,576 kB
  • sloc: java: 57,479; lisp: 13,721; objc: 1,300; xml: 988; makefile: 114; awk: 95; sh: 38
file content (36 lines) | stat: -rw-r--r-- 862 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

/*
 * Example: brute force search to check Goldbach's conjecture.
 * Goldbachs conjecture: for each even number n larger than 2 there
 * are at least two primes p and q such that p+q=n. The function 
 * GoldBach returns a list of pairs of numbers that sum up to the
 * even number supplied as input.
 *
 * Examples:
 * In> GoldBach(10)
 * Out> {{7,3},{5,5}};
 * In> MapSingle("Length",GoldBach(2*(2 .. 10)))
 * Out> {1,1,1,2,1,2,2,2,2};
 * 
 */
 
 
 
/* Main routine */
GoldBach(m_IsEven) <--
[
  Local(p);

  /* Select all primes up to m/2 */
  p:=Select("IsPrime", 1 .. (m/2));

  /* Given the primes p, select all the primes in (m-p) */
  p:=Select("IsPrime",m-p);

  /* Return a list with the solutions */
  Transpose({p,m-p});
];

/* Given a list of numbers, apply the goldbach test on each one of them. */
GoldBach(m_IsList) <-- MapSingle("GoldBach",m);