def evaluation(self, assumptions=USE_DEFAULTS, *, automation=True, minimal_automation=False, **kwargs): ''' Attempt to determine whether this disjunction evaluates to true or false under the given assumptions. If automation is false, it will only succeed if the evaluation is already known. If automation and minimal_automation are True, it will only rely upon known evaluations of the operands to determine whether to try to prove or disprove the disjunction. ''' from proveit.logic import TRUE, SimplificationError from ._axioms_ import orTT, orTF, orFT, orFF # load in truth-table evaluations if len(self.operands) == 0: return self.unaryReduction(assumptions=assumptions) # First just see if it has a known evaluation. try: return Operation.evaluation(self, assumptions, automation=False) except SimplificationError as e: if not automation: raise e # Depending upon evaluations of operands, we will either # attempt to prove or disprove this conjunction. if minimal_automation: # Only do non-automated evaluations of operands # if minimal_automation is True. operand_automations = (False, ) else: # First try non-automated operand evaluation, then # automated only if necessary. operand_automations = (False, True) for operand_automation in operand_automations: operands_evals = [] for operand in self.operands: try: operand_eval = operand.evaluation( assumptions, automation=operand_automations) operands_evals.append(operand_eval.rhs) except: operands_evals.append(None) if TRUE in operands_evals: # If any operand is true, the disjunction may # only evaluate to true if it can be evaluated. self.prove(assumptions) break elif not None in operands_evals: # If no operand is true and all the evaluations # are known, the conjunction may only evaluate # to false if it can be evaluated. self.disprove(assumptions) break # If we had any success proving or disproving this conjunction # there should be a known evaluation now. return Operation.evaluation(self, assumptions, automation=False)
def evaluation(self, assumptions=USE_DEFAULTS, automation=True): ''' Given operands that evaluate to TRUE or FALSE, derive and return the equality of this expression with TRUE or FALSE. ''' from . import iff_t_t, iff_t_f, iff_f_t, iff_f_f # IMPORTANT: load in truth-table evaluations return Operation.evaluation(self, assumptions, automation)
def evaluation(self, assumptions=USE_DEFAULTS, automation=True): ''' Given operands that evaluate to TRUE or FALSE, derive and return the equality of this expression with TRUE or FALSE. ''' from ._theorems_ import impliesTT, impliesFT, impliesFF, impliesTF # load in truth-table evaluations return Operation.evaluation(self, assumptions, automation=automation)
def evaluation(self, assumptions=USE_DEFAULTS): ''' Attempt to form evaluation of whether (element in domain) is TRUE or FALSE. If the domain has a 'membershipObject' method, attempt to use the 'equivalence' method from the object it generates. ''' from proveit.logic import Equals, TRUE, NotIn evaluation = None try: # try an 'equivalence' method (via the membership object) equiv = self.membershipObject.equivalence(assumptions) val = equiv.evaluation(assumptions).rhs evaluation = Equals(equiv, val).prove(assumptions=assumptions) except: # try the default evaluation method if necessary evaluation = Operation.evaluation(self, assumptions) # try also to evaluate this by deducing membership or non-membership in case it # generates a shorter proof. try: if evaluation.rhs == TRUE: if hasattr(self, 'membershipObject'): self.membershipObject.conclude(assumptions=assumptions) else: notInDomain = NotIn(self.element, self.domain) if hasattr(notInDomain, 'nonmembershipObject'): notInDomain.nonmembershipObject.conclude( assumptions=assumptions) except: pass return evaluation
def evaluation(self, assumptions=USE_DEFAULTS): ''' Given operands that evaluate to TRUE or FALSE, derive and return the equality of this expression with TRUE or FALSE. ''' from _theorems_ import iffTT, iffTF, iffFT, iffFF # IMPORTANT: load in truth-table evaluations return Operation.evaluation(self, assumptions)
def evaluation(self, assumptions=USE_DEFAULTS, *, automation=True, **kwargs): ''' Given an operand that evaluates to TRUE or FALSE, derive and return the equality of this expression with TRUE or FALSE. ''' from ._theorems_ import notT, notF # load in truth-table evaluations return Operation.evaluation(self, assumptions, automation=automation)
def evaluation(self, assumptions=USE_DEFAULTS): ''' Given operands that evaluate to TRUE or FALSE, derive and return the equality of this expression with TRUE or FALSE. ''' from ._axioms_ import orTT, orTF, orFT, orFF # load in truth-table evaluations from ._theorems_ import trueEval, falseEval from proveit.logic.boolean._common_ import TRUE, FALSE trueIndex = -1 for i, operand in enumerate(self.operands): if operand != TRUE and operand != FALSE: # The operands are not always true/false, so try the default evaluation method # which will attempt to evaluate each of the operands. return Operation.evaluation(self, assumptions) if operand == TRUE: trueIndex = i if len(self.operands) == 2: # This will automatically return orTT, orTF, orFT, or orFF return Operation.evaluation(self, assumptions) if trueIndex >= 0: # one operand is TRUE so the whole disjunction evaluates to TRUE. from proveit.number import num mVal, nVal = num(trueIndex), num( len(self.operands) - trueIndex - 1) return trueEval.specialize( { m: mVal, n: nVal, AA: self.operands[:trueIndex], CC: self.operands[trueIndex + 1:] }, assumptions=assumptions) else: # no operand is TRUE so the whole disjunction evaluates to FALSE. from proveit.number import num return falseEval.specialize( { m: num(len(self.operands)), AA: self.operands }, assumptions=assumptions)
def evaluation(self, assumptions=USE_DEFAULTS, automation=True): ''' Given operands that may be evaluated to irreducible values that may be compared, or if there is a known evaluation of this inequality, derive and return this expression equated to TRUE or FALSE. ''' if automation: definitionEquality = self.definition() unfoldedEvaluation = definitionEquality.rhs.evaluation(assumptions) return Equals(self, unfoldedEvaluation.rhs).prove(assumptions) return Operation.evaluation(self, assumptions, automation)
def evaluation(self, assumptions=USE_DEFAULTS): ''' Given operands that evaluate to TRUE or FALSE, derive and return the equality of this expression with TRUE or FALSE. ''' from ._axioms_ import andTT, andTF, andFT, andFF # load in truth-table evaluations try: self.prove(assumptions) except ProofFailure: try: self.disprove(assumptions) except ProofFailure: pass return Operation.evaluation(self, assumptions)
def evaluation(self, assumptions=USE_DEFAULTS, *, automation=True, **kwargs): ''' Given an operand that evaluates to TRUE or FALSE, derive and return the equality of this expression with TRUE or FALSE. ''' from . import not_t, not_f # load in truth-table evaluations from proveit.logic.booleans import TRUE from proveit.logic.booleans.negation import falsified_negation_intro if self.operand.proven(assumptions) and self.operand != TRUE: # evaluate to FALSE via falsified_negation_intro return falsified_negation_intro.instantiate( {A: self.operand}, assumptions=assumptions) return Operation.evaluation(self, assumptions, automation=automation)
def evaluation(self, assumptions=USE_DEFAULTS): ''' Given an operand that evaluates to TRUE or FALSE, derive and return the equality of this expression with TRUE or FALSE. ''' from ._theorems_ import notT, notF # load in truth-table evaluations from proveit.logic.boolean._common_ import TRUE, FALSE from proveit.logic.boolean.negation._axioms_ import falsifiedNegationIntro if self.operand == TRUE: return notT if self.operand == FALSE: return notF opValue = self.operand.evaluation(assumptions=assumptions).rhs if opValue == TRUE: # evaluate to FALSE via falsifiedNegationIntro return falsifiedNegationIntro.specialize({A: self.operand}, assumptions=assumptions) return Operation.evaluation(self, assumptions)
def evaluation(self, assumptions=USE_DEFAULTS, automation=True): ''' Given operands that may be evaluated to irreducible values that may be compared, or if there is a known evaluation of this equality, derive and return this expression equated to TRUE or FALSE. ''' if automation: if self.lhs == self.rhs: # prove equality is true by reflexivity return evaluateTruth(self.prove().expr, assumptions=[]) if isIrreducibleValue(self.lhs) and isIrreducibleValue(self.rhs): # Irreducible values must know how to evaluate the equality # between each other, where appropriate. return self.lhs.evalEquality(self.rhs) return TransitiveRelation.evaluation(self, assumptions) return Operation.evaluation(self, assumptions, automation)
def evaluation(self, assumptions=USE_DEFAULTS): ''' Given operands that evaluate to TRUE or FALSE, derive and return the equality of this expression with TRUE or FALSE. ''' from ._axioms_ import emptyDisjunction from ._axioms_ import orTT, orTF, orFT, orFF # load in truth-table evaluations if len(self.operands) == 0: return emptyDisjunction try: self.prove(assumptions) except ProofFailure: try: self.disprove(assumptions) except ProofFailure: pass return Operation.evaluation(self, assumptions)
def evaluation(self, **defaults_config): if hasattr(self.operand, 'compute_norm'): # If the operand has a 'deduce_norm' method, use # it in an attempt to evaluate the norm. return self.computation().inner_expr().rhs.evaluate() return Operation.evaluation(self)