veritas-optimizer 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (349) hide show
  1. data/.gemtest +0 -0
  2. data/.rvmrc +1 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +20 -10
  5. data/Guardfile +22 -0
  6. data/README.rdoc +2 -0
  7. data/Rakefile +4 -2
  8. data/TODO +43 -2
  9. data/config/flay.yml +2 -2
  10. data/config/flog.yml +1 -1
  11. data/config/roodi.yml +4 -4
  12. data/lib/veritas/optimizer/aggregate/count.rb +17 -0
  13. data/lib/veritas/optimizer/aggregate/maximum.rb +17 -0
  14. data/lib/veritas/optimizer/aggregate/mean.rb +17 -0
  15. data/lib/veritas/optimizer/aggregate/minimum.rb +17 -0
  16. data/lib/veritas/optimizer/aggregate/standard_deviation.rb +17 -0
  17. data/lib/veritas/optimizer/aggregate/sum.rb +17 -0
  18. data/lib/veritas/optimizer/aggregate/variance.rb +17 -0
  19. data/lib/veritas/optimizer/aggregate.rb +16 -0
  20. data/lib/veritas/optimizer/algebra/difference.rb +3 -1
  21. data/lib/veritas/optimizer/algebra/extension.rb +58 -3
  22. data/lib/veritas/optimizer/algebra/intersection.rb +3 -1
  23. data/lib/veritas/optimizer/algebra/join.rb +6 -4
  24. data/lib/veritas/optimizer/algebra/product.rb +3 -1
  25. data/lib/veritas/optimizer/algebra/projection.rb +23 -54
  26. data/lib/veritas/optimizer/algebra/rename.rb +55 -80
  27. data/lib/veritas/optimizer/algebra/restriction.rb +33 -66
  28. data/lib/veritas/optimizer/algebra/summarization.rb +161 -3
  29. data/lib/veritas/optimizer/algebra/union.rb +3 -1
  30. data/lib/veritas/optimizer/function/binary.rb +124 -0
  31. data/lib/veritas/optimizer/{logic → function}/connective/binary.rb +48 -102
  32. data/lib/veritas/optimizer/{logic → function}/connective/conjunction.rb +12 -11
  33. data/lib/veritas/optimizer/{logic → function}/connective/disjunction.rb +15 -14
  34. data/lib/veritas/optimizer/function/connective/negation.rb +65 -0
  35. data/lib/veritas/optimizer/function/numeric/absolute.rb +20 -0
  36. data/lib/veritas/optimizer/function/numeric/addition.rb +20 -0
  37. data/lib/veritas/optimizer/function/numeric/division.rb +20 -0
  38. data/lib/veritas/optimizer/function/numeric/exponentiation.rb +20 -0
  39. data/lib/veritas/optimizer/function/numeric/modulo.rb +20 -0
  40. data/lib/veritas/optimizer/function/numeric/multiplication.rb +20 -0
  41. data/lib/veritas/optimizer/function/numeric/square_root.rb +20 -0
  42. data/lib/veritas/optimizer/function/numeric/subtraction.rb +20 -0
  43. data/lib/veritas/optimizer/function/numeric/unary_minus.rb +20 -0
  44. data/lib/veritas/optimizer/function/numeric/unary_plus.rb +20 -0
  45. data/lib/veritas/optimizer/function/numeric.rb +34 -0
  46. data/lib/veritas/optimizer/{logic → function}/predicate/comparable.rb +6 -4
  47. data/lib/veritas/optimizer/{logic → function}/predicate/enumerable.rb +24 -26
  48. data/lib/veritas/optimizer/{logic → function}/predicate/equality.rb +6 -6
  49. data/lib/veritas/optimizer/{logic → function}/predicate/exclusion.rb +6 -16
  50. data/lib/veritas/optimizer/{logic → function}/predicate/greater_than.rb +6 -5
  51. data/lib/veritas/optimizer/{logic → function}/predicate/greater_than_or_equal_to.rb +6 -6
  52. data/lib/veritas/optimizer/{logic → function}/predicate/inclusion.rb +6 -16
  53. data/lib/veritas/optimizer/{logic → function}/predicate/inequality.rb +6 -6
  54. data/lib/veritas/optimizer/{logic → function}/predicate/less_than.rb +6 -5
  55. data/lib/veritas/optimizer/{logic → function}/predicate/less_than_or_equal_to.rb +6 -6
  56. data/lib/veritas/optimizer/{logic → function}/predicate/match.rb +5 -4
  57. data/lib/veritas/optimizer/{logic → function}/predicate/no_match.rb +5 -4
  58. data/lib/veritas/optimizer/function/predicate.rb +61 -0
  59. data/lib/veritas/optimizer/function/string/length.rb +31 -0
  60. data/lib/veritas/optimizer/function/unary.rb +86 -0
  61. data/lib/veritas/optimizer/function.rb +87 -0
  62. data/lib/veritas/optimizer/optimizable.rb +6 -3
  63. data/lib/veritas/optimizer/relation/operation/binary.rb +36 -70
  64. data/lib/veritas/optimizer/relation/operation/limit.rb +1 -9
  65. data/lib/veritas/optimizer/relation/operation/offset.rb +1 -9
  66. data/lib/veritas/optimizer/relation/operation/order.rb +1 -9
  67. data/lib/veritas/optimizer/relation/operation/reverse.rb +1 -9
  68. data/lib/veritas/optimizer/relation/operation/unary.rb +50 -13
  69. data/lib/veritas/optimizer/version.rb +1 -1
  70. data/lib/veritas/optimizer.rb +43 -16
  71. data/spec/integration/veritas/algebra/difference/optimize_spec.rb +6 -4
  72. data/spec/integration/veritas/algebra/intersection/optimize_spec.rb +6 -4
  73. data/spec/integration/veritas/algebra/join/optimize_spec.rb +4 -2
  74. data/spec/integration/veritas/algebra/product/optimize_spec.rb +2 -0
  75. data/spec/integration/veritas/algebra/projection/optimize_spec.rb +6 -4
  76. data/spec/integration/veritas/algebra/rename/optimize_spec.rb +2 -0
  77. data/spec/integration/veritas/algebra/restriction/optimize_spec.rb +9 -7
  78. data/spec/integration/veritas/algebra/summarization/optimize_spec.rb +49 -0
  79. data/spec/integration/veritas/algebra/union/optimize_spec.rb +6 -4
  80. data/spec/integration/veritas/{logic → function}/connective/conjunction/optimize_spec.rb +33 -31
  81. data/spec/integration/veritas/{logic → function}/connective/disjunction/optimize_spec.rb +30 -28
  82. data/spec/integration/veritas/{logic → function}/connective/negation/optimize_spec.rb +7 -5
  83. data/spec/integration/veritas/{logic/expression → function}/optimize_spec.rb +5 -3
  84. data/spec/integration/veritas/{logic → function}/predicate/equality/optimize_spec.rb +9 -7
  85. data/spec/integration/veritas/{logic → function}/predicate/exclusion/optimize_spec.rb +13 -11
  86. data/spec/integration/veritas/{logic → function}/predicate/greater_than/optimize_spec.rb +17 -15
  87. data/spec/integration/veritas/{logic → function}/predicate/greater_than_or_equal_to/optimize_spec.rb +17 -15
  88. data/spec/integration/veritas/{logic → function}/predicate/inclusion/optimize_spec.rb +13 -11
  89. data/spec/integration/veritas/{logic → function}/predicate/inequality/optimize_spec.rb +9 -7
  90. data/spec/integration/veritas/{logic → function}/predicate/less_than/optimize_spec.rb +17 -15
  91. data/spec/integration/veritas/{logic → function}/predicate/less_than_or_equal_to/optimize_spec.rb +17 -15
  92. data/spec/integration/veritas/relation/empty/optimize_spec.rb +2 -0
  93. data/spec/integration/veritas/relation/materialized/optimize_spec.rb +2 -0
  94. data/spec/integration/veritas/relation/operation/limit/optimize_spec.rb +3 -1
  95. data/spec/integration/veritas/relation/operation/offset/optimize_spec.rb +3 -1
  96. data/spec/integration/veritas/relation/operation/order/optimize_spec.rb +4 -2
  97. data/spec/integration/veritas/relation/operation/reverse/optimize_spec.rb +4 -2
  98. data/spec/integration/veritas/relation/optimize_spec.rb +2 -0
  99. data/spec/shared/{logic_connective_binary_optimize_behavior.rb → function_connective_binary_optimize_behavior.rb} +14 -12
  100. data/spec/shared/idempotent_method_behavior.rb +2 -0
  101. data/spec/shared/optimize_method_behavior.rb +2 -0
  102. data/spec/support/add_method_missing.rb +2 -0
  103. data/spec/unit/veritas/optimizer/algebra/difference/empty_left/optimize_spec.rb +2 -0
  104. data/spec/unit/veritas/optimizer/algebra/difference/empty_right/optimize_spec.rb +2 -0
  105. data/spec/unit/veritas/optimizer/algebra/difference/equal_operands/optimize_spec.rb +2 -0
  106. data/spec/unit/veritas/optimizer/algebra/extension/extensions_spec.rb +31 -0
  107. data/spec/unit/veritas/optimizer/algebra/extension/order_operand/optimizable_spec.rb +23 -0
  108. data/spec/unit/veritas/optimizer/algebra/extension/order_operand/optimize_spec.rb +22 -0
  109. data/spec/unit/veritas/optimizer/algebra/extension/unoptimized_operand/optimizable_spec.rb +18 -8
  110. data/spec/unit/veritas/optimizer/algebra/extension/unoptimized_operand/optimize_spec.rb +4 -2
  111. data/spec/unit/veritas/optimizer/algebra/intersection/empty_left/optimize_spec.rb +2 -0
  112. data/spec/unit/veritas/optimizer/algebra/intersection/empty_right/optimize_spec.rb +2 -0
  113. data/spec/unit/veritas/optimizer/algebra/intersection/equal_operands/optimize_spec.rb +2 -0
  114. data/spec/unit/veritas/optimizer/algebra/join/equal_headers/optimizable_spec.rb +2 -0
  115. data/spec/unit/veritas/optimizer/algebra/join/equal_headers/optimize_spec.rb +2 -0
  116. data/spec/unit/veritas/optimizer/algebra/product/table_dee_left/optimizable_spec.rb +2 -0
  117. data/spec/unit/veritas/optimizer/algebra/product/table_dee_left/optimize_spec.rb +2 -0
  118. data/spec/unit/veritas/optimizer/algebra/product/table_dee_right/optimizable_spec.rb +2 -0
  119. data/spec/unit/veritas/optimizer/algebra/product/table_dee_right/optimize_spec.rb +2 -0
  120. data/spec/unit/veritas/optimizer/algebra/projection/empty_operand/optimizable_spec.rb +2 -0
  121. data/spec/unit/veritas/optimizer/algebra/projection/empty_operand/optimize_spec.rb +2 -0
  122. data/spec/unit/veritas/optimizer/algebra/projection/projection_operand/optimizable_spec.rb +2 -0
  123. data/spec/unit/veritas/optimizer/algebra/projection/projection_operand/optimize_spec.rb +2 -0
  124. data/spec/unit/veritas/optimizer/algebra/projection/{set_operand → union_operand}/optimizable_spec.rb +3 -1
  125. data/spec/unit/veritas/optimizer/algebra/projection/{set_operand → union_operand}/optimize_spec.rb +4 -2
  126. data/spec/unit/veritas/optimizer/algebra/projection/unoptimized_operand/optimizable_spec.rb +3 -1
  127. data/spec/unit/veritas/optimizer/algebra/projection/unoptimized_operand/optimize_spec.rb +6 -4
  128. data/spec/unit/veritas/optimizer/algebra/rename/aliases_spec.rb +5 -13
  129. data/spec/unit/veritas/optimizer/algebra/rename/empty_operand/optimizable_spec.rb +2 -0
  130. data/spec/unit/veritas/optimizer/algebra/rename/empty_operand/optimize_spec.rb +2 -0
  131. data/spec/unit/veritas/optimizer/algebra/rename/limit_operand/optimizable_spec.rb +2 -0
  132. data/spec/unit/veritas/optimizer/algebra/rename/limit_operand/optimize_spec.rb +2 -0
  133. data/spec/unit/veritas/optimizer/algebra/rename/offset_operand/optimizable_spec.rb +2 -0
  134. data/spec/unit/veritas/optimizer/algebra/rename/offset_operand/optimize_spec.rb +2 -0
  135. data/spec/unit/veritas/optimizer/algebra/rename/order_operand/optimizable_spec.rb +2 -0
  136. data/spec/unit/veritas/optimizer/algebra/rename/order_operand/optimize_spec.rb +2 -0
  137. data/spec/unit/veritas/optimizer/algebra/rename/projection_operand/optimizable_spec.rb +17 -7
  138. data/spec/unit/veritas/optimizer/algebra/rename/projection_operand/optimize_spec.rb +2 -0
  139. data/spec/unit/veritas/optimizer/algebra/rename/rename_operand/optimizable_spec.rb +2 -0
  140. data/spec/unit/veritas/optimizer/algebra/rename/rename_operand/optimize_spec.rb +2 -0
  141. data/spec/unit/veritas/optimizer/algebra/rename/rename_operand_and_empty_aliases/optimizable_spec.rb +2 -0
  142. data/spec/unit/veritas/optimizer/algebra/rename/rename_operand_and_empty_aliases/optimize_spec.rb +2 -0
  143. data/spec/unit/veritas/optimizer/algebra/rename/restriction_operand/optimizable_spec.rb +3 -1
  144. data/spec/unit/veritas/optimizer/algebra/rename/restriction_operand/optimize_spec.rb +7 -5
  145. data/spec/unit/veritas/optimizer/algebra/rename/reverse_operand/optimizable_spec.rb +2 -0
  146. data/spec/unit/veritas/optimizer/algebra/rename/reverse_operand/optimize_spec.rb +2 -0
  147. data/spec/unit/veritas/optimizer/algebra/rename/set_operand/optimizable_spec.rb +2 -0
  148. data/spec/unit/veritas/optimizer/algebra/rename/set_operand/optimize_spec.rb +2 -0
  149. data/spec/unit/veritas/optimizer/algebra/rename/unoptimized_operand/optimizable_spec.rb +7 -20
  150. data/spec/unit/veritas/optimizer/algebra/rename/unoptimized_operand/optimize_spec.rb +2 -0
  151. data/spec/unit/veritas/optimizer/algebra/restriction/contradiction/optimizable_spec.rb +23 -3
  152. data/spec/unit/veritas/optimizer/algebra/restriction/contradiction/optimize_spec.rb +7 -5
  153. data/spec/unit/veritas/optimizer/algebra/restriction/order_operand/optimizable_spec.rb +3 -1
  154. data/spec/unit/veritas/optimizer/algebra/restriction/order_operand/optimize_spec.rb +7 -3
  155. data/spec/unit/veritas/optimizer/algebra/restriction/predicate_spec.rb +3 -1
  156. data/spec/unit/veritas/optimizer/algebra/restriction/restriction_operand/optimizable_spec.rb +5 -3
  157. data/spec/unit/veritas/optimizer/algebra/restriction/restriction_operand/optimize_spec.rb +8 -6
  158. data/spec/unit/veritas/optimizer/algebra/restriction/set_operand/optimizable_spec.rb +3 -1
  159. data/spec/unit/veritas/optimizer/algebra/restriction/set_operand/optimize_spec.rb +5 -3
  160. data/spec/unit/veritas/optimizer/algebra/restriction/tautology/optimizable_spec.rb +11 -3
  161. data/spec/unit/veritas/optimizer/algebra/restriction/tautology/optimize_spec.rb +4 -2
  162. data/spec/unit/veritas/optimizer/algebra/restriction/unoptimized_operand/optimizable_spec.rb +7 -5
  163. data/spec/unit/veritas/optimizer/algebra/restriction/unoptimized_operand/optimize_spec.rb +2 -0
  164. data/spec/unit/veritas/optimizer/algebra/summarization/empty_operand/class_methods/extension_default_spec.rb +22 -0
  165. data/spec/unit/veritas/optimizer/algebra/summarization/empty_operand/optimizable_spec.rb +29 -0
  166. data/spec/unit/veritas/optimizer/algebra/summarization/empty_operand/optimize_spec.rb +47 -0
  167. data/spec/unit/veritas/optimizer/algebra/summarization/empty_summarize_per/optimizable_spec.rb +29 -0
  168. data/spec/unit/veritas/optimizer/algebra/summarization/empty_summarize_per/optimize_spec.rb +23 -0
  169. data/spec/unit/veritas/optimizer/algebra/summarization/order_operand/optimizable_spec.rb +23 -0
  170. data/spec/unit/veritas/optimizer/algebra/summarization/order_operand/optimize_spec.rb +22 -0
  171. data/spec/unit/veritas/optimizer/algebra/summarization/summarize_per_spec.rb +29 -0
  172. data/spec/unit/veritas/optimizer/algebra/summarization/summarizers_spec.rb +31 -0
  173. data/spec/unit/veritas/optimizer/algebra/summarization/unoptimized_operand/optimizable_spec.rb +30 -8
  174. data/spec/unit/veritas/optimizer/algebra/summarization/unoptimized_operand/optimize_spec.rb +12 -9
  175. data/spec/unit/veritas/optimizer/algebra/union/empty_left/optimize_spec.rb +2 -0
  176. data/spec/unit/veritas/optimizer/algebra/union/empty_right/optimize_spec.rb +2 -0
  177. data/spec/unit/veritas/optimizer/algebra/union/equal_operands/optimize_spec.rb +2 -0
  178. data/spec/unit/veritas/optimizer/class_methods/chain_spec.rb +2 -0
  179. data/spec/unit/veritas/optimizer/function/binary/constant_operands/optimizable_spec.rb +36 -0
  180. data/spec/unit/veritas/optimizer/function/binary/constant_operands/optimize_spec.rb +18 -0
  181. data/spec/unit/veritas/optimizer/function/binary/left_spec.rb +28 -0
  182. data/spec/unit/veritas/optimizer/function/binary/right_spec.rb +28 -0
  183. data/spec/unit/veritas/optimizer/function/binary/unoptimized_operands/optimizable_spec.rb +37 -0
  184. data/spec/unit/veritas/optimizer/function/binary/unoptimized_operands/optimize_spec.rb +23 -0
  185. data/spec/unit/veritas/optimizer/function/class_methods/optimize_functions_spec.rb +26 -0
  186. data/spec/unit/veritas/optimizer/function/class_methods/optimize_operand_spec.rb +22 -0
  187. data/spec/unit/veritas/optimizer/function/connective/binary/constant_operands/optimize_spec.rb +16 -0
  188. data/spec/unit/veritas/optimizer/{logic → function}/connective/binary/equal_operands/optimizable_spec.rb +4 -2
  189. data/spec/unit/veritas/optimizer/{logic → function}/connective/binary/equal_operands/optimize_spec.rb +3 -1
  190. data/spec/unit/veritas/optimizer/{logic → function}/connective/binary/left_spec.rb +3 -1
  191. data/spec/unit/veritas/optimizer/{logic → function}/connective/binary/redundant_left_operand/optimizable_spec.rb +4 -2
  192. data/spec/unit/veritas/optimizer/{logic → function}/connective/binary/redundant_left_operand/optimize_spec.rb +4 -2
  193. data/spec/unit/veritas/optimizer/{logic → function}/connective/binary/redundant_right_operand/optimizable_spec.rb +4 -2
  194. data/spec/unit/veritas/optimizer/{logic → function}/connective/binary/redundant_right_operand/optimize_spec.rb +4 -2
  195. data/spec/unit/veritas/optimizer/{logic → function}/connective/binary/right_spec.rb +3 -1
  196. data/spec/unit/veritas/optimizer/function/connective/conjunction/contradiction/optimizable_spec.rb +64 -0
  197. data/spec/unit/veritas/optimizer/function/connective/conjunction/contradiction/optimize_spec.rb +19 -0
  198. data/spec/unit/veritas/optimizer/{logic/connective/disjunction/contradiction_left_operand → function/connective/conjunction/left_operand_tautology}/optimizable_spec.rb +9 -7
  199. data/spec/unit/veritas/optimizer/{logic → function}/connective/conjunction/left_operand_tautology/optimize_spec.rb +8 -6
  200. data/spec/unit/veritas/optimizer/{logic → function}/connective/conjunction/optimizable_to_exclusion/optimizable_spec.rb +4 -2
  201. data/spec/unit/veritas/optimizer/{logic → function}/connective/conjunction/optimizable_to_exclusion/optimize_spec.rb +5 -3
  202. data/spec/unit/veritas/optimizer/{logic → function}/connective/conjunction/right_operand_tautology/optimizable_spec.rb +6 -4
  203. data/spec/unit/veritas/optimizer/function/connective/conjunction/right_operand_tautology/optimize_spec.rb +19 -0
  204. data/spec/unit/veritas/optimizer/{logic/connective/conjunction/left_operand_tautology → function/connective/disjunction/contradiction_left_operand}/optimizable_spec.rb +9 -7
  205. data/spec/unit/veritas/optimizer/{logic → function}/connective/disjunction/contradiction_left_operand/optimize_spec.rb +8 -6
  206. data/spec/unit/veritas/optimizer/{logic → function}/connective/disjunction/contradiction_right_operand/optimizable_spec.rb +6 -4
  207. data/spec/unit/veritas/optimizer/{logic → function}/connective/disjunction/contradiction_right_operand/optimize_spec.rb +8 -6
  208. data/spec/unit/veritas/optimizer/{logic → function}/connective/disjunction/optimizable_to_inclusion/optimizable_spec.rb +4 -2
  209. data/spec/unit/veritas/optimizer/{logic → function}/connective/disjunction/optimizable_to_inclusion/optimize_spec.rb +5 -3
  210. data/spec/unit/veritas/optimizer/function/connective/disjunction/tautology/optimizable_spec.rb +64 -0
  211. data/spec/unit/veritas/optimizer/function/connective/disjunction/tautology/optimize_spec.rb +19 -0
  212. data/spec/unit/veritas/optimizer/function/connective/negation/constant_operand/optimize_spec.rb +16 -0
  213. data/spec/unit/veritas/optimizer/function/connective/negation/invertible_operand/optimizable_spec.rb +28 -0
  214. data/spec/unit/veritas/optimizer/function/connective/negation/invertible_operand/optimize_spec.rb +22 -0
  215. data/spec/unit/veritas/optimizer/{logic → function}/connective/negation/operand_spec.rb +3 -1
  216. data/spec/unit/veritas/optimizer/{logic → function}/predicate/comparable/never_comparable/optimizable_spec.rb +23 -7
  217. data/spec/unit/veritas/optimizer/{logic → function}/predicate/comparable/never_equivalent/optimizable_spec.rb +23 -7
  218. data/spec/unit/veritas/optimizer/{logic → function}/predicate/comparable/normalizable_operands/optimizable_spec.rb +7 -5
  219. data/spec/unit/veritas/optimizer/{logic → function}/predicate/comparable/normalizable_operands/optimize_spec.rb +7 -5
  220. data/spec/unit/veritas/optimizer/function/predicate/constant_operands/optimize_spec.rb +16 -0
  221. data/spec/unit/veritas/optimizer/function/predicate/contradiction/optimize_spec.rb +18 -0
  222. data/spec/unit/veritas/optimizer/function/predicate/enumerable/class_methods/sort_by_value_spec.rb +27 -0
  223. data/spec/unit/veritas/optimizer/{logic → function}/predicate/enumerable/empty_right_operand/optimizable_spec.rb +6 -4
  224. data/spec/unit/veritas/optimizer/{logic → function}/predicate/enumerable/one_right_operand/optimizable_spec.rb +9 -7
  225. data/spec/unit/veritas/optimizer/{logic/predicate/enumerable/unoptimized_operand → function/predicate/enumerable/unoptimized_operands}/optimizable_spec.rb +4 -2
  226. data/spec/unit/veritas/optimizer/{logic/predicate/enumerable/unoptimized_operand → function/predicate/enumerable/unoptimized_operands}/optimize_spec.rb +18 -5
  227. data/spec/unit/veritas/optimizer/{logic → function}/predicate/equality/tautology/optimizable_spec.rb +4 -2
  228. data/spec/unit/veritas/optimizer/{logic → function}/predicate/exclusion/empty_right_operand/optimize_spec.rb +8 -6
  229. data/spec/unit/veritas/optimizer/{logic → function}/predicate/exclusion/one_right_operand/optimize_spec.rb +8 -6
  230. data/spec/unit/veritas/optimizer/{logic → function}/predicate/greater_than/contradiction/optimizable_spec.rb +4 -2
  231. data/spec/unit/veritas/optimizer/{logic → function}/predicate/greater_than/tautology/optimizable_spec.rb +4 -2
  232. data/spec/unit/veritas/optimizer/{logic → function}/predicate/greater_than_or_equal_to/contradiction/optimizable_spec.rb +4 -2
  233. data/spec/unit/veritas/optimizer/{logic → function}/predicate/greater_than_or_equal_to/tautology/optimizable_spec.rb +4 -2
  234. data/spec/unit/veritas/optimizer/{logic → function}/predicate/inclusion/empty_right_operand/optimize_spec.rb +8 -6
  235. data/spec/unit/veritas/optimizer/{logic → function}/predicate/inclusion/one_right_operand/optimize_spec.rb +8 -6
  236. data/spec/unit/veritas/optimizer/{logic → function}/predicate/inequality/contradiction/optimizable_spec.rb +4 -2
  237. data/spec/unit/veritas/optimizer/{logic → function}/predicate/less_than/contradiction/optimizable_spec.rb +4 -2
  238. data/spec/unit/veritas/optimizer/{logic → function}/predicate/less_than/tautology/optimizable_spec.rb +4 -2
  239. data/spec/unit/veritas/optimizer/{logic → function}/predicate/less_than_or_equal_to/contradiction/optimizable_spec.rb +4 -2
  240. data/spec/unit/veritas/optimizer/{logic → function}/predicate/less_than_or_equal_to/tautology/optimizable_spec.rb +4 -2
  241. data/spec/unit/veritas/optimizer/function/predicate/tautology/optimize_spec.rb +18 -0
  242. data/spec/unit/veritas/optimizer/function/unary/constant_operand/optimizable_spec.rb +27 -0
  243. data/spec/unit/veritas/optimizer/function/unary/constant_operand/optimize_spec.rb +18 -0
  244. data/spec/unit/veritas/optimizer/function/unary/operand_spec.rb +27 -0
  245. data/spec/unit/veritas/optimizer/function/unary/unoptimized_operand/optimizable_spec.rb +27 -0
  246. data/spec/unit/veritas/optimizer/function/unary/unoptimized_operand/optimize_spec.rb +18 -0
  247. data/spec/unit/veritas/optimizer/{logic/predicate → function}/util/class_methods/attribute_spec.rb +4 -2
  248. data/spec/unit/veritas/optimizer/{logic/predicate → function}/util/class_methods/constant_spec.rb +13 -5
  249. data/spec/unit/veritas/optimizer/function/util/class_methods/max_spec.rb +27 -0
  250. data/spec/unit/veritas/optimizer/function/util/class_methods/min_spec.rb +27 -0
  251. data/spec/unit/veritas/optimizer/operation_spec.rb +2 -0
  252. data/spec/unit/veritas/optimizer/optimizable/class_methods/optimizer_spec.rb +2 -0
  253. data/spec/unit/veritas/optimizer/optimizable/optimize_spec.rb +3 -1
  254. data/spec/unit/veritas/optimizer/optimizable_spec.rb +2 -0
  255. data/spec/unit/veritas/optimizer/optimize_spec.rb +2 -0
  256. data/spec/unit/veritas/optimizer/relation/materialized/empty_operand/optimizable_spec.rb +2 -0
  257. data/spec/unit/veritas/optimizer/relation/materialized/empty_operand/optimize_spec.rb +2 -0
  258. data/spec/unit/veritas/optimizer/relation/operation/binary/empty_left/optimizable_spec.rb +2 -4
  259. data/spec/unit/veritas/optimizer/relation/operation/binary/empty_right/optimizable_spec.rb +2 -4
  260. data/spec/unit/veritas/optimizer/relation/operation/binary/equal_operands/optimizable_spec.rb +2 -5
  261. data/spec/unit/veritas/optimizer/relation/operation/binary/left_order_operand/optimizable_spec.rb +23 -0
  262. data/spec/unit/veritas/optimizer/relation/operation/binary/left_order_operand/optimize_spec.rb +23 -0
  263. data/spec/unit/veritas/optimizer/relation/operation/binary/left_spec.rb +2 -4
  264. data/spec/unit/veritas/optimizer/relation/operation/binary/materialized_operand/optimizable_spec.rb +2 -0
  265. data/spec/unit/veritas/optimizer/relation/operation/binary/materialized_operand/optimize_spec.rb +2 -0
  266. data/spec/unit/veritas/optimizer/relation/operation/binary/right_order_operand/optimizable_spec.rb +23 -0
  267. data/spec/unit/veritas/optimizer/relation/operation/binary/right_order_operand/optimize_spec.rb +23 -0
  268. data/spec/unit/veritas/optimizer/relation/operation/binary/right_spec.rb +2 -4
  269. data/spec/unit/veritas/optimizer/relation/operation/binary/{unoptimized_operand → unoptimized_operands}/optimizable_spec.rb +3 -1
  270. data/spec/unit/veritas/optimizer/relation/operation/binary/{unoptimized_operand → unoptimized_operands}/optimize_spec.rb +3 -1
  271. data/spec/unit/veritas/optimizer/relation/operation/combination/optimize_spec.rb +2 -0
  272. data/spec/unit/veritas/optimizer/relation/operation/limit/equal_limit_operand/optimizable_spec.rb +2 -0
  273. data/spec/unit/veritas/optimizer/relation/operation/limit/equal_limit_operand/optimize_spec.rb +2 -0
  274. data/spec/unit/veritas/optimizer/relation/operation/limit/limit_operand/optimizable_spec.rb +2 -0
  275. data/spec/unit/veritas/optimizer/relation/operation/limit/limit_operand/optimize_spec.rb +2 -0
  276. data/spec/unit/veritas/optimizer/relation/operation/limit/unoptimized_operand/optimizable_spec.rb +2 -0
  277. data/spec/unit/veritas/optimizer/relation/operation/limit/unoptimized_operand/optimize_spec.rb +2 -0
  278. data/spec/unit/veritas/optimizer/relation/operation/limit/zero_limit/optimizable_spec.rb +2 -0
  279. data/spec/unit/veritas/optimizer/relation/operation/limit/zero_limit/optimize_spec.rb +2 -0
  280. data/spec/unit/veritas/optimizer/relation/operation/offset/offset_operand/optimizable_spec.rb +2 -0
  281. data/spec/unit/veritas/optimizer/relation/operation/offset/offset_operand/optimize_spec.rb +2 -0
  282. data/spec/unit/veritas/optimizer/relation/operation/offset/unoptimized_operand/optimizable_spec.rb +2 -0
  283. data/spec/unit/veritas/optimizer/relation/operation/offset/unoptimized_operand/optimize_spec.rb +2 -0
  284. data/spec/unit/veritas/optimizer/relation/operation/offset/zero_offset/optimizable_spec.rb +2 -0
  285. data/spec/unit/veritas/optimizer/relation/operation/offset/zero_offset/optimize_spec.rb +2 -0
  286. data/spec/unit/veritas/optimizer/relation/operation/order/one_limit_operand/optimizable_spec.rb +2 -0
  287. data/spec/unit/veritas/optimizer/relation/operation/order/one_limit_operand/optimize_spec.rb +2 -0
  288. data/spec/unit/veritas/optimizer/relation/operation/order/order_operand/optimizable_spec.rb +2 -0
  289. data/spec/unit/veritas/optimizer/relation/operation/order/order_operand/optimize_spec.rb +3 -1
  290. data/spec/unit/veritas/optimizer/relation/operation/order/unoptimized_operand/optimizable_spec.rb +2 -0
  291. data/spec/unit/veritas/optimizer/relation/operation/order/unoptimized_operand/optimize_spec.rb +2 -0
  292. data/spec/unit/veritas/optimizer/relation/operation/reverse/order_operand/optimizable_spec.rb +2 -0
  293. data/spec/unit/veritas/optimizer/relation/operation/reverse/order_operand/optimize_spec.rb +2 -0
  294. data/spec/unit/veritas/optimizer/relation/operation/reverse/reverse_operand/optimizable_spec.rb +2 -0
  295. data/spec/unit/veritas/optimizer/relation/operation/reverse/reverse_operand/optimize_spec.rb +2 -0
  296. data/spec/unit/veritas/optimizer/relation/operation/reverse/unoptimized_operand/optimizable_spec.rb +2 -0
  297. data/spec/unit/veritas/optimizer/relation/operation/reverse/unoptimized_operand/optimize_spec.rb +2 -0
  298. data/spec/unit/veritas/optimizer/relation/operation/unary/empty_operand/optimizable_spec.rb +5 -2
  299. data/spec/unit/veritas/optimizer/relation/operation/unary/empty_operand/optimize_spec.rb +2 -0
  300. data/spec/unit/veritas/optimizer/relation/operation/unary/header_spec.rb +15 -0
  301. data/spec/unit/veritas/optimizer/relation/operation/unary/materialized_operand/optimizable_spec.rb +5 -2
  302. data/spec/unit/veritas/optimizer/relation/operation/unary/materialized_operand/optimize_spec.rb +2 -0
  303. data/spec/unit/veritas/optimizer/relation/operation/unary/operand_spec.rb +8 -5
  304. data/spec/unit/veritas/optimizer/relation/operation/unary/order_operand/optimizable_spec.rb +28 -0
  305. data/spec/unit/veritas/optimizer/relation/operation/unary/order_operand/optimize_spec.rb +27 -0
  306. data/spec/unit/veritas/optimizer/relation/operation/unary/unchanged_header/optimizable_spec.rb +24 -0
  307. data/spec/unit/veritas/optimizer/relation/operation/unary/unchanged_header/optimize_spec.rb +14 -0
  308. data/tasks/metrics/ci.rake +7 -0
  309. data/tasks/{quality → metrics}/flay.rake +0 -0
  310. data/tasks/{quality → metrics}/flog.rake +0 -0
  311. data/tasks/{quality → metrics}/heckle.rake +1 -0
  312. data/tasks/{quality → metrics}/metric_fu.rake +3 -0
  313. data/tasks/{quality → metrics}/reek.rake +0 -0
  314. data/tasks/{quality → metrics}/roodi.rake +0 -0
  315. data/tasks/{quality → metrics}/yardstick.rake +0 -0
  316. data/tasks/spec.rake +1 -0
  317. data/veritas-optimizer.gemspec +183 -352
  318. metadata +232 -357
  319. data/lib/veritas/optimizer/logic/connective/negation.rb +0 -71
  320. data/lib/veritas/optimizer/logic/predicate.rb +0 -177
  321. data/spec/unit/veritas/optimizer/algebra/projection/header_spec.rb +0 -16
  322. data/spec/unit/veritas/optimizer/algebra/projection/unchanged_header/optimizable_spec.rb +0 -26
  323. data/spec/unit/veritas/optimizer/algebra/projection/unchanged_header/optimize_spec.rb +0 -16
  324. data/spec/unit/veritas/optimizer/algebra/rename/class_methods/union_aliases_spec.rb +0 -27
  325. data/spec/unit/veritas/optimizer/algebra/rename/header_spec.rb +0 -19
  326. data/spec/unit/veritas/optimizer/algebra/rename/unchanged_header/optimizable_spec.rb +0 -26
  327. data/spec/unit/veritas/optimizer/algebra/rename/unchanged_header/optimize_spec.rb +0 -16
  328. data/spec/unit/veritas/optimizer/algebra/restriction/class_methods/optimize_predicate_spec.rb +0 -31
  329. data/spec/unit/veritas/optimizer/algebra/restriction/reverse_operand/optimizable_spec.rb +0 -26
  330. data/spec/unit/veritas/optimizer/algebra/restriction/reverse_operand/optimize_spec.rb +0 -18
  331. data/spec/unit/veritas/optimizer/logic/connective/binary/unoptimized_operand/optimizable_spec.rb +0 -34
  332. data/spec/unit/veritas/optimizer/logic/connective/binary/unoptimized_operand/optimize_spec.rb +0 -21
  333. data/spec/unit/veritas/optimizer/logic/connective/conjunction/contradiction/optimizable_spec.rb +0 -41
  334. data/spec/unit/veritas/optimizer/logic/connective/conjunction/contradiction/optimize_spec.rb +0 -17
  335. data/spec/unit/veritas/optimizer/logic/connective/conjunction/right_operand_tautology/optimize_spec.rb +0 -17
  336. data/spec/unit/veritas/optimizer/logic/connective/disjunction/tautology/optimizable_spec.rb +0 -41
  337. data/spec/unit/veritas/optimizer/logic/connective/disjunction/tautology/optimize_spec.rb +0 -17
  338. data/spec/unit/veritas/optimizer/logic/connective/negation/invertible_operand/optimizable_spec.rb +0 -26
  339. data/spec/unit/veritas/optimizer/logic/connective/negation/invertible_operand/optimize_spec.rb +0 -20
  340. data/spec/unit/veritas/optimizer/logic/predicate/class_methods/optimize_operand_spec.rb +0 -20
  341. data/spec/unit/veritas/optimizer/logic/predicate/constant_operands/optimizable_spec.rb +0 -29
  342. data/spec/unit/veritas/optimizer/logic/predicate/constant_operands/optimize_spec.rb +0 -14
  343. data/spec/unit/veritas/optimizer/logic/predicate/contradiction/optimize_spec.rb +0 -16
  344. data/spec/unit/veritas/optimizer/logic/predicate/left_spec.rb +0 -25
  345. data/spec/unit/veritas/optimizer/logic/predicate/right_spec.rb +0 -25
  346. data/spec/unit/veritas/optimizer/logic/predicate/tautology/optimize_spec.rb +0 -16
  347. data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/max_spec.rb +0 -19
  348. data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/min_spec.rb +0 -19
  349. data/tasks/quality/ci.rake +0 -2
