Search in sources :

Example 11 with Implication

use of nars.language.Implication in project opennars by opennars.

the class RuleTables method conditionalDedIndWithVar.

/**
 * Conditional deduction or induction, with variable unification
 *
 * @param conditional The premise that is an Implication with a Conjunction
 * as condition
 * @param index The location of the shared term in the condition
 * @param statement The second premise that is a statement
 * @param side The location of the shared term in the statement
 * @param nal Reference to the memory
 */
private static void conditionalDedIndWithVar(Sentence conditionalSentence, Implication conditional, short index, Statement statement, short side, DerivationContext nal) {
    if (!(conditional.getSubject() instanceof CompoundTerm))
        return;
    CompoundTerm condition = (CompoundTerm) conditional.getSubject();
    if (condition instanceof Conjunction) {
        // conditionalDedIndWithVar
        for (Term t : condition.term) {
            // does not support the case where
            if (t instanceof Variable) {
                // (this can happen since we have # due to image transform,
                return;
            }
        // although not for other conjunctions)
        }
    }
    Term component = condition.term[index];
    Term component2 = null;
    if (statement instanceof Inheritance) {
        component2 = statement;
        side = -1;
    } else if (statement instanceof Implication) {
        component2 = statement.term[side];
    }
    if (component2 != null) {
        Term[] u = new Term[] { conditional, statement };
        if (Variables.unify(VAR_INDEPENDENT, component, component2, u)) {
            conditional = (Implication) u[0];
            statement = (Statement) u[1];
            SyllogisticRules.conditionalDedInd(conditionalSentence, conditional, index, statement, side, nal);
        }
    }
}
Also used : CompoundTerm(nars.language.CompoundTerm) Variable(nars.language.Variable) Inheritance(nars.language.Inheritance) Conjunction(nars.language.Conjunction) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Implication(nars.language.Implication)

Example 12 with Implication

use of nars.language.Implication in project opennars by opennars.

the class RuleTables method syllogisms.

/* ----- syllogistic inferences ----- */
/**
 * Meta-table of syllogistic rules, indexed by the content classes of the
 * taskSentence and the belief
 *
 * @param tLink The link to task
 * @param bLink The link to belief
 * @param taskTerm The content of task
 * @param beliefTerm The content of belief
 * @param nal Reference to the memory
 */
private static void syllogisms(TaskLink tLink, TermLink bLink, Term taskTerm, Term beliefTerm, DerivationContext nal) {
    Sentence taskSentence = nal.getCurrentTask().sentence;
    Sentence belief = nal.getCurrentBelief();
    int figure;
    if (taskTerm instanceof Inheritance) {
        if (beliefTerm instanceof Inheritance) {
            figure = indexToFigure(tLink, bLink);
            asymmetricAsymmetric(taskSentence, belief, figure, nal);
        } else if (beliefTerm instanceof Similarity) {
            figure = indexToFigure(tLink, bLink);
            asymmetricSymmetric(taskSentence, belief, figure, nal);
        } else {
            detachmentWithVar(belief, taskSentence, bLink.getIndex(0), nal);
        }
    } else if (taskTerm instanceof Similarity) {
        if (beliefTerm instanceof Inheritance) {
            figure = indexToFigure(bLink, tLink);
            asymmetricSymmetric(belief, taskSentence, figure, nal);
        } else if (beliefTerm instanceof Similarity) {
            figure = indexToFigure(bLink, tLink);
            symmetricSymmetric(belief, taskSentence, figure, nal);
        } else if (beliefTerm instanceof Implication) {
            // Bridge to higher order statements:
            figure = indexToFigure(tLink, bLink);
            asymmetricSymmetric(belief, taskSentence, figure, nal);
        } else if (beliefTerm instanceof Equivalence) {
            // Bridge to higher order statements:
            figure = indexToFigure(tLink, bLink);
            symmetricSymmetric(belief, taskSentence, figure, nal);
        }
    } else if (taskTerm instanceof Implication) {
        if (beliefTerm instanceof Implication) {
            figure = indexToFigure(tLink, bLink);
            asymmetricAsymmetric(taskSentence, belief, figure, nal);
        } else if (beliefTerm instanceof Equivalence) {
            figure = indexToFigure(tLink, bLink);
            asymmetricSymmetric(taskSentence, belief, figure, nal);
        } else if (beliefTerm instanceof Inheritance) {
            detachmentWithVar(taskSentence, belief, tLink.getIndex(0), nal);
        } else if (beliefTerm instanceof Similarity) {
            // Bridge to higher order statements:
            figure = indexToFigure(tLink, bLink);
            asymmetricSymmetric(taskSentence, belief, figure, nal);
        }
    } else if (taskTerm instanceof Equivalence) {
        if (beliefTerm instanceof Implication) {
            figure = indexToFigure(bLink, tLink);
            asymmetricSymmetric(belief, taskSentence, figure, nal);
        } else if (beliefTerm instanceof Equivalence) {
            figure = indexToFigure(bLink, tLink);
            symmetricSymmetric(belief, taskSentence, figure, nal);
        } else if (beliefTerm instanceof Inheritance) {
            detachmentWithVar(taskSentence, belief, tLink.getIndex(0), nal);
        } else if (beliefTerm instanceof Similarity) {
            // Bridge to higher order statements:
            figure = indexToFigure(tLink, bLink);
            symmetricSymmetric(belief, taskSentence, figure, nal);
        }
    }
}
Also used : Similarity(nars.language.Similarity) Equivalence(nars.language.Equivalence) Inheritance(nars.language.Inheritance) Sentence(nars.entity.Sentence) Implication(nars.language.Implication)

