|
3 | 3 | * SPDX-License-Identifier: GPL-2.0-only */ |
4 | 4 | package de.uka.ilkd.key.strategy.quantifierHeuristics.theory; |
5 | 5 |
|
| 6 | + |
| 7 | +import java.util.ArrayList; |
| 8 | +import java.util.LinkedHashMap; |
6 | 9 | import java.util.List; |
| 10 | +import java.util.Map; |
| 11 | +import java.util.Set; |
7 | 12 |
|
8 | 13 | import de.uka.ilkd.key.java.Services; |
9 | 14 | import de.uka.ilkd.key.logic.JTerm; |
| 15 | +import de.uka.ilkd.key.logic.TermBuilder; |
10 | 16 | import de.uka.ilkd.key.logic.op.Equality; |
11 | 17 | import de.uka.ilkd.key.logic.op.Junctor; |
| 18 | +import de.uka.ilkd.key.logic.op.LogicVariable; |
| 19 | +import de.uka.ilkd.key.proof.OpReplacer; |
| 20 | +import de.uka.ilkd.key.strategy.quantifierHeuristics.constraint.Constraint; |
| 21 | +import de.uka.ilkd.key.strategy.quantifierHeuristics.constraint.EqualityConstraint; |
| 22 | +import de.uka.ilkd.key.strategy.quantifierHeuristics.constraint.Metavariable; |
12 | 23 |
|
13 | 24 | import org.key_project.logic.op.Operator; |
14 | 25 | import org.key_project.logic.op.QuantifiableVariable; |
@@ -103,4 +114,66 @@ public LiteralDecision decideFromAxiom(JTerm literal, JTerm axiom, Services serv |
103 | 114 | } |
104 | 115 | return LiteralDecision.UNKNOWN; |
105 | 116 | } |
| 117 | + |
| 118 | + @Override |
| 119 | + public List<JTerm> fallbackTriggers(ClauseTriggers selection, Services services, |
| 120 | + MetavariableFactory metavariableFactory) { |
| 121 | + List<JTerm> fallbackTriggers = new ArrayList<>(); |
| 122 | + final ClauseAnalysis clauseInfo = selection.clause(); |
| 123 | + |
| 124 | + final Map<QuantifiableVariable, Metavariable> qv2mv = new LinkedHashMap<>(); |
| 125 | + final Map<Metavariable, QuantifiableVariable> mv2qv = new LinkedHashMap<>(); |
| 126 | + for (QuantifiableVariable var : clauseInfo.clause().freeVars()) { |
| 127 | + final Metavariable mv = metavariableFactory.fresh(var.sort()); |
| 128 | + qv2mv.put(var, mv); |
| 129 | + if (clauseInfo.universalVariables().contains(var)) { |
| 130 | + mv2qv.put(mv, var); |
| 131 | + } |
| 132 | + } |
| 133 | + final OpReplacer qv2mvReplacer = |
| 134 | + new OpReplacer(qv2mv, services.getTermFactory()); |
| 135 | + final OpReplacer mv2qvReplacer = |
| 136 | + new OpReplacer(mv2qv, services.getTermFactory()); |
| 137 | + for (JTerm lit : clauseInfo.literals()) { |
| 138 | + if (lit.op() == Equality.EQUALS) { |
| 139 | + fallbackTriggers.addAll( |
| 140 | + solveEquation(mv2qv.keySet(), qv2mvReplacer, mv2qvReplacer, lit, services)); |
| 141 | + } |
| 142 | + } |
| 143 | + return fallbackTriggers; |
| 144 | + } |
| 145 | + |
| 146 | + /// solves equation f(u) = f(g(v)) to u = g(MV_V) |
| 147 | + /// @param mvs set of Metavariables used to replace **universal** bound variables |
| 148 | + /// @param qv2mv OpReplacer to replace all free variables in lit by their meta variables |
| 149 | + /// @param mv2qv OpReplacer to restore universal (not existential) bound variables |
| 150 | + /// @param lit the JTerm representing an uncovered literal |
| 151 | + /// @param services the Services class provides access to term construction and other services |
| 152 | + /// @return list of solved equations that describe triggers |
| 153 | + private List<JTerm> solveEquation(Set<Metavariable> mvs, OpReplacer qv2mv, |
| 154 | + OpReplacer mv2qv, JTerm lit, |
| 155 | + Services services) { |
| 156 | + final TermBuilder tb = services.getTermBuilder(); |
| 157 | + final JTerm litWithMV = qv2mv.replace(lit); |
| 158 | + final Constraint c = |
| 159 | + EqualityConstraint.BOTTOM.unify(litWithMV.sub(0), litWithMV.sub(1), services); |
| 160 | + List<JTerm> solvedEquations = new ArrayList<>(); |
| 161 | + if (c.isSatisfiable()) { |
| 162 | + for (final Metavariable mv : mvs) { |
| 163 | + final JTerm solution = c.getInstantiation(mv, services); |
| 164 | + final Operator instOp = solution.op(); |
| 165 | + if (instOp instanceof LogicVariable || |
| 166 | + instOp instanceof Metavariable) { |
| 167 | + // solutions that are a variable |
| 168 | + // and contain no function symbol do not |
| 169 | + // make useful triggers |
| 170 | + continue; |
| 171 | + } |
| 172 | + final JTerm solvedEquation = mv2qv.replace(tb.equals(tb.var(mv), solution)); |
| 173 | + solvedEquations.add(solvedEquation); |
| 174 | + solvedEquations.add(tb.equals(solvedEquation.sub(1), solvedEquation.sub(0))); |
| 175 | + } |
| 176 | + } |
| 177 | + return solvedEquations; |
| 178 | + } |
106 | 179 | } |
0 commit comments