@@ -0,0 +1,124 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ class Optimizer
5
+ module Function
6
+
7
+ # Mixin for optimizations to Binary functions
8
+ module Binary
9
+
10
+ # The optimized left operand
11
+ #
12
+ # @return [Object]
13
+ #
14
+ # @api private
15
+ attr_reader :left
16
+
17
+ # The optimized right operand
18
+ #
19
+ # @return [Object]
20
+ #
21
+ # @api private
22
+ attr_reader :right
23
+
24
+ # Initialize an Predicate optimizer
25
+ #
26
+ # @return [undefined]
27
+ #
28
+ # @api private
29
+ def initialize(*)
30
+ super
31
+ @left = optimize_left
32
+ @right = optimize_right
33
+ end
34
+
35
+ private
36
+
37
+ # Optimize the left operand
38
+ #
39
+ # @return [Object]
40
+ #
41
+ # @api private
42
+ def optimize_left
43
+ Function.optimize_operand(operation.left)
44
+ end
45
+
46
+ # Optimize the right operand
47
+ #
48
+ # @return [Object]
49
+ #
50
+ # @api private
51
+ def optimize_right
52
+ Function.optimize_operand(operation.right)
53
+ end
54
+
55
+ # Optimize when the operands are constants
56
+ module ConstantOperands
57
+
58
+ # Test if the operands are constants
59
+ #
60
+ # @return [Boolean]
61
+ #
62
+ # @api private
63
+ def optimizable?
64
+ util = Util
65
+ util.constant?(left) && util.constant?(right)
66
+ end
67
+
68
+ # Evaluate the operands and return the constant
69
+ #
70
+ # @return [Object]
71
+ #
72
+ # @api private
73
+ def optimize
74
+ operation.class.call(left, right)
75
+ end
76
+
77
+ end # module ConstantOperands
78
+
79
+ # Optimize when the operand is unoptimized
80
+ module UnoptimizedOperands
81
+
82
+ # Test if the operands are unoptimized
83
+ #
84
+ # @return [Boolean]
85
+ #
86
+ # @api private
87
+ def optimizable?
88
+ left_optimizable? || right_optimizable?
89
+ end
90
+
91
+ # Return a Binary connective with optimized operands
92
+ #
93
+ # @return [Binary]
94
+ #
95
+ # @api private
96
+ def optimize
97
+ operation.class.new(left, right)
98
+ end
99
+
100
+ private
101
+
102
+ # Test if the left operand is optimizable
103
+ #
104
+ # @return [Boolean]
105
+ #
106
+ # @api private
107
+ def left_optimizable?
108
+ !left.equal?(operation.left)
109
+ end
110
+
111
+ # Test if the right operand is optimizable
112
+ #
113
+ # @return [Boolean]
114
+ #
115
+ # @api private
116
+ def right_optimizable?
117
+ !right.equal?(operation.right)
118
+ end
119
+
120
+ end # module UnoptimizedOperands
121
+ end # class Binary
122
+ end # module Function
123
+ end # class Optimizer
124
+ end # module Veritas
@@ -2,68 +2,24 @@
2
2
 
