Program: 166799
Project: 166799
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 Memory memory){
  final Task task=memory.getCurrentTask();
  Sentence taskSentence=task.getSentence();
  Term taskTerm=(Term)taskSentence.getContent().clone();
  Term beliefTerm=(Term)bLink.getTarget().clone();
  if (CompoundTerm.EqualSubTermsInRespectToImageAndProduct(taskTerm,beliefTerm)) {
    return;
  }
  Concept beliefConcept=memory.termToConcept(beliefTerm);
  Sentence belief=null;
  if (beliefConcept != null) {
    belief=beliefConcept.getBelief(task);
  }
  memory.setCurrentBelief(belief);
  if (belief != null) {
    LocalRules.match(task,belief,memory);
  }
  Sentence buf1=memory.getCurrentBelief();
  Task buf2=memory.getCurrentTask();
  CompositionalRules.dedSecondLayerVariableUnification(task,memory);
  memory.setCurrentBelief(buf1);
  memory.setCurrentTask(buf2);
  if (!memory.noResult() && task.getSentence().isJudgment()) {
    return;
  }
  CompositionalRules.dedConjunctionByQuestion(taskSentence,belief,memory);
  short tIndex=tLink.getIndex(0);
  short bIndex=bLink.getIndex(0);
switch (tLink.getType()) {
case TermLink.SELF:
switch (bLink.getType()) {
case TermLink.COMPONENT:
      compoundAndSelf((CompoundTerm)taskTerm,beliefTerm,true,memory);
    break;
case TermLink.COMPOUND:
  compoundAndSelf((CompoundTerm)beliefTerm,taskTerm,false,memory);
break;
case TermLink.COMPONENT_STATEMENT:
if (belief != null) {
SyllogisticRules.detachment(task.getSentence(),belief,bIndex,memory);
}
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
SyllogisticRules.detachment(belief,task.getSentence(),bIndex,memory);
}
break;
case TermLink.COMPONENT_CONDITION:
if (belief != null) {
bIndex=bLink.getIndex(1);
SyllogisticRules.conditionalDedInd((Implication)taskTerm,bIndex,beliefTerm,tIndex,memory);
}
break;
case TermLink.COMPOUND_CONDITION:
if (belief != null) {
bIndex=bLink.getIndex(1);
SyllogisticRules.conditionalDedInd((Implication)beliefTerm,bIndex,taskTerm,tIndex,memory);
}
break;
}
break;
case TermLink.COMPOUND:
switch (bLink.getType()) {
case TermLink.COMPOUND:
compoundAndCompound((CompoundTerm)taskTerm,(CompoundTerm)beliefTerm,memory);
break;
case TermLink.COMPOUND_STATEMENT:
compoundAndStatement((CompoundTerm)taskTerm,tIndex,(Statement)beliefTerm,bIndex,beliefTerm,memory);
break;
case TermLink.COMPOUND_CONDITION:
if (belief != null) {
if (beliefTerm instanceof Implication) {
if (Variable.unify(Symbols.VAR_INDEPENDENT,((Implication)beliefTerm).getSubject(),taskTerm,beliefTerm,taskTerm)) {
detachmentWithVar(belief,taskSentence,bIndex,memory);
}
 else {
SyllogisticRules.conditionalDedInd((Implication)beliefTerm,bIndex,taskTerm,-1,memory);
}
}
 else if (beliefTerm instanceof Equivalence) {
SyllogisticRules.conditionalAna((Equivalence)beliefTerm,bIndex,taskTerm,-1,memory);
}
}
break;
}
break;
case TermLink.COMPOUND_STATEMENT:
switch (bLink.getType()) {
case TermLink.COMPONENT:
componentAndStatement((CompoundTerm)memory.getCurrentTerm(),bIndex,(Statement)taskTerm,tIndex,memory);
break;
case TermLink.COMPOUND:
compoundAndStatement((CompoundTerm)beliefTerm,bIndex,(Statement)taskTerm,tIndex,beliefTerm,memory);
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
syllogisms(tLink,bLink,taskTerm,beliefTerm,memory);
}
break;
case TermLink.COMPOUND_CONDITION:
if (belief != null) {
bIndex=bLink.getIndex(1);
if (beliefTerm instanceof Implication) {
conditionalDedIndWithVar((Implication)beliefTerm,bIndex,(Statement)taskTerm,tIndex,memory);
}
}
break;
}
break;
case TermLink.COMPOUND_CONDITION:
switch (bLink.getType()) {
case TermLink.COMPOUND:
if (belief != null) {
detachmentWithVar(taskSentence,belief,tIndex,memory);
}
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
if (taskTerm instanceof Implication) {
Term subj=((Implication)taskTerm).getSubject();
if (subj instanceof Negation) {
if (task.getSentence().isJudgment()) {
componentAndStatement((CompoundTerm)subj,bIndex,(Statement)taskTerm,tIndex,memory);
}
 else {
componentAndStatement((CompoundTerm)subj,tIndex,(Statement)beliefTerm,bIndex,memory);
}
}
 else {
conditionalDedIndWithVar((Implication)taskTerm,tIndex,(Statement)beliefTerm,bIndex,memory);
}
}
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 Memory memory){
  final Task task=memory.getCurrentTask();
  Sentence taskSentence=task.getSentence();
  Term taskTerm=(Term)taskSentence.getContent().clone();
  Term beliefTerm=(Term)bLink.target.clone();
  if (CompoundTerm.EqualSubTermsInRespectToImageAndProduct(taskTerm,beliefTerm)) {
    return;
  }
  Concept beliefConcept=memory.termToConcept(beliefTerm);
  Sentence belief=null;
  if (beliefConcept != null) {
    belief=beliefConcept.getBelief(task);
  }
  memory.setCurrentBelief(belief);
  if (belief != null) {
    LocalRules.match(task,belief,memory);
  }
  Sentence buf1=memory.getCurrentBelief();
  Task buf2=memory.getCurrentTask();
  CompositionalRules.dedSecondLayerVariableUnification(task,memory);
  memory.setCurrentBelief(buf1);
  memory.setCurrentTask(buf2);
  if (!memory.noResult() && task.getSentence().isJudgment()) {
    return;
  }
  CompositionalRules.dedConjunctionByQuestion(taskSentence,belief,memory);
  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,memory);
    break;
