use of com.acgist.snail.pojo.bean.M3u8.Type in project java-smt by sosy-lab.
the class CVC4NativeAPITest method checkLIAUfsSat.
@Test
public void checkLIAUfsSat() {
// f(x) = x + 1
// f(y) = y - 1
// x = y -> f(x) + f(y) = x AND f(x) + f(y) = y
Expr one = exprMgr.mkConst(new Rational(1));
Type intType = exprMgr.integerType();
// Type for UFs later
Type intToInt = exprMgr.mkFunctionType(intType, intType);
Expr xInt = exprMgr.mkVar("x", intType);
Expr yInt = exprMgr.mkVar("y", intType);
// declare UFs
Expr f = exprMgr.mkVar("f", intToInt);
// Apply UFs
Expr fx = exprMgr.mkExpr(Kind.APPLY_UF, f, xInt);
Expr fy = exprMgr.mkExpr(Kind.APPLY_UF, f, yInt);
Expr plus = exprMgr.mkExpr(Kind.PLUS, fx, fy);
Expr plusEqx = exprMgr.mkExpr(Kind.EQUAL, plus, xInt);
Expr plusEqy = exprMgr.mkExpr(Kind.EQUAL, plus, yInt);
Expr xEqy = exprMgr.mkExpr(Kind.EQUAL, yInt, xInt);
Expr xEqyImplplusEqxAndy = exprMgr.mkExpr(Kind.IMPLIES, xEqy, exprMgr.mkExpr(Kind.AND, plusEqx, plusEqy));
Expr assumptions = exprMgr.mkExpr(Kind.AND, exprMgr.mkExpr(Kind.EQUAL, fx, exprMgr.mkExpr(Kind.PLUS, xInt, one)), exprMgr.mkExpr(Kind.EQUAL, fy, exprMgr.mkExpr(Kind.MINUS, yInt, one)), xEqyImplplusEqxAndy);
smtEngine.assertFormula(assumptions);
Result satCheck = smtEngine.checkSat();
assertThat(satCheck.isSat()).isEqualTo(Sat.SAT);
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project java-smt by sosy-lab.
the class CVC4NativeAPITest method checkQuantifierWithUf.
@SuppressWarnings("unused")
@Test
public void checkQuantifierWithUf() throws FileNotFoundException, UnsupportedEncodingException {
Expr var = exprMgr.mkVar("var", exprMgr.integerType());
// start with a normal, free variable!
Expr boundVar = exprMgr.mkVar("boundVar", exprMgr.integerType());
Expr varIsOne = exprMgr.mkExpr(Kind.EQUAL, var, exprMgr.mkConst(new Rational(1)));
// try not to use 0 as this is the default value for CVC4 models
Expr boundVarIsTwo = exprMgr.mkExpr(Kind.EQUAL, boundVar, exprMgr.mkConst(new Rational(2)));
Expr boundVarIsOne = exprMgr.mkExpr(Kind.EQUAL, boundVar, exprMgr.mkConst(new Rational(1)));
String func = "func";
Type intType = exprMgr.integerType();
Type ufType = exprMgr.mkFunctionType(intType, intType);
Expr uf = exprMgr.mkVar(func, ufType);
Expr funcAtBoundVar = exprMgr.mkExpr(uf, boundVar);
Expr body = exprMgr.mkExpr(Kind.AND, boundVarIsTwo, exprMgr.mkExpr(Kind.EQUAL, var, funcAtBoundVar));
// This is the bound variable used for boundVar
Expr boundVarBound = exprMgr.mkBoundVar("boundVar", exprMgr.integerType());
vectorExpr vec = new vectorExpr();
vec.add(boundVarBound);
Expr quantifiedVars = exprMgr.mkExpr(Kind.BOUND_VAR_LIST, vec);
// Subst all boundVar variables with the bound version
Expr bodySubst = body.substitute(boundVar, boundVarBound);
Expr quantFormula = exprMgr.mkExpr(Kind.EXISTS, quantifiedVars, bodySubst);
// var = 1 & boundVar = 1 & exists boundVar . ( boundVar = 2 & f(boundVar) = var )
Expr overallFormula = exprMgr.mkExpr(Kind.AND, varIsOne, boundVarIsOne, quantFormula);
smtEngine.assertFormula(overallFormula);
Result satCheck = smtEngine.checkSat();
// SAT
assertThat(satCheck.isSat()).isEqualTo(Sat.SAT);
// check Model
// var = 1 & boundVar = 1 & exists boundVar . ( boundVar = 2 & f(2) = 1 )
// It seems like CVC4 can't return quantified variables,
// therefore we can't get a value for the uf!
assertThat(smtEngine.getValue(var).toString()).isEqualTo("1");
assertThat(smtEngine.getValue(boundVar).toString()).isEqualTo("1");
assertThat(smtEngine.getValue(funcAtBoundVar).toString()).isEqualTo("1");
assertThat(smtEngine.getValue(boundVarBound).toString()).isEqualTo("boundVar");
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project java-smt by sosy-lab.
the class CVC4NativeAPITest method checkCustomTypesAndUFs.
@Test
public void checkCustomTypesAndUFs() {
// 0 <= f(x)
// 0 <= f(y)
// f(x) + f(y) <= 1
// not p(0)
// p(f(y))
Expr zero = exprMgr.mkConst(new Rational(0));
Expr one = exprMgr.mkConst(new Rational(1));
Type boolType = exprMgr.booleanType();
Type intType = exprMgr.integerType();
// You may use custom sorts just like bool or int
SortType mySort = exprMgr.mkSort("f");
// Type for UFs later
Type mySortToInt = exprMgr.mkFunctionType(mySort, intType);
Type intToBool = exprMgr.mkFunctionType(intType, boolType);
Expr xTyped = exprMgr.mkVar("x", mySort);
Expr yTyped = exprMgr.mkVar("y", mySort);
// declare UFs
Expr f = exprMgr.mkVar("f", mySortToInt);
Expr p = exprMgr.mkVar("p", intToBool);
// Apply UFs
Expr fx = exprMgr.mkExpr(Kind.APPLY_UF, f, xTyped);
Expr fy = exprMgr.mkExpr(Kind.APPLY_UF, f, yTyped);
Expr sum = exprMgr.mkExpr(Kind.PLUS, fx, fy);
Expr p0 = exprMgr.mkExpr(Kind.APPLY_UF, p, zero);
Expr pfy = exprMgr.mkExpr(Kind.APPLY_UF, p, fy);
// Make some assumptions
Expr assumptions = exprMgr.mkExpr(Kind.AND, exprMgr.mkExpr(Kind.LEQ, zero, fx), exprMgr.mkExpr(Kind.LEQ, zero, fy), exprMgr.mkExpr(Kind.LEQ, sum, one), p0.notExpr(), pfy);
smtEngine.assertFormula(assumptions);
Result satCheck = smtEngine.checkSat();
assertThat(satCheck.isSat()).isEqualTo(Sat.SAT);
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project openwebbeans by apache.
the class SubclassProxyFactory method delegateNonInterceptedMethods.
@Override
protected void delegateNonInterceptedMethods(ClassLoader classLoader, ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, Method[] noninterceptedMethods) throws ProxyGenerationException {
for (Method delegatedMethod : noninterceptedMethods) {
if (unproxyableMethod(delegatedMethod)) {
continue;
}
String methodDescriptor = Type.getMethodDescriptor(delegatedMethod);
// X TODO handle generic exception types?
Class[] exceptionTypes = delegatedMethod.getExceptionTypes();
String[] exceptionTypeNames = new String[exceptionTypes.length];
for (int i = 0; i < exceptionTypes.length; i++) {
exceptionTypeNames[i] = Type.getType(exceptionTypes[i]).getInternalName();
}
int targetModifiers = delegatedMethod.getModifiers() & (Modifier.PROTECTED | Modifier.PUBLIC | MODIFIER_VARARGS);
MethodVisitor mv = cw.visitMethod(targetModifiers, delegatedMethod.getName(), methodDescriptor, null, exceptionTypeNames);
// fill method body
mv.visitCode();
boolean abstractMethod = Modifier.isAbstract(delegatedMethod.getModifiers());
// now calculate the parameters
int offset = 1;
for (Class<?> aClass : delegatedMethod.getParameterTypes()) {
Type type = Type.getType(aClass);
mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), offset);
offset += type.getSize();
}
// and finally invoke the target method on the provided Contextual Instance
Type declaringClass = Type.getType(delegatedMethod.getDeclaringClass());
if (!abstractMethod) {
// invoke the method on the super class;
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, declaringClass.getInternalName(), delegatedMethod.getName(), methodDescriptor, false);
}
generateReturn(mv, delegatedMethod);
mv.visitMaxs(-1, -1);
mv.visitEnd();
}
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project openwebbeans by apache.
the class InterceptorDecoratorProxyFactory method delegateNonInterceptedMethods.
/**
* Directly delegate all non intercepted nor decorated methods to the internal instance.
*
* @param noninterceptedMethods all methods which are neither intercepted nor decorated
*/
@Override
protected void delegateNonInterceptedMethods(ClassLoader classLoader, ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, Method[] noninterceptedMethods) {
for (Method delegatedMethod : noninterceptedMethods) {
if (unproxyableMethod(delegatedMethod) || isIgnoredMethod(delegatedMethod)) {
continue;
}
int modifiers = delegatedMethod.getModifiers();
if (Modifier.isProtected(modifiers) && !delegatedMethod.getDeclaringClass().getPackage().getName().equals(classToProxy.getPackage().getName())) {
continue;
}
String methodDescriptor = Type.getMethodDescriptor(delegatedMethod);
// X TODO handle generic exception types?
Class[] exceptionTypes = delegatedMethod.getExceptionTypes();
String[] exceptionTypeNames = new String[exceptionTypes.length];
for (int i = 0; i < exceptionTypes.length; i++) {
exceptionTypeNames[i] = Type.getType(exceptionTypes[i]).getInternalName();
}
int targetModifiers = modifiers & (Modifier.PROTECTED | Modifier.PUBLIC | MODIFIER_VARARGS);
MethodVisitor mv = cw.visitMethod(targetModifiers, delegatedMethod.getName(), methodDescriptor, null, exceptionTypeNames);
// fill method body
mv.visitCode();
// load the delegate variable
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, proxyClassFileName, FIELD_PROXIED_INSTANCE, Type.getDescriptor(classToProxy));
int offset = 1;
for (Class<?> aClass : delegatedMethod.getParameterTypes()) {
Type type = Type.getType(aClass);
mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), offset);
offset += type.getSize();
}
Type declaringClass = Type.getType(delegatedMethod.getDeclaringClass());
boolean isItf = delegatedMethod.getDeclaringClass().isInterface();
mv.visitMethodInsn(isItf ? Opcodes.INVOKEINTERFACE : Opcodes.INVOKEVIRTUAL, declaringClass.getInternalName(), delegatedMethod.getName(), methodDescriptor, isItf);
generateReturn(mv, delegatedMethod);
mv.visitMaxs(-1, -1);
mv.visitEnd();
}
}
Aggregations