3
3
  module Veritas
4
4
  class Optimizer
5
- module Logic
5
+ module Function
6
6
  module Connective
7
7
 
8
8
  # Abstract base class representing Binary connective optimizations
9
9
  class Binary < Optimizer
10
-
11
- # The optimized left operand
12
- #
13
- # @return [Expression]
14
- #
15
- # @api private
16
- attr_reader :left
17
-
18
- # The optimized right operand
19
- #
20
- # @return [Expression]
21
- #
22
- # @api private
23
- attr_reader :right
24
-
25
- # Initialize an Binary optimizer
26
- #
27
- # @return [undefined]
28
- #
29
- # @api private
30
- def initialize(*)
31
- super
32
- @left = optimize_left
33
- @right = optimize_right
34
- end
10
+ include Function::Binary
35
11
 
36
12
  private
37
13
 
38
- # Optimize the left operand
39
- #
40
- # @return [Expression]
41
- #
42
- # @api private
43
- def optimize_left
44
- # TODO: move Predicate.optimize_operand to a better location
45
- Predicate.optimize_operand(operation.left)
46
- end
47
-
48
- # Optimize the right operand
49
- #
50
- # @return [Expression]
51
- #
52
- # @api private
53
- def optimize_right
54
- # TODO: move Predicate.optimize_operand to a better location
55
- Predicate.optimize_operand(operation.right)
56
- end
57
-
58
14
  # Test if the operands are equality predicates for the same attribute
