import { Z3_ast, Z3_ast_map, Z3_ast_vector, Z3_context, Z3_decl_kind, Z3_func_decl, Z3_func_entry, Z3_func_interp, Z3_model, Z3_probe, Z3_solver, Z3_optimize, Z3_sort, Z3_sort_kind, Z3_tactic, Z3_goal, Z3_apply_result } from '../low-level'; /** @hidden */ export type AnySort = Sort | BoolSort | ArithSort | BitVecSort | SMTArraySort; /** @hidden */ export type AnyExpr = Expr | Bool | Arith | IntNum | RatNum | BitVec | BitVecNum | SMTArray; /** @hidden */ export type AnyAst = AnyExpr | AnySort | FuncDecl; /** @hidden */ export type SortToExprMap, Name extends string = 'main'> = S extends BoolSort ? Bool : S extends ArithSort ? Arith : S extends BitVecSort ? BitVec : S extends SMTArraySort ? SMTArray : S extends Sort ? Expr : never; /** @hidden */ export type CoercibleFromMap, Name extends string = 'main'> = S extends bigint ? Arith : S extends number | CoercibleRational ? RatNum : S extends boolean ? Bool : S extends Expr ? S : never; /** @hidden */ export type CoercibleToBitVec = bigint | number | BitVec; export type CoercibleRational = { numerator: bigint | number; denominator: bigint | number; }; /** @hidden */ export type CoercibleToExpr = number | string | bigint | boolean | CoercibleRational | Expr; /** @hidden */ export type CoercibleToArith = number | string | bigint | CoercibleRational | Arith; /** @hidden */ export type CoercibleToMap, Name extends string = 'main'> = T extends Bool ? boolean | Bool : T extends IntNum ? bigint | number | IntNum : T extends RatNum ? bigint | number | CoercibleRational | RatNum : T extends Arith ? CoercibleToArith : T extends BitVec ? CoercibleToBitVec : T extends SMTArray ? SMTArray : T extends Expr ? Expr : never; /** * Used to create a Real constant * * ```typescript * const x = from({ numerator: 1, denominator: 3 }) * * x * // 1/3 * isReal(x) * // true * isRealVal(x) * // true * x.asNumber() * // 0.3333333333333333 * ``` * @see {@link Context.from} * @category Global */ export declare class Z3Error extends Error { } export declare class Z3AssertionError extends Z3Error { } /** @category Global */ export type CheckSatResult = 'sat' | 'unsat' | 'unknown'; /** @hidden */ export interface ContextCtor { (name: Name, options?: Record): Context; } export interface Context { /** @hidden */ readonly ptr: Z3_context; /** * Name of the current Context * * ```typescript * const c = new Context('main') * * c.name * // 'main' * ``` */ readonly name: Name; /** @category Functions */ interrupt(): void; /** @category Functions */ isModel(obj: unknown): obj is Model; /** @category Functions */ isAst(obj: unknown): obj is Ast; /** @category Functions */ isSort(obj: unknown): obj is Sort; /** @category Functions */ isFuncDecl(obj: unknown): obj is FuncDecl; /** @category Functions */ isFuncInterp(obj: unknown): obj is FuncInterp; /** @category Functions */ isApp(obj: unknown): boolean; /** @category Functions */ isConst(obj: unknown): boolean; /** @category Functions */ isExpr(obj: unknown): obj is Expr; /** @category Functions */ isVar(obj: unknown): boolean; /** @category Functions */ isAppOf(obj: unknown, kind: Z3_decl_kind): boolean; /** @category Functions */ isBool(obj: unknown): obj is Bool; /** @category Functions */ isTrue(obj: unknown): boolean; /** @category Functions */ isFalse(obj: unknown): boolean; /** @category Functions */ isAnd(obj: unknown): boolean; /** @category Functions */ isOr(obj: unknown): boolean; /** @category Functions */ isImplies(obj: unknown): boolean; /** @category Functions */ isNot(obj: unknown): boolean; /** @category Functions */ isEq(obj: unknown): boolean; /** @category Functions */ isDistinct(obj: unknown): boolean; /** @category Functions */ isQuantifier(obj: unknown): obj is Quantifier; /** @category Functions */ isArith(obj: unknown): obj is Arith; /** @category Functions */ isArithSort(obj: unknown): obj is ArithSort; /** @category Functions */ isInt(obj: unknown): boolean; /** @category Functions */ isIntVal(obj: unknown): obj is IntNum; /** @category Functions */ isIntSort(obj: unknown): boolean; /** @category Functions */ isReal(obj: unknown): boolean; /** @category Functions */ isRealVal(obj: unknown): obj is RatNum; /** @category Functions */ isRealSort(obj: unknown): boolean; /** @category Functions */ isBitVecSort(obj: unknown): obj is BitVecSort; /** @category Functions */ isBitVec(obj: unknown): obj is BitVec; /** @category Functions */ isBitVecVal(obj: unknown): obj is BitVecNum; /** @category Functions */ isArraySort(obj: unknown): obj is SMTArraySort; /** @category Functions */ isArray(obj: unknown): obj is SMTArray; /** @category Functions */ isConstArray(obj: unknown): boolean; /** @category Functions */ isProbe(obj: unknown): obj is Probe; /** @category Functions */ isTactic(obj: unknown): obj is Tactic; /** @category Functions */ isGoal(obj: unknown): obj is Goal; /** @category Functions */ isApplyResult(obj: unknown): obj is ApplyResult; /** @category Functions */ isAstVector(obj: unknown): obj is AstVector>; /** * Returns whether two Asts are the same thing * @category Functions */ eqIdentity(a: Ast, b: Ast): boolean; /** @category Functions */ getVarIndex(obj: Expr): number; /** * Coerce a boolean into a Bool expression * @category Functions */ from(primitive: boolean): Bool; /** * Coerce a number to an Int or Real expression (integral numbers become Ints) * @category Functions */ from(primitive: number): IntNum | RatNum; /** * Coerce a rational into a Real expression * @category Functions */ from(primitive: CoercibleRational): RatNum; /** * Coerce a big number into a Integer expression * @category Functions */ from(primitive: bigint): IntNum; /** * Returns whatever expression was given * @category Functions */ from>(expr: E): E; /** @hidden */ from(value: CoercibleToExpr): AnyExpr; /** * Sugar function for getting a model for given assertions * * ```typescript * const x = Int.const('x'); * const y = Int.const('y'); * const result = await solve(x.le(y)); * if (isModel(result)) { * console.log('Z3 found a solution'); * console.log(`x=${result.get(x)}, y=${result.get(y)}`); * } else { * console.error('No solution found'); * } * ``` * * @see {@link Solver} * @category Functions */ solve(...assertions: Bool[]): Promise | 'unsat' | 'unknown'>; solveSync(...assertions: Bool[]): Model | 'unsat' | 'unknown'; /** * Creates a Solver * @param logic - Optional logic which the solver will use. Creates a general Solver otherwise * @category Classes */ readonly Solver: new (logic?: string) => Solver; readonly Optimize: new () => Optimize; /** * Creates an empty Model * @see {@link Solver.model} for common usage of Model * @category Classes */ readonly Model: new () => Model; /** @category Classes */ readonly AstVector: new = AnyAst>() => AstVector; /** @category Classes */ readonly AstMap: new = AnyAst, Value extends Ast = AnyAst>() => AstMap; /** @category Classes */ readonly Tactic: new (name: string) => Tactic; readonly Goal: new (opts?: { z3Goal?: Z3_goal; }) => Goal; readonly ApplyResult: new (tactic: Tactic, goal: Goal) => ApplyResult; /** @category Expressions */ readonly Sort: SortCreation; /** @category Expressions */ readonly Function: FuncDeclCreation; /** @category Expressions */ readonly RecFunc: RecFuncCreation; /** @category Expressions */ readonly Bool: BoolCreation; /** @category Expressions */ readonly Int: IntCreation; /** @category Expressions */ readonly Real: RealCreation; /** @category Expressions */ readonly BitVec: BitVecCreation; /** @category Expressions */ readonly Array: SMTArrayCreation; /** @category Expressions */ readonly Set: SMTSetCreation; /** @category Operations */ Const>(name: string, sort: S): SortToExprMap; /** @category Operations */ Consts>(name: string | string[], sort: S): SortToExprMap[]; /** @category Operations */ FreshConst>(sort: S, prefix?: string): SortToExprMap; /** @category Operations */ Var>(idx: number, sort: S): SortToExprMap; /** @category Operations */ If(condition: Probe, onTrue: Tactic, onFalse: Tactic): Tactic; /** @category Operations */ If, OnFalseRef extends CoercibleToExpr>(condition: Bool | boolean, onTrue: OnTrueRef, onFalse: OnFalseRef): CoercibleFromMap; /** @category Operations */ Distinct(...args: CoercibleToExpr[]): Bool; /** @category Operations */ Implies(a: Bool | boolean, b: Bool | boolean): Bool; /** @category Operations */ Iff(a: Bool | boolean, b: Bool | boolean): Bool; /** @category Operations */ Eq(a: CoercibleToExpr, b: CoercibleToExpr): Bool; /** @category Operations */ Xor(a: Bool | boolean, b: Bool | boolean): Bool; /** @category Operations */ Not(a: Probe): Probe; /** @category Operations */ Not(a: Bool | boolean): Bool; /** @category Operations */ And(): Bool; /** @category Operations */ And(vector: AstVector>): Bool; /** @category Operations */ And(...args: (Bool | boolean)[]): Bool; /** @category Operations */ And(...args: Probe[]): Probe; /** @category Operations */ Or(): Bool; /** @category Operations */ Or(vector: AstVector>): Bool; /** @category Operations */ Or(...args: (Bool | boolean)[]): Bool; /** @category Operations */ Or(...args: Probe[]): Probe; /** @category Operations */ PbEq(args: [Bool, ...Bool[]], coeffs: [number, ...number[]], k: number): Bool; /** @category Operations */ PbGe(args: [Bool, ...Bool[]], coeffs: [number, ...number[]], k: number): Bool; /** @category Operations */ PbLe(args: [Bool, ...Bool[]], coeffs: [number, ...number[]], k: number): Bool; /** @category Operations */ ForAll>(quantifiers: ArrayIndexType, body: Bool, weight?: number): Quantifier> & Bool; /** @category Operations */ Exists>(quantifiers: ArrayIndexType, body: Bool, weight?: number): Quantifier> & Bool; /** @category Operations */ Lambda, RangeSort extends Sort>(quantifiers: ArrayIndexType, expr: SortToExprMap): Quantifier> & SMTArray; /** @category Operations */ ToReal(expr: Arith | bigint): Arith; /** @category Operations */ ToInt(expr: Arith | number | CoercibleRational | string): Arith; /** * Create an IsInt Z3 predicate * * ```typescript * const x = Real.const('x'); * await solve(IsInt(x.add("1/2")), x.gt(0), x.lt(1)) * // x = 1/2 * await solve(IsInt(x.add("1/2")), x.gt(0), x.lt(1), x.neq("1/2")) * // unsat * ``` * @category Operations */ IsInt(expr: Arith | number | CoercibleRational | string): Bool; /** * Returns a Z3 expression representing square root of a * * ```typescript * const a = Real.const('a'); * * Sqrt(a); * // a**(1/2) * ``` * @category Operations */ Sqrt(a: CoercibleToArith): Arith; /** * Returns a Z3 expression representing cubic root of a * * ```typescript * const a = Real.const('a'); * * Cbrt(a); * // a**(1/3) * ``` * @category Operations */ Cbrt(a: CoercibleToArith): Arith; /** @category Operations */ BV2Int(a: BitVec, isSigned: boolean): Arith; /** @category Operations */ Int2BV(a: Arith | bigint | number, bits: Bits): BitVec; /** @category Operations */ Concat(...bitvecs: BitVec[]): BitVec; /** @category Operations */ Cond(probe: Probe, onTrue: Tactic, onFalse: Tactic): Tactic; /** @category Operations */ LT(a: Arith, b: CoercibleToArith): Bool; /** @category Operations */ GT(a: Arith, b: CoercibleToArith): Bool; /** @category Operations */ LE(a: Arith, b: CoercibleToArith): Bool; /** @category Operations */ GE(a: Arith, b: CoercibleToArith): Bool; /** @category Operations */ ULT(a: BitVec, b: CoercibleToBitVec): Bool; /** @category Operations */ UGT(a: BitVec, b: CoercibleToBitVec): Bool; /** @category Operations */ ULE(a: BitVec, b: CoercibleToBitVec): Bool; /** @category Operations */ UGE(a: BitVec, b: CoercibleToBitVec): Bool; /** @category Operations */ SLT(a: BitVec, b: CoercibleToBitVec): Bool; /** @category Operations */ SGT(a: BitVec, b: CoercibleToBitVec): Bool; /** @category Operations */ SGE(a: BitVec, b: CoercibleToBitVec): Bool; /** @category Operations */ SLE(a: BitVec, b: CoercibleToBitVec): Bool; /** @category Operations */ Sum(arg0: Arith, ...args: CoercibleToArith[]): Arith; Sum(arg0: BitVec, ...args: CoercibleToBitVec[]): BitVec; Sub(arg0: Arith, ...args: CoercibleToArith[]): Arith; Sub(arg0: BitVec, ...args: CoercibleToBitVec[]): BitVec; Product(arg0: Arith, ...args: CoercibleToArith[]): Arith; Product(arg0: BitVec, ...args: CoercibleToBitVec[]): BitVec; Div(arg0: Arith, arg1: CoercibleToArith): Arith; Div(arg0: BitVec, arg1: CoercibleToBitVec): BitVec; BUDiv(arg0: BitVec, arg1: CoercibleToBitVec): BitVec; Neg(a: Arith): Arith; Neg(a: BitVec): BitVec; Mod(a: Arith, b: CoercibleToArith): Arith; Mod(a: BitVec, b: CoercibleToBitVec): BitVec; /** @category Operations */ Select, RangeSort extends Sort = Sort>(array: SMTArray, ...indices: CoercibleToArrayIndexType): SortToExprMap; /** @category Operations */ Store, RangeSort extends Sort = Sort>(array: SMTArray, ...indicesAndValue: [ ...CoercibleToArrayIndexType, CoercibleToMap, Name> ]): SMTArray; /** @category Operations */ Extract(hi: number, lo: number, val: BitVec): BitVec; /** @category Operations */ ast_from_string(s: string): Ast; /** @category Operations */ substitute(t: Expr, ...substitutions: [Expr, Expr][]): Expr; simplify(expr: Expr): Promise>; /** @category Operations */ SetUnion>(...args: SMTSet[]): SMTSet; /** @category Operations */ SetIntersect>(...args: SMTSet[]): SMTSet; /** @category Operations */ SetDifference>(a: SMTSet, b: SMTSet): SMTSet; /** @category Operations */ SetHasSize>(set: SMTSet, size: bigint | number | string | IntNum): Bool; /** @category Operations */ SetAdd>(set: SMTSet, elem: CoercibleToMap, Name>): SMTSet; /** @category Operations */ SetDel>(set: SMTSet, elem: CoercibleToMap, Name>): SMTSet; /** @category Operations */ SetComplement>(set: SMTSet): SMTSet; /** @category Operations */ EmptySet>(sort: ElemSort): SMTSet; /** @category Operations */ FullSet>(sort: ElemSort): SMTSet; /** @category Operations */ isMember>(elem: CoercibleToMap, Name>, set: SMTSet): Bool; /** @category Operations */ isSubset>(a: SMTSet, b: SMTSet): Bool; simplifySync(expr: Expr): Expr; } export interface Ast { /** @hidden */ readonly __typename: 'Ast' | Sort['__typename'] | FuncDecl['__typename'] | Expr['__typename']; readonly ctx: Context; /** @hidden */ readonly ptr: Ptr; /** @virtual */ get ast(): Z3_ast; /** @virtual */ id(): number; eqIdentity(other: Ast): boolean; neqIdentity(other: Ast): boolean; sexpr(): string; hash(): number; } /** @hidden */ export interface SolverCtor { new (): Solver; } export interface Solver { /** @hidden */ readonly __typename: 'Solver'; readonly ctx: Context; readonly ptr: Z3_solver; set(key: string, value: any): void; push(): void; pop(num?: number): void; numScopes(): number; reset(): void; add(...exprs: (Bool | AstVector>)[]): void; addAndTrack(expr: Bool, constant: Bool | string): void; assertions(): AstVector>; fromString(s: string): void; check(...exprs: (Bool | AstVector>)[]): Promise; checkSync(...exprs: (Bool | AstVector>)[]): CheckSatResult; model(): Model; /** * Manually decrease the reference count of the solver * This is automatically done when the solver is garbage collected, * but calling this eagerly can help release memory sooner. */ release(): void; unsatCore(): AstVector>; } export interface Optimize { /** @hidden */ readonly __typename: 'Optimize'; readonly ctx: Context; readonly ptr: Z3_optimize; set(key: string, value: any): void; push(): void; pop(num?: number): void; add(...exprs: (Bool | AstVector>)[]): void; addSoft(expr: Bool, weight: number | bigint | string | CoercibleRational, id?: number | string): void; addAndTrack(expr: Bool, constant: Bool | string): void; assertions(): AstVector>; fromString(s: string): void; maximize(expr: Arith): void; minimize(expr: Arith): void; check(...exprs: (Bool | AstVector>)[]): Promise; checkSync(...exprs: (Bool | AstVector>)[]): CheckSatResult; model(): Model; /** * Manually decrease the reference count of the optimize * This is automatically done when the optimize is garbage collected, * but calling this eagerly can help release memory sooner. */ release(): void; } /** @hidden */ export interface ModelCtor { new (): Model; } export interface Model extends Iterable> { /** @hidden */ readonly __typename: 'Model'; readonly ctx: Context; readonly ptr: Z3_model; length(): number; entries(): IterableIterator<[number, FuncDecl]>; keys(): IterableIterator; values(): IterableIterator>; decls(): FuncDecl[]; sexpr(): string; eval(expr: Bool, modelCompletion?: boolean): Bool; eval(expr: Arith, modelCompletion?: boolean): Arith; eval(expr: BitVec, modelCompletion?: boolean): BitVecNum; eval(expr: Expr, modelCompletion?: boolean): Expr; get(i: number): FuncDecl; get(from: number, to: number): FuncDecl[]; get(declaration: FuncDecl): FuncInterp | Expr; get(constant: Expr): Expr; get(sort: Sort): AstVector>; updateValue(decl: FuncDecl | Expr, a: Ast | FuncInterp): void; addFuncInterp[] = Sort[], RangeSort extends Sort = Sort>(decl: FuncDecl, defaultValue: CoercibleToMap, Name>): FuncInterp; /** * Manually decrease the reference count of the model * This is automatically done when the model is garbage collected, * but calling this eagerly can help release memory sooner. */ release(): void; } /** * Part of {@link Context}. Used to declare uninterpreted sorts * * ```typescript * const A = context.Sort.declare('A'); * const a = context.Const('a', A); * const b = context.const('b', A); * * a.sort.eqIdentity(A) * // true * b.sort.eqIdentity(A) * // true * a.eq(b) * // a == b * ``` */ export interface SortCreation { declare(name: string): Sort; enumSort(name: string, constantNames: string[]): EnumSort; } export interface EnumSort extends Sort { /** @hidden */ readonly __typename: 'EnumSort'; sortName: string; constantNames: string[]; numConstructors: number; datatypeConstructors: FuncDecl[], Sort>[]; constants: Expr>[]; } export interface Sort extends Ast { /** @hidden */ readonly __typename: 'Sort' | BoolSort['__typename'] | ArithSort['__typename'] | BitVecSort['__typename'] | SMTArraySort['__typename'] | EnumSort['__typename']; kind(): Z3_sort_kind; /** @virtual */ subsort(other: Sort): boolean; /** @virtual */ cast(expr: CoercibleToExpr): Expr; name(): string | number; } /** * @category Functions */ export interface FuncEntry { /** @hidden */ readonly __typename: 'FuncEntry'; readonly ctx: Context; readonly ptr: Z3_func_entry; numArgs(): number; argValue(i: number): Expr; value(): Expr; } /** * @category Functions */ export interface FuncInterp { /** @hidden */ readonly __typename: 'FuncInterp'; readonly ctx: Context; readonly ptr: Z3_func_interp; elseValue(): Expr; numEntries(): number; arity(): number; entry(i: number): FuncEntry; addEntry(args: Expr[], value: Expr): void; } /** @hidden */ export type FuncDeclSignature = [Sort, Sort, ...Sort[]]; /** * Part of {@link Context}. Used to declare functions * @category Functions */ export interface FuncDeclCreation { /** * Declare a new function * * ```typescript * const f = ctx.Function.declare('f', ctx.Bool.sort(), ctx.Real.sort(), ctx.Int.sort()) * * f.call(true, "1/3").eq(5) * // f(true, 1/3) == 5 * ``` * @param name Name of the function * @param signature The domains, and last parameter - the range of the function */ declare[], RangeSort extends Sort>(name: string, ...signature: [...DomainSort, RangeSort]): FuncDecl; fresh[], RangeSort extends Sort>(...signature: [...DomainSort, RangeSort]): FuncDecl; } /** * @category Functions */ export interface RecFuncCreation { declare(name: string, ...signature: FuncDeclSignature): FuncDecl; addDefinition(f: FuncDecl, args: Expr[], body: Expr): void; } /** * @category Functions */ export interface FuncDecl[] = Sort[], RangeSort extends Sort = Sort> extends Ast { /** @hidden */ readonly __typename: 'FuncDecl'; name(): string | number; arity(): number; domain(i: T): DomainSort[T]; range(): RangeSort; kind(): Z3_decl_kind; params(): (number | string | Sort | Expr | FuncDecl)[]; call(...args: CoercibleToArrayIndexType): SortToExprMap; } export interface Expr = AnySort, Ptr = unknown> extends Ast { /** @hidden */ readonly __typename: 'Expr' | Bool['__typename'] | Arith['__typename'] | BitVec['__typename'] | SMTArray['__typename']; get sort(): S; eq(other: CoercibleToExpr): Bool; neq(other: CoercibleToExpr): Bool; params(): ReturnType['params']>; name(): ReturnType['name']>; decl(): FuncDecl; numArgs(): number; arg(i: number): AnyExpr; children(): AnyExpr[]; } /** @category Booleans */ export interface BoolSort extends Sort { /** @hidden */ readonly __typename: 'BoolSort'; cast(expr: Bool | boolean): Bool; cast(expr: CoercibleToExpr): never; } /** @category Booleans */ export interface BoolCreation { sort(): BoolSort; const(name: string): Bool; consts(names: string | string[]): Bool[]; vector(prefix: string, count: number): Bool[]; fresh(prefix?: string): Bool; val(value: boolean): Bool; } /** @category Booleans */ export interface Bool extends Expr, Z3_ast> { /** @hidden */ readonly __typename: 'Bool' | 'NonLambdaQuantifier'; not(): Bool; and(other: Bool | boolean): Bool; or(other: Bool | boolean): Bool; xor(other: Bool | boolean): Bool; implies(other: Bool | boolean): Bool; } /** @category Quantifiers */ export interface Pattern { /** @hidden */ readonly __typename: 'Pattern'; } /** * A Sort that represents Integers or Real numbers * @category Arithmetic */ export interface ArithSort extends Sort { /** @hidden */ readonly __typename: 'ArithSort'; cast(other: bigint | number | string): IntNum | RatNum; cast(other: CoercibleRational | RatNum): RatNum; cast(other: IntNum): IntNum; cast(other: bigint | number | string | Bool | Arith | CoercibleRational): Arith; cast(other: CoercibleToExpr | string): never; } /** @category Arithmetic */ export interface IntCreation { sort(): ArithSort; const(name: string): Arith; consts(names: string | string[]): Arith[]; vector(prefix: string, count: number): Arith[]; fresh(prefix?: string): Arith; val(value: bigint | number | string): IntNum; } /** @category Arithmetic */ export interface RealCreation { sort(): ArithSort; const(name: string): Arith; consts(names: string | string[]): Arith[]; vector(prefix: string, count: number): Arith[]; fresh(prefix?: string): Arith; val(value: number | string | bigint | CoercibleRational): RatNum; } /** * Represents Integer or Real number expression * @category Arithmetic */ export interface Arith extends Expr, Z3_ast> { /** @hidden */ readonly __typename: 'Arith' | IntNum['__typename'] | RatNum['__typename']; /** * Adds two numbers together */ add(other: CoercibleToArith): Arith; /** * Multiplies two numbers together */ mul(other: CoercibleToArith): Arith; /** * Subtract second number from the first one */ sub(other: CoercibleToArith): Arith; /** * Applies power to the number * * ```typescript * const x = Int.const('x'); * * await solve(x.pow(2).eq(4), x.lt(0)); // x**2 == 4, x < 0 * // x=-2 * ``` */ pow(exponent: CoercibleToArith): Arith; /** * Divides the number by the second one */ div(other: CoercibleToArith): Arith; /** * Returns a number modulo second one * * ```typescript * const x = Int.const('x'); * * await solve(x.mod(7).eq(1), x.gt(7)) // x % 7 == 1, x > 7 * // x=8 * ``` */ mod(other: CoercibleToArith): Arith; /** * Returns a negation of the number */ neg(): Arith; /** * Return whether the number is less or equal than the second one (`<=`) */ le(other: CoercibleToArith): Bool; /** * Returns whether the number is less than the second one (`<`) */ lt(other: CoercibleToArith): Bool; /** * Returns whether the number is greater than the second one (`>`) */ gt(other: CoercibleToArith): Bool; /** * Returns whether the number is greater or equal than the second one (`>=`) */ ge(other: CoercibleToArith): Bool; } /** * A constant Integer value expression * @category Arithmetic */ export interface IntNum extends Arith { /** @hidden */ readonly __typename: 'IntNum'; value(): bigint; asString(): string; asBinary(): string; } /** * A constant Rational value expression * * ```typescript * const num = Real.val('1/3'); * * num.asString() * // '1/3' * num.value * // { numerator: 1n, denominator: 3n } * num.asNumber() * // 0.3333333333333333 * ``` * @category Arithmetic */ export interface RatNum extends Arith { /** @hidden */ readonly __typename: 'RatNum'; value(): { numerator: bigint; denominator: bigint; }; numerator(): IntNum; denominator(): IntNum; asNumber(): number; asDecimal(prec?: number): string; asString(): string; } /** * A Sort representing Bit Vector numbers of specified {@link BitVecSort.size size} * * @typeParam Bits - A number representing amount of bits for this sort * @category Bit Vectors */ export interface BitVecSort extends Sort { /** @hidden */ readonly __typename: 'BitVecSort'; /** * The amount of bits inside the sort * * ```typescript * const x = BitVec.const('x', 32); * * console.log(x.sort.size) * // 32 * ``` */ size(): Bits; cast(other: CoercibleToBitVec): BitVec; cast(other: CoercibleToExpr): Expr; } /** @category Bit Vectors */ export interface BitVecCreation { sort(bits: Bits): BitVecSort; const(name: string, bits: Bits | BitVecSort): BitVec; consts(names: string | string[], bits: Bits | BitVecSort): BitVec[]; val(value: bigint | number | boolean, bits: Bits | BitVecSort): BitVecNum; } /** * Represents Bit Vector expression * @category Bit Vectors */ export interface BitVec extends Expr, Z3_ast> { /** @hidden */ readonly __typename: 'BitVec' | BitVecNum['__typename']; /** * The amount of bits of this BitVectors sort * * ```typescript * const x = BitVec.const('x', 32); * * x.size * // 32 * * const Y = BitVec.sort(8); * const y = BitVec.const('y', Y); * * y.size * // 8 * ``` */ size(): Bits; /** @category Arithmetic */ add(other: CoercibleToBitVec): BitVec; /** @category Arithmetic */ mul(other: CoercibleToBitVec): BitVec; /** @category Arithmetic */ sub(other: CoercibleToBitVec): BitVec; /** @category Arithmetic */ sdiv(other: CoercibleToBitVec): BitVec; /** @category Arithmetic */ udiv(other: CoercibleToBitVec): BitVec; /** @category Arithmetic */ smod(other: CoercibleToBitVec): BitVec; /** @category Arithmetic */ urem(other: CoercibleToBitVec): BitVec; /** @category Arithmetic */ srem(other: CoercibleToBitVec): BitVec; /** @category Arithmetic */ neg(): BitVec; /** * Creates a bitwise-or between two bitvectors * @category4 Bitwise */ or(other: CoercibleToBitVec): BitVec; /** * Creates a bitwise-and between two bitvectors * @category Bitwise */ and(other: CoercibleToBitVec): BitVec; /** * Creates a bitwise-not-and between two bitvectors * @category Bitwise */ nand(other: CoercibleToBitVec): BitVec; /** * Creates a bitwise-exclusive-or between two bitvectors * @category Bitwise */ xor(other: CoercibleToBitVec): BitVec; /** * Creates a bitwise-exclusive-not-or between two bitvectors * @category Bitwise */ xnor(other: CoercibleToBitVec): BitVec; /** * Creates an arithmetic shift right operation * @category Bitwise */ shr(count: CoercibleToBitVec): BitVec; /** * Creates a logical shift right operation * @category Bitwise */ lshr(count: CoercibleToBitVec): BitVec; /** * Creates a shift left operation * @category Bitwise */ shl(count: CoercibleToBitVec): BitVec; /** * Creates a rotate right operation * @category Bitwise */ rotateRight(count: CoercibleToBitVec): BitVec; /** * Creates a rotate left operation * @category Bitwise */ rotateLeft(count: CoercibleToBitVec): BitVec; /** * Creates a bitwise not operation * @category Bitwise */ not(): BitVec; /** * Creates an extraction operation. * Bits are indexed starting from 1 from the most right one (least significant) increasing to left (most significant) * * ```typescript * const x = BitVec.const('x', 8); * * x.extract(6, 2) * // Extract(6, 2, x) * x.extract(6, 2).sort * // BitVec(5) * ``` * @param high The most significant bit to be extracted * @param low The least significant bit to be extracted */ extract(high: number, low: number): BitVec; signExt(count: number): BitVec; zeroExt(count: number): BitVec; repeat(count: number): BitVec; /** * Creates a signed less-or-equal operation (`<=`) * @category Comparison */ sle(other: CoercibleToBitVec): Bool; /** * Creates an unsigned less-or-equal operation (`<=`) * @category Comparison */ ule(other: CoercibleToBitVec): Bool; /** * Creates a signed less-than operation (`<`) * @category Comparison */ slt(other: CoercibleToBitVec): Bool; /** * Creates an unsigned less-than operation (`<`) * @category Comparison */ ult(other: CoercibleToBitVec): Bool; /** * Creates a signed greater-or-equal operation (`>=`) * @category Comparison */ sge(other: CoercibleToBitVec): Bool; /** * Creates an unsigned greater-or-equal operation (`>=`) * @category Comparison */ uge(other: CoercibleToBitVec): Bool; /** * Creates a signed greater-than operation (`>`) * @category Comparison */ sgt(other: CoercibleToBitVec): Bool; /** * Creates an unsigned greater-than operation (`>`) * @category Comparison */ ugt(other: CoercibleToBitVec): Bool; /** * Creates a reduction-and operation */ redAnd(): BitVec; /** * Creates a reduction-or operation */ redOr(): BitVec; /** @category Boolean */ addNoOverflow(other: CoercibleToBitVec, isSigned: boolean): Bool; /** @category Boolean */ addNoUnderflow(other: CoercibleToBitVec): Bool; /** @category Boolean */ subNoOverflow(other: CoercibleToBitVec): Bool; /** @category Boolean */ subNoUndeflow(other: CoercibleToBitVec, isSigned: boolean): Bool; /** @category Boolean */ sdivNoOverflow(other: CoercibleToBitVec): Bool; /** @category Boolean */ mulNoOverflow(other: CoercibleToBitVec, isSigned: boolean): Bool; /** @category Boolean */ mulNoUndeflow(other: CoercibleToBitVec): Bool; /** @category Boolean */ negNoOverflow(): Bool; } /** * Represents Bit Vector constant value * @category Bit Vectors */ export interface BitVecNum extends BitVec { /** @hidden */ readonly __typename: 'BitVecNum'; value(): bigint; asSignedValue(): bigint; asString(): string; asBinaryString(): string; } /** * A Sort representing a SMT Array with range of sort {@link SMTArraySort.range range} * and a domain of sort {@link SMTArraySort.domain domain} * * @typeParam DomainSort The sort of the domain of the array (provided as an array of sorts) * @typeParam RangeSort The sort of the array range * @category Arrays */ export interface SMTArraySort = [Sort, ...Sort[]], RangeSort extends AnySort = AnySort> extends Sort { /** @hidden */ readonly __typename: 'ArraySort'; /** * The sort of the first dimension of the domain */ domain(): DomainSort[0]; /** * The sort of the i-th (0-indexed) dimension of the domain * * @param i index of the dimension of the domain being requested */ domain_n(i: T): DomainSort[T]; /** * The sort of the range */ range(): RangeSort; } /** @category Arrays */ export interface SMTArrayCreation { sort, RangeSort extends Sort>(...sig: [...DomainSort, RangeSort]): SMTArraySort; const, RangeSort extends Sort>(name: string, ...sig: [...DomainSort, RangeSort]): SMTArray; consts, RangeSort extends Sort>(names: string | string[], ...sig: [...DomainSort, RangeSort]): SMTArray[]; K, RangeSort extends AnySort>(domain: DomainSort, value: SortToExprMap): SMTArray; } export type NonEmptySortArray = [Sort, ...Array>]; export type ArrayIndexType[]> = [ ...{ [Key in keyof DomainSort]: DomainSort[Key] extends AnySort ? SortToExprMap : DomainSort[Key]; } ]; export type CoercibleToArrayIndexType[]> = [ ...{ [Key in keyof DomainSort]: DomainSort[Key] extends AnySort ? CoercibleToMap, Name> : DomainSort[Key]; } ]; /** * Represents Array expression * * @typeParam DomainSort The sort of the domain of the array (provided as an array of sorts) * @typeParam RangeSort The sort of the array range * @category Arrays */ export interface SMTArray = [Sort, ...Sort[]], RangeSort extends Sort = Sort> extends Expr, Z3_ast> { /** @hidden */ readonly __typename: 'Array' | 'Lambda'; domain(): DomainSort[0]; domain_n(i: T): DomainSort[T]; range(): RangeSort; select(...indices: CoercibleToArrayIndexType): SortToExprMap; /** * value should be coercible to RangeSort * * @param indicesAndValue (idx0, idx1, ..., idxN, value) */ store(...indicesAndValue: [ ...CoercibleToArrayIndexType, CoercibleToMap, Name> ]): SMTArray; } /** * Set Implemented using Arrays * * @typeParam ElemSort The sort of the element of the set * @category Sets */ export type SMTSetSort = Sort> = SMTArraySort>; /** @category Sets*/ export interface SMTSetCreation { sort>(elemSort: ElemSort): SMTSetSort; const>(name: string, elemSort: ElemSort): SMTSet; consts>(names: string | string[], elemSort: ElemSort): SMTSet[]; empty>(sort: ElemSort): SMTSet; val>(values: CoercibleToMap, Name>[], sort: ElemSort): SMTSet; } /** * Represents Set expression * * @typeParam ElemSort The sort of the element of the set * @category Arrays */ export interface SMTSet = Sort> extends Expr, Z3_ast> { readonly __typename: 'Array'; elemSort(): ElemSort; union(...args: SMTSet[]): SMTSet; intersect(...args: SMTSet[]): SMTSet; diff(b: SMTSet): SMTSet; hasSize(size: bigint | number | string | IntNum): Bool; add(elem: CoercibleToMap, Name>): SMTSet; del(elem: CoercibleToMap, Name>): SMTSet; complement(): SMTSet; contains(elem: CoercibleToMap, Name>): Bool; subsetOf(b: SMTSet): Bool; } /** * Defines the expression type of the body of a quantifier expression * * @category Quantifiers */ export type BodyT = [Sort, ...Sort[]], QSort extends BoolSort | SMTArraySort = BoolSort | SMTArraySort> = QSort extends BoolSort ? Bool : QSort extends SMTArray ? SortToExprMap : never; /** @category Quantifiers */ export interface Quantifier = [Sort, ...Sort[]], QSort extends BoolSort | SMTArraySort = BoolSort | SMTArraySort> extends Expr { readonly __typename: 'NonLambdaQuantifier' | 'Lambda'; is_forall(): boolean; is_exists(): boolean; is_lambda(): boolean; weight(): number; num_patterns(): number; pattern(i: number): Pattern; num_no_patterns(): number; no_pattern(i: number): Expr; body(): BodyT; num_vars(): number; var_name(i: number): string | number; var_sort(i: T): QVarSorts[T]; children(): [BodyT]; } export interface Probe { /** @hidden */ readonly __typename: 'Probe'; readonly ctx: Context; readonly ptr: Z3_probe; } /** @hidden */ export interface TacticCtor { new (name: string): Tactic; } export interface Tactic { /** @hidden */ readonly __typename: 'Tactic'; readonly ctx: Context; readonly ptr: Z3_tactic; } export interface Goal { /** @hidden */ readonly __typename: 'Goal'; readonly ctx: Context; readonly ptr: Z3_goal; add(expr: Expr): void; asExpr(): Bool; get(idx: number): Expr; size(): number; sexpr(): string; } export interface ApplyResult { /** @hidden */ readonly __typename: 'ApplyResult'; readonly ctx: Context; readonly ptr: Z3_apply_result; readonly tactic: Tactic; readonly goal: Goal; getApplyResult(idx: number): Goal; length(): number; sexpr(): string; } /** @hidden */ export interface AstVectorCtor { new = AnyAst>(): AstVector; } /** * Stores multiple {@link Ast} objects * * ```typescript * const vector = new AstVector(); * vector.push(Bool.val(5)); * vector.push(Bool.const('x')) * * vector.length * // 2 * vector.get(1) * // x * [...vector.values()] * // [2, x] * ``` */ export interface AstVector = AnyAst> extends Iterable { /** @hidden */ readonly __typename: 'AstVector'; readonly ctx: Context; readonly ptr: Z3_ast_vector; length(): number; entries(): IterableIterator<[number, Item]>; keys(): IterableIterator; values(): IterableIterator; get(i: number): Item; get(from: number, to: number): Item[]; set(i: number, v: Item): void; push(v: Item): void; resize(size: number): void; has(v: Item): boolean; sexpr(): string; } /** @hidden */ export interface AstMapCtor { new = AnyAst, Value extends Ast = AnyAst>(): AstMap; } /** * Stores a mapping between different {@link Ast} objects * * ```typescript * const map = new Map(); * const x = Int.const('x') * const y = Int.const('y') * map.set(x, Bool.val(true)) * map.Set(y, Bool.val(false)) * * map.size * // 2 * map.has(x) * // true * [...map.entries()] * // [[x, true], [y, false]] * map.clear() * map.size * // 0 * ``` */ export interface AstMap = AnyAst, Value extends Ast = AnyAst> extends Iterable<[Key, Value]> { /** @hidden */ readonly __typename: 'AstMap'; readonly ctx: Context; readonly ptr: Z3_ast_map; get size(): number; entries(): IterableIterator<[Key, Value]>; keys(): AstVector; values(): IterableIterator; get(key: Key): Value | undefined; set(key: Key, value: Value): void; delete(key: Key): void; clear(): void; has(key: Key): boolean; sexpr(): string; } /** * @category Global */ export interface Z3HighLevel { enableTrace(tag: string): void; disableTrace(tag: string): void; getVersion(): { major: number; minor: number; build_number: number; revision_number: number; }; getVersionString(): string; getFullVersion(): string; openLog(filename: string): boolean; appendLog(s: string): void; /** * Set a Z3 parameter * * ```typescript * setParam('pp.decimal', true); * ``` */ setParam(key: string, value: any): void; /** * Set multiple Z3 parameters at once * * ```typescript * setParam({ * 'pp.decimal': true, * 'pp.decimal_precision': 20 * }); * ``` */ setParam(key: Record): void; /** * Resets all Z3 parameters */ resetParams(): void; /** * Returns a global Z3 parameter */ getParam(name: string): string | null; /** * Use this to create new contexts * @see {@link Context} */ readonly Context: ContextCtor; }