/** * {<S ==> M>, <M ==> P>} |- {<S ==> P>, * * <P ==>S>} * * @param term1 Subject of the first new task * @param term2 Predicate of the first new task * @param sentence The first premise * @param belief The second premise */ static void dedExe(Term term1, Term term2, Sentence sentence, Judgment belief) { if (RDFStatement.invalidStatement(term1, term2)) { return; } TruthValue value1 = sentence.getTruth(); TruthValue value2 = belief.getTruth(); TruthValue truth1 = null; TruthValue truth2 = null; BudgetValue budget1, budget2; if (sentence instanceof Question) { budget1 = BudgetFunctions.backwardWeak(value2); budget2 = BudgetFunctions.backwardWeak(value2); } else { if (sentence instanceof Goal) { truth1 = TruthFunctions.desireWeak(value1, value2); truth2 = TruthFunctions.desireWeak(value1, value2); } else { truth1 = TruthFunctions.deduction(value1, value2); truth2 = TruthFunctions.exemplification(value1, value2); } budget1 = BudgetFunctions.forward(truth1); budget2 = BudgetFunctions.forward(truth2); } TemporalValue order1 = sentence.getContent().getOrder(); TemporalValue order2 = belief.getContent().getOrder(); TemporalValue order = TemporalRules.syllogistic(order1, order2); RDFStatement content1 = RDFStatement.make((RDFStatement) sentence.getContent(), term1, term2, order); RDFStatement content2 = RDFStatement.make( (RDFStatement) sentence.getContent(), term2, term1, TemporalValue.getReverse(order)); Memory.doublePremiseTask(budget1, content1, truth1); Memory.doublePremiseTask(budget2, content2, truth2); }
/** * {<(&&, S1, S2, S3) ==> P>, S1} |- <(&&, S2, S3) ==> P> {<(&&, S2, S3) ==> P>, <S1 ==> S2>} |- * <(&&, S1, S3) ==> P> {<(&&, S1, S3) ==> P>, <S1 ==> S2>} |- <(&&, S2, S3) ==> P> * * @param premise1 The conditional premise * @param index The location of the shared term in the condition of premise1 * @param premise2 The premise which, or part of which, appears in the condition of premise1 * @param side The location of the shared term in premise2: 0 for subject, 1 for predicate, -1 for * the whole term */ static void conditionalDedInd(Implication premise1, short index, Term premise2, int side) { Task task = Memory.currentTask; Sentence taskSentence = task.getSentence(); Judgment belief = Memory.currentBelief; boolean deduction = (side != 0); HashMap substitute = Variable.findSubstitute(Variable.VarType.ALL, premise2, belief.getContent()); boolean conditionalTask = (substitute != null); TemporalValue tense1 = (conditionalTask ? taskSentence.getTense() : belief.getTense()); TemporalValue tense2 = (conditionalTask ? belief.getTense() : taskSentence.getTense()); TemporalValue order1 = premise1.getOrder(); TemporalValue order2 = premise2.getOrder(); if ((side == -1) && (tense2 != null) && (tense2.getDelta() > 0)) { return; } if ((side == 0) && (order2 != null) && (order2.getDelta() > 0)) { return; } if ((side == 1) && (order2 != null) && (order2.getDelta() < 0)) { return; } TemporalValue tense = TemporalRules.syllogistic(tense1, tense2); if (tense != null) { tense = new TemporalValue(0); } Term commonComponent; Term newComponent = null; if (side == 0) { commonComponent = ((RDFStatement) premise2).getSubject(); newComponent = ((RDFStatement) premise2).getPredicate(); } else if (side == 1) { commonComponent = ((RDFStatement) premise2).getPredicate(); newComponent = ((RDFStatement) premise2).getSubject(); } else { commonComponent = premise2; } Conjunction oldCondition = (Conjunction) premise1.getSubject(); boolean match = Variable.unify( Variable.VarType.INDEPENDENT, oldCondition.componentAt(index), commonComponent, premise1, premise2); if (!match && (commonComponent.getClass() == oldCondition.getClass())) { match = Variable.unify( Variable.VarType.INDEPENDENT, oldCondition.componentAt(index), ((CompoundTerm) commonComponent).componentAt(index), premise1, premise2); } if (!match) { return; } Term newCondition; if (oldCondition.equals(commonComponent)) { newCondition = null; } else { newCondition = CompoundTerm.replaceComponent(oldCondition, index, newComponent); if ((newCondition instanceof Conjunction) && ((CompoundTerm) newCondition).size() == 1) { newCondition = ((CompoundTerm) newCondition).componentAt(0); } } Term content; if (newCondition != null) { content = RDFStatement.make(premise1, newCondition, premise1.getPredicate(), order1); } else { content = premise1.getPredicate(); } if (content == null) { return; } TruthValue truth1 = taskSentence.getTruth(); TruthValue truth2 = belief.getTruth(); TruthValue truth = null; BudgetValue budget; if (taskSentence instanceof Question) { budget = BudgetFunctions.backwardWeak(truth2); } else { if (taskSentence instanceof Goal) { if (conditionalTask) { truth = TruthFunctions.desireWeak(truth1, truth2); } else if (deduction) { truth = TruthFunctions.desireInd(truth1, truth2); } else { truth = TruthFunctions.desireDed(truth1, truth2); } budget = BudgetFunctions.forward(truth); } else { if (deduction) { truth = TruthFunctions.deduction(truth1, truth2); } else if (conditionalTask) { truth = TruthFunctions.induction(truth2, truth1); } else { truth = TruthFunctions.induction(truth1, truth2); } } budget = BudgetFunctions.forward(truth); } Memory.currentTense = tense; Memory.doublePremiseTask(budget, content, truth); }
/** * {<<M --> S> ==> <M --> P>>, <M --> S>} |- <M --> P> {<<M --> S> ==> <M --> P>>, <M --> P>} |- * <M --> S> * * @param mainSentence The implication/equivalence premise * @param subSentence The premise on part of s1 * @param s The location of s2 in s1 */ static void detachment(Sentence mainSentence, Sentence subSentence, int s) { RDFStatement statement = (RDFStatement) mainSentence.getContent(); Term subject = statement.getSubject(); Term predicate = statement.getPredicate(); Term term = subSentence.getContent(); Term content; int side; if (term.equals(subject)) { side = 0; content = predicate; } else if (term.equals(predicate)) { side = 1; content = subject; } else { return; } if ((content instanceof RDFStatement) && ((RDFStatement) content).invalid()) { return; } Sentence taskSentence = Memory.currentTask.getSentence(); Sentence beliefSentence = Memory.currentBelief; TruthValue beliefTruth = beliefSentence.getTruth(); TruthValue truth1 = mainSentence.getTruth(); TruthValue truth2 = subSentence.getTruth(); TruthValue truth = null; BudgetValue budget; if (taskSentence instanceof Question) { if (statement instanceof Equivalence) { budget = BudgetFunctions.backward(beliefTruth); } else if (side == 0) { budget = BudgetFunctions.backwardWeak(beliefTruth); } else { budget = BudgetFunctions.backward(beliefTruth); } } else { if (taskSentence instanceof Goal) { if (statement instanceof Equivalence) { truth = TruthFunctions.desireStrong(truth1, truth2); } else if (side == 0) { truth = TruthFunctions.desireInd(truth1, truth2); } else { truth = TruthFunctions.desireDed(truth1, truth2); } } else { if (statement instanceof Equivalence) { truth = TruthFunctions.analogy(truth1, truth2); } else if (side == 0) { truth = TruthFunctions.deduction(truth1, truth2); } else { truth = TruthFunctions.abduction(truth2, truth1); } } budget = BudgetFunctions.forward(truth); } TemporalValue tense0 = subSentence.getTense(); TemporalValue order0 = statement.getOrder(); TemporalValue tense; if (order0 == null) { tense = tense0; } else if (side == 0) { tense = TemporalRules.tenseSyllogistic(tense0, subSentence.getCreationTime(), order0); } else { tense = TemporalRules.tenseSyllogistic( tense0, subSentence.getCreationTime(), TemporalValue.getReverse(order0)); } Memory.currentTense = tense; Memory.doublePremiseTask(budget, content, truth); }