private void resetVars(K... normals) { vars = inferNormalizationFromTerm(normals); counter = vars.size(); }
private int convert(List<Rule> rules, StringBuilder sb, String functionName, String recursionName, RuleType ruleType, int ruleNum) { NormalizeVariables t = new NormalizeVariables(); Map<AttCompare, List<Rule>> grouping = rules.stream().collect( Collectors.groupingBy(r -> new AttCompare(t.normalize(RewriteToTop.toLeft(r.body())), Sort.class.getName()))); Map<Tuple3<AttCompare, KLabel, AttCompare>, List<Rule>> groupByFirstPrefix = new HashMap<>(); for (Map.Entry<AttCompare, List<Rule>> entry : grouping.entrySet()) { if (lookup == null) return null; K left2 = t.normalize(RewriteToTop.toLeft(r.body())); K normal = t.normalize(t.applyNormalization(lookup.klist().items().get(1), left2), left2); return Tuple3.apply(left, lookup.klabel(), new AttCompare(normal, Sort.class.getName())); }))); left = t.normalize(RewriteToTop.toLeft(r.body())); lookup = t.normalize(t.applyNormalization(getLookup(r, 0).klist().items().get(1), left), left); r = t.normalize(t.applyNormalization(r, left, lookup)); left = t.normalize(RewriteToTop.toLeft(r.body())); lookup = t.normalize(t.applyNormalization(getLookup(r, 0).klist().items().get(1), left), left); r = t.normalize(t.applyNormalization(r, left, lookup));
private String ruleHash(Sentence s) { String text = new NormalizeVariables().normalize(s).toString(); SHA3.Digest256 sha3engine = new SHA3.Digest256(); byte[] digest = sha3engine.digest(text.getBytes()); String digestString = Hex.toHexString(digest); return digestString; } }
public Rule applyNormalization(Rule denormal, K... normals) { return Rule( applyNormalization(denormal.body(), normals), applyNormalization(denormal.requires(), normals), applyNormalization(denormal.ensures(), normals), denormal.att()); }
/** * Applies the normalization existing in a particular set of normalized terms to a denormal term * @param denormal The term to be normalized. Only variables which exist in the specified * {@code normals} are normalized. * @param normals A list of terms that have previously been normalized using this class, or which * have been constructed manually with all variables given the "denormal" * attribute specifying their denormal name. The term to be normalized * will be normalized according to the same normalization as these terms. * @return The normalized version of {@code denormal}, in which each variable present in * the denormal version of the specified {@code normals} is replaced with its normalized * name. */ public K applyNormalization(K denormal, K... normals) { Map<KVariable, String> normalization = inferNormalizationFromTerm(normals); return new TransformK() { @Override public K apply(KVariable k) { if (normalization.containsKey(k)) { return KVariable(normalization.get(k), k.att().add("denormal", k.name())); } return super.apply(k); } }.apply(denormal); }