Example 13 with Implication

use of nars.language.Implication in project opennars by opennars.

the class RuleTables method transformTask.

/* ----- inference with one TaskLink only ----- */
/**
 * The TaskLink is of type TRANSFORM, and the conclusion is an equivalent
 * transformation
 *
 * @param tLink The task link
 * @param nal Reference to the memory
 */
public static void transformTask(TaskLink tLink, DerivationContext nal) {
    CompoundTerm content = (CompoundTerm) nal.getCurrentTask().getTerm();
    short[] indices = tLink.index;
    Term inh = null;
    if ((indices.length == 2) || (content instanceof Inheritance)) {
        // <(*, term, #) --> #>
        inh = content;
    } else if (indices.length == 3) {
        // <<(*, term, #) --> #> ==> #>
        inh = content.term[indices[0]];
    } else if (indices.length == 4) {
        // <(&&, <(*, term, #) --> #>, #) ==> #>
        Term component = content.term[indices[0]];
        if ((component instanceof Conjunction) && (((content instanceof Implication) && (indices[0] == 0)) || (content instanceof Equivalence))) {
            Term[] cterms = ((CompoundTerm) component).term;
            if (indices[1] < cterms.length - 1) {
                inh = cterms[indices[1]];
            } else {
                return;
            }
        } else {
            return;
        }
    }
    if (inh instanceof Inheritance) {
        StructuralRules.transformProductImage((Inheritance) inh, content, indices, nal);
    }
}
Also used : CompoundTerm(nars.language.CompoundTerm) Equivalence(nars.language.Equivalence) Inheritance(nars.language.Inheritance) Conjunction(nars.language.Conjunction) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Implication(nars.language.Implication)

Example 14 with Implication

use of nars.language.Implication in project opennars by opennars.

the class RuleTables method goalFromQuestion.

