Esempio n. 1
0
 def shallow_simplification(self,
                            *,
                            must_evaluate=False,
                            **defaults_config):
     '''
     If the left side has a 'not_equal' method, use that for
     evalaution.  Otherwise, if appropriate (must_evaluate is TRUE
     or the answer is already known) apply the definition to
     perform the evaluation: A ≠ B via ¬(A = B).
     '''
     from proveit import ProofFailure
     from proveit.logic import evaluate_truth
     if self.lhs != self.rhs and hasattr(self.lhs, 'not_equal'):
         try:
             # If there is a 'not_equal' method, try to use that.
             neq = self.lhs.not_equal(self.rhs, automation=must_evaluate)
             return evaluate_truth(neq)
         except ProofFailure:
             pass
     eq = Equals(self.lhs, self.rhs)
     if must_evaluate or eq.proven() or eq.disproven():
         # Evaluate A ≠ B via evaluating ¬(A = B),
         definition_equality = self.definition()
         unfolded_evaluation = definition_equality.rhs.evaluation(
             automation=must_evaluate)
         return definition_equality.apply_transitivity(unfolded_evaluation)
     return Operation.shallow_simplification(self)
Esempio n. 2
0
 def shallow_simplification(self,
                            *,
                            must_evaluate=False,
                            **defaults_config):
     if must_evaluate and hasattr(self.operand, 'compute_norm'):
         return self.evaluation()
     return Operation.shallow_simplification(self)
Esempio n. 3
0
 def shallow_simplification(self, *, must_evaluate=False,
                            **defaults_config):
     '''
     Simplify via inner product linearity:
     <a x, y> = a <x, y>
     <x, y> = <x, a y>
     <x + y, z> = <x, z> + <y, z>
     <x, y + z> = <x, y> + <x, z>
     '''
     from proveit.linear_algebra import VecSpaces, ScalarMult, VecAdd
     from proveit.linear_algebra.inner_products import (
             inner_prod_scalar_mult_left, inner_prod_scalar_mult_right,
             inner_prod_vec_add_left, inner_prod_vec_add_right)
     _u, _v = self.operands
     try:
         vec_space = VecSpaces.common_known_vec_space((_u, _v))
     except UnsatisfiedPrerequisites:
         # No known common vectors space for the operands, so
         # we have no specific shallow_simplication we can do here.
         return Operation.shallow_simplification(
                 self, must_evaluate=must_evaluate)
     field = VecSpaces.known_field(vec_space)
     simp = None
     if isinstance(_u, ScalarMult):
         simp = inner_prod_scalar_mult_left.instantiate(
                 {K:field, H:vec_space, a:_u.scalar, x:_u.scaled, y:_v})
     if isinstance(_v, ScalarMult):
         simp = inner_prod_scalar_mult_right.instantiate(
                 {K:field, H:vec_space, a:_v.scalar, x:_u, y:_v.scaled})
     if isinstance(_u, VecAdd):
         simp = inner_prod_vec_add_left.instantiate(
                 {K:field, H:vec_space, x:_u.terms[0], y:_u.terms[1], z:_v})
     if isinstance(_v, VecAdd):
         simp = inner_prod_vec_add_right.instantiate(
                 {K:field, H:vec_space, x:_u, y:_v.terms[0], z:_v.terms[1]})
     if simp is None:
         return Operation.shallow_simplification(
                 self, must_evaluate=must_evaluate)
     if must_evaluate and not is_irreducible_value(simp.rhs):
         return simp.inner_expr().rhs.evaluate()
     return simp
Esempio n. 4
0
 def shallow_simplification(self,
                            *,
                            must_evaluate=False,
                            **defaults_config):
     '''
     If the function is a Lambda map, simplify the Image via
     its definition.
     '''
     if isinstance(self.elem_function, Lambda):
         return self.definition()
     return Operation.shallow_simplification(self,
                                             must_evaluate=must_evaluate)
Esempio n. 5
0
 def shallow_simplification(self,
                            *,
                            must_evaluate=False,
                            **defaults_config):
     '''
     Returns a proven simplification equation for this Len
     expression assuming.  Performs the "computation" of the
     Len expression and then simplifies the right side.
     '''
     if must_evaluate:
         return self.computation(auto_simplify=True)
     else:
         return Operation.shallow_simplification(self)
Esempio n. 6
0
 def shallow_simplification(self, *, must_evaluate=False,
                            **defaults_config):
     '''
     If the operands that to TRUE or FALSE, we can 
     evaluate this expression as TRUE or FALSE.
     '''
     # IMPORTANT: load in truth-table evaluations
     from . import implies_t_t, implies_t_f, implies_f_t, implies_f_f  
     try:
         return Operation.shallow_simplification(
                 self, must_evaluate=must_evaluate)
     except NotImplementedError:
         # Should have been able to do the evaluation from the
         # loaded truth table.
         # If it can't we are unable to evaluate it.
         from proveit.logic import EvaluationError
         raise EvaluationError(self)
Esempio n. 7
0
 def shallow_simplification(self, *, must_evaluate=False,
                            **defaults_config):
     '''
     Given operands that evaluate to TRUE or FALSE, derive and
     return the equality of this expression with TRUE or FALSE.
     '''
     from proveit.logic import TRUE, FALSE
     # load in truth-table evaluations
     from . import implies_t_f, implies_t_t, implies_f_t, implies_f_f
     if must_evaluate:
         start_over = False
         for operand in self.operands:
             if operand not in (TRUE, FALSE):
                 # The simplification of the operands may not have
                 # worked hard enough.  Let's work harder if we
                 # must evaluate.
                 operand.evaluation()
                 start_over = True
         if start_over: return self.evaluation()
     # May now be able to evaluate via loaded truth tables.
     return Operation.shallow_simplification(
             self, must_evaluate=must_evaluate)
Esempio n. 8
0
    def shallow_simplification(self,
                               *,
                               must_evaluate=False,
                               **defaults_config):
        from proveit.logic import TRUE, FALSE, EvaluationError, evaluate_truth
        from proveit.logic.booleans.negation import (negation_intro,
                                                     falsified_negation_intro)
        from . import not_t, not_f  # load in truth-table evaluations
        if self.operand == TRUE:
            return not_t
        elif self.operand == FALSE:
            return not_f
        elif self.operand.proven():
            # evaluate to FALSE via falsified_negation_intro
            return falsified_negation_intro.instantiate({A: self.operand})
        elif self.operand.disproven():
            # evaluate to TRUE via falsified_negation_intro
            return evaluate_truth(negation_intro.instantiate({A:
                                                              self.operand}))
        elif must_evaluate:
            # The simplification of the operands may not have
            # worked hard enough.  Let's work harder if we must
            # evaluate.
            evaluated = self.operand.evaluation().rhs
            if evaluated in (TRUE, FALSE):
                # All the pieces should be there now.
                return self.evaluation(automation=True)
            raise EvaluationError(self)

        if hasattr(self.operand, 'shallow_simplification_of_negation'):
            # If the operand has a 'shallow_simplification_of_negation',
            # use that.
            return self.operand.shallow_simplification_of_negation()

        # May now be able to evaluate via loaded truth tables.
        return Operation.shallow_simplification(self)