59
15
  #
60
16
  # @return [Boolean]
61
17
  #
62
18
  # @api private
63
19
  def equality_with_same_attributes?
64
- left.kind_of?(Veritas::Logic::Predicate::Equality) &&
65
- right.kind_of?(Veritas::Logic::Predicate::Equality) &&
66
- same_attribute? &&
20
+ left.kind_of?(Veritas::Function::Predicate::Equality) &&
21
+ right.kind_of?(Veritas::Function::Predicate::Equality) &&
22
+ same_attribute? &&
67
23
  constant_value?
68
24
  end
69
25
 
@@ -73,9 +29,9 @@ module Veritas
73
29
  #
74
30
  # @api private
75
31
  def inequality_with_same_attributes?
76
- left.kind_of?(Veritas::Logic::Predicate::Inequality) &&
77
- right.kind_of?(Veritas::Logic::Predicate::Inequality) &&
78
- same_attribute? &&
32
+ left.kind_of?(Veritas::Function::Predicate::Inequality) &&
33
+ right.kind_of?(Veritas::Function::Predicate::Inequality) &&
34
+ same_attribute? &&
79
35
  constant_value?
80
36
  end
81
37
 
@@ -94,7 +50,7 @@ module Veritas
94
50
  #
95
51
  # @api private
