Search in sources :

Example 1 with DifferenceExt

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

the class CompositionalRules method decomposeCompound.

/**
 * {<(S|P) ==> M>, <P ==> M>} |- <S ==> M>
 *
 * @param implication The implication term to be decomposed
 * @param componentCommon The part of the implication to be removed
 * @param term1 The other term in the contentInd
 * @param index The location of the shared term: 0 for subject, 1 for
 * predicate
 * @param compoundTask Whether the implication comes from the task
 * @param nal Reference to the memory
 */
private static void decomposeCompound(CompoundTerm compound, Term component, Term term1, int index, boolean compoundTask, int order, DerivationContext nal) {
    if ((compound instanceof Statement) || (compound instanceof ImageExt) || (compound instanceof ImageInt)) {
        return;
    }
    Term term2 = reduceComponents(compound, component, nal.mem());
    if (term2 == null) {
        return;
    }
    long delta = 0;
    while ((term2 instanceof Conjunction) && (((CompoundTerm) term2).term[0] instanceof Interval)) {
        Interval interval = (Interval) ((CompoundTerm) term2).term[0];
        delta += interval.time;
        term2 = ((CompoundTerm) term2).setComponent(0, null, nal.mem());
    }
    Task task = nal.getCurrentTask();
    Sentence sentence = task.sentence;
    Sentence belief = nal.getCurrentBelief();
    Statement oldContent = (Statement) task.getTerm();
    TruthValue v1, v2;
    if (compoundTask) {
        v1 = sentence.truth;
        v2 = belief.truth;
    } else {
        v1 = belief.truth;
        v2 = sentence.truth;
    }
    TruthValue truth = null;
    Term content;
    if (index == 0) {
        content = Statement.make(oldContent, term1, term2, order);
        if (content == null) {
            return;
        }
        if (oldContent instanceof Inheritance) {
            if (compound instanceof IntersectionExt) {
                truth = reduceConjunction(v1, v2);
            } else if (compound instanceof IntersectionInt) {
                truth = reduceDisjunction(v1, v2);
            } else if ((compound instanceof SetInt) && (component instanceof SetInt)) {
                truth = reduceConjunction(v1, v2);
            } else if ((compound instanceof SetExt) && (component instanceof SetExt)) {
                truth = reduceDisjunction(v1, v2);
            } else if (compound instanceof DifferenceExt) {
                if (compound.term[0].equals(component)) {
                    truth = reduceDisjunction(v2, v1);
                } else {
                    truth = reduceConjunctionNeg(v1, v2);
                }
            }
        } else if (oldContent instanceof Implication) {
            if (compound instanceof Conjunction) {
                truth = reduceConjunction(v1, v2);
            } else if (compound instanceof Disjunction) {
                truth = reduceDisjunction(v1, v2);
            }
        }
    } else {
        content = Statement.make(oldContent, term2, term1, order);
        if (content == null) {
            return;
        }
        if (oldContent instanceof Inheritance) {
            if (compound instanceof IntersectionInt) {
                truth = reduceConjunction(v1, v2);
            } else if (compound instanceof IntersectionExt) {
                truth = reduceDisjunction(v1, v2);
            } else if ((compound instanceof SetExt) && (component instanceof SetExt)) {
                truth = reduceConjunction(v1, v2);
            } else if ((compound instanceof SetInt) && (component instanceof SetInt)) {
                truth = reduceDisjunction(v1, v2);
            } else if (compound instanceof DifferenceInt) {
                if (compound.term[1].equals(component)) {
                    truth = reduceDisjunction(v2, v1);
                } else {
                    truth = reduceConjunctionNeg(v1, v2);
                }
            }
        } else if (oldContent instanceof Implication) {
            if (compound instanceof Disjunction) {
                truth = reduceConjunction(v1, v2);
            } else if (compound instanceof Conjunction) {
                truth = reduceDisjunction(v1, v2);
            }
        }
    }
    if (truth != null) {
        BudgetValue budget = BudgetFunctions.compoundForward(truth, content, nal);
        if (delta != 0) {
            long baseTime = task.sentence.getOccurenceTime();
            if (baseTime != Stamp.ETERNAL) {
                baseTime += delta;
                nal.getTheNewStamp().setOccurrenceTime(baseTime);
            }
        }
        // (allow overlap), a form of detachment
        nal.doublePremiseTask(content, truth, budget, false, true);
    }
}
Also used : CompoundTerm(nars.language.CompoundTerm) BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Statement(nars.language.Statement) Inheritance(nars.language.Inheritance) ImageInt(nars.language.ImageInt) SetInt(nars.language.SetInt) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) IntersectionInt(nars.language.IntersectionInt) Implication(nars.language.Implication) DifferenceInt(nars.language.DifferenceInt) Disjunction(nars.language.Disjunction) TruthFunctions.reduceDisjunction(nars.inference.TruthFunctions.reduceDisjunction) IntersectionExt(nars.language.IntersectionExt) TruthValue(nars.entity.TruthValue) TruthFunctions.reduceConjunction(nars.inference.TruthFunctions.reduceConjunction) Conjunction(nars.language.Conjunction) SetExt(nars.language.SetExt) ImageExt(nars.language.ImageExt) DifferenceExt(nars.language.DifferenceExt) Sentence(nars.entity.Sentence) Interval(nars.language.Interval)

Example 2 with DifferenceExt

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

the class StructuralRules method structuralCompose1.

/**
 * {<S --> P>, P@(P|Q)} |- <S --> (P|Q)>
 *
 * @param compound The compound term
 * @param index The location of the indicated term in the compound
 * @param statement The premise
 * @param nal Reference to the memory
 */
