Program: 166739
Project: 166739
Buggy source:
/** 
 * Entry point of the inference engine
 * @param tLink The selected TaskLink, which will provide a task
 * @param bLink The selected TermLink, which may provide a belief
 * @param memory Reference to the memory
 */
public static void reason(final TaskLink tLink,final TermLink bLink,final NAL nal){
  final Memory memory=nal.mem();
  memory.logic.REASON.commit(tLink.getPriority());
  final Task task=nal.getCurrentTask();
  final Sentence taskSentence=task.sentence;
  final Term taskTerm=taskSentence.content;
  final Term beliefTerm=bLink.target;
  if ((taskTerm instanceof Statement) && (taskTerm instanceof Implication) && (taskSentence.isJudgment())) {
    if (((Statement)taskTerm).getSubject() instanceof Negation && bLink.target.equals(((Statement)taskTerm).getSubject())) {
      StructuralRules.contraposition((Statement)taskTerm,taskSentence,nal);
    }
  }
  if (equalSubTermsInRespectToImageAndProduct(taskTerm,beliefTerm))   return;
  Concept beliefConcept=memory.concept(beliefTerm);
  Sentence belief=(beliefConcept != null) ? beliefConcept.getBelief(nal,task) : null;
  nal.setCurrentBelief(belief);
  if (belief != null) {
    InternalOperations(memory,belief,nal,beliefTerm,taskTerm);
    if (beliefTerm instanceof Implication && belief.isEternal() && (beliefTerm.getTemporalOrder() == TemporalRules.ORDER_FORWARD || beliefTerm.getTemporalOrder() == TemporalRules.ORDER_CONCURRENT)) {
      for (int i=0; i < Parameters.TEMPORAL_CHAINING_ATTEMPTS; i++) {
        Task best=nal.memory.temporalCoherences.takeNext();
        if (best == null) {
          break;
        }
        nal.memory.temporalCoherences.putBack(best,memory.param.cycles(memory.param.termLinkForgetDurations),memory);
        Sentence s=best.sentence;
        Term t=s.content;
        if (!(t instanceof Implication) || s.getOccurenceTime() != Stamp.ETERNAL)         continue;
        Implication Imp=(Implication)t;
        if (Imp.getTemporalOrder() != TemporalRules.ORDER_FORWARD && Imp.getTemporalOrder() != TemporalRules.ORDER_CONCURRENT) {
          continue;
        }
        Task sich=nal.getCurrentTask();
        nal.setCurrentTask(best);
        if (TemporalRules.temporalInductionChain(s,belief,nal)) {
          break;
        }
        nal.setCurrentTask(sich);
      }
    }
    if (beliefTerm instanceof Implication && (beliefTerm.getTemporalOrder() == TemporalRules.ORDER_FORWARD || beliefTerm.getTemporalOrder() == TemporalRules.ORDER_CONCURRENT) && taskTerm instanceof Implication&& (taskTerm.getTemporalOrder() == TemporalRules.ORDER_FORWARD || taskTerm.getTemporalOrder() == TemporalRules.ORDER_CONCURRENT)) {
      if (taskSentence.isEternal() && belief.isEternal() || belief.after(taskSentence,memory.param.duration.get())) {
        TemporalRules.temporalInductionChain(taskSentence,belief,nal);
      }
    }
    if (LocalRules.match(task,belief,nal)) {
      return;
    }
  }
  if (CompositionalRules.dedSecondLayerVariableUnification(task,nal)) {
    if (taskSentence.isJudgment())     return;
  }
  nal.setCurrentBelief(belief);
  nal.setCurrentTask(task);
  CompositionalRules.dedConjunctionByQuestion(taskSentence,belief,nal);
  final short tIndex=tLink.getIndex(0);
  short bIndex=bLink.getIndex(0);
switch (tLink.type) {
case TermLink.SELF:
switch (bLink.type) {
case TermLink.COMPONENT:
      compoundAndSelf((CompoundTerm)taskTerm,beliefTerm,true,bIndex,nal);
    break;
case TermLink.COMPOUND:
  compoundAndSelf((CompoundTerm)beliefTerm,taskTerm,false,bIndex,nal);
break;
case TermLink.COMPONENT_STATEMENT:
if (belief != null) {
if (taskTerm instanceof Statement) {
  SyllogisticRules.detachment(taskSentence,belief,bIndex,nal);
}
}
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
SyllogisticRules.detachment(belief,taskSentence,bIndex,nal);
}
break;
case TermLink.COMPONENT_CONDITION:
if ((belief != null) && (taskTerm instanceof Implication)) {
bIndex=bLink.getIndex(1);
SyllogisticRules.conditionalDedInd((Implication)taskTerm,bIndex,beliefTerm,tIndex,nal);
}
break;
case TermLink.COMPOUND_CONDITION:
if ((belief != null) && (taskTerm instanceof Implication) && (beliefTerm instanceof Implication)) {
bIndex=bLink.getIndex(1);
SyllogisticRules.conditionalDedInd((Implication)beliefTerm,bIndex,taskTerm,tIndex,nal);
}
break;
}
break;
case TermLink.COMPOUND:
switch (bLink.type) {
case TermLink.COMPOUND:
compoundAndCompound((CompoundTerm)taskTerm,(CompoundTerm)beliefTerm,bIndex,nal);
break;
case TermLink.COMPOUND_STATEMENT:
compoundAndStatement((CompoundTerm)taskTerm,tIndex,(Statement)beliefTerm,bIndex,beliefTerm,nal);
break;
case TermLink.COMPOUND_CONDITION:
if (belief != null) {
if (beliefTerm instanceof Implication) {
Term[] u=new Term[]{beliefTerm,taskTerm};
if (Variables.unify(VAR_INDEPENDENT,((Statement)beliefTerm).getSubject(),taskTerm,u)) {
Sentence newBelief=belief.clone(u[0]);
Sentence newTaskSentence=taskSentence.clone(u[1]);
detachmentWithVar(newBelief,newTaskSentence,bIndex,nal);
}
 else {
SyllogisticRules.conditionalDedInd((Implication)beliefTerm,bIndex,taskTerm,-1,nal);
}
}
 else if (beliefTerm instanceof Equivalence) {
SyllogisticRules.conditionalAna((Equivalence)beliefTerm,bIndex,taskTerm,-1,nal);
}
}
break;
}
break;
case TermLink.COMPOUND_STATEMENT:
switch (bLink.type) {
case TermLink.COMPONENT:
if (taskTerm instanceof Statement) {
componentAndStatement((CompoundTerm)nal.getCurrentTerm(),bIndex,(Statement)taskTerm,tIndex,nal);
}
break;
case TermLink.COMPOUND:
if (taskTerm instanceof Statement) {
compoundAndStatement((CompoundTerm)beliefTerm,bIndex,(Statement)taskTerm,tIndex,beliefTerm,nal);
}
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
syllogisms(tLink,bLink,taskTerm,beliefTerm,nal);
}
break;
case TermLink.COMPOUND_CONDITION:
if (belief != null) {
bIndex=bLink.getIndex(1);
if ((taskTerm instanceof Statement) && (beliefTerm instanceof Implication)) {
conditionalDedIndWithVar((Implication)beliefTerm,bIndex,(Statement)taskTerm,tIndex,nal);
}
}
break;
}
break;
case TermLink.COMPOUND_CONDITION:
switch (bLink.type) {
case TermLink.COMPOUND:
if (belief != null) {
detachmentWithVar(taskSentence,belief,tIndex,nal);
}
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
if (taskTerm instanceof Implication) {
Term subj=((Statement)taskTerm).getSubject();
if (subj instanceof Negation) {
if (taskSentence.isJudgment()) {
componentAndStatement((CompoundTerm)subj,bIndex,(Statement)taskTerm,tIndex,nal);
}
 else {
componentAndStatement((CompoundTerm)subj,tIndex,(Statement)beliefTerm,bIndex,nal);
}
}
 else {
conditionalDedIndWithVar((Implication)taskTerm,tIndex,(Statement)beliefTerm,bIndex,nal);
}
}
break;
}
break;
}
}
}