96
52
  def constant_value?
97
- util = Predicate::Util
53
+ util = Util
98
54
  util.constant?(left.right) && util.constant?(right.right)
99
55
  end
100
56
 
@@ -104,7 +60,7 @@ module Veritas
104
60
  #
105
61
  # @api private
106
62
  def left_tautology?
107
- left.equal?(Veritas::Logic::Proposition::Tautology.instance)
63
+ left.equal?(Veritas::Function::Proposition::Tautology.instance)
108
64
  end
109
65
 
110
66
  # Test if the right is a tautology
@@ -113,7 +69,7 @@ module Veritas
113
69
  #
114
70
  # @api private
115
71
  def right_tautology?
116
- right.equal?(Veritas::Logic::Proposition::Tautology.instance)
72
+ right.equal?(Veritas::Function::Proposition::Tautology.instance)
117
73
  end
118
74
 
119
75
  # Test if the left is a contradiction
@@ -122,7 +78,7 @@ module Veritas
122
78
  #
123
79
  # @api private
124
80
  def left_contradiction?
125
- left.equal?(Veritas::Logic::Proposition::Contradiction.instance)
81
+ left.equal?(Veritas::Function::Proposition::Contradiction.instance)
126
82
  end
127
83
 
128
84
  # Test if the right is a contradiction
