Program: 166676
Project: 166676
Buggy source:
/** 
 * Introduce a dependent variable in an outer-layer conjunction {<S --> P1>, <S --> P2>} |- (&&, <#x --> P1>, <#x --> P2>)
 * @param taskContent The first premise <M --> S>
 * @param beliefContent The second premise <M --> P>
 * @param index The location of the shared term: 0 for subject, 1 forpredicate
 * @param nal Reference to the memory
 */
public static void introVarOuter(final Statement taskContent,final Statement beliefContent,final int index,final DerivationContext nal){
  if (!(taskContent instanceof Inheritance)) {
    return;
  }
  final Variable varInd1=new Variable("String_Node_Str");
  final Variable varInd2=new Variable("String_Node_Str");
  Term term11dependent=null, term12dependent=null, term21dependent=null, term22dependent=null;
  Term term11=index == 0 ? varInd1 : taskContent.getSubject();
  Term term21=index == 0 ? varInd1 : beliefContent.getSubject();
  Term term12=index == 0 ? taskContent.getPredicate() : varInd1;
  Term term22=index == 0 ? beliefContent.getPredicate() : varInd1;
  if (index == 0) {
    term12dependent=term12;
    term22dependent=term22;
  }
 else {
    term11dependent=term11;
    term21dependent=term21;
  }
  Term commonTerm=null;
  final Map<Term,Term> subs=new HashMap<>();
  if (index == 0) {
    if (term12 instanceof ImageExt) {
      boolean firstIsImage=term22 instanceof ImageExt;
      boolean secondIsSameImage=true;
      commonTerm=findCommonTermPredicate(term12,term22,commonTerm,firstIsImage,secondIsSameImage);
      if (commonTerm != null) {
        subs.put(commonTerm,varInd2);
        term12=((CompoundTerm)term12).applySubstitute(subs);
        term22=applySubstituteIfCompoundTerm(varInd2,term22,subs);
      }
    }
    if (commonTerm == null && term22 instanceof ImageExt) {
      boolean firstIsImage=term12 instanceof ImageExt;
      boolean secondIsSameImage=true;
      commonTerm=findCommonTermPredicate(term22,term12,commonTerm,firstIsImage,secondIsSameImage);
      if (commonTerm != null) {
        subs.put(commonTerm,varInd2);
        term22=((CompoundTerm)term22).applySubstitute(subs);
        term12=applySubstituteIfCompoundTerm(varInd2,term12,subs);
      }
    }
  }
 else {
    if (term21 instanceof ImageInt) {
      boolean firstIsImage=true;
      boolean secondIsSameImage=term11 instanceof ImageInt;
      commonTerm=findCommonSubject(term11,term21,commonTerm,firstIsImage,secondIsSameImage);
      if (commonTerm != null) {
        subs.put(commonTerm,varInd2);
        term21=((CompoundTerm)term21).applySubstitute(subs);
        term11=applySubstituteIfCompoundTerm(varInd2,term11,subs);
      }
    }
    if (commonTerm == null && term11 instanceof ImageInt) {
      boolean firstIsImage=true;
      boolean secondIsSameImage=term21 instanceof ImageInt;
      commonTerm=findCommonSubject(term21,term11,commonTerm,firstIsImage,secondIsSameImage);
      if (commonTerm != null) {
        subs.put(commonTerm,varInd2);
        term11=((CompoundTerm)term11).applySubstitute(subs);
        term21=applySubstituteIfCompoundTerm(varInd2,term21,subs);
      }
    }
  }
  Statement state1=Inheritance.make(term11,term12);
  Statement state2=Inheritance.make(term21,term22);
  Term content=Implication.make(state1,state2);
  if (content == null) {
    return;
  }
  final TruthValue truthT=nal.getCurrentTask().sentence.truth;
  final TruthValue truthB=nal.getCurrentBelief().truth;
  if ((truthT == null) || (truthB == null)) {
    if (Parameters.DEBUG) {
      System.out.println("String_Node_Str");
    }
    return;
  }
  TruthValue truth=induction(truthT,truthB);
  BudgetValue budget=BudgetFunctions.compoundForward(truth,content,nal);
  nal.doublePremiseTask(content,truth,budget,false,false);
  content=Implication.make(state2,state1);
  truth=induction(truthB,truthT);
  budget=BudgetFunctions.compoundForward(truth,content,nal);
  nal.doublePremiseTask(content,truth,budget,false,false);
  content=Equivalence.make(state1,state2);
  truth=comparison(truthT,truthB);
  budget=BudgetFunctions.compoundForward(truth,content,nal);
  nal.doublePremiseTask(content,truth,budget,false,false);
  final Variable varDep=new Variable("String_Node_Str");
  if (index == 0) {
    state1=Inheritance.make(varDep,term12dependent);
    state2=Inheritance.make(varDep,term22dependent);
  }
 else {
    state1=Inheritance.make(term11dependent,varDep);
    state2=Inheritance.make(term21dependent,varDep);
  }
  if ((state1 == null) || (state2 == null))   return;
  content=Conjunction.make(state1,state2);
  truth=intersection(truthT,truthB);
  budget=BudgetFunctions.compoundForward(truth,content,nal);
  nal.doublePremiseTask(content,truth,budget,false,false);
}