private static void goalFromQuestion(final Task task, final Term taskTerm, final DerivationContext nal) {
    if (task.sentence.punctuation == Symbols.QUESTION_MARK && (taskTerm instanceof Implication || taskTerm instanceof Equivalence)) {
        // <a =/> b>? |- a!
        Term goalterm = null;
        Term goalterm2 = null;
        if (taskTerm instanceof Implication) {
            Implication imp = (Implication) taskTerm;
            if (imp.getTemporalOrder() != TemporalRules.ORDER_BACKWARD || imp.getTemporalOrder() == TemporalRules.ORDER_CONCURRENT) {
                if (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || imp.getSubject() instanceof Operation) {
                    goalterm = imp.getSubject();
                }
                if (goalterm instanceof Variable && goalterm.hasVarQuery() && (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || imp.getPredicate() instanceof Operation)) {
                    // overwrite, it is a how question, in case of <?how =/> b> it is b! which is desired
                    goalterm = imp.getPredicate();
                }
            } else if (imp.getTemporalOrder() == TemporalRules.ORDER_BACKWARD) {
                if (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || imp.getPredicate() instanceof Operation) {
                    goalterm = imp.getPredicate();
                }
                if (goalterm instanceof Variable && goalterm.hasVarQuery() && (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || imp.getSubject() instanceof Operation)) {
                    // overwrite, it is a how question, in case of <?how =/> b> it is b! which is desired
                    goalterm = imp.getSubject();
                }
            }
        } else if (taskTerm instanceof Equivalence) {
            Equivalence qu = (Equivalence) taskTerm;
            if (qu.getTemporalOrder() == TemporalRules.ORDER_FORWARD || qu.getTemporalOrder() == TemporalRules.ORDER_CONCURRENT) {
                if (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || qu.getSubject() instanceof Operation) {
                    goalterm = qu.getSubject();
                }
                if (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || qu.getPredicate() instanceof Operation) {
                    goalterm2 = qu.getPredicate();
                }
            }
        }
        TruthValue truth = new TruthValue(1.0f, Parameters.DEFAULT_GOAL_CONFIDENCE * Parameters.CURIOSITY_DESIRE_CONFIDENCE_MUL);
        if (goalterm != null && !(goalterm instanceof Variable) && goalterm instanceof CompoundTerm) {
            goalterm = ((CompoundTerm) goalterm).transformIndependentVariableToDependentVar((CompoundTerm) goalterm);
            Sentence sent = new Sentence(goalterm, Symbols.GOAL_MARK, truth, new Stamp(task.sentence.stamp, nal.memory.time()));
            nal.singlePremiseTask(sent, new BudgetValue(task.getPriority() * Parameters.CURIOSITY_DESIRE_PRIORITY_MUL, task.getDurability() * Parameters.CURIOSITY_DESIRE_DURABILITY_MUL, BudgetFunctions.truthToQuality(truth)));
        }
        if (goalterm2 != null && !(goalterm2 instanceof Variable) && goalterm2 instanceof CompoundTerm) {
            goalterm2 = ((CompoundTerm) goalterm).transformIndependentVariableToDependentVar((CompoundTerm) goalterm2);
            Sentence sent = new Sentence(goalterm2, Symbols.GOAL_MARK, truth.clone(), new Stamp(task.sentence.stamp, nal.memory.time()));
            nal.singlePremiseTask(sent, new BudgetValue(task.getPriority() * Parameters.CURIOSITY_DESIRE_PRIORITY_MUL, task.getDurability() * Parameters.CURIOSITY_DESIRE_DURABILITY_MUL, BudgetFunctions.truthToQuality(truth)));
        }
    }
}
Also used : CompoundTerm(nars.language.CompoundTerm) BudgetValue(nars.entity.BudgetValue) Variable(nars.language.Variable) Equivalence(nars.language.Equivalence) Stamp(nars.entity.Stamp) TruthValue(nars.entity.TruthValue) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Operation(nars.operator.Operation) Implication(nars.language.Implication) Sentence(nars.entity.Sentence)

Example 15 with Implication

use of nars.language.Implication in project opennars by opennars.

the class StructuralRules method contraposition.

/**
 * {<A ==> B>, A@(--, A)} |- <(--, B) ==> (--, A)>
 *
 * @param statement The premise
 * @param memory Reference to the memory
 */
protected static boolean contraposition(final Statement statement, final Sentence sentence, final DerivationContext nal) {
    Memory memory = nal.mem();
    // memory.logic.CONTRAPOSITION.commit(statement.complexity);
    Term subj = statement.getSubject();
    Term pred = statement.getPredicate();
    Statement content = Statement.make(statement, Negation.make(pred), Negation.make(subj), TemporalRules.reverseOrder(statement.getTemporalOrder()));
    if (content == null)
        return false;
    TruthValue truth = sentence.truth;
    BudgetValue budget;
    if (sentence.isQuestion() || sentence.isQuest()) {
        if (content instanceof Implication) {
            budget = BudgetFunctions.compoundBackwardWeak(content, nal);
        } else {
            budget = BudgetFunctions.compoundBackward(content, nal);
        }
        return nal.singlePremiseTask(content, Symbols.QUESTION_MARK, truth, budget);
    } else {
        if (content instanceof Implication) {
            truth = TruthFunctions.contraposition(truth);
        }
        budget = BudgetFunctions.compoundForward(truth, content, nal);
        return nal.singlePremiseTask(content, Symbols.JUDGMENT_MARK, truth, budget);
    }
}
Also used : BudgetValue(nars.entity.BudgetValue) Memory(nars.storage.Memory) Statement(nars.language.Statement) TruthValue(nars.entity.TruthValue) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Implication(nars.language.Implication)

Aggregations

Implication (nars.language.Implication)16 Term (nars.language.Term)13 CompoundTerm (nars.language.CompoundTerm)11 Sentence (nars.entity.Sentence)10 TruthValue (nars.entity.TruthValue)9 BudgetValue (nars.entity.BudgetValue)8 Equivalence (nars.language.Equivalence)8 Conjunction (nars.language.Conjunction)7 Task (nars.entity.Task)6 Inheritance (nars.language.Inheritance)6 Statement (nars.language.Statement)6 Stamp (nars.entity.Stamp)4 Memory (nars.storage.Memory)4 Events (nars.io.events.Events)3 Interval (nars.language.Interval)3 Variable (nars.language.Variable)3 Concept (nars.entity.Concept)2 ImageExt (nars.language.ImageExt)2 ImageInt (nars.language.ImageInt)2 Product (nars.language.Product)2