@@ -131,9 +87,37 @@ module Veritas
131
87
  #
132
88
  # @api private
133
89
  def right_contradiction?
134
- right.equal?(Veritas::Logic::Proposition::Contradiction.instance)
90
+ right.equal?(Veritas::Function::Proposition::Contradiction.instance)
91
+ end
92
+
93
+ # Test if the left and right
94
+ #
95
+ # @return [Boolean]
96
+ #
97
+ # @api private
98
+ def contradiction?
99
+ left = self.left
100
+ right = self.right
101
+ left.respond_to?(:inverse) &&
102
+ right.respond_to?(:inverse) &&
103
+ left.inverse.eql?(right)
135
104
  end
136
105
 
106
+ # Optimize when the operands are constants
107
+ class ConstantOperands < self
108
+ include Function::Binary::ConstantOperands
109
+
110
+ # A Connective with constant values is equivalent to a Proposition
111
+ #
112
+ # @return [Proposition]
113
+ #
114
+ # @api private
115
+ def optimize
116
+ Veritas::Function::Proposition.new(super)
117
+ end
118
+
119
+ end # class ConstantOperands
120
+
137
121
  # Optimize when the operands are equal
138
122
  class EqualOperands < self
139
123
 
@@ -148,7 +132,7 @@ module Veritas
148
132
 
