Advertisement
logicmoo

QuantifyOnSets

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