static void structuralCompose1(CompoundTerm compound, short index, Statement statement, DerivationContext nal) {
    if (!nal.getCurrentTask().sentence.isJudgment()) {
        // forward inference only
        return;
    }
    Term component = compound.term[index];
    Task task = nal.getCurrentTask();
    Sentence sentence = task.sentence;
    int order = sentence.getTemporalOrder();
    TruthValue truth = sentence.truth;
    final float reliance = Parameters.reliance;
    TruthValue truthDed = TruthFunctions.deduction(truth, reliance);
    TruthValue truthNDed = TruthFunctions.negation(TruthFunctions.deduction(truth, reliance));
    Term subj = statement.getSubject();
    Term pred = statement.getPredicate();
    if (component.equals(subj)) {
        if (compound instanceof IntersectionExt) {
            structuralStatement(compound, pred, order, truthDed, nal);
        } else if (compound instanceof IntersectionInt) {
        } else if ((compound instanceof DifferenceExt) && (index == 0)) {
            structuralStatement(compound, pred, order, truthDed, nal);
        } else if (compound instanceof DifferenceInt) {
            if (index == 0) {
            } else {
                structuralStatement(compound, pred, order, truthNDed, nal);
            }
        }
    } else if (component.equals(pred)) {
        if (compound instanceof IntersectionExt) {
        } else if (compound instanceof IntersectionInt) {
            structuralStatement(subj, compound, order, truthDed, nal);
        } else if (compound instanceof DifferenceExt) {
            if (index == 0) {
            } else {
                structuralStatement(subj, compound, order, truthNDed, nal);
            }
        } else if ((compound instanceof DifferenceInt) && (index == 0)) {
            structuralStatement(subj, compound, order, truthDed, nal);
        }
    }
}
Also used : Task(nars.entity.Task) IntersectionExt(nars.language.IntersectionExt) TruthValue(nars.entity.TruthValue) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) DifferenceExt(nars.language.DifferenceExt) Sentence(nars.entity.Sentence) IntersectionInt(nars.language.IntersectionInt) DifferenceInt(nars.language.DifferenceInt)

Example 3 with DifferenceExt

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

the class StructuralRules method structuralDecompose1.

/**
 * {<(S|T) --> P>, S@(S|T)} |- <S --> P> {<S --> (P&T)>, P@(P&T)} |- <S --> P>
 *
 * @param compound The compound term
 * @param index The location of the indicated term in the compound
 * @param statement The premise
 * @param nal Reference to the memory
 */
static void structuralDecompose1(CompoundTerm compound, short index, Statement statement, DerivationContext nal) {
    if (index >= compound.term.length) {
        return;
    }
    Term component = compound.term[index];
    Task task = nal.getCurrentTask();
    Sentence sentence = task.sentence;
    int order = sentence.getTemporalOrder();
    TruthValue truth = sentence.truth;
    if (truth == null) {
        return;
    }
    final float reliance = Parameters.reliance;
    TruthValue truthDed = TruthFunctions.deduction(truth, reliance);
    TruthValue truthNDed = TruthFunctions.negation(TruthFunctions.deduction(truth, reliance));
    Term subj = statement.getSubject();
    Term pred = statement.getPredicate();
    if (compound.equals(subj)) {
        if (compound instanceof IntersectionInt) {
            structuralStatement(component, pred, order, truthDed, nal);
        } else if ((compound instanceof SetExt) && (compound.size() > 1)) {
            Term[] t1 = new Term[] { component };
            structuralStatement(new SetExt(t1), pred, order, truthDed, nal);
        } else if (compound instanceof DifferenceInt) {
            if (index == 0) {
                structuralStatement(component, pred, order, truthDed, nal);
            } else {
                structuralStatement(component, pred, order, truthNDed, nal);
            }
        }
    } else if (compound.equals(pred)) {
        if (compound instanceof IntersectionExt) {
            structuralStatement(subj, component, order, truthDed, nal);
        } else if ((compound instanceof SetInt) && (compound.size() > 1)) {
            structuralStatement(subj, new SetInt(component), order, truthDed, nal);
        } else if (compound instanceof DifferenceExt) {
            if (index == 0) {
                structuralStatement(subj, component, order, truthDed, nal);
            } else {
                structuralStatement(subj, component, order, truthNDed, nal);
            }
        }
    }
}
Also used : Task(nars.entity.Task) IntersectionExt(nars.language.IntersectionExt) TruthValue(nars.entity.TruthValue) SetExt(nars.language.SetExt) SetInt(nars.language.SetInt) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) DifferenceExt(nars.language.DifferenceExt) Sentence(nars.entity.Sentence) IntersectionInt(nars.language.IntersectionInt) DifferenceInt(nars.language.DifferenceInt)

Aggregations

Sentence (nars.entity.Sentence)3 Task (nars.entity.Task)3 TruthValue (nars.entity.TruthValue)3 CompoundTerm (nars.language.CompoundTerm)3 DifferenceExt (nars.language.DifferenceExt)3 DifferenceInt (nars.language.DifferenceInt)3 IntersectionExt (nars.language.IntersectionExt)3 IntersectionInt (nars.language.IntersectionInt)3 Term (nars.language.Term)3 SetExt (nars.language.SetExt)2 SetInt (nars.language.SetInt)2 BudgetValue (nars.entity.BudgetValue)1 TruthFunctions.reduceConjunction (nars.inference.TruthFunctions.reduceConjunction)1 TruthFunctions.reduceDisjunction (nars.inference.TruthFunctions.reduceDisjunction)1 Conjunction (nars.language.Conjunction)1 Disjunction (nars.language.Disjunction)1 ImageExt (nars.language.ImageExt)1 ImageInt (nars.language.ImageInt)1 Implication (nars.language.Implication)1 Inheritance (nars.language.Inheritance)1