declare class Predicate { private cppInstance; constructor(cppInstance: any); value(): number; is_equal(): boolean; getCppInstance(): any; } declare class QuantumProperty { private cppInstance; constructor(dimension: number); index(): number; dimension(): number; is(value: number): Predicate; is_not(value: number): Predicate; /** Number of qudits in this property's shared quantum state. */ num_active_qudits(): number; /** Current number of basis amplitudes in the state vector (sparse size). */ state_vector_size(): number; /** Factorize this qudit out of any shared state and release the property. */ destroy(): void; /** Check whether this property still holds a valid quantum state. */ is_valid(): boolean; getCppInstance(): any; /** @internal Create a QuantumProperty from an existing C++ instance. */ static _fromCpp(cppInstance: any): QuantumProperty; } declare class QuantumSimulation { private cppInstance; constructor(); createProperty(dimension: number): QuantumProperty; /** Factorize a property out of this simulation's shared state and destroy it. * Automatically factors out any remaining qudits that became separable. * Frees memory incrementally — critical for search algorithms with many ancillas. */ destroyProperty(prop: QuantumProperty): void; /** Factor out any separable qudits across all shared states in this simulation. * Call after undo operations (e.g. i_swap reversal) that may have restored separability. * Separable qudits are split into independent states, reducing entanglement overhead. */ factorizeAllSeparable(): void; destroy(): void; isDestroyed(): boolean; } declare function cycle(prop: QuantumProperty, fraction?: number, predicates?: Predicate[]): void; declare function shift(prop: QuantumProperty, fraction?: number, predicates?: Predicate[]): void; declare function clock(prop: QuantumProperty, fraction?: number, predicates?: Predicate[]): void; declare function hadamard(prop: QuantumProperty, fraction?: number, predicates?: Predicate[]): void; declare function inverse_hadamard(prop: QuantumProperty, predicates?: Predicate[]): void; declare function swap(prop1: QuantumProperty, prop2: QuantumProperty, predicates?: Predicate[]): void; declare function i_swap(prop1: QuantumProperty, prop2: QuantumProperty, fraction: number, predicates?: Predicate[]): void; declare function x(prop: QuantumProperty, fraction?: number, predicates?: Predicate[]): void; declare function z(prop: QuantumProperty, fraction?: number, predicates?: Predicate[]): void; declare function y(prop: QuantumProperty, fraction?: number, predicates?: Predicate[]): void; declare function reset(prop: QuantumProperty, currentValue: number): void; declare function phase_rotate(predicates: Predicate[], angle: number): void; declare function measure_properties(props: QuantumProperty[]): number[]; declare function forced_measure_properties(props: QuantumProperty[], forcedValues: number[]): number[]; declare function measure_predicate(predicates: Predicate[]): number; /** Force a predicate measurement to a specific outcome. * If the forced value is impossible (zero probability), falls back to * stochastic measurement and returns the actual outcome instead of throwing. */ declare function forced_measure_predicate(predicates: Predicate[], forcedValue: number): number; /** Get the probability that all predicates are simultaneously satisfied. * Read-only — does not collapse or modify quantum state. */ declare function predicate_probability(predicates: Predicate[]): number; declare function probabilities(props: QuantumProperty[]): Array<{ probability: number; qudit_values: number[]; }>; declare function reduced_density_matrix(props: QuantumProperty[]): Array<{ row_values: number[]; col_values: number[]; value: { real: number; imag: number; }; }>; /** Gate opcode for batch execution. */ type OpCode = 'cycle' | 'shift' | 'clock' | 'x' | 'z' | 'y' | 'hadamard' | 'inverse_hadamard' | 'swap' | 'i_swap' | 'phase_rotate'; /** A single gate operation descriptor for batch execution. */ interface BatchOp { op: OpCode; target?: QuantumProperty; target2?: QuantumProperty; /** Gate fraction. Omit for non-fractional (discrete permutation) variant. */ fraction?: number; /** Rotation angle (phase_rotate only). */ angle?: number; predicates?: Predicate[]; } /** Result of a batch execution. */ interface BatchResult { opsExecuted: number; success: boolean; errorMessage: string; } /** * Execute a sequence of gate operations in a single WASM call. * * Operations execute sequentially. On the first error, execution stops. * Already-executed operations are not rolled back. */ declare function executeBatch(ops: BatchOp[]): BatchResult; /** Numeric opcode values matching the C++ OpCode enum for tape encoding. */ declare const OP: { readonly CYCLE: 0; readonly SHIFT: 1; readonly CLOCK: 2; readonly X: 3; readonly Z: 4; readonly Y: 5; readonly HADAMARD: 6; readonly INVERSE_HADAMARD: 7; readonly SWAP: 8; readonly I_SWAP: 9; readonly PHASE_ROTATE: 10; /** Fused rotation between two basis states. Tape format: * [11, nq, -1, NaN, angle, 0, a[0]..a[nq-1], b[0]..b[nq-1]] */ readonly ROTATE_BASIS_PAIR: 11; }; type OpNum = typeof OP[keyof typeof OP]; /** * Fast-path batch execution using a pre-encoded Float64Array tape. * * Bypasses embind per-op marshaling entirely. The tape is bulk-copied to WASM * in one memcpy (~0.1ms for 3000+ ops) instead of parsing thousands of JS * objects through embind val accessors (~300ms). * * **Tape format per operation (variable length):** * ``` * [opcode, target_idx, target2_idx, fraction, angle, pred_count, * (pred_prop_idx, pred_value, pred_is_equal) × pred_count] * ``` * - Minimum 6 doubles per op (no predicates) * - `target_idx` / `target2_idx`: index into `properties` array, or -1 for none * - `fraction`: NaN for non-fractional gate variant * - `pred_prop_idx`: index into `properties` array * - `pred_is_equal`: 1.0 for is(), 0.0 for is_not() * * Use the `OP` enum for opcodes. Build the tape directly for maximum throughput — * avoid creating intermediate JS objects. * * @example * ```typescript * import { executeBatchTape, OP } from "quantum-forge/quantum"; * * // Register properties by index * const properties = [prop1, prop2, prop3]; * * // Build tape: 3 non-fractional shifts on prop[0] * const tape = new Float64Array([ * OP.SHIFT, 0, -1, NaN, 0, 0, // shift(prop1) * OP.SHIFT, 0, -1, NaN, 0, 0, // shift(prop1) * OP.SHIFT, 0, -1, NaN, 0, 0, // shift(prop1) * ]); * * const result = executeBatchTape(properties, tape); * ``` * * @param properties Array of properties referenced by index in the tape * @param tape Pre-encoded Float64Array of operations * @returns BatchResult */ declare function executeBatchTape(properties: QuantumProperty[], tape: Float64Array): BatchResult; declare class QuantumForge { /** * Initialize QuantumForge * Automatically detects and loads the appropriate WASM module format */ static initialize(): Promise; /** * Check if QuantumForge is initialized */ static isInitialized(): boolean; static createQuantumProperty(dimension: number): QuantumProperty; static createSimulation(): QuantumSimulation; static getVersion(): string; static getMaxDimension(): number; static getMaxQudits(): number; static isValidDimension(dimension: number): boolean; /** Returns the compile-time maximum number of basis amplitudes allowed. */ static getMaxStateSize(): number; } export { type BatchOp, type BatchResult, OP, type OpCode, type OpNum, Predicate, QuantumForge, QuantumProperty, QuantumSimulation, clock, cycle, executeBatch, executeBatchTape, forced_measure_predicate, forced_measure_properties, hadamard, i_swap, inverse_hadamard, measure_predicate, measure_properties, phase_rotate, predicate_probability, probabilities, reduced_density_matrix, reset, shift, swap, x, y, z };