149
133
  # A Binary connective with equal operands is equivalent to the left
150
134
  #
151
- # @return [Expression]
135
+ # @return [Function]
152
136
  #
153
137
  # @api private
154
138
  def optimize
@@ -172,7 +156,7 @@ module Veritas
172
156
 
173
157
  # A Binary connective with a redundant left operand is equivalent to the left
174
158
  #
175
- # @return [Expression]
159
+ # @return [Function]
176
160
  #
177
161
  # @api private
178
162
  def optimize
@@ -196,7 +180,7 @@ module Veritas
196
180
 
197
181
  # A Binary connective with a redundant right operand is equivalent to the right
198
182
  #
199
- # @return [Expression]
183
+ # @return [Function]
200
184
  #
201
185
  # @api private
202
186
  def optimize
@@ -206,49 +190,11 @@ module Veritas
206
190
  end # class RedundantRightOperand
207
191
 
208
192
  # Optimize when the operands are unoptimized
209
- class UnoptimizedOperand < self
210
-
211
- # Test if the operands are unoptimized
212
- #
213
- # @return [Boolean]
214
- #
215
- # @api private
216
- def optimizable?
217
- left_optimizable? || right_optimizable?
218
- end
219
-
220
- # Return a Binary connective with optimized operands
221
- #
222
- # @return [Binary]
223
- #
224
- # @api private
225
- def optimize
226
- operation.class.new(left, right)
227
- end
228
-
229
- private
230
-
231
- # Test if the left operand is optimizable
232
- #
233
- # @return [Boolean]
234
- #
235
- # @api private
236
- def left_optimizable?
237
- !left.equal?(operation.left)
238
- end
239
-
240
- # Test if the right operand is optimizable
241
- #
242
- # @return [Boolean]
243
- #
244
- # @api private
245
- def right_optimizable?
246
- !right.equal?(operation.right)
247
- end
248
-
249
- end # class UnoptimizedOperand
193
+ class UnoptimizedOperands < self
194
+ include Function::Binary::UnoptimizedOperands
195
+ end # class UnoptimizedOperands
250
196
  end # class Binary
251
197
  end # module Connective
252
- end # module Logic
198
+ end # module Function
253
199
  end # class Optimizer
254
200
  end # module Veritas
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Veritas
4
4
  class Optimizer
5
- module Logic
5
+ module Function
6
6
  module Connective
7
7
 
8
8
  # Abstract base class representing Conjunction optimizations
@@ -22,7 +22,7 @@ module Veritas
22
22
 
23
23
  # A Conjunction with a tautology left operand is equivalent to the right
24
24
  #
25
- # @return [Expression]
25
+ # @return [Function]
26
26
  #
27
27
  # @api private
28
28
  def optimize
@@ -45,7 +45,7 @@ module Veritas
45
45
 
46
46
  # A Conjunction with a tautology right operand is equivalent to the left
47
47
  #
48
- # @return [Expression]
48
+ # @return [Function]
49
49
  #
50
50
  # @api private
51
51
  def optimize
@@ -73,7 +73,7 @@ module Veritas
73
73
  # @api private
74
74
  def optimize
75
75
  left = self.left
76
- Veritas::Logic::Predicate::Exclusion.new(left.left, [ left.right, right.right ]).optimize
76
+ Veritas::Function::Predicate::Exclusion.new(left.left, [ left.right, right.right ]).optimize
77
77
  end
78
78
 
79
79
  end # class OptimizableToExclusion
@@ -87,10 +87,10 @@ module Veritas
87
87
  #
88
88
  # @api private
89
89
  def optimizable?
90
- left_contradiction? ||
91
- right_contradiction? ||
90
+ left_contradiction? ||
91
+ right_contradiction? ||
92
92
  equality_with_same_attributes? ||
93
- left.inverse.eql?(right)
93
+ contradiction?
94
94
  end
95
95
 
96
96
  # Return a contradiction
@@ -99,12 +99,13 @@ module Veritas
99
99
  #
100
100
  # @api private
101
101
  def optimize
102
- Veritas::Logic::Proposition::Contradiction.instance
102
+ Veritas::Function::Proposition::Contradiction.instance
103
103
  end
104
104
 
105
105
  end # class Contradiction
106
106
 
