<commit_before>module Veritas
  module Logic
    class Connective
      class Disjunction < Connective
        include BinaryConnective

        def self.eval(left, right)
          left || right
        end

        def optimize
          left, right = optimize_left, optimize_right

          if always_true?
            Proposition::True.instance
          elsif right.kind_of?(Proposition::False)
            left
          elsif left.kind_of?(Proposition::False)
            right
          elsif collapse_to_inclusion?
            new_inclusion
          else
            super
          end
        end

        def inspect
          "(#{left.inspect} OR #{right.inspect})"
        end

      private

        def always_true?
          optimize_left.kind_of?(Proposition::True) || optimize_right.kind_of?(Proposition::True)
        end

        def new_inclusion
          left = optimize_left
          Predicate::Inclusion.new(left.left, [ left.right, optimize_right.right ]).optimize
        end

        def collapse_to_inclusion?
          left_and_right_equality?       &&
          left_and_right_same_attribute? &&
          left_and_right_constants?
        end

        def left_and_right_equality?
          optimize_left.kind_of?(Predicate::Equality) &&
          optimize_right.kind_of?(Predicate::Equality)
        end

        def left_and_right_same_attribute?
          optimize_left.left.eql?(optimize_right.left)
        end

        def left_and_right_constants?
          left_constant? && right_constant?
        end

        def left_constant?
          !optimize_left.right.kind_of?(Attribute)
        end

        def right_constant?
          !optimize_right.right.kind_of?(Attribute)
        end

        memoize :optimize

        module Methods
          extend Aliasable

          inheritable_alias(:| => :or)

          def or(other)
            Disjunction.new(self, other)
          end

        end # module Methods

        Connective::Methods.class_eval { include Methods }

      end # class Disjunction
    end # class Connective
  end # module Logic
end # module Veritas<commit_msg>An object that does not respond to #call is considered constant<commit_after>module Veritas
  module Logic
    class Connective
      class Disjunction < Connective
        include BinaryConnective

        def self.eval(left, right)
          left || right
        end

        def optimize
          left, right = optimize_left, optimize_right

          if always_true?
            Proposition::True.instance
          elsif right.kind_of?(Proposition::False)
            left
          elsif left.kind_of?(Proposition::False)
            right
          elsif collapse_to_inclusion?
            new_inclusion
          else
            super
          end
        end

        def inspect
          "(#{left.inspect} OR #{right.inspect})"
        end

      private

        def always_true?
          optimize_left.kind_of?(Proposition::True) || optimize_right.kind_of?(Proposition::True)
        end

        def new_inclusion
          left = optimize_left
          Predicate::Inclusion.new(left.left, [ left.right, optimize_right.right ]).optimize
        end

        def collapse_to_inclusion?
          left_and_right_equality?       &&
          left_and_right_same_attribute? &&
          left_and_right_constants?
        end

        def left_and_right_equality?
          optimize_left.kind_of?(Predicate::Equality) &&
          optimize_right.kind_of?(Predicate::Equality)
        end

        def left_and_right_same_attribute?
          optimize_left.left.eql?(optimize_right.left)
        end

        def left_and_right_constants?
          left_constant? && right_constant?
        end

        def left_constant?
          !optimize_left.right.respond_to?(:call)
        end

        def right_constant?
          !optimize_right.right.respond_to?(:call)
        end

        memoize :optimize

        module Methods
          extend Aliasable

          inheritable_alias(:| => :or)

          def or(other)
            Disjunction.new(self, other)
          end

        end # module Methods

        Connective::Methods.class_eval { include Methods }

      end # class Disjunction
    end # class Connective
  end # module Logic
end # module Veritas
{'fraction_non_alphanumeric': 0.06754874651810584, 'fraction_numerical': 0.0, 'mean_word_length': 1.836734693877551, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '663690', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1165, 'n_words': 247}