Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :: creates a gate that takes an atom as the sample
- |= n=@
- :: evaluates the (goldbach n) expression with ref to the core declared below.
- :: (goldbach n) calls the goldbach arm passing in n as its sample.
- =< (goldbach n)
- :: declares the core
- |%
- ::
- :: The prime arm takes an atom and checks if it is a prime number.
- :: Output %.y if prime, %.n if not prime.
- ::
- ++ prime
- :: creates a gate that takes an atom as the sample
- |= n=@
- :: cast output to loobean ie. %.y or %.n
- ^- ?
- :: if n is less than 2, return %.n (not prime)
- ?: (lth n 2) |
- :: else if n is less than 4, ie. n is 2 or 3, return %.y (prime)
- ?: (lth n 4) &
- :: else
- ::
- :: declare variable i as atom and initialise i to 2
- =/ i=@ 2
- :: declare variable j as atom and initialise j to 2
- =/ j=@ 2
- :: creates the trap for the gate, cast output to loobean
- |- ^- ?
- :: if i*j is value of sample n, then return %.n (not prime)
- :: ie. 2 positive integers (other than 1, n) can be multiplied to give n.
- ?: =((mul i j) n) |
- :: else if the quotient of n/2 is value j, return %.y (prime)
- ?: =(j (div n 2)) &
- :: else if i*j is greater than sample n,
- ?: (gth (mul i j) n)
- :: then reset i to 2, increment j, recursive call,
- :: passing new i, j to the gate to check for prime
- $(i 2, j +(j))
- :: else recursive call, passing i=i+1 to the gate to check for prime
- $(i +(i))
- ::
- :: The goldbach arm takes an atom and checks if it is a counterexample of
- :: the unproven Goldbach conjecture.
- :: Makes use of the prime arm.
- :: Output:
- :: %.n - The sample is not a Goldbach number.
- :: %.y - The sample is a counterexample of the unproven Goldbach conjecture.
- :: [[i=@ j=@] %.n] - The sample is not a counterexample of the Goldbach
- :: conjecture because the sample = prime number i + prime number j.
- ::
- ++ goldbach
- :: creates a gate that takes an atom as the sample
- |= n=@
- :: cast output to either a loobean, or
- :: a noun with format [[atom atom] loobean]
- ^- ?(? [[@ @] ?])
- :: if n<4 or n is odd, return %.n (sample n is not a Goldbach number)
- ?: |((lth n 4) =((mod n 2) 1)) |
- ::
- :: The next 2 expressions declare variables i and j as atoms,
- :: initialise i to 2, j to n-2, such that i+j = sample n.
- ::
- =/ i=@ 2
- =/ j=@ (sub n 2)
- ::
- :: creates the trap for the gate,
- :: cast output to either a loobean, or
- :: a noun with format [[atom atom] loobean]
- |- ^- ?(? [[@ @] ?])
- ::
- :: if i and j are both prime numbers (by calling the prime arm),
- :: then output result in format [[i j] %.n],
- :: ie. sample n is not a counterexample of the Goldbach conjecture
- :: because the sum of prime number i and prime number j equals sample n.
- ::
- ?: &((prime i) (prime j)) [[i j] |]
- :: else if i+2 is the value of sample n, output result %.y,
- :: ie. found sample n as a counterexample of the Goldbach conjecture!
- ?: =((add 2 i) n) &
- :: else increment i, decrement j,
- :: recursive call, passing new i, j to the gate.
- $(i +(i), j (dec j))
- :: terminates the core expression
- --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement