Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. :: creates a gate that takes an atom as the sample
  2. |= n=@
  3. :: evaluates the (goldbach n) expression with ref to the core declared below.
  4. :: (goldbach n) calls the goldbach arm passing in n as its sample.
  5. =< (goldbach n)
  6. :: declares the core
  7. |%
  8. ::
  9. :: The prime arm takes an atom and checks if it is a prime number.
  10. :: Output %.y if prime, %.n if not prime.
  11. ::
  12. ++ prime
  13. :: creates a gate that takes an atom as the sample
  14. |= n=@
  15. :: cast output to loobean ie. %.y or %.n
  16. ^- ?
  17. :: if n is less than 2, return %.n (not prime)
  18. ?: (lth n 2) |
  19. :: else if n is less than 4, ie. n is 2 or 3, return %.y (prime)
  20. ?: (lth n 4) &
  21. :: else
  22. ::
  23. :: declare variable i as atom and initialise i to 2
  24. =/ i=@ 2
  25. :: declare variable j as atom and initialise j to 2
  26. =/ j=@ 2
  27. :: creates the trap for the gate, cast output to loobean
  28. |- ^- ?
  29. :: if i*j is value of sample n, then return %.n (not prime)
  30. :: ie. 2 positive integers (other than 1, n) can be multiplied to give n.
  31. ?: =((mul i j) n) |
  32. :: else if the quotient of n/2 is value j, return %.y (prime)
  33. ?: =(j (div n 2)) &
  34. :: else if i*j is greater than sample n,
  35. ?: (gth (mul i j) n)
  36. :: then reset i to 2, increment j, recursive call,
  37. :: passing new i, j to the gate to check for prime
  38. $(i 2, j +(j))
  39. :: else recursive call, passing i=i+1 to the gate to check for prime
  40. $(i +(i))
  41. ::
  42. :: The goldbach arm takes an atom and checks if it is a counterexample of
  43. :: the unproven Goldbach conjecture.
  44. :: Makes use of the prime arm.
  45. :: Output:
  46. :: %.n - The sample is not a Goldbach number.
  47. :: %.y - The sample is a counterexample of the unproven Goldbach conjecture.
  48. :: [[i=@ j=@] %.n] - The sample is not a counterexample of the Goldbach
  49. :: conjecture because the sample = prime number i + prime number j.
  50. ::
  51. ++ goldbach
  52. :: creates a gate that takes an atom as the sample
  53. |= n=@
  54. :: cast output to either a loobean, or
  55. :: a noun with format [[atom atom] loobean]
  56. ^- ?(? [[@ @] ?])
  57. :: if n<4 or n is odd, return %.n (sample n is not a Goldbach number)
  58. ?: |((lth n 4) =((mod n 2) 1)) |
  59. ::
  60. :: The next 2 expressions declare variables i and j as atoms,
  61. :: initialise i to 2, j to n-2, such that i+j = sample n.
  62. ::
  63. =/ i=@ 2
  64. =/ j=@ (sub n 2)
  65. ::
  66. :: creates the trap for the gate,
  67. :: cast output to either a loobean, or
  68. :: a noun with format [[atom atom] loobean]
  69. |- ^- ?(? [[@ @] ?])
  70. ::
  71. :: if i and j are both prime numbers (by calling the prime arm),
  72. :: then output result in format [[i j] %.n],
  73. :: ie. sample n is not a counterexample of the Goldbach conjecture
  74. :: because the sum of prime number i and prime number j equals sample n.
  75. ::
  76. ?: &((prime i) (prime j)) [[i j] |]
  77. :: else if i+2 is the value of sample n, output result %.y,
  78. :: ie. found sample n as a counterexample of the Goldbach conjecture!
  79. ?: =((add 2 i) n) &
  80. :: else increment i, decrement j,
  81. :: recursive call, passing new i, j to the gate.
  82. $(i +(i), j (dec j))
  83. :: terminates the core expression
  84. --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement