|
@@ -60,7 +60,7 @@ public class Matcher {
|
|
|
|
|
|
public static List<Substitution> matchS(BetaEtaNormal rigid, BetaEtaNormal flexible) {
|
|
public static List<Substitution> matchS(BetaEtaNormal rigid, BetaEtaNormal flexible) {
|
|
List<Term> matches = match(rigid, flexible);
|
|
List<Term> matches = match(rigid, flexible);
|
|
- Variable v = HeadOps.asVariable(flexible.getHead()).get();
|
|
|
|
|
|
+ Variable v = HeadOps.asVariableYolo(flexible.getHead());
|
|
List<Substitution> substitutions = new ArrayList<>(matches.size());
|
|
List<Substitution> substitutions = new ArrayList<>(matches.size());
|
|
for (Term match : matches) {
|
|
for (Term match : matches) {
|
|
Substitution sub = new Substitution(v, match);
|
|
Substitution sub = new Substitution(v, match);
|
|
@@ -78,7 +78,6 @@ public class Matcher {
|
|
|
|
|
|
public static List<Term> match(RigidFlexible rigidFlexible) {
|
|
public static List<Term> match(RigidFlexible rigidFlexible) {
|
|
BetaEtaNormal rigid = rigidFlexible.getRigid();
|
|
BetaEtaNormal rigid = rigidFlexible.getRigid();
|
|
- BetaEtaNormal flexible = rigidFlexible.getFlexible();
|
|
|
|
List<Term> res = new ArrayList<>();
|
|
List<Term> res = new ArrayList<>();
|
|
Optional<Constant> rigidConstant = HeadOps.asConstant(rigid.getHead());
|
|
Optional<Constant> rigidConstant = HeadOps.asConstant(rigid.getHead());
|
|
rigidConstant.ifPresent(c -> res.add(imitate(rigidFlexible)));
|
|
rigidConstant.ifPresent(c -> res.add(imitate(rigidFlexible)));
|
|
@@ -95,7 +94,7 @@ public class Matcher {
|
|
// yooo check if the type matches
|
|
// yooo check if the type matches
|
|
Type pType = TypeCalculator.calculateType(e);
|
|
Type pType = TypeCalculator.calculateType(e);
|
|
Type acType = ((Variable) rigidFlexible.flexible.getHead().getTerm()).getType();
|
|
Type acType = ((Variable) rigidFlexible.flexible.getHead().getTerm()).getType();
|
|
- // it's not mentioned in paper, but it can (and likely) will) happen that the type of arg is different than contnt
|
|
|
|
|
|
+ // it's not mentioned in paper, but it can (and likely will) happen that the type of arg is different from content
|
|
if (pType.equals(acType)) {
|
|
if (pType.equals(acType)) {
|
|
res.add(e);
|
|
res.add(e);
|
|
}
|
|
}
|
|
@@ -113,20 +112,7 @@ public class Matcher {
|
|
for (int j = 0; j < headType.arity(); j++) {
|
|
for (int j = 0; j < headType.arity(); j++) {
|
|
// arg od benheadBinder, index J
|
|
// arg od benheadBinder, index J
|
|
Term l3l = benHeadBinder.getArguments().get(j);
|
|
Term l3l = benHeadBinder.getArguments().get(j);
|
|
- Type targetType = TypeCalculator.calculateType(l3l);
|
|
|
|
-
|
|
|
|
- for (int k = binders.size() - 1; k >= 0; k--) {
|
|
|
|
- targetType = new ArrowType(binders.get(k).getType(), targetType);
|
|
|
|
- }
|
|
|
|
- Variable hi = new Variable(Id.uniqueId(), targetType);
|
|
|
|
- BetaEtaNormal arg = BetaEtaNormal.fromFakeNormal(
|
|
|
|
- new Head.HeadVariable(hi),
|
|
|
|
- new ArrayList<>(),
|
|
|
|
- new ArrayList<>(binders) // replacement binders are arg's argyments
|
|
|
|
- );
|
|
|
|
- Term term = arg.backToTerm();
|
|
|
|
- TypeCalculator.calculateType(term); //sanity check
|
|
|
|
- args.add(term);
|
|
|
|
|
|
+ args.add(argOfArg(binders, l3l));
|
|
}
|
|
}
|
|
Term term = BetaEtaNormal.fromFakeNormal(newHead, binders, args).backToTerm();
|
|
Term term = BetaEtaNormal.fromFakeNormal(newHead, binders, args).backToTerm();
|
|
TypeCalculator.calculateType(term);
|
|
TypeCalculator.calculateType(term);
|
|
@@ -147,23 +133,30 @@ public class Matcher {
|
|
Head newHead = rigidFlexible.getRigid().getHead();
|
|
Head newHead = rigidFlexible.getRigid().getHead();
|
|
List<Term> args = new ArrayList<>(rigidFlexible.rigidTermsArgumentsSize());
|
|
List<Term> args = new ArrayList<>(rigidFlexible.rigidTermsArgumentsSize());
|
|
for (Term rigidArg : rigidFlexible.rigidTermArguments()) {
|
|
for (Term rigidArg : rigidFlexible.rigidTermArguments()) {
|
|
- Type targetType = TypeCalculator.calculateType(rigidArg);
|
|
|
|
- for (int i = binders.size() - 1; i >= 0; i--) {
|
|
|
|
- targetType = new ArrowType(binders.get(i).getType(), targetType);
|
|
|
|
- }
|
|
|
|
- Variable hi = new Variable(Id.uniqueId(), targetType);
|
|
|
|
- BetaEtaNormal arg = BetaEtaNormal.fromFakeNormal(
|
|
|
|
- new Head.HeadVariable(hi),
|
|
|
|
- new ArrayList<>(),
|
|
|
|
- new ArrayList<>(binders) // replacement binders are arg's arguments
|
|
|
|
- );
|
|
|
|
- Term term = arg.backToTerm();
|
|
|
|
- TypeCalculator.calculateType(term); //sanity check
|
|
|
|
- args.add(term);
|
|
|
|
|
|
+ args.add(argOfArg(binders, rigidArg));
|
|
}
|
|
}
|
|
|
|
|
|
Term term = BetaEtaNormal.fromFakeNormal(newHead, binders, args).backToTerm();
|
|
Term term = BetaEtaNormal.fromFakeNormal(newHead, binders, args).backToTerm();
|
|
TypeCalculator.calculateType(term);
|
|
TypeCalculator.calculateType(term);
|
|
return term;
|
|
return term;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private static Term argOfArg(List<Variable> binders, Term realArgUponWhichTheArgArgIsBased) {
|
|
|
|
+
|
|
|
|
+ Type targetType = TypeCalculator.calculateType(realArgUponWhichTheArgArgIsBased);
|
|
|
|
+
|
|
|
|
+ for (int k = binders.size() - 1; k >= 0; k--) {
|
|
|
|
+ targetType = new ArrowType(binders.get(k).getType(), targetType);
|
|
|
|
+ }
|
|
|
|
+ Variable hi = new Variable(Id.uniqueId(), targetType);
|
|
|
|
+ BetaEtaNormal arg = BetaEtaNormal.fromFakeNormal(
|
|
|
|
+ new Head.HeadVariable(hi),
|
|
|
|
+ new ArrayList<>(),
|
|
|
|
+ new ArrayList<>(binders) // replacement binders are arg's arguments
|
|
|
|
+ );
|
|
|
|
+ Term term = arg.backToTerm();
|
|
|
|
+ TypeCalculator.calculateType(term); //sanity check
|
|
|
|
+ return term;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|