← All comparisons

Fanal vs. CoqQ

POPL 2023 · Coq / MathComp

About CoqQ

Framework for foundational verification of quantum programs in Coq. Provides deeply embedded quantum programming language qwhile, labelled Dirac notation, and verified quantum Hoare logic. Case studies include HHL, Grover, QPE, and QFT.

Proof Assistant and Foundation

AspectCoqQFanal
Proof assistantCoqLean 4
Math libraryMathComp + MathComp Analysis + ~22K LOC custom extensionsMathlib (community-maintained, existing infrastructure)
Type theoryCIC (Calculus of Inductive Constructions)CIC variant (Lean 4 kernel)
Codebase size~33,000 lines Coq (spec + proof + comments)Under active development
FoundednessFully foundational: all proof rules proved as lemmas w.r.t. denotational semanticsFoundational for Dirac notation; program logic planned

Quantum State Representation

AspectCoqQFanal
ApproachAbstract linear algebra (Hilbert spaces via MathComp)Concrete matrices over C (via Mathlib Matrix)
State typeDensity operators in D^1(H), operators in L(H1, H2)Matrix (ketType.interp) (braType.interp) C
Tensor productsBig operators (bigotimes) with commutative monoid structuretsr constructor + bigTsr for parametric tensor products
Type hierarchyHermType, PsdType, DenType, ObsType, UnitaryType, ProjType via canonical structuresOperator predicates (IsHermitian, IsUnitary, IsProjection) defined semantically
Algebraic propertiesAutomatically inherited from MathComp abstract algebraRequires explicit proofs; amenable to native_decide for small cases

Label System

AspectCoqQFanal
ModelFlat set of labels: each label p maps to Hilbert space H_pHierarchical access paths: root variable + list of AccessSteps
Variablesvars T mapping to subset of labels, composition via [x1, x2]LabelTerm inductive: var, tuple, tupleIdx, arrayIdx
Array supportn-tuple types with for-loop constructsFirst-class DataType.array n t with arrayIdx and bigTsr
DisjointnessStatic set intersection = emptyDynamic runtime atom overlap check
Cylindrical extensioncl_T(A_S) = A_S tensor I_{T\S} lifts local operatorsAccess path model with RegAtom lists and dimValAppendEquiv

Type System

AspectCoqQFanal
ApproachShallow embedding: Coq types + canonical structures for automatic inferenceDeep embedding: explicit DataType, DiracSort, UnifiedContext, DTIso
Data typesCoq finite types {t_1, t_2, ...}DataType inductive: fin n | tuple ts | array n t
Type isomorphismHandled implicitly by canonical structuresDTIso: structural isomorphism (unit elimination, tuple flattening)
InferenceCoq's elaboration with canonical structure resolutionDeterministic, decidable synthesizeType functions
Semantic equalityMatrix equality via MathCompSemEq (same-sort) and HSemEq (cross-sort via SortIso)

Dirac Notation

AspectCoqQFanal
ArchitectureSingle integrated labelled Dirac notation layerTwo layers: plain Dirac (DiracTerm) + labelled Dirac (LDiracTerm)
Notation elementsKets |t>_S, bras <t|_S, inner/outer products, tensor productsFull AST: cpx, ket, bra, delta, add, neg, sca, mul, tsr, adj, smul, bigSum, bigTsr, dVar
LabellingImplicit via disjoint labels with automatic liftingExplicit register patterns via label constructor with ket/bra patterns
Big tensor productNo direct constructor; handled via for-loops in program languageFirst-class bigTsr constructor for parametric tensor products
Equational reasoningBasic rewriting with linearity, associativity, commutativityCertified dirac_eq tactic based on term rewriting with soundness proofs

Program Logic

AspectCoqQFanal
StatusComplete, verified quantum Hoare logic for qwhilePlanned (roadmap item D)
Judgments{A_S1} C {B_S2} with total and partial correctnessPlanned: Hoare logic over labelled Dirac assertions
Proof rules~30 rules: syntax-directed, structural, state-based, R.InnerPlanned: syntax-directed + structural rules
SoundnessProved from first principles (Theorem 6.1)Will be proved foundationally in Lean
Weakest preconditionExistence and characterization provedPlanned

Automation

AspectCoqQFanal
Type inferenceCanonical structures for automatic Hilbert space resolutionsynthesizeType functions producing typing derivations
Equational reasoningManual proof assembly from lemmas; no dedicated decision proceduredirac_eq tactic: push-button certified equational reasoning
ParsingCoq notationsLean 4 macro-based parsing syntax for natural Dirac encoding
D-HammerNot availablePlanned integration of D-Hammer decision procedure

Expressiveness

AspectCoqQFanal
Fixed-size tuplesx : vars (T1 * T2)tuple [r1, r2]
Parametric n-tuplesx : n.-tuple (vars T) with for-loopsarrayIdx r idx with bigTsr
Array indexingx_i via tuple projectionr[i] via arrayIdx with classical expression index
Classical expressionsCoq native types (full dependent types)CExprTerm AST: arithmetic, booleans, comparisons, casting
Classical variablesNot supported (acknowledged as future work)Built-in eVar with UnifiedContext
Programsqwhile: skip, abort, sequence, init, unitary, if-meas, while, forPlanned: classical-quantum language with full control flow

Case Studies

AspectCoqQFanal
Hidden Subgroup ProblemVerified (~390 lines) — first-ever formalizationNot yet
HHL algorithmVerified (~280 lines)Not yet
Grover's searchVerified (~180 lines)Not yet
QPEVerified (~90 lines)Not yet
QFTVerified (~140 lines)Not yet
Dirac identitiesUsed in proofs but not isolatedEncoded and verified (QCQI examples, Pauli identities, circuit equivalences)

Summary: Key Differences

AspectCoqQFanal
Proof SystemCoq (Calculus of Constructions)Lean 4 (CIC with quotients)
Math LibraryMathComp (SSReflect style)Mathlib (tactic style)
Register ModelFlat labelled qubitsHierarchical access paths with value-dependent labels
AutomationManual Coq tacticsdirac_eq tactic + D-Hammer integration
DevelopmentTraditional manual developmentAI-native, specification-driven workflow