Sha256: 8fadc8734be9dcfa8cdaca6bd0b4ebe1ef5f532c008ea33bb0bf32a9ae6a7c44

Contents?: true

Size: 1.72 KB

Versions: 4

Compression:

Stored size: 1.72 KB

Contents

# encoding: utf-8

module Veritas
  class Optimizer
    module Function
      module Connective

        # Abstract base class representing Negation optimizations
        class Negation < Optimizer
          include Unary

          # Optimize when the operand can be inverted
          class InvertibleOperand < self

            # Test if the operand can be inverted
            #
            # @return [Boolean]
            #
            # @api private
            def optimizable?
              operand.respond_to?(:inverse)
            end

            # A Negation of an Function is equivalent to the inverted Function
            #
            # @return [Function]
            #
            # @api private
            def optimize
              operand.inverse
            end

          end # class InvertibleOperand

          # Optimize when the operand is constant
          class ConstantOperand < self
            include Unary::ConstantOperand

            # A Negation with constant values is equivalent to a Proposition
            #
            # @return [Proposition]
            #
            # @api private
            def optimize
              Veritas::Function::Proposition.new(super)
            end

          end # class ConstantOperand

          # Optimize when the operand is unoptimized
          class UnoptimizedOperand < self
            include Function::Unary::UnoptimizedOperand
          end # class UnoptimizedOperand

          Veritas::Function::Connective::Negation.optimizer = chain(
            ConstantOperand,
            InvertibleOperand,
            UnoptimizedOperand
          )

        end # class Negation
      end # module Connective
    end # module Function
  end # class Optimizer
end # module Veritas

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
veritas-optimizer-0.0.7 lib/veritas/optimizer/function/connective/negation.rb
veritas-optimizer-0.0.6 lib/veritas/optimizer/function/connective/negation.rb
veritas-optimizer-0.0.5 lib/veritas/optimizer/function/connective/negation.rb
veritas-optimizer-0.0.4 lib/veritas/optimizer/function/connective/negation.rb