Fixed version (ground truth):
/** 
 * Entry point of the inference engine
 * @param tLink The selected TaskLink, which will provide a task
 * @param bLink The selected TermLink, which may provide a belief
 * @param memory Reference to the memory
 */
public static void reason(final TaskLink tLink,final TermLink bLink,final NAL nal){
  final Memory memory=nal.mem();
  memory.logic.REASON.commit(tLink.getPriority());
  final Task task=nal.getCurrentTask();
  final Sentence taskSentence=task.sentence;
  final Term taskTerm=taskSentence.content;
  final Term beliefTerm=bLink.target;
  if ((taskTerm instanceof Statement) && (taskTerm instanceof Implication) && (taskSentence.isJudgment())) {
    if (((Statement)taskTerm).getSubject() instanceof Negation && bLink.target.equals(((Statement)taskTerm).getSubject())) {
      StructuralRules.contraposition((Statement)taskTerm,taskSentence,nal);
    }
  }
  if (equalSubTermsInRespectToImageAndProduct(taskTerm,beliefTerm))   return;
  Concept beliefConcept=memory.concept(beliefTerm);
  Sentence belief=(beliefConcept != null) ? beliefConcept.getBelief(nal,task) : null;
  nal.setCurrentBelief(belief);
  if (belief != null) {
    InternalOperations(memory,belief,nal,beliefTerm,taskTerm);
    if (beliefTerm instanceof Implication && belief.isEternal() && (beliefTerm.getTemporalOrder() == TemporalRules.ORDER_FORWARD || beliefTerm.getTemporalOrder() == TemporalRules.ORDER_CONCURRENT)) {
      for (int i=0; i < Parameters.TEMPORAL_CHAINING_ATTEMPTS; i++) {
        Task best=nal.memory.temporalCoherences.takeNext();
        if (best == null) {
          break;
        }
        nal.memory.temporalCoherences.putBack(best,memory.param.cycles(memory.param.termLinkForgetDurations),memory);
        Sentence s=best.sentence;
        Term t=s.content;
        if (!(t instanceof Implication) || s.getOccurenceTime() != Stamp.ETERNAL)         continue;
        Implication Imp=(Implication)t;
        if (Imp.getTemporalOrder() != TemporalRules.ORDER_FORWARD && Imp.getTemporalOrder() != TemporalRules.ORDER_CONCURRENT) {
          continue;
        }
        Task sich=nal.getCurrentTask();
        nal.setCurrentTask(best);
        if (TemporalRules.temporalInductionChain(s,belief,nal)) {
          break;
        }
        nal.setCurrentTask(sich);
      }
    }
    if (beliefTerm instanceof Implication && (beliefTerm.getTemporalOrder() == TemporalRules.ORDER_FORWARD || beliefTerm.getTemporalOrder() == TemporalRules.ORDER_CONCURRENT) && taskTerm instanceof Implication&& (taskTerm.getTemporalOrder() == TemporalRules.ORDER_FORWARD || taskTerm.getTemporalOrder() == TemporalRules.ORDER_CONCURRENT)) {
      if (taskSentence.isEternal() && belief.isEternal() || belief.after(taskSentence,memory.param.duration.get())) {
        TemporalRules.temporalInductionChain(taskSentence,belief,nal);
      }
    }
    if (LocalRules.match(task,belief,nal)) {
      return;
    }
  }
  if (CompositionalRules.dedSecondLayerVariableUnification(task,nal)) {
    if (taskSentence.isJudgment())     return;
  }
  nal.setCurrentBelief(belief);
  nal.setCurrentTask(task);
  CompositionalRules.dedConjunctionByQuestion(taskSentence,belief,nal);
  final short tIndex=tLink.getIndex(0);
  short bIndex=bLink.getIndex(0);
switch (tLink.type) {
case TermLink.SELF:
switch (bLink.type) {
case TermLink.COMPONENT:
      compoundAndSelf((CompoundTerm)taskTerm,beliefTerm,true,bIndex,nal);
    break;
case TermLink.COMPOUND:
  compoundAndSelf((CompoundTerm)beliefTerm,taskTerm,false,bIndex,nal);
break;
case TermLink.COMPONENT_STATEMENT:
if (belief != null) {
if (taskTerm instanceof Statement) {
  SyllogisticRules.detachment(taskSentence,belief,bIndex,nal);
}
}
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
SyllogisticRules.detachment(belief,taskSentence,bIndex,nal);
}
break;
case TermLink.COMPONENT_CONDITION:
if ((belief != null) && (taskTerm instanceof Implication)) {
bIndex=bLink.getIndex(1);
SyllogisticRules.conditionalDedInd((Implication)taskTerm,bIndex,beliefTerm,tIndex,nal);
}
break;
case TermLink.COMPOUND_CONDITION:
if ((belief != null) && (taskTerm instanceof Implication) && (beliefTerm instanceof Implication)) {
bIndex=bLink.getIndex(1);
SyllogisticRules.conditionalDedInd((Implication)beliefTerm,bIndex,taskTerm,tIndex,nal);
}
break;
}
break;
case TermLink.COMPOUND:
switch (bLink.type) {
case TermLink.COMPOUND:
compoundAndCompound((CompoundTerm)taskTerm,(CompoundTerm)beliefTerm,bIndex,nal);
break;
case TermLink.COMPOUND_STATEMENT:
compoundAndStatement((CompoundTerm)taskTerm,tIndex,(Statement)beliefTerm,bIndex,beliefTerm,nal);
break;
case TermLink.COMPOUND_CONDITION:
if (belief != null) {
if (beliefTerm instanceof Implication) {
Term[] u=new Term[]{beliefTerm,taskTerm};
if (Variables.unify(VAR_INDEPENDENT,((Statement)beliefTerm).getSubject(),taskTerm,u)) {
Sentence newBelief=belief.clone(u[0]);
Sentence newTaskSentence=taskSentence.clone(u[1]);
detachmentWithVar(newBelief,newTaskSentence,bIndex,nal);
}
 else {
SyllogisticRules.conditionalDedInd((Implication)beliefTerm,bIndex,taskTerm,-1,nal);
}
}
 else if (beliefTerm instanceof Equivalence) {
SyllogisticRules.conditionalAna((Equivalence)beliefTerm,bIndex,taskTerm,-1,nal);
}
}
break;
}
break;
case TermLink.COMPOUND_STATEMENT:
switch (bLink.type) {
case TermLink.COMPONENT:
if (taskTerm instanceof Statement) {
componentAndStatement((CompoundTerm)nal.getCurrentTerm(),bIndex,(Statement)taskTerm,tIndex,nal);
}
break;
case TermLink.COMPOUND:
if (taskTerm instanceof Statement) {
compoundAndStatement((CompoundTerm)beliefTerm,bIndex,(Statement)taskTerm,tIndex,beliefTerm,nal);
}
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
syllogisms(tLink,bLink,taskTerm,beliefTerm,nal);
}
break;
case TermLink.COMPOUND_CONDITION:
if (belief != null) {
bIndex=bLink.getIndex(1);
if ((taskTerm instanceof Statement) && (beliefTerm instanceof Implication)) {
if (taskSentence.punctuation != Symbols.JUDGMENT_MARK) {
conditionalDedIndWithVar((Implication)beliefTerm,bIndex,(Statement)taskTerm,tIndex,nal);
}
}
}
break;
}
break;
case TermLink.COMPOUND_CONDITION:
switch (bLink.type) {
case TermLink.COMPOUND:
if (belief != null) {
detachmentWithVar(taskSentence,belief,tIndex,nal);
}
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
if (taskTerm instanceof Implication) {
Term subj=((Statement)taskTerm).getSubject();
if (subj instanceof Negation) {
if (taskSentence.isJudgment()) {
componentAndStatement((CompoundTerm)subj,bIndex,(Statement)taskTerm,tIndex,nal);
}
 else {
componentAndStatement((CompoundTerm)subj,tIndex,(Statement)beliefTerm,bIndex,nal);
}
}
 else {
conditionalDedIndWithVar((Implication)taskTerm,tIndex,(Statement)beliefTerm,bIndex,nal);
}
}
break;
}
break;
}
}
}