Search in sources :

Example 1 with TranslationOptions

use of de.bmoth.backend.TranslationOptions in project bmoth by hhu-stups.

the class MachineTranslatorTest method testInvariantGeneration.

@Test
public void testInvariantGeneration() {
    assertEquals(translator.getInvariantConstraint(), translator.getInvariantConstraint(TranslationOptions.UNPRIMED));
    assertEquals("(let ((a!1 (forall ((a Int) (b Int))\n" + "             (! (let ((a!1 (ite (= 0 (mod b 2))\n" + "                                (* (POWER_OF a (div b 2))\n" + "                                   (POWER_OF a (div b 2)))\n" + "                                (* a (POWER_OF a (- b 1))))))\n" + "                  (= (POWER_OF a b) (ite (= 0 b) 1 a!1)))\n" + "                :pattern ((POWER_OF a b))\n" + "                :weight 2\n" + "                :qid |:rec-fun|))))\n" + "  (and true (= (POWER_OF x 2) (* x x)) a!1))", translator.getInvariantConstraint().toString());
    assertEquals("(let ((a!1 (forall ((a Int) (b Int))\n" + "             (! (let ((a!1 (ite (= 0 (mod b 2))\n" + "                                (* (POWER_OF a (div b 2))\n" + "                                   (POWER_OF a (div b 2)))\n" + "                                (* a (POWER_OF a (- b 1))))))\n" + "                  (= (POWER_OF a b) (ite (= 0 b) 1 a!1)))\n" + "                :pattern ((POWER_OF a b))\n" + "                :weight 2\n" + "                :qid |:rec-fun|))))\n" + "  (and true (= (POWER_OF |x'24| 2) (* |x'24| |x'24|)) a!1))", translator.getInvariantConstraint(new TranslationOptions(24)).toString());
}
Also used : TranslationOptions(de.bmoth.backend.TranslationOptions) Test(org.junit.Test)

Example 2 with TranslationOptions

use of de.bmoth.backend.TranslationOptions in project bmoth by hhu-stups.

the class MachineTranslatorTest method testInitialValueGeneration.

@Test
public void testInitialValueGeneration() {
    assertEquals(translator.getInitialValueConstraint(), translator.getInitialValueConstraint(TranslationOptions.PRIMED_0));
    assertEquals("(= |x'0| (- 3))", translator.getInitialValueConstraint().toString());
    assertEquals("(= |x'1024| (- 3))", translator.getInitialValueConstraint(new TranslationOptions(1024)).toString());
}
Also used : TranslationOptions(de.bmoth.backend.TranslationOptions) Test(org.junit.Test)

Example 3 with TranslationOptions

use of de.bmoth.backend.TranslationOptions in project bmoth by hhu-stups.

the class MachineToZ3Translator method getDistinctVars.

public BoolExpr getDistinctVars(int from, int to) {
    if (tuple == null) {
        Expr[] variables = getVariables().stream().map(this::getVariable).toArray(Expr[]::new);
        Symbol[] symbols = Arrays.stream(variables).map(var -> var.getFuncDecl().getName()).toArray(Symbol[]::new);
        Sort[] sorts = Arrays.stream(variables).map(Expr::getSort).toArray(Sort[]::new);
        tuple = z3Context.mkTupleSort(z3Context.mkSymbol("tuple"), symbols, sorts);
    }
    Expr[] distinct = new Expr[to - from + 1];
    for (int v = from, i = 0; v <= to; v++, i++) {
        int finalV = v;
        Expr[] vector = getVariables().stream().map(var -> getPrimedVariable(var, new TranslationOptions(finalV))).toArray(Expr[]::new);
        distinct[i] = tuple.mkDecl().apply(vector);
    }
    return z3Context.mkDistinct(distinct);
}
Also used : SubstitutionOptions(de.bmoth.backend.SubstitutionOptions) java.util(java.util) com.microsoft.z3(com.microsoft.z3) PRIMED_0(de.bmoth.backend.TranslationOptions.PRIMED_0) UNPRIMED(de.bmoth.backend.TranslationOptions.UNPRIMED) de.bmoth.parser.ast.nodes(de.bmoth.parser.ast.nodes) SubstitutionVisitor(de.bmoth.parser.ast.visitors.SubstitutionVisitor) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) TranslationOptions(de.bmoth.backend.TranslationOptions) TranslationOptions(de.bmoth.backend.TranslationOptions)

Example 4 with TranslationOptions

use of de.bmoth.backend.TranslationOptions in project bmoth by hhu-stups.

the class TranslationOptionTest method testToString.

@Test
public void testToString() {
    TranslationOptions ops = new TranslationOptions(234);
    assertEquals("prime level 234", ops.toString());
    assertEquals("prime level 0", PRIMED_0.toString());
    assertEquals("not primed", UNPRIMED.toString());
}
Also used : TranslationOptions(de.bmoth.backend.TranslationOptions) Test(org.junit.Test)

Example 5 with TranslationOptions

use of de.bmoth.backend.TranslationOptions in project bmoth by hhu-stups.

the class MachineTranslatorTest method testOperationsGeneration.

@Test
public void testOperationsGeneration() {
    assertEquals(1, translator.getOperationConstraints().size());
    assertEquals(translator.getOperationConstraints(), translator.getOperationConstraints(new SubstitutionOptions(TranslationOptions.PRIMED_0, TranslationOptions.UNPRIMED)));
    assertEquals("[(and (< x 50) (= |x'0| (+ x 1)))]", translator.getOperationConstraints().toString());
    assertEquals("[(and (< |x'128| 50) (= |x'512| (+ |x'128| 1)))]", translator.getOperationConstraints(new SubstitutionOptions(new TranslationOptions(512), new TranslationOptions(128))).toString());
}
Also used : SubstitutionOptions(de.bmoth.backend.SubstitutionOptions) TranslationOptions(de.bmoth.backend.TranslationOptions) Test(org.junit.Test)

Aggregations

TranslationOptions (de.bmoth.backend.TranslationOptions)6 Test (org.junit.Test)5 SubstitutionOptions (de.bmoth.backend.SubstitutionOptions)3 Streams (com.google.common.collect.Streams)1 com.microsoft.z3 (com.microsoft.z3)1 PRIMED_0 (de.bmoth.backend.TranslationOptions.PRIMED_0)1 UNPRIMED (de.bmoth.backend.TranslationOptions.UNPRIMED)1 de.bmoth.parser.ast.nodes (de.bmoth.parser.ast.nodes)1 SubstitutionVisitor (de.bmoth.parser.ast.visitors.SubstitutionVisitor)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1