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.
- data/.gemtest +0 -0
- data/.rvmrc +1 -0
- data/.travis.yml +8 -0
- data/Gemfile +20 -10
- data/Guardfile +22 -0
- data/README.rdoc +2 -0
- data/Rakefile +4 -2
- data/TODO +43 -2
- data/config/flay.yml +2 -2
- data/config/flog.yml +1 -1
- data/config/roodi.yml +4 -4
- data/lib/veritas/optimizer/aggregate/count.rb +17 -0
- data/lib/veritas/optimizer/aggregate/maximum.rb +17 -0
- data/lib/veritas/optimizer/aggregate/mean.rb +17 -0
- data/lib/veritas/optimizer/aggregate/minimum.rb +17 -0
- data/lib/veritas/optimizer/aggregate/standard_deviation.rb +17 -0
- data/lib/veritas/optimizer/aggregate/sum.rb +17 -0
- data/lib/veritas/optimizer/aggregate/variance.rb +17 -0
- data/lib/veritas/optimizer/aggregate.rb +16 -0
- data/lib/veritas/optimizer/algebra/difference.rb +3 -1
- data/lib/veritas/optimizer/algebra/extension.rb +58 -3
- data/lib/veritas/optimizer/algebra/intersection.rb +3 -1
- data/lib/veritas/optimizer/algebra/join.rb +6 -4
- data/lib/veritas/optimizer/algebra/product.rb +3 -1
- data/lib/veritas/optimizer/algebra/projection.rb +23 -54
- data/lib/veritas/optimizer/algebra/rename.rb +55 -80
- data/lib/veritas/optimizer/algebra/restriction.rb +33 -66
- data/lib/veritas/optimizer/algebra/summarization.rb +161 -3
- data/lib/veritas/optimizer/algebra/union.rb +3 -1
- data/lib/veritas/optimizer/function/binary.rb +124 -0
- data/lib/veritas/optimizer/{logic → function}/connective/binary.rb +48 -102
- data/lib/veritas/optimizer/{logic → function}/connective/conjunction.rb +12 -11
- data/lib/veritas/optimizer/{logic → function}/connective/disjunction.rb +15 -14
- data/lib/veritas/optimizer/function/connective/negation.rb +65 -0
- data/lib/veritas/optimizer/function/numeric/absolute.rb +20 -0
- data/lib/veritas/optimizer/function/numeric/addition.rb +20 -0
- data/lib/veritas/optimizer/function/numeric/division.rb +20 -0
- data/lib/veritas/optimizer/function/numeric/exponentiation.rb +20 -0
- data/lib/veritas/optimizer/function/numeric/modulo.rb +20 -0
- data/lib/veritas/optimizer/function/numeric/multiplication.rb +20 -0
- data/lib/veritas/optimizer/function/numeric/square_root.rb +20 -0
- data/lib/veritas/optimizer/function/numeric/subtraction.rb +20 -0
- data/lib/veritas/optimizer/function/numeric/unary_minus.rb +20 -0
- data/lib/veritas/optimizer/function/numeric/unary_plus.rb +20 -0
- data/lib/veritas/optimizer/function/numeric.rb +34 -0
- data/lib/veritas/optimizer/{logic → function}/predicate/comparable.rb +6 -4
- data/lib/veritas/optimizer/{logic → function}/predicate/enumerable.rb +24 -26
- data/lib/veritas/optimizer/{logic → function}/predicate/equality.rb +6 -6
- data/lib/veritas/optimizer/{logic → function}/predicate/exclusion.rb +6 -16
- data/lib/veritas/optimizer/{logic → function}/predicate/greater_than.rb +6 -5
- data/lib/veritas/optimizer/{logic → function}/predicate/greater_than_or_equal_to.rb +6 -6
- data/lib/veritas/optimizer/{logic → function}/predicate/inclusion.rb +6 -16
- data/lib/veritas/optimizer/{logic → function}/predicate/inequality.rb +6 -6
- data/lib/veritas/optimizer/{logic → function}/predicate/less_than.rb +6 -5
- data/lib/veritas/optimizer/{logic → function}/predicate/less_than_or_equal_to.rb +6 -6
- data/lib/veritas/optimizer/{logic → function}/predicate/match.rb +5 -4
- data/lib/veritas/optimizer/{logic → function}/predicate/no_match.rb +5 -4
- data/lib/veritas/optimizer/function/predicate.rb +61 -0
- data/lib/veritas/optimizer/function/string/length.rb +31 -0
- data/lib/veritas/optimizer/function/unary.rb +86 -0
- data/lib/veritas/optimizer/function.rb +87 -0
- data/lib/veritas/optimizer/optimizable.rb +6 -3
- data/lib/veritas/optimizer/relation/operation/binary.rb +36 -70
- data/lib/veritas/optimizer/relation/operation/limit.rb +1 -9
- data/lib/veritas/optimizer/relation/operation/offset.rb +1 -9
- data/lib/veritas/optimizer/relation/operation/order.rb +1 -9
- data/lib/veritas/optimizer/relation/operation/reverse.rb +1 -9
- data/lib/veritas/optimizer/relation/operation/unary.rb +50 -13
- data/lib/veritas/optimizer/version.rb +1 -1
- data/lib/veritas/optimizer.rb +43 -16
- data/spec/integration/veritas/algebra/difference/optimize_spec.rb +6 -4
- data/spec/integration/veritas/algebra/intersection/optimize_spec.rb +6 -4
- data/spec/integration/veritas/algebra/join/optimize_spec.rb +4 -2
- data/spec/integration/veritas/algebra/product/optimize_spec.rb +2 -0
- data/spec/integration/veritas/algebra/projection/optimize_spec.rb +6 -4
- data/spec/integration/veritas/algebra/rename/optimize_spec.rb +2 -0
- data/spec/integration/veritas/algebra/restriction/optimize_spec.rb +9 -7
- data/spec/integration/veritas/algebra/summarization/optimize_spec.rb +49 -0
- data/spec/integration/veritas/algebra/union/optimize_spec.rb +6 -4
- data/spec/integration/veritas/{logic → function}/connective/conjunction/optimize_spec.rb +33 -31
- data/spec/integration/veritas/{logic → function}/connective/disjunction/optimize_spec.rb +30 -28
- data/spec/integration/veritas/{logic → function}/connective/negation/optimize_spec.rb +7 -5
- data/spec/integration/veritas/{logic/expression → function}/optimize_spec.rb +5 -3
- data/spec/integration/veritas/{logic → function}/predicate/equality/optimize_spec.rb +9 -7
- data/spec/integration/veritas/{logic → function}/predicate/exclusion/optimize_spec.rb +13 -11
- data/spec/integration/veritas/{logic → function}/predicate/greater_than/optimize_spec.rb +17 -15
- data/spec/integration/veritas/{logic → function}/predicate/greater_than_or_equal_to/optimize_spec.rb +17 -15
- data/spec/integration/veritas/{logic → function}/predicate/inclusion/optimize_spec.rb +13 -11
- data/spec/integration/veritas/{logic → function}/predicate/inequality/optimize_spec.rb +9 -7
- data/spec/integration/veritas/{logic → function}/predicate/less_than/optimize_spec.rb +17 -15
- data/spec/integration/veritas/{logic → function}/predicate/less_than_or_equal_to/optimize_spec.rb +17 -15
- data/spec/integration/veritas/relation/empty/optimize_spec.rb +2 -0
- data/spec/integration/veritas/relation/materialized/optimize_spec.rb +2 -0
- data/spec/integration/veritas/relation/operation/limit/optimize_spec.rb +3 -1
- data/spec/integration/veritas/relation/operation/offset/optimize_spec.rb +3 -1
- data/spec/integration/veritas/relation/operation/order/optimize_spec.rb +4 -2
- data/spec/integration/veritas/relation/operation/reverse/optimize_spec.rb +4 -2
- data/spec/integration/veritas/relation/optimize_spec.rb +2 -0
- data/spec/shared/{logic_connective_binary_optimize_behavior.rb → function_connective_binary_optimize_behavior.rb} +14 -12
- data/spec/shared/idempotent_method_behavior.rb +2 -0
- data/spec/shared/optimize_method_behavior.rb +2 -0
- data/spec/support/add_method_missing.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/difference/empty_left/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/difference/empty_right/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/difference/equal_operands/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/extension/extensions_spec.rb +31 -0
- data/spec/unit/veritas/optimizer/algebra/extension/order_operand/optimizable_spec.rb +23 -0
- data/spec/unit/veritas/optimizer/algebra/extension/order_operand/optimize_spec.rb +22 -0
- data/spec/unit/veritas/optimizer/algebra/extension/unoptimized_operand/optimizable_spec.rb +18 -8
- data/spec/unit/veritas/optimizer/algebra/extension/unoptimized_operand/optimize_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/algebra/intersection/empty_left/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/intersection/empty_right/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/intersection/equal_operands/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/join/equal_headers/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/join/equal_headers/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/product/table_dee_left/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/product/table_dee_left/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/product/table_dee_right/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/product/table_dee_right/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/projection/empty_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/projection/empty_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/projection/projection_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/projection/projection_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/projection/{set_operand → union_operand}/optimizable_spec.rb +3 -1
- data/spec/unit/veritas/optimizer/algebra/projection/{set_operand → union_operand}/optimize_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/algebra/projection/unoptimized_operand/optimizable_spec.rb +3 -1
- data/spec/unit/veritas/optimizer/algebra/projection/unoptimized_operand/optimize_spec.rb +6 -4
- data/spec/unit/veritas/optimizer/algebra/rename/aliases_spec.rb +5 -13
- data/spec/unit/veritas/optimizer/algebra/rename/empty_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/rename/empty_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/rename/limit_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/rename/limit_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/rename/offset_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/rename/offset_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/rename/order_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/rename/order_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/rename/projection_operand/optimizable_spec.rb +17 -7
- data/spec/unit/veritas/optimizer/algebra/rename/projection_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/rename/rename_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/rename/rename_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/rename/rename_operand_and_empty_aliases/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/rename/rename_operand_and_empty_aliases/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/rename/restriction_operand/optimizable_spec.rb +3 -1
- data/spec/unit/veritas/optimizer/algebra/rename/restriction_operand/optimize_spec.rb +7 -5
- data/spec/unit/veritas/optimizer/algebra/rename/reverse_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/rename/reverse_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/rename/set_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/rename/set_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/rename/unoptimized_operand/optimizable_spec.rb +7 -20
- data/spec/unit/veritas/optimizer/algebra/rename/unoptimized_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/contradiction/optimizable_spec.rb +23 -3
- data/spec/unit/veritas/optimizer/algebra/restriction/contradiction/optimize_spec.rb +7 -5
- data/spec/unit/veritas/optimizer/algebra/restriction/order_operand/optimizable_spec.rb +3 -1
- data/spec/unit/veritas/optimizer/algebra/restriction/order_operand/optimize_spec.rb +7 -3
- data/spec/unit/veritas/optimizer/algebra/restriction/predicate_spec.rb +3 -1
- data/spec/unit/veritas/optimizer/algebra/restriction/restriction_operand/optimizable_spec.rb +5 -3
- data/spec/unit/veritas/optimizer/algebra/restriction/restriction_operand/optimize_spec.rb +8 -6
- data/spec/unit/veritas/optimizer/algebra/restriction/set_operand/optimizable_spec.rb +3 -1
- data/spec/unit/veritas/optimizer/algebra/restriction/set_operand/optimize_spec.rb +5 -3
- data/spec/unit/veritas/optimizer/algebra/restriction/tautology/optimizable_spec.rb +11 -3
- data/spec/unit/veritas/optimizer/algebra/restriction/tautology/optimize_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/algebra/restriction/unoptimized_operand/optimizable_spec.rb +7 -5
- data/spec/unit/veritas/optimizer/algebra/restriction/unoptimized_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/summarization/empty_operand/class_methods/extension_default_spec.rb +22 -0
- data/spec/unit/veritas/optimizer/algebra/summarization/empty_operand/optimizable_spec.rb +29 -0
- data/spec/unit/veritas/optimizer/algebra/summarization/empty_operand/optimize_spec.rb +47 -0
- data/spec/unit/veritas/optimizer/algebra/summarization/empty_summarize_per/optimizable_spec.rb +29 -0
- data/spec/unit/veritas/optimizer/algebra/summarization/empty_summarize_per/optimize_spec.rb +23 -0
- data/spec/unit/veritas/optimizer/algebra/summarization/order_operand/optimizable_spec.rb +23 -0
- data/spec/unit/veritas/optimizer/algebra/summarization/order_operand/optimize_spec.rb +22 -0
- data/spec/unit/veritas/optimizer/algebra/summarization/summarize_per_spec.rb +29 -0
- data/spec/unit/veritas/optimizer/algebra/summarization/summarizers_spec.rb +31 -0
- data/spec/unit/veritas/optimizer/algebra/summarization/unoptimized_operand/optimizable_spec.rb +30 -8
- data/spec/unit/veritas/optimizer/algebra/summarization/unoptimized_operand/optimize_spec.rb +12 -9
- data/spec/unit/veritas/optimizer/algebra/union/empty_left/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/union/empty_right/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/algebra/union/equal_operands/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/class_methods/chain_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/function/binary/constant_operands/optimizable_spec.rb +36 -0
- data/spec/unit/veritas/optimizer/function/binary/constant_operands/optimize_spec.rb +18 -0
- data/spec/unit/veritas/optimizer/function/binary/left_spec.rb +28 -0
- data/spec/unit/veritas/optimizer/function/binary/right_spec.rb +28 -0
- data/spec/unit/veritas/optimizer/function/binary/unoptimized_operands/optimizable_spec.rb +37 -0
- data/spec/unit/veritas/optimizer/function/binary/unoptimized_operands/optimize_spec.rb +23 -0
- data/spec/unit/veritas/optimizer/function/class_methods/optimize_functions_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/function/class_methods/optimize_operand_spec.rb +22 -0
- data/spec/unit/veritas/optimizer/function/connective/binary/constant_operands/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/{logic → function}/connective/binary/equal_operands/optimizable_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic → function}/connective/binary/equal_operands/optimize_spec.rb +3 -1
- data/spec/unit/veritas/optimizer/{logic → function}/connective/binary/left_spec.rb +3 -1
- data/spec/unit/veritas/optimizer/{logic → function}/connective/binary/redundant_left_operand/optimizable_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic → function}/connective/binary/redundant_left_operand/optimize_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic → function}/connective/binary/redundant_right_operand/optimizable_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic → function}/connective/binary/redundant_right_operand/optimize_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic → function}/connective/binary/right_spec.rb +3 -1
- data/spec/unit/veritas/optimizer/function/connective/conjunction/contradiction/optimizable_spec.rb +64 -0
- data/spec/unit/veritas/optimizer/function/connective/conjunction/contradiction/optimize_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/{logic/connective/disjunction/contradiction_left_operand → function/connective/conjunction/left_operand_tautology}/optimizable_spec.rb +9 -7
- data/spec/unit/veritas/optimizer/{logic → function}/connective/conjunction/left_operand_tautology/optimize_spec.rb +8 -6
- data/spec/unit/veritas/optimizer/{logic → function}/connective/conjunction/optimizable_to_exclusion/optimizable_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic → function}/connective/conjunction/optimizable_to_exclusion/optimize_spec.rb +5 -3
- data/spec/unit/veritas/optimizer/{logic → function}/connective/conjunction/right_operand_tautology/optimizable_spec.rb +6 -4
- data/spec/unit/veritas/optimizer/function/connective/conjunction/right_operand_tautology/optimize_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/{logic/connective/conjunction/left_operand_tautology → function/connective/disjunction/contradiction_left_operand}/optimizable_spec.rb +9 -7
- data/spec/unit/veritas/optimizer/{logic → function}/connective/disjunction/contradiction_left_operand/optimize_spec.rb +8 -6
- data/spec/unit/veritas/optimizer/{logic → function}/connective/disjunction/contradiction_right_operand/optimizable_spec.rb +6 -4
- data/spec/unit/veritas/optimizer/{logic → function}/connective/disjunction/contradiction_right_operand/optimize_spec.rb +8 -6
- data/spec/unit/veritas/optimizer/{logic → function}/connective/disjunction/optimizable_to_inclusion/optimizable_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic → function}/connective/disjunction/optimizable_to_inclusion/optimize_spec.rb +5 -3
- data/spec/unit/veritas/optimizer/function/connective/disjunction/tautology/optimizable_spec.rb +64 -0
- data/spec/unit/veritas/optimizer/function/connective/disjunction/tautology/optimize_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/function/connective/negation/constant_operand/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/function/connective/negation/invertible_operand/optimizable_spec.rb +28 -0
- data/spec/unit/veritas/optimizer/function/connective/negation/invertible_operand/optimize_spec.rb +22 -0
- data/spec/unit/veritas/optimizer/{logic → function}/connective/negation/operand_spec.rb +3 -1
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/comparable/never_comparable/optimizable_spec.rb +23 -7
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/comparable/never_equivalent/optimizable_spec.rb +23 -7
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/comparable/normalizable_operands/optimizable_spec.rb +7 -5
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/comparable/normalizable_operands/optimize_spec.rb +7 -5
- data/spec/unit/veritas/optimizer/function/predicate/constant_operands/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/function/predicate/contradiction/optimize_spec.rb +18 -0
- data/spec/unit/veritas/optimizer/function/predicate/enumerable/class_methods/sort_by_value_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/enumerable/empty_right_operand/optimizable_spec.rb +6 -4
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/enumerable/one_right_operand/optimizable_spec.rb +9 -7
- data/spec/unit/veritas/optimizer/{logic/predicate/enumerable/unoptimized_operand → function/predicate/enumerable/unoptimized_operands}/optimizable_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic/predicate/enumerable/unoptimized_operand → function/predicate/enumerable/unoptimized_operands}/optimize_spec.rb +18 -5
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/equality/tautology/optimizable_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/exclusion/empty_right_operand/optimize_spec.rb +8 -6
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/exclusion/one_right_operand/optimize_spec.rb +8 -6
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/greater_than/contradiction/optimizable_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/greater_than/tautology/optimizable_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/greater_than_or_equal_to/contradiction/optimizable_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/greater_than_or_equal_to/tautology/optimizable_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/inclusion/empty_right_operand/optimize_spec.rb +8 -6
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/inclusion/one_right_operand/optimize_spec.rb +8 -6
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/inequality/contradiction/optimizable_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/less_than/contradiction/optimizable_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/less_than/tautology/optimizable_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/less_than_or_equal_to/contradiction/optimizable_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic → function}/predicate/less_than_or_equal_to/tautology/optimizable_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/function/predicate/tautology/optimize_spec.rb +18 -0
- data/spec/unit/veritas/optimizer/function/unary/constant_operand/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/function/unary/constant_operand/optimize_spec.rb +18 -0
- data/spec/unit/veritas/optimizer/function/unary/operand_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/function/unary/unoptimized_operand/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/function/unary/unoptimized_operand/optimize_spec.rb +18 -0
- data/spec/unit/veritas/optimizer/{logic/predicate → function}/util/class_methods/attribute_spec.rb +4 -2
- data/spec/unit/veritas/optimizer/{logic/predicate → function}/util/class_methods/constant_spec.rb +13 -5
- data/spec/unit/veritas/optimizer/function/util/class_methods/max_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/function/util/class_methods/min_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/operation_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/optimizable/class_methods/optimizer_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/optimizable/optimize_spec.rb +3 -1
- data/spec/unit/veritas/optimizer/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/materialized/empty_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/materialized/empty_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/empty_left/optimizable_spec.rb +2 -4
- data/spec/unit/veritas/optimizer/relation/operation/binary/empty_right/optimizable_spec.rb +2 -4
- data/spec/unit/veritas/optimizer/relation/operation/binary/equal_operands/optimizable_spec.rb +2 -5
- data/spec/unit/veritas/optimizer/relation/operation/binary/left_order_operand/optimizable_spec.rb +23 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/left_order_operand/optimize_spec.rb +23 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/left_spec.rb +2 -4
- data/spec/unit/veritas/optimizer/relation/operation/binary/materialized_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/materialized_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/right_order_operand/optimizable_spec.rb +23 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/right_order_operand/optimize_spec.rb +23 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/right_spec.rb +2 -4
- data/spec/unit/veritas/optimizer/relation/operation/binary/{unoptimized_operand → unoptimized_operands}/optimizable_spec.rb +3 -1
- data/spec/unit/veritas/optimizer/relation/operation/binary/{unoptimized_operand → unoptimized_operands}/optimize_spec.rb +3 -1
- data/spec/unit/veritas/optimizer/relation/operation/combination/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/equal_limit_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/equal_limit_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/limit_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/limit_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/unoptimized_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/unoptimized_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/zero_limit/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/zero_limit/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/offset_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/offset_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/unoptimized_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/unoptimized_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/zero_offset/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/zero_offset/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/order/one_limit_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/order/one_limit_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/order/order_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/order/order_operand/optimize_spec.rb +3 -1
- data/spec/unit/veritas/optimizer/relation/operation/order/unoptimized_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/order/unoptimized_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/order_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/order_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/reverse_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/reverse_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/unoptimized_operand/optimizable_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/unoptimized_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/unary/empty_operand/optimizable_spec.rb +5 -2
- data/spec/unit/veritas/optimizer/relation/operation/unary/empty_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/unary/header_spec.rb +15 -0
- data/spec/unit/veritas/optimizer/relation/operation/unary/materialized_operand/optimizable_spec.rb +5 -2
- data/spec/unit/veritas/optimizer/relation/operation/unary/materialized_operand/optimize_spec.rb +2 -0
- data/spec/unit/veritas/optimizer/relation/operation/unary/operand_spec.rb +8 -5
- data/spec/unit/veritas/optimizer/relation/operation/unary/order_operand/optimizable_spec.rb +28 -0
- data/spec/unit/veritas/optimizer/relation/operation/unary/order_operand/optimize_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/relation/operation/unary/unchanged_header/optimizable_spec.rb +24 -0
- data/spec/unit/veritas/optimizer/relation/operation/unary/unchanged_header/optimize_spec.rb +14 -0
- data/tasks/metrics/ci.rake +7 -0
- data/tasks/{quality → metrics}/flay.rake +0 -0
- data/tasks/{quality → metrics}/flog.rake +0 -0
- data/tasks/{quality → metrics}/heckle.rake +1 -0
- data/tasks/{quality → metrics}/metric_fu.rake +3 -0
- data/tasks/{quality → metrics}/reek.rake +0 -0
- data/tasks/{quality → metrics}/roodi.rake +0 -0
- data/tasks/{quality → metrics}/yardstick.rake +0 -0
- data/tasks/spec.rake +1 -0
- data/veritas-optimizer.gemspec +183 -352
- metadata +232 -357
- data/lib/veritas/optimizer/logic/connective/negation.rb +0 -71
- data/lib/veritas/optimizer/logic/predicate.rb +0 -177
- data/spec/unit/veritas/optimizer/algebra/projection/header_spec.rb +0 -16
- data/spec/unit/veritas/optimizer/algebra/projection/unchanged_header/optimizable_spec.rb +0 -26
- data/spec/unit/veritas/optimizer/algebra/projection/unchanged_header/optimize_spec.rb +0 -16
- data/spec/unit/veritas/optimizer/algebra/rename/class_methods/union_aliases_spec.rb +0 -27
- data/spec/unit/veritas/optimizer/algebra/rename/header_spec.rb +0 -19
- data/spec/unit/veritas/optimizer/algebra/rename/unchanged_header/optimizable_spec.rb +0 -26
- data/spec/unit/veritas/optimizer/algebra/rename/unchanged_header/optimize_spec.rb +0 -16
- data/spec/unit/veritas/optimizer/algebra/restriction/class_methods/optimize_predicate_spec.rb +0 -31
- data/spec/unit/veritas/optimizer/algebra/restriction/reverse_operand/optimizable_spec.rb +0 -26
- data/spec/unit/veritas/optimizer/algebra/restriction/reverse_operand/optimize_spec.rb +0 -18
- data/spec/unit/veritas/optimizer/logic/connective/binary/unoptimized_operand/optimizable_spec.rb +0 -34
- data/spec/unit/veritas/optimizer/logic/connective/binary/unoptimized_operand/optimize_spec.rb +0 -21
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/contradiction/optimizable_spec.rb +0 -41
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/contradiction/optimize_spec.rb +0 -17
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/right_operand_tautology/optimize_spec.rb +0 -17
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/tautology/optimizable_spec.rb +0 -41
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/tautology/optimize_spec.rb +0 -17
- data/spec/unit/veritas/optimizer/logic/connective/negation/invertible_operand/optimizable_spec.rb +0 -26
- data/spec/unit/veritas/optimizer/logic/connective/negation/invertible_operand/optimize_spec.rb +0 -20
- data/spec/unit/veritas/optimizer/logic/predicate/class_methods/optimize_operand_spec.rb +0 -20
- data/spec/unit/veritas/optimizer/logic/predicate/constant_operands/optimizable_spec.rb +0 -29
- data/spec/unit/veritas/optimizer/logic/predicate/constant_operands/optimize_spec.rb +0 -14
- data/spec/unit/veritas/optimizer/logic/predicate/contradiction/optimize_spec.rb +0 -16
- data/spec/unit/veritas/optimizer/logic/predicate/left_spec.rb +0 -25
- data/spec/unit/veritas/optimizer/logic/predicate/right_spec.rb +0 -25
- data/spec/unit/veritas/optimizer/logic/predicate/tautology/optimize_spec.rb +0 -16
- data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/max_spec.rb +0 -19
- data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/min_spec.rb +0 -19
- 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
|
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::
|
65
|
-
right.kind_of?(Veritas::
|
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::
|
77
|
-
right.kind_of?(Veritas::
|
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 =
|
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::
|
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::
|
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::
|
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::
|
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 [
|
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 [
|
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 [
|
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
|
210
|
-
|
211
|
-
|
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
|
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
|
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 [
|
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 [
|
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::
|
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
|
-
|
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::
|
102
|
+
Veritas::Function::Proposition::Contradiction.instance
|
103
103
|
end
|
104
104
|
|
105
105
|
end # class Contradiction
|
106
106
|
|
107
|
-
Veritas::
|
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
|
-
|
116
|
+
UnoptimizedOperands
|
116
117
|
)
|
117
118
|
|
118
119
|
end # class Conjunction
|
119
120
|
end # module Connective
|
120
|
-
end # module
|
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
|
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 [
|
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 [
|
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::
|
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
|
81
|
+
# Optimize when the operands are a tautology
|
82
82
|
class Tautology < self
|
83
83
|
|
84
|
-
# Test if the operands are a
|
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
|
-
|
93
|
+
contradiction?
|
94
94
|
end
|
95
95
|
|
96
|
-
# Return a
|
96
|
+
# Return a tautology
|
97
97
|
#
|
98
98
|
# @return [Tautology]
|
99
99
|
#
|
100
100
|
# @api private
|
101
101
|
def optimize
|
102
|
-
Veritas::
|
102
|
+
Veritas::Function::Proposition::Tautology.instance
|
103
103
|
end
|
104
104
|
|
105
105
|
end # class Tautology
|
106
106
|
|
107
|
-
Veritas::
|
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
|
-
|
116
|
+
UnoptimizedOperands
|
116
117
|
)
|
117
118
|
|
118
119
|
end # class Disjunction
|
119
120
|
end # module Connective
|
120
|
-
end # module
|
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
|