Fixed version (ground truth):
/** 
 * Introduce a dependent variable in an outer-layer conjunction {<S --> P1>, <S --> P2>} |- (&&, <#x --> P1>, <#x --> P2>)
 * @param taskContent The first premise <M --> S>
 * @param beliefContent The second premise <M --> P>
 * @param index The location of the shared term: 0 for subject, 1 forpredicate
 * @param nal Reference to the memory
 */
public static void introVarOuter(final Statement taskContent,final Statement beliefContent,final int index,final DerivationContext nal){
  if (!(taskContent instanceof Inheritance)) {
    return;
  }
  final Variable varInd1=new Variable("String_Node_Str");
  final Variable varInd2=new Variable("String_Node_Str");
  Term term11dependent=null, term12dependent=null, term21dependent=null, term22dependent=null;
  Term term11=index == 0 ? varInd1 : taskContent.getSubject();
  Term term21=index == 0 ? varInd1 : beliefContent.getSubject();
  Term term12=index == 0 ? taskContent.getPredicate() : varInd1;
  Term term22=index == 0 ? beliefContent.getPredicate() : varInd1;
  if (index == 0) {
    term12dependent=term12;
    term22dependent=term22;
  }
 else {
    term11dependent=term11;
    term21dependent=term21;
  }
  Term commonTerm=null;
  final Map<Term,Term> subs=new HashMap<>();
  if (index == 0) {
    if (term12 instanceof ImageExt) {
      boolean firstIsImage=term22 instanceof ImageExt;
      boolean secondIsSameImage=true;
      commonTerm=findCommonTermPredicate(term12,term22,commonTerm,firstIsImage,secondIsSameImage);
      if (commonTerm != null) {
        subs.put(commonTerm,varInd2);
        term12=((CompoundTerm)term12).applySubstitute(subs);
        term22=applySubstituteIfCompoundTerm(varInd2,term22,subs);
      }
    }
    if (commonTerm == null && term22 instanceof ImageExt) {
      boolean firstIsImage=term12 instanceof ImageExt;
      boolean secondIsSameImage=true;
      commonTerm=findCommonTermPredicate(term22,term12,commonTerm,firstIsImage,secondIsSameImage);
      if (commonTerm != null) {
        subs.put(commonTerm,varInd2);
        term22=((CompoundTerm)term22).applySubstitute(subs);
        term12=applySubstituteIfCompoundTerm(varInd2,term12,subs);
      }
    }
  }
 else {
    if (term21 instanceof ImageInt) {
      boolean firstIsImage=true;
      boolean secondIsSameImage=term11 instanceof ImageInt;
      commonTerm=findCommonSubject(term11,term21,commonTerm,firstIsImage,secondIsSameImage);
      if (commonTerm != null) {
        subs.put(commonTerm,varInd2);
        term21=((CompoundTerm)term21).applySubstitute(subs);
        term11=applySubstituteIfCompoundTerm(varInd2,term11,subs);
      }
    }
    if (commonTerm == null && term11 instanceof ImageInt) {
      boolean firstIsImage=true;
      boolean secondIsSameImage=term21 instanceof ImageInt;
      commonTerm=findCommonSubject(term21,term11,commonTerm,firstIsImage,secondIsSameImage);
      if (commonTerm != null) {
        subs.put(commonTerm,varInd2);
        term11=((CompoundTerm)term11).applySubstitute(subs);
        term21=applySubstituteIfCompoundTerm(varInd2,term21,subs);
      }
    }
  }
  Statement state1=Inheritance.make(term11,term12);
  Statement state2=Inheritance.make(term21,term22);
  Term content=Implication.make(state1,state2);
  if (content == null) {
    return;
  }
  final TruthValue truthT=nal.getCurrentTask().sentence.truth;
  final TruthValue truthB=nal.getCurrentBelief().truth;
  if ((truthT == null) || (truthB == null)) {
    if (Parameters.DEBUG) {
      System.out.println("String_Node_Str");
    }
    return;
  }
  TruthValue truth=induction(truthT,truthB);
  BudgetValue budget=BudgetFunctions.compoundForward(truth,content,nal);
  nal.doublePremiseTask(content,truth,budget,false,false);
  content=Implication.make(state2,state1);
  truth=induction(truthB,truthT);
  budget=BudgetFunctions.compoundForward(truth,content,nal);
  nal.doublePremiseTask(content,truth,budget,false,false);
  content=Equivalence.make(state1,state2);
  truth=comparison(truthT,truthB);
  budget=BudgetFunctions.compoundForward(truth,content,nal);
  nal.doublePremiseTask(content,truth,budget,false,false);
  final Variable varDep=new Variable("String_Node_Str");
  if (index == 0) {
    state1=Inheritance.make(varDep,term12dependent);
    state2=Inheritance.make(varDep,term22dependent);
  }
 else {
    state1=Inheritance.make(term11dependent,varDep);
    state2=Inheritance.make(term21dependent,varDep);
  }
  if ((state1 == null) || (state2 == null)) {
    return;
  }
  if (state1.cloneDeep().equals(state2.cloneDeep())) {
    return;
  }
  content=Conjunction.make(state1,state2);
  truth=intersection(truthT,truthB);
  budget=BudgetFunctions.compoundForward(truth,content,nal);
  nal.doublePremiseTask(content,truth,budget,false,false);
}