case TermLink.COMPOUND:
  compoundAndSelf((CompoundTerm)beliefTerm,taskTerm,false,memory);
break;
case TermLink.COMPONENT_STATEMENT:
if (belief != null) {
SyllogisticRules.detachment(task.getSentence(),belief,bIndex,memory);
}
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
SyllogisticRules.detachment(belief,task.getSentence(),bIndex,memory);
}
break;
case TermLink.COMPONENT_CONDITION:
if (belief != null) {
bIndex=bLink.getIndex(1);
SyllogisticRules.conditionalDedInd((Implication)taskTerm,bIndex,beliefTerm,tIndex,memory);
}
break;
case TermLink.COMPOUND_CONDITION:
if (belief != null) {
bIndex=bLink.getIndex(1);
SyllogisticRules.conditionalDedInd((Implication)beliefTerm,bIndex,taskTerm,tIndex,memory);
}
break;
}
break;
case TermLink.COMPOUND:
switch (bLink.type) {
case TermLink.COMPOUND:
compoundAndCompound((CompoundTerm)taskTerm,(CompoundTerm)beliefTerm,memory);
break;
case TermLink.COMPOUND_STATEMENT:
compoundAndStatement((CompoundTerm)taskTerm,tIndex,(Statement)beliefTerm,bIndex,beliefTerm,memory);
break;
case TermLink.COMPOUND_CONDITION:
if (belief != null) {
if (beliefTerm instanceof Implication) {
if (Variable.unify(Symbols.VAR_INDEPENDENT,((Implication)beliefTerm).getSubject(),taskTerm,beliefTerm,taskTerm)) {
detachmentWithVar(belief,taskSentence,bIndex,memory);
}
 else {
SyllogisticRules.conditionalDedInd((Implication)beliefTerm,bIndex,taskTerm,-1,memory);
}
}
 else if (beliefTerm instanceof Equivalence) {
SyllogisticRules.conditionalAna((Equivalence)beliefTerm,bIndex,taskTerm,-1,memory);
}
}
break;
}
break;
case TermLink.COMPOUND_STATEMENT:
switch (bLink.type) {
case TermLink.COMPONENT:
componentAndStatement((CompoundTerm)memory.getCurrentTerm(),bIndex,(Statement)taskTerm,tIndex,memory);
break;
case TermLink.COMPOUND:
compoundAndStatement((CompoundTerm)beliefTerm,bIndex,(Statement)taskTerm,tIndex,beliefTerm,memory);
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
syllogisms(tLink,bLink,taskTerm,beliefTerm,memory);
}
break;
case TermLink.COMPOUND_CONDITION:
if (belief != null) {
bIndex=bLink.getIndex(1);
if (beliefTerm instanceof Implication) {
conditionalDedIndWithVar((Implication)beliefTerm,bIndex,(Statement)taskTerm,tIndex,memory);
}
}
break;
}
break;
case TermLink.COMPOUND_CONDITION:
switch (bLink.type) {
case TermLink.COMPOUND:
if (belief != null) {
detachmentWithVar(taskSentence,belief,tIndex,memory);
}
break;
case TermLink.COMPOUND_STATEMENT:
if (belief != null) {
if (taskTerm instanceof Implication) {
Term subj=((Implication)taskTerm).getSubject();
if (subj instanceof Negation) {
if (task.getSentence().isJudgment()) {
componentAndStatement((CompoundTerm)subj,bIndex,(Statement)taskTerm,tIndex,memory);
}
 else {
componentAndStatement((CompoundTerm)subj,tIndex,(Statement)beliefTerm,bIndex,memory);
}
}
 else {
conditionalDedIndWithVar((Implication)taskTerm,tIndex,(Statement)beliefTerm,bIndex,memory);
}
}
break;
}
break;
}
}
}