logicmoo

Testcase: equal_papers_v1 <-> equal_papers_v2 are the same?

Jul 29th, 2017
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 3.14 KB | None | 0 0
  1.  
  2. #import: written-on(word,paper).
  3.  
  4.  
  5. my-minus-one(N,M) <->  (N > 1)  &  (M = N-1)
  6.  
  7. forall x. same(x,x)
  8.  
  9. legal-pad(paper) <-> min-elements(1, paper)
  10.  
  11. exactly-n-elements(1,paper) <->
  12. (exists paper word.  
  13.     (   written-on(word,paper)
  14.       & ~(exists other-word.
  15.            (  written-on(other-word,paper)
  16.              & ~same(other-word,word)))))
  17.  
  18. exactly-n-elements(2,paper) <->
  19. (exists paper word1 word2.
  20.   (  written-on(word1,paper)
  21.    & written-on(word2,paper)
  22.    & ~same(word1,word2)  
  23.    & ~ (exists other-word.
  24.          (   written-on(other-word,paper)
  25.           & ~same(other-word,word1)
  26.           & ~same(other-word,word2)))))
  27.  
  28. exactly-n-elements(N,paper) <->
  29.    range-elements(N,N,paper)  
  30.  
  31. range-elements(N,M,paper) <->
  32.  (exists paper.
  33.   ( min-elements(N,paper)
  34.     & max-elements(M,paper)))
  35.  
  36. min-elements(1,paper) <->
  37.  (exists paper word1.
  38.      (written-on(word1,paper)))
  39.  
  40. min-elements(2,paper) <->
  41.  (exists paper word1 word2.
  42.    (  written-on(word1,paper)
  43.     & written-on(word2,paper)
  44.     & ~same(word1,word2)))
  45.  
  46. max-elements(2,paper) <->  
  47. (exists paper word1 word2.
  48.    (  written-on(word1,paper)
  49.     & written-on(word2,paper)
  50.     &  ~(exists other-word.
  51.           (  written-on(other-word,paper)
  52.             & ~same(other-word,word1)
  53.             & ~same(other-word,word2)))))
  54.  
  55. % exists a paper with no elements
  56. exactly-n-elements(0,paper) <->
  57.   (exists paper
  58.      ~(exists word1. written-on(word1,paper)))
  59.  
  60. max-elements(1,paper) <->
  61.  exactly-n-elements(0,paper) v exactly-n-elements(1,paper)
  62.  
  63. containsAtLeastOneUnique(paper1,paper2) <->
  64.   (exists word. (written-on(word,paper1) -> ~written-on(word,paper2)))
  65.  
  66. disjoint(paper1,paper2) <->
  67.   ~(exists word. (written-on(word,paper1) & written-on(word,paper2)))
  68.  
  69. subset(paper1,paper2) <->
  70.     (forall word.
  71.       written-on(word,paper1) -> written-on(word,paper2) )
  72.  
  73. union(paper1,paper2,paper) <->
  74.  (forall word.
  75.    (written-on(word,paper) <->
  76.        (written-on(word,paper1) v written-on(word,paper2))))
  77.  
  78. union(paper1,paper2,paper) <->
  79.   (exists scratchpad.
  80.       union(paper1,paper2,scratchpad)
  81.      & ~containsAtLeastOneUnique(paper,scratchpad))
  82.  
  83.  
  84. union-disjoint(paper1,paper2,paper) <->
  85.    (   union(paper1,paper2,paper)
  86.      & disjoint(paper1,paper2))
  87.  
  88.  
  89. min-elements(4,paper) <->
  90.   (exists paper1 paper2.
  91.      min-elements(2,paper1)
  92.    & min-elements(2,paper2)
  93.    & union-disjoint(paper1,paper2))
  94.  
  95. min-elements(N,paper) <->
  96.   (exists paper1 paper2.
  97.      min-elements(1,paper1)
  98.    & min-elements(M,paper2)
  99.    & legal-pad(paper2)
  100.    & union-disjoint(paper1,paper2)
  101.    & my-minus-one(N,M))
  102.  
  103.  
  104. max-elements(N,paper) <->
  105.   (exists paper1 paper2.
  106.      max-elements(1,paper1)
  107.    & max-elements(M,paper2)
  108.    & legal-pad(paper2)
  109.    & union-disjoint(paper1,paper2)
  110.    & my-minus-one(N,M))
  111.  
  112.  
  113. equal_papers_v2(paper1,paper2) <->
  114.    ( ~containsAtLeastOneUnique(paper1,paper2)
  115.      & ~containsAtLeastOneUnique(paper2,paper1)
  116.      & legal-pad(paper1)
  117.      & legal-pad(paper2))
  118.  
  119. equal_papers_v1(paper1,paper2) <->
  120.  ( legal-pad(paper1)
  121.    & (forall word.
  122.       (written-on(word,paper1) <-> written-on(word,paper2))))
Add Comment
Please, Sign In to add comment