107
- Veritas::Logic::Connective::Conjunction.optimizer = chain(
107
+ Veritas::Function::Connective::Conjunction.optimizer = chain(
108
+ ConstantOperands,
108
109
  LeftOperandTautology,
109
110
  RightOperandTautology,
110
111
  OptimizableToExclusion,
@@ -112,11 +113,11 @@ module Veritas
112
113
  RedundantLeftOperand,
113
114
  RedundantRightOperand,
114
115
  Contradiction,
115
- UnoptimizedOperand
116
+ UnoptimizedOperands
116
117
  )
117
118
 
118
119
  end # class Conjunction
119
120
  end # module Connective
120
- end # module Logic
121
+ end # module Function
121
122
  end # class Optimizer
122
123
  end # module Veritas
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Veritas
4
4
  class Optimizer
5
- module Logic
5
+ module Function
6
6
  module Connective
7
7
 
8
8
  # Abstract base class representing Disjunction optimizations
@@ -22,7 +22,7 @@ module Veritas
22
22
 
23
23
  # A Disjunction with a contradiction left operand is equivalent to the right
24
24
  #
25
- # @return [Expression]
25
+ # @return [Function]
26
26
  #
27
27
  # @api private
28
28
  def optimize
@@ -45,7 +45,7 @@ module Veritas
45
45
 
46
46
  # A Disjunction with a contradiction right operand is equivalent to the left
47
47
  #
48
- # @return [Expression]
48
+ # @return [Function]
49
49
  #
50
50
  # @api private
51
51
  def optimize
@@ -73,38 +73,39 @@ module Veritas
73
73
  # @api private
74
74
  def optimize
75
75
  left = self.left
76
- Veritas::Logic::Predicate::Inclusion.new(left.left, [ left.right, right.right ]).optimize
76
+ Veritas::Function::Predicate::Inclusion.new(left.left, [ left.right, right.right ]).optimize
77
77
  end
78
78
 
79
79
  end # class OptimizableToInclusion
80
80
 
81
- # Optimize when the operands are a tuatology
81
+ # Optimize when the operands are a tautology
82
82
  class Tautology < self
83
83
 
84
- # Test if the operands are a tuatology
84
+ # Test if the operands are a tautology
85
85
  #
86
86
  # @return [Boolean]
87
87
  #
88
88
  # @api private
89
89
  def optimizable?
90
- left_tautology? ||
91
- right_tautology? ||
90
+ left_tautology? ||
91
+ right_tautology? ||
92
92
  inequality_with_same_attributes? ||
93
- left.inverse.eql?(right)
93
+ contradiction?
94
94
  end
95
95
 
96
- # Return a tuatology
96
+ # Return a tautology
97
97
  #
98
98
  # @return [Tautology]
99
99
  #
100
100
  # @api private
101
101
  def optimize
102
- Veritas::Logic::Proposition::Tautology.instance
102
+ Veritas::Function::Proposition::Tautology.instance
103
103
  end
104
104
 
105
105
  end # class Tautology
106
106
 
107
- Veritas::Logic::Connective::Disjunction.optimizer = chain(
107
+ Veritas::Function::Connective::Disjunction.optimizer = chain(
108
+ ConstantOperands,
108
109
  ContradictionLeftOperand,
109
110
  ContradictionRightOperand,
110
111
  OptimizableToInclusion,
@@ -112,11 +113,11 @@ module Veritas
112
113
  RedundantLeftOperand,
113
114
  RedundantRightOperand,
114
115
  Tautology,
115
- UnoptimizedOperand
116
+ UnoptimizedOperands
116
117
  )
117
118
 
118
119
  end # class Disjunction
119
120
  end # module Connective
120
- end # module Logic
121
+ end # module Function
121
122
  end # class Optimizer
122
123
  end # module Veritas
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ class Optimizer
5
+ module Function
6
+ module Connective
7
+
8
+ # Abstract base class representing Negation optimizations
9
+ class Negation < Optimizer
10
+ include Unary
11
+
12
+ # Optimize when the operand can be inverted
13
+ class InvertibleOperand < self
14
+
15
+ # Test if the operand can be inverted
16
+ #
17
+ # @return [Boolean]
18
+ #
19
+ # @api private
20
+ def optimizable?
21
+ operand.respond_to?(:inverse)
22
+ end
23
+
24
+ # A Negation of an Function is equivalent to the inverted Function
25
+ #
26
+ # @return [Function]
27
+ #
28
+ # @api private
29
+ def optimize
30
+ operand.inverse
31
+ end
32
+
33
+ end # class InvertibleOperand
34
+
35
+ # Optimize when the operand is constant
36
+ class ConstantOperand < self
37
+ include Unary::ConstantOperand
38
+
39
+ # A Negation with constant values is equivalent to a Proposition
40
+ #
41
+ # @return [Proposition]
42
+ #
43
+ # @api private
44
+ def optimize
45
+ Veritas::Function::Proposition.new(super)
46
+ end
47
+
48
+ end # class ConstantOperand
49
+
50
+ # Optimize when the operand is unoptimized
51
+ class UnoptimizedOperand < self
52
+ include Function::Unary::UnoptimizedOperand
53
+ end # class UnoptimizedOperand
54
+
55
+ Veritas::Function::Connective::Negation.optimizer = chain(
56
+ ConstantOperand,
57
+ InvertibleOperand,
58
+ UnoptimizedOperand
59
+ )
60
+
61
+ end # class Negation
62
+ end # module Connective
63
+ end # module Function
64
+ end # class Optimizer
65
+ end # module Veritas
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ class Optimizer
5
+ module Function
6
+ class Numeric
7
+
8
+ # Abstract base class representing Absolute optimizations
9
+ class Absolute < self
10
+
11
+ Veritas::Function::Numeric::Absolute.optimizer = chain(
12
+ ConstantOperand,
13
+ UnoptimizedOperand
14
+ )
15
+
16
+ end # class Absolute
17
+ end # class Numeric
18
+ end # module Function
19
+ end # class Optimizer
20
+ end # module Veritas
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ class Optimizer
5
+ module Function
6
+ class Numeric
7
+
8
+ # Abstract base class representing Addition optimizations
9
+ class Addition < self
10
+
11
+ Veritas::Function::Numeric::Addition.optimizer = chain(
12
+ ConstantOperands,
13
+ UnoptimizedOperands
14
+ )
15
+
16
+ end # class Addition
17
+ end # class Numeric
18
+ end # module Function
19
+ end # class Optimizer
20
+ end # module Veritas
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ class Optimizer
5
+ module Function
6
+ class Numeric
7
+
8
+ # Abstract base class representing Division optimizations
9
+ class Division < self
10
+
11
+ Veritas::Function::Numeric::Division.optimizer = chain(
12
+ ConstantOperands,
13
+ UnoptimizedOperands
14
+ )
15
+
16
+ end # class Division
17
+ end # class Numeric
18
+ end # module Function
19
+ end # class Optimizer
20
+ end # module Veritas
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ class Optimizer
5
+ module Function
6
+ class Numeric
7
+
8
+ # Abstract base class representing Exponentiation optimizations
9
+ class Exponentiation < self
10
+
11
+ Veritas::Function::Numeric::Exponentiation.optimizer = chain(
12
+ ConstantOperands,
13
+ UnoptimizedOperands
14
+ )
15
+
16
+ end # class Exponentiation
17
+ end # class Numeric
18
+ end # module Function
19
+ end # class Optimizer
20
+ end # module Veritas
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ class Optimizer
5
+ module Function
6
+ class Numeric
7
+
8
+ # Abstract base class representing Modulo optimizations
9
+ class Modulo < self
10
+
11
+ Veritas::Function::Numeric::Modulo.optimizer = chain(
12
+ ConstantOperands,
13
+ UnoptimizedOperands
14
+ )
15
+
16
+ end # class Modulo
17
+ end # class Numeric
18
+ end # module Function
19
+ end # class Optimizer
20
+ end # module Veritas