use of com.acgist.snail.pojo.bean.M3u8.Type in project java-smt by sosy-lab.
the class CVC4FormulaCreator method convertValue.
@Override
public Object convertValue(Expr expForType, Expr value) {
final Type type = expForType.getType();
final Type valueType = value.getType();
if (value.getKind() == Kind.BOUND_VARIABLE) {
// CVC4 does not allow model values for bound vars
return value.toString();
} else if (valueType.isBoolean()) {
return value.getConstBoolean();
} else if (valueType.isInteger() && type.isInteger()) {
return new BigInteger(value.getConstRational().toString());
} else if (valueType.isReal() && type.isReal()) {
Rational rat = value.getConstRational();
return org.sosy_lab.common.rationals.Rational.of(new BigInteger(rat.getNumerator().toString()), new BigInteger(rat.getDenominator().toString()));
} else if (valueType.isBitVector()) {
Integer bv = value.getConstBitVector().getValue();
if (bv.fitsSignedLong()) {
return BigInteger.valueOf(bv.getUnsignedLong());
} else {
// default
return value.toString();
}
} else if (valueType.isFloatingPoint()) {
return parseFloatingPoint(value);
} else if (valueType.isString()) {
return value.getConstString().toString();
} else {
// String serialization for unknown terms.
return value.toString();
}
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project java-smt by sosy-lab.
the class CVC4FormulaCreator method makeBoundCopy.
/**
* Makes a bound copy of a variable for use in quantifier. Note that all occurrences of the free
* var have to be substituted by the bound once it exists.
*
* @param var Variable you want a bound copy of.
* @return Bound Variable
*/
public Expr makeBoundCopy(Expr var) {
Type type = var.getType();
String name = getName(var);
Expr boundCopy = exprManager.mkBoundVar(name, type);
return boundCopy;
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project java-smt by sosy-lab.
the class CVC4ArrayFormulaManager method internalMakeArray.
@Override
@SuppressWarnings("MethodTypeParameterName")
protected <TI extends Formula, TE extends Formula> Expr internalMakeArray(String pName, FormulaType<TI> pIndexType, FormulaType<TE> pElementType) {
final ArrayFormulaType<TI, TE> arrayFormulaType = FormulaType.getArrayType(pIndexType, pElementType);
final Type cvc4ArrayType = toSolverType(arrayFormulaType);
return getFormulaCreator().makeVariable(cvc4ArrayType, pName);
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project java-smt by sosy-lab.
the class CVC4FloatingPointFormulaManager method genericCast.
private Expr genericCast(Expr pNumber, FormulaType<?> pTargetType) {
Type type = pNumber.getType();
FormulaType<?> argType = getFormulaCreator().getFormulaType(pNumber);
Expr castFuncDecl = getFormulaCreator().declareUFImpl("__cast_" + argType + "_to_" + pTargetType, toSolverType(pTargetType), ImmutableList.of(type));
return exprManager.mkExpr(Kind.APPLY_UF, castFuncDecl, pNumber);
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project java-smt by sosy-lab.
the class CVC4FormulaCreator method visit.
@Override
public <R> R visit(FormulaVisitor<R> visitor, Formula formula, final Expr f) {
checkState(!f.isNull());
Type type = f.getType();
if (f.isConst()) {
if (type.isBoolean()) {
return visitor.visitConstant(formula, f.getConstBoolean());
} else if (type.isInteger() || type.isReal()) {
return visitor.visitConstant(formula, f.getConstRational());
} else if (type.isBitVector()) {
// TODO is this correct?
return visitor.visitConstant(formula, f.getConstBitVector().getValue());
} else if (type.isFloatingPoint()) {
// TODO is this correct?
return visitor.visitConstant(formula, f.getConstFloatingPoint());
} else if (type.isRoundingMode()) {
// TODO is this correct?
return visitor.visitConstant(formula, f.getConstRoundingMode());
} else if (type.isString()) {
return visitor.visitConstant(formula, f.getConstString());
} else {
throw new UnsupportedOperationException("Unhandled constant " + f + " with type " + type);
}
} else if (f.getKind() == Kind.BOUND_VARIABLE) {
// BOUND vars are used for all vars that are bound to a quantifier in CVC4.
// We resubstitute them back to the original free.
// CVC4 doesn't give you the de-brujin index
Expr originalVar = variablesCache.get(formula.toString());
return visitor.visitBoundVariable(encapsulate(originalVar), 0);
} else if (f.getKind() == Kind.FORALL || f.getKind() == Kind.EXISTS) {
// QUANTIFIER: replace bound variable with free variable for visitation
assert f.getNumChildren() == 2;
Expr body = f.getChildren().get(1);
List<Formula> freeVars = new ArrayList<>();
for (Expr boundVar : f.getChild(0)) {
// unpack grand-children of f.
String name = getName(boundVar);
Expr freeVar = Preconditions.checkNotNull(variablesCache.get(name));
body = body.substitute(boundVar, freeVar);
freeVars.add(encapsulate(freeVar));
}
BooleanFormula fBody = encapsulateBoolean(body);
Quantifier quant = f.getKind() == Kind.EXISTS ? Quantifier.EXISTS : Quantifier.FORALL;
return visitor.visitQuantifier((BooleanFormula) formula, quant, freeVars, fBody);
} else if (f.isVariable()) {
assert f.getKind() != Kind.BOUND_VARIABLE;
return visitor.visitFreeVariable(formula, getName(f));
} else {
// Expressions like uninterpreted function calls (Kind.APPLY_UF) or operators (e.g. Kind.AND).
// These are all treated like operators, so we can get the declaration by f.getOperator()!
List<Formula> args = ImmutableList.copyOf(Iterables.transform(f, this::encapsulate));
List<FormulaType<?>> argsTypes = new ArrayList<>();
Expr operator = normalize(f.getOperator());
if (operator.getType().isFunction()) {
vectorType argTypes = new FunctionType(operator.getType()).getArgTypes();
for (int i = 0; i < argTypes.size(); i++) {
argsTypes.add(getFormulaTypeFromTermType(argTypes.get(i)));
}
} else {
for (Expr arg : f) {
argsTypes.add(getFormulaType(arg));
}
}
checkState(args.size() == argsTypes.size());
// additional parameters? We do so for some methods of Princess.
return visitor.visitFunction(formula, args, FunctionDeclarationImpl.of(getName(f), getDeclarationKind(f), argsTypes, getFormulaType(f), operator));
}
}
Aggregations