libpetri 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -388,6 +388,7 @@ declare class SmtVerifier {
|
|
|
388
388
|
private _initialMarking;
|
|
389
389
|
private _property;
|
|
390
390
|
private readonly _environmentPlaces;
|
|
391
|
+
private readonly _sinkPlaces;
|
|
391
392
|
private _environmentMode;
|
|
392
393
|
private _timeoutMs;
|
|
393
394
|
private constructor();
|
|
@@ -397,6 +398,11 @@ declare class SmtVerifier {
|
|
|
397
398
|
property(property: SmtProperty): this;
|
|
398
399
|
environmentPlaces(...places: EnvironmentPlace<any>[]): this;
|
|
399
400
|
environmentMode(mode: EnvironmentAnalysisMode): this;
|
|
401
|
+
/**
|
|
402
|
+
* Declares expected sink (terminal) places for deadlock-freedom analysis.
|
|
403
|
+
* Markings where any sink place has a token are not considered deadlocks.
|
|
404
|
+
*/
|
|
405
|
+
sinkPlaces(...places: Place<any>[]): this;
|
|
400
406
|
timeout(ms: number): this;
|
|
401
407
|
/**
|
|
402
408
|
* Runs the verification pipeline.
|
|
@@ -484,7 +490,7 @@ interface EncodingResult {
|
|
|
484
490
|
* - Reachable(M') :- Reachable(M) AND enabled(M,t) AND fire(M,M',t) — transition rules
|
|
485
491
|
* - Error() :- Reachable(M) AND property_violation(M) — safety property
|
|
486
492
|
*/
|
|
487
|
-
declare function encode(ctx: Z3Context, fp: Z3Fixedpoint, flatNet: FlatNet, initialMarking: MarkingState, property: SmtProperty, invariants: readonly PInvariant[]): EncodingResult;
|
|
493
|
+
declare function encode(ctx: Z3Context, fp: Z3Fixedpoint, flatNet: FlatNet, initialMarking: MarkingState, property: SmtProperty, invariants: readonly PInvariant[], sinkPlaces?: ReadonlySet<Place<any>>): EncodingResult;
|
|
488
494
|
|
|
489
495
|
/**
|
|
490
496
|
* Result of counterexample decoding.
|
|
@@ -698,7 +698,7 @@ async function createSpacerRunner(timeoutMs) {
|
|
|
698
698
|
}
|
|
699
699
|
|
|
700
700
|
// src/verification/z3/smt-encoder.ts
|
|
701
|
-
function encode(ctx, fp, flatNet, initialMarking, property, invariants) {
|
|
701
|
+
function encode(ctx, fp, flatNet, initialMarking, property, invariants, sinkPlaces = /* @__PURE__ */ new Set()) {
|
|
702
702
|
const P = flatNet.places.length;
|
|
703
703
|
const Int = ctx.Int;
|
|
704
704
|
const Bool_ = ctx.Bool;
|
|
@@ -720,7 +720,7 @@ function encode(ctx, fp, flatNet, initialMarking, property, invariants) {
|
|
|
720
720
|
const ft = flatNet.transitions[t];
|
|
721
721
|
encodeTransitionRule(ctx, fp, reachable, ft, flatNet, invariants, P);
|
|
722
722
|
}
|
|
723
|
-
encodeErrorRule(ctx, fp, reachable, error, flatNet, property, P);
|
|
723
|
+
encodeErrorRule(ctx, fp, reachable, error, flatNet, property, sinkPlaces, P);
|
|
724
724
|
return {
|
|
725
725
|
errorExpr: error.call(),
|
|
726
726
|
reachableDecl: reachable
|
|
@@ -791,24 +791,36 @@ function encodeFire(ctx, ft, _flatNet, mVars, mPrimeVars, P) {
|
|
|
791
791
|
}
|
|
792
792
|
return result;
|
|
793
793
|
}
|
|
794
|
-
function encodeErrorRule(ctx, fp, reachable, error, flatNet, property, P) {
|
|
794
|
+
function encodeErrorRule(ctx, fp, reachable, error, flatNet, property, sinkPlaces, P) {
|
|
795
795
|
const Int = ctx.Int;
|
|
796
796
|
const mVars = [];
|
|
797
797
|
for (let i = 0; i < P; i++) {
|
|
798
798
|
mVars.push(Int.const(`em${i}`));
|
|
799
799
|
}
|
|
800
800
|
const reachBody = reachable.call(...mVars);
|
|
801
|
-
const violation = encodePropertyViolation(ctx, flatNet, property, mVars, P);
|
|
801
|
+
const violation = encodePropertyViolation(ctx, flatNet, property, sinkPlaces, mVars, P);
|
|
802
802
|
const head = error.call();
|
|
803
803
|
const body = ctx.And(reachBody, violation);
|
|
804
804
|
const rule = ctx.Implies(body, head);
|
|
805
805
|
const qRule = ctx.ForAll(mVars, rule);
|
|
806
806
|
fp.addRule(qRule, `error_${property.type}`);
|
|
807
807
|
}
|
|
808
|
-
function encodePropertyViolation(ctx, flatNet, property, mVars, P) {
|
|
808
|
+
function encodePropertyViolation(ctx, flatNet, property, sinkPlaces, mVars, P) {
|
|
809
809
|
switch (property.type) {
|
|
810
|
-
case "deadlock-free":
|
|
811
|
-
|
|
810
|
+
case "deadlock-free": {
|
|
811
|
+
const deadlock = encodeDeadlock(ctx, flatNet, mVars, P);
|
|
812
|
+
if (sinkPlaces.size > 0) {
|
|
813
|
+
let notAtSink = ctx.Bool.val(true);
|
|
814
|
+
for (const sink of sinkPlaces) {
|
|
815
|
+
const idx = flatNetIndexOf(flatNet, sink);
|
|
816
|
+
if (idx >= 0) {
|
|
817
|
+
notAtSink = ctx.And(notAtSink, mVars[idx].eq(0));
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
return ctx.And(deadlock, notAtSink);
|
|
821
|
+
}
|
|
822
|
+
return deadlock;
|
|
823
|
+
}
|
|
812
824
|
case "mutual-exclusion": {
|
|
813
825
|
const idx1 = flatNetIndexOf(flatNet, property.p1);
|
|
814
826
|
const idx2 = flatNetIndexOf(flatNet, property.p2);
|
|
@@ -926,6 +938,7 @@ var SmtVerifier = class _SmtVerifier {
|
|
|
926
938
|
_initialMarking = MarkingState.empty();
|
|
927
939
|
_property = deadlockFree();
|
|
928
940
|
_environmentPlaces = /* @__PURE__ */ new Set();
|
|
941
|
+
_sinkPlaces = /* @__PURE__ */ new Set();
|
|
929
942
|
_environmentMode = unbounded();
|
|
930
943
|
_timeoutMs = 6e4;
|
|
931
944
|
static forNet(net) {
|
|
@@ -953,6 +966,14 @@ var SmtVerifier = class _SmtVerifier {
|
|
|
953
966
|
this._environmentMode = mode;
|
|
954
967
|
return this;
|
|
955
968
|
}
|
|
969
|
+
/**
|
|
970
|
+
* Declares expected sink (terminal) places for deadlock-freedom analysis.
|
|
971
|
+
* Markings where any sink place has a token are not considered deadlocks.
|
|
972
|
+
*/
|
|
973
|
+
sinkPlaces(...places) {
|
|
974
|
+
for (const p of places) this._sinkPlaces.add(p);
|
|
975
|
+
return this;
|
|
976
|
+
}
|
|
956
977
|
timeout(ms) {
|
|
957
978
|
this._timeoutMs = ms;
|
|
958
979
|
return this;
|
|
@@ -965,7 +986,8 @@ var SmtVerifier = class _SmtVerifier {
|
|
|
965
986
|
const report = [];
|
|
966
987
|
report.push("=== IC3/PDR SAFETY VERIFICATION ===\n");
|
|
967
988
|
report.push(`Net: ${this.net.name}`);
|
|
968
|
-
|
|
989
|
+
const propDesc = this._sinkPlaces.size === 0 ? propertyDescription(this._property) : `${propertyDescription(this._property)} (sinks: ${[...this._sinkPlaces].map((p) => p.name).join(", ")})`;
|
|
990
|
+
report.push(`Property: ${propDesc}`);
|
|
969
991
|
report.push(`Timeout: ${(this._timeoutMs / 1e3).toFixed(0)}s
|
|
970
992
|
`);
|
|
971
993
|
report.push("Phase 1: Flattening net...");
|
|
@@ -992,7 +1014,7 @@ var SmtVerifier = class _SmtVerifier {
|
|
|
992
1014
|
}
|
|
993
1015
|
report.push(` Result: ${structResultStr}
|
|
994
1016
|
`);
|
|
995
|
-
if (this._property.type === "deadlock-free" && structResult.type === "no-potential-deadlock") {
|
|
1017
|
+
if (this._property.type === "deadlock-free" && this._sinkPlaces.size === 0 && structResult.type === "no-potential-deadlock") {
|
|
996
1018
|
report.push("=== RESULT ===\n");
|
|
997
1019
|
report.push("PROVEN (structural): Deadlock-freedom verified by Commoner's theorem.");
|
|
998
1020
|
report.push(" All siphons contain initially marked traps.");
|
|
@@ -1038,7 +1060,7 @@ var SmtVerifier = class _SmtVerifier {
|
|
|
1038
1060
|
);
|
|
1039
1061
|
}
|
|
1040
1062
|
try {
|
|
1041
|
-
const encoding = encode(runner.ctx, runner.fp, flatNet, this._initialMarking, this._property, invariants);
|
|
1063
|
+
const encoding = encode(runner.ctx, runner.fp, flatNet, this._initialMarking, this._property, invariants, this._sinkPlaces);
|
|
1042
1064
|
const queryResult = await runner.query(encoding.errorExpr, encoding.reachableDecl);
|
|
1043
1065
|
switch (queryResult.type) {
|
|
1044
1066
|
case "proven": {
|
|
@@ -1063,7 +1085,7 @@ var SmtVerifier = class _SmtVerifier {
|
|
|
1063
1085
|
report.push("");
|
|
1064
1086
|
}
|
|
1065
1087
|
report.push("=== RESULT ===\n");
|
|
1066
|
-
report.push(`PROVEN (IC3/PDR): ${
|
|
1088
|
+
report.push(`PROVEN (IC3/PDR): ${propDesc}`);
|
|
1067
1089
|
report.push(" Z3 Spacer proved no reachable state violates the property.");
|
|
1068
1090
|
report.push(" NOTE: Verification ignores timing constraints and JS guards.");
|
|
1069
1091
|
report.push(" An untimed proof is STRONGER than a timed one (timing only restricts behavior).");
|
|
@@ -1086,7 +1108,7 @@ var SmtVerifier = class _SmtVerifier {
|
|
|
1086
1108
|
report.push(" Status: SAT (counterexample found)\n");
|
|
1087
1109
|
const decoded = decode(runner.ctx, queryResult.answer, flatNet);
|
|
1088
1110
|
report.push("=== RESULT ===\n");
|
|
1089
|
-
report.push(`VIOLATED: ${
|
|
1111
|
+
report.push(`VIOLATED: ${propDesc}`);
|
|
1090
1112
|
if (decoded.trace.length > 0) {
|
|
1091
1113
|
report.push(` Counterexample trace (${decoded.trace.length} states):`);
|
|
1092
1114
|
for (let i = 0; i < decoded.trace.length; i++) {
|
|
@@ -1114,7 +1136,7 @@ var SmtVerifier = class _SmtVerifier {
|
|
|
1114
1136
|
report.push(` Status: UNKNOWN (${queryResult.reason})
|
|
1115
1137
|
`);
|
|
1116
1138
|
report.push("=== RESULT ===\n");
|
|
1117
|
-
report.push(`UNKNOWN: Could not determine ${
|
|
1139
|
+
report.push(`UNKNOWN: Could not determine ${propDesc}`);
|
|
1118
1140
|
report.push(` Reason: ${queryResult.reason}`);
|
|
1119
1141
|
return buildResult(
|
|
1120
1142
|
{ type: "unknown", reason: queryResult.reason },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/verification/marking-state.ts","../../src/verification/encoding/flat-transition.ts","../../src/verification/encoding/flat-net.ts","../../src/verification/encoding/incidence-matrix.ts","../../src/verification/encoding/net-flattener.ts","../../src/verification/invariant/p-invariant.ts","../../src/verification/invariant/p-invariant-computer.ts","../../src/verification/invariant/structural-check.ts","../../src/verification/smt-property.ts","../../src/verification/smt-verification-result.ts","../../src/verification/z3/spacer-runner.ts","../../src/verification/z3/smt-encoder.ts","../../src/verification/z3/counterexample-decoder.ts","../../src/verification/smt-verifier.ts"],"sourcesContent":["import type { Place } from '../core/place.js';\n\n/** @internal Symbol key restricting construction to the builder and factory methods. */\nconst MARKING_STATE_KEY = Symbol('MarkingState.internal');\n\n/**\n * Immutable snapshot of a Petri net marking for state space analysis.\n *\n * Maps places (by name) to integer token counts. Only stores places with count > 0.\n * Used for invariant computation and structural verification, not runtime execution.\n */\nexport class MarkingState {\n private readonly tokenCounts: ReadonlyMap<string, number>;\n private readonly placesByName: ReadonlyMap<string, Place<any>>;\n\n /** @internal Use {@link MarkingState.builder} or {@link MarkingState.empty} to create instances. */\n constructor(key: symbol, tokenCounts: Map<string, number>, placesByName: Map<string, Place<any>>) {\n if (key !== MARKING_STATE_KEY) throw new Error('Use MarkingState.builder() to create instances');\n this.tokenCounts = tokenCounts;\n this.placesByName = placesByName;\n }\n\n /** Returns the token count for a place (0 if absent). */\n tokens(place: Place<any>): number {\n return this.tokenCounts.get(place.name) ?? 0;\n }\n\n /** Checks if a place has at least one token. */\n hasTokens(place: Place<any>): boolean {\n return this.tokens(place) > 0;\n }\n\n /** Checks if any of the given places has tokens. */\n hasTokensInAny(places: Iterable<Place<any>>): boolean {\n for (const p of places) {\n if (this.hasTokens(p)) return true;\n }\n return false;\n }\n\n /** Returns all places with tokens > 0. */\n placesWithTokens(): Place<any>[] {\n return [...this.placesByName.values()];\n }\n\n /** Returns the total number of tokens. */\n totalTokens(): number {\n let sum = 0;\n for (const count of this.tokenCounts.values()) sum += count;\n return sum;\n }\n\n /** Checks if no tokens exist anywhere. */\n isEmpty(): boolean {\n return this.tokenCounts.size === 0;\n }\n\n toString(): string {\n if (this.tokenCounts.size === 0) return '{}';\n const entries = [...this.tokenCounts.entries()]\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([name, count]) => `${name}:${count}`);\n return `{${entries.join(', ')}}`;\n }\n\n static empty(): MarkingState {\n return new MarkingState(MARKING_STATE_KEY, new Map(), new Map());\n }\n\n static builder(): MarkingStateBuilder {\n return new MarkingStateBuilder();\n }\n}\n\nexport class MarkingStateBuilder {\n private readonly tokenCounts = new Map<string, number>();\n private readonly placesByName = new Map<string, Place<any>>();\n\n /** Sets the token count for a place. */\n tokens(place: Place<any>, count: number): this {\n if (count < 0) throw new Error(`Token count cannot be negative: ${count}`);\n if (count > 0) {\n this.tokenCounts.set(place.name, count);\n this.placesByName.set(place.name, place);\n } else {\n this.tokenCounts.delete(place.name);\n this.placesByName.delete(place.name);\n }\n return this;\n }\n\n /** Adds tokens to a place. */\n addTokens(place: Place<any>, count: number): this {\n if (count < 0) throw new Error(`Token count cannot be negative: ${count}`);\n if (count > 0) {\n const current = this.tokenCounts.get(place.name) ?? 0;\n this.tokenCounts.set(place.name, current + count);\n this.placesByName.set(place.name, place);\n }\n return this;\n }\n\n build(): MarkingState {\n return new MarkingState(MARKING_STATE_KEY, new Map(this.tokenCounts), new Map(this.placesByName));\n }\n}\n","import type { Transition } from '../../core/transition.js';\n\n/**\n * A flattened transition with pre/post vectors for SMT encoding.\n *\n * Each Transition with XOR outputs is expanded into multiple FlatTransitions\n * (one per branch). Non-XOR transitions map 1:1.\n */\nexport interface FlatTransition {\n /** Display name (e.g. \"Search_b0\", \"Search_b1\"). */\n readonly name: string;\n /** The original transition. */\n readonly source: Transition;\n /** Which XOR branch (-1 if no XOR). */\n readonly branchIndex: number;\n /** Tokens consumed per place (indexed by place index). */\n readonly preVector: readonly number[];\n /** Tokens produced per place (indexed by place index). */\n readonly postVector: readonly number[];\n /** Place indices where inhibitor arcs block firing. */\n readonly inhibitorPlaces: readonly number[];\n /** Place indices requiring a token without consuming. */\n readonly readPlaces: readonly number[];\n /** Place indices set to 0 on firing. */\n readonly resetPlaces: readonly number[];\n /** True at index i means place i uses All/AtLeast semantics. */\n readonly consumeAll: readonly boolean[];\n}\n\nexport function flatTransition(\n name: string,\n source: Transition,\n branchIndex: number,\n preVector: number[],\n postVector: number[],\n inhibitorPlaces: number[],\n readPlaces: number[],\n resetPlaces: number[],\n consumeAll: boolean[],\n): FlatTransition {\n return {\n name,\n source,\n branchIndex,\n preVector,\n postVector,\n inhibitorPlaces,\n readPlaces,\n resetPlaces,\n consumeAll,\n };\n}\n","import type { Place } from '../../core/place.js';\nimport type { FlatTransition } from './flat-transition.js';\n\n/**\n * A flattened Petri net with indexed places and XOR-expanded transitions.\n *\n * Intermediate representation between the high-level PetriNet and Z3 CHC encoding.\n */\nexport interface FlatNet {\n /** Ordered list of places (index = position). */\n readonly places: readonly Place<any>[];\n /** Reverse lookup: place name -> index. */\n readonly placeIndex: ReadonlyMap<string, number>;\n /** XOR-expanded flat transitions. */\n readonly transitions: readonly FlatTransition[];\n /** For bounded environment places: place name -> max tokens. */\n readonly environmentBounds: ReadonlyMap<string, number>;\n}\n\nexport function flatNetPlaceCount(net: FlatNet): number {\n return net.places.length;\n}\n\nexport function flatNetTransitionCount(net: FlatNet): number {\n return net.transitions.length;\n}\n\nexport function flatNetIndexOf(net: FlatNet, place: Place<any>): number {\n return net.placeIndex.get(place.name) ?? -1;\n}\n","import type { FlatNet } from './flat-net.js';\n\n/**\n * Incidence matrix for a flattened Petri net.\n *\n * The incidence matrix C is defined as C[t][p] = post[t][p] - pre[t][p].\n * It captures the net effect of each transition on each place.\n *\n * P-invariants are solutions to y^T * C = 0, found via null space\n * computation on C^T.\n */\nexport class IncidenceMatrix {\n private readonly _pre: readonly (readonly number[])[];\n private readonly _post: readonly (readonly number[])[];\n private readonly _incidence: readonly (readonly number[])[];\n private readonly _numTransitions: number;\n private readonly _numPlaces: number;\n\n private constructor(\n pre: number[][],\n post: number[][],\n incidence: number[][],\n numTransitions: number,\n numPlaces: number,\n ) {\n this._pre = pre;\n this._post = post;\n this._incidence = incidence;\n this._numTransitions = numTransitions;\n this._numPlaces = numPlaces;\n }\n\n /**\n * Computes the incidence matrix from a FlatNet.\n */\n static from(flatNet: FlatNet): IncidenceMatrix {\n const T = flatNet.transitions.length;\n const P = flatNet.places.length;\n\n const pre: number[][] = [];\n const post: number[][] = [];\n const incidence: number[][] = [];\n\n for (let t = 0; t < T; t++) {\n const ft = flatNet.transitions[t]!;\n const preRow = new Array<number>(P);\n const postRow = new Array<number>(P);\n const incRow = new Array<number>(P);\n\n for (let p = 0; p < P; p++) {\n preRow[p] = ft.preVector[p]!;\n postRow[p] = ft.postVector[p]!;\n incRow[p] = postRow[p]! - preRow[p]!;\n }\n\n pre.push(preRow);\n post.push(postRow);\n incidence.push(incRow);\n }\n\n return new IncidenceMatrix(pre, post, incidence, T, P);\n }\n\n /**\n * Returns C^T (transpose of incidence matrix), dimensions [P][T].\n * Used for P-invariant computation: null space of C^T gives P-invariants.\n */\n transposedIncidence(): number[][] {\n const ct: number[][] = [];\n for (let p = 0; p < this._numPlaces; p++) {\n const row = new Array<number>(this._numTransitions);\n for (let t = 0; t < this._numTransitions; t++) {\n row[t] = this._incidence[t]![p]!;\n }\n ct.push(row);\n }\n return ct;\n }\n\n /** Returns the pre-matrix (tokens consumed). T×P. */\n pre(): readonly (readonly number[])[] { return this._pre; }\n\n /** Returns the post-matrix (tokens produced). T×P. */\n post(): readonly (readonly number[])[] { return this._post; }\n\n /** Returns the incidence matrix C[t][p] = post - pre. T×P. */\n incidence(): readonly (readonly number[])[] { return this._incidence; }\n\n numTransitions(): number { return this._numTransitions; }\n numPlaces(): number { return this._numPlaces; }\n}\n","/**\n * @module net-flattener\n *\n * Flattens a PetriNet into integer-indexed pre/post vectors for SMT encoding.\n *\n * **XOR expansion**: Transitions with XOR output specs are expanded into multiple\n * flat transitions — one per deterministic branch. Each branch produces tokens to\n * exactly one XOR child's places. This converts non-deterministic output routing\n * into separate transitions that the SMT solver can reason about independently.\n *\n * **Vector construction**: For each flat transition, builds:\n * - `preVector[p]`: tokens consumed from place p (input cardinality)\n * - `postVector[p]`: tokens produced to place p (from the selected branch)\n * - `consumeAll[p]`: true for `all`/`at-least` inputs (consume everything)\n * - Index arrays for inhibitor, read, and reset arcs\n *\n * Places are sorted by name for stable, deterministic indexing across runs.\n */\nimport type { PetriNet } from '../../core/petri-net.js';\nimport type { Place, EnvironmentPlace } from '../../core/place.js';\nimport type { Out } from '../../core/out.js';\nimport type { FlatNet } from './flat-net.js';\nimport { flatTransition } from './flat-transition.js';\nimport { enumerateBranches, allPlaces as outAllPlaces } from '../../core/out.js';\n\n/**\n * How to treat environment places during analysis.\n */\nexport type EnvironmentAnalysisMode =\n | { readonly type: 'unbounded' }\n | { readonly type: 'bounded'; readonly maxTokens: number };\n\nexport function unbounded(): EnvironmentAnalysisMode {\n return { type: 'unbounded' };\n}\n\nexport function bounded(maxTokens: number): EnvironmentAnalysisMode {\n return { type: 'bounded', maxTokens };\n}\n\n/**\n * Flattens a PetriNet into a FlatNet suitable for SMT encoding.\n *\n * Flattening involves:\n * 1. Assigning each place a stable integer index (sorted by name)\n * 2. Expanding XOR outputs into separate flat transitions (one per branch)\n * 3. Building pre/post vectors from input/output specs\n * 4. Recording inhibitor, read, and reset arcs\n * 5. Setting environment bounds for bounded analysis mode\n */\nexport function flatten(\n net: PetriNet,\n environmentPlaces: Set<EnvironmentPlace<any>> = new Set(),\n environmentMode: EnvironmentAnalysisMode = unbounded(),\n): FlatNet {\n // 1. Collect ALL places\n const allPlacesSet = new Map<string, Place<any>>();\n for (const p of net.places) {\n allPlacesSet.set(p.name, p);\n }\n for (const t of net.transitions) {\n for (const inSpec of t.inputSpecs) {\n allPlacesSet.set(inSpec.place.name, inSpec.place);\n }\n if (t.outputSpec !== null) {\n for (const p of outAllPlaces(t.outputSpec)) {\n allPlacesSet.set(p.name, p);\n }\n }\n for (const arc of t.inhibitors) allPlacesSet.set(arc.place.name, arc.place);\n for (const arc of t.reads) allPlacesSet.set(arc.place.name, arc.place);\n for (const arc of t.resets) allPlacesSet.set(arc.place.name, arc.place);\n }\n\n // Sort by name for stable indexing\n const places = [...allPlacesSet.values()].sort((a, b) => a.name.localeCompare(b.name));\n\n const placeIndex = new Map<string, number>();\n for (let i = 0; i < places.length; i++) {\n placeIndex.set(places[i]!.name, i);\n }\n\n // 2. Compute environment bounds\n const environmentBounds = new Map<string, number>();\n if (environmentMode.type === 'bounded') {\n for (const ep of environmentPlaces) {\n environmentBounds.set(ep.place.name, environmentMode.maxTokens);\n }\n }\n\n // 3. Expand transitions\n const n = places.length;\n const flatTransitions = [];\n\n for (const transition of net.transitions) {\n const branches = enumerateOutputBranches(transition);\n\n for (let branchIdx = 0; branchIdx < branches.length; branchIdx++) {\n const branchPlaces = branches[branchIdx]!;\n const name = branches.length > 1\n ? `${transition.name}_b${branchIdx}`\n : transition.name;\n\n // Build pre-vector and consumeAll flags\n const preVector = new Array<number>(n).fill(0);\n const consumeAll = new Array<boolean>(n).fill(false);\n\n for (const inSpec of transition.inputSpecs) {\n const idx = placeIndex.get(inSpec.place.name);\n if (idx === undefined) continue;\n\n switch (inSpec.type) {\n case 'one':\n preVector[idx] = 1;\n break;\n case 'exactly':\n preVector[idx] = inSpec.count;\n break;\n case 'all':\n preVector[idx] = 1;\n consumeAll[idx] = true;\n break;\n case 'at-least':\n preVector[idx] = inSpec.minimum;\n consumeAll[idx] = true;\n break;\n }\n }\n\n // Build post-vector from branch output places\n const postVector = new Array<number>(n).fill(0);\n for (const p of branchPlaces) {\n const idx = placeIndex.get(p.name);\n if (idx !== undefined) {\n postVector[idx] = 1;\n }\n }\n\n // Inhibitor places\n const inhibitorPlaces = transition.inhibitors\n .map(arc => placeIndex.get(arc.place.name))\n .filter((idx): idx is number => idx !== undefined);\n\n // Read places\n const readPlaces = transition.reads\n .map(arc => placeIndex.get(arc.place.name))\n .filter((idx): idx is number => idx !== undefined);\n\n // Reset places\n const resetPlaces = transition.resets\n .map(arc => placeIndex.get(arc.place.name))\n .filter((idx): idx is number => idx !== undefined);\n\n flatTransitions.push(flatTransition(\n name,\n transition,\n branches.length > 1 ? branchIdx : -1,\n preVector,\n postVector,\n inhibitorPlaces,\n readPlaces,\n resetPlaces,\n consumeAll,\n ));\n }\n }\n\n return {\n places,\n placeIndex,\n transitions: flatTransitions,\n environmentBounds,\n };\n}\n\nfunction enumerateOutputBranches(t: { outputSpec: Out | null }): ReadonlySet<Place<any>>[] {\n if (t.outputSpec !== null) {\n return enumerateBranches(t.outputSpec) as ReadonlySet<Place<any>>[];\n }\n // No outputs (sink transition)\n return [new Set()];\n}\n","/**\n * A P-invariant (place invariant) of a Petri net.\n *\n * A P-invariant is a vector y such that y^T * C = 0, where C is the\n * incidence matrix. This means that for any reachable marking M:\n * sum(y_i * M_i) = constant, where constant = sum(y_i * M0_i).\n *\n * P-invariants provide structural bounds on places and are used as\n * strengthening lemmas for the IC3/PDR engine.\n */\nexport interface PInvariant {\n /** Weight vector (one entry per place index). */\n readonly weights: readonly number[];\n /** The invariant value sum(y_i * M0_i). */\n readonly constant: number;\n /** Set of place indices where weight != 0. */\n readonly support: ReadonlySet<number>;\n}\n\nexport function pInvariant(weights: number[], constant: number, support: Set<number>): PInvariant {\n return { weights, constant, support };\n}\n\nexport function pInvariantToString(inv: PInvariant): string {\n const parts: string[] = [];\n for (const i of inv.support) {\n if (inv.weights[i] !== 1) {\n parts.push(`${inv.weights[i]}*p${i}`);\n } else {\n parts.push(`p${i}`);\n }\n }\n return `PInvariant[${parts.join(' + ')} = ${inv.constant}]`;\n}\n","/**\n * @module p-invariant-computer\n *\n * Computes P-invariants of a Petri net via integer Gaussian elimination (Farkas' algorithm).\n *\n * **Algorithm**: A P-invariant is a non-negative integer vector y such that y^T · C = 0\n * (where C is the incidence matrix). This expresses a conservation law: the weighted\n * token sum Σ(y_i · M[i]) is constant across all reachable markings.\n *\n * **Farkas variant**: Constructs the augmented matrix [C^T | I_P] and row-reduces\n * the C^T portion to zero using integer elimination (no floating point). Rows where\n * the C^T part becomes all-zero yield invariant vectors from the identity part.\n * Row normalization by GCD keeps values small during elimination.\n *\n * **Integer Gaussian elimination**: Each elimination step multiplies rows by pivot\n * coefficients (a·row - b·pivotRow) to avoid fractions. This preserves integer\n * arithmetic throughout, critical for exact invariant computation.\n *\n * Invariants are used to strengthen SMT queries (added as constraints on M').\n */\nimport type { FlatNet } from '../encoding/flat-net.js';\nimport type { IncidenceMatrix } from '../encoding/incidence-matrix.js';\nimport type { MarkingState } from '../marking-state.js';\nimport type { PInvariant } from './p-invariant.js';\nimport { pInvariant } from './p-invariant.js';\n\n/**\n * Computes P-invariants of a Petri net via integer Gaussian elimination.\n *\n * P-invariants are non-negative integer vectors y where y^T * C = 0.\n * They express conservation laws: the weighted token sum is constant\n * across all reachable markings.\n *\n * Algorithm: compute the null space of C^T using integer row reduction\n * with an augmented identity matrix (Farkas' algorithm variant).\n */\nexport function computePInvariants(\n matrix: IncidenceMatrix,\n flatNet: FlatNet,\n initialMarking: MarkingState,\n): PInvariant[] {\n const P = matrix.numPlaces();\n const T = matrix.numTransitions();\n\n if (P === 0 || T === 0) return [];\n\n // We want to find y such that y^T * C = 0, i.e., C^T * y = 0\n // Start with augmented matrix [C^T | I_P]\n // Row-reduce C^T part to zero; the I_P part gives the invariant vectors.\n const ct = matrix.transposedIncidence(); // P × T\n\n // Augmented matrix: P rows, T + P columns\n // Use regular numbers (safe for nets with < ~50 places/transitions)\n const cols = T + P;\n const augmented: number[][] = [];\n for (let i = 0; i < P; i++) {\n const row = new Array<number>(cols).fill(0);\n for (let j = 0; j < T; j++) {\n row[j] = ct[i]![j]!;\n }\n row[T + i] = 1; // identity part\n augmented.push(row);\n }\n\n // Integer Gaussian elimination on the C^T part (columns 0..T-1)\n let pivotRow = 0;\n for (let col = 0; col < T && pivotRow < P; col++) {\n // Find pivot (non-zero entry in this column)\n let pivot = -1;\n for (let row = pivotRow; row < P; row++) {\n if (augmented[row]![col] !== 0) {\n pivot = row;\n break;\n }\n }\n if (pivot === -1) continue; // free variable\n\n // Swap pivot row\n if (pivot !== pivotRow) {\n const tmp = augmented[pivotRow]!;\n augmented[pivotRow] = augmented[pivot]!;\n augmented[pivot] = tmp;\n }\n\n // Eliminate this column in all other rows\n for (let row = 0; row < P; row++) {\n if (row === pivotRow || augmented[row]![col] === 0) continue;\n\n const a = augmented[pivotRow]![col]!;\n const b = augmented[row]![col]!;\n\n // row = a*row - b*pivotRow (keeps integers, eliminates col)\n for (let c = 0; c < cols; c++) {\n augmented[row]![c] = a * augmented[row]![c]! - b * augmented[pivotRow]![c]!;\n }\n\n // Normalize by GCD to keep values small\n normalizeRow(augmented[row]!, cols);\n }\n\n pivotRow++;\n }\n\n // Extract invariants: rows where C^T part is all zeros\n const invariants: PInvariant[] = [];\n for (let row = 0; row < P; row++) {\n let isZero = true;\n for (let col = 0; col < T; col++) {\n if (augmented[row]![col] !== 0) {\n isZero = false;\n break;\n }\n }\n if (!isZero) continue;\n\n // Extract the weight vector from the identity part\n const weights = new Array<number>(P);\n let allNonNegative = true;\n let hasPositive = false;\n\n for (let i = 0; i < P; i++) {\n weights[i] = augmented[row]![T + i]!;\n if (weights[i]! < 0) {\n allNonNegative = false;\n break;\n }\n if (weights[i]! > 0) hasPositive = true;\n }\n\n // We want semi-positive invariants (all weights >= 0, at least one > 0)\n if (!allNonNegative) {\n // Try negating\n let allNonPositive = true;\n for (let i = 0; i < P; i++) {\n if (augmented[row]![T + i]! > 0) {\n allNonPositive = false;\n break;\n }\n }\n if (allNonPositive) {\n for (let i = 0; i < P; i++) {\n weights[i] = -augmented[row]![T + i]!;\n }\n hasPositive = true;\n allNonNegative = true;\n }\n }\n\n if (!allNonNegative || !hasPositive) continue;\n\n // Normalize: divide by GCD of weights\n let g = 0;\n for (const w of weights) {\n if (w > 0) g = gcd(g, w);\n }\n if (g > 1) {\n for (let i = 0; i < P; i++) {\n weights[i] = weights[i]! / g;\n }\n }\n\n // Compute support and constant\n const support = new Set<number>();\n let constant = 0;\n for (let i = 0; i < P; i++) {\n if (weights[i] !== 0) {\n support.add(i);\n const place = flatNet.places[i]!;\n constant += weights[i]! * initialMarking.tokens(place);\n }\n }\n\n invariants.push(pInvariant(weights, constant, support));\n }\n\n return invariants;\n}\n\n/**\n * Checks if every place is covered by at least one P-invariant.\n * If true, the net is structurally bounded.\n */\nexport function isCoveredByInvariants(invariants: readonly PInvariant[], numPlaces: number): boolean {\n const covered = new Array<boolean>(numPlaces).fill(false);\n for (const inv of invariants) {\n for (const idx of inv.support) {\n if (idx < numPlaces) covered[idx] = true;\n }\n }\n return covered.every(c => c);\n}\n\nfunction normalizeRow(row: number[], cols: number): void {\n let g = 0;\n for (let c = 0; c < cols; c++) {\n if (row[c] !== 0) {\n g = gcd(g, Math.abs(row[c]!));\n }\n }\n if (g > 1) {\n for (let c = 0; c < cols; c++) {\n row[c] = row[c]! / g;\n }\n }\n}\n\nfunction gcd(a: number, b: number): number {\n while (b !== 0) {\n const t = b;\n b = a % b;\n a = t;\n }\n return a;\n}\n","/**\n * @module structural-check\n *\n * Structural deadlock pre-check using siphon/trap analysis (Commoner's theorem).\n *\n * **Commoner's theorem**: A Petri net is deadlock-free if every siphon contains\n * an initially marked trap.\n *\n * **Siphon**: A set of places S where every transition that outputs to S also\n * inputs from S. Key property: once all places in a siphon become empty,\n * they can never be re-marked. An empty siphon can cause deadlock.\n *\n * **Trap**: A set of places S where every transition that inputs from S also\n * outputs to S. Key property: once any place in a trap is marked,\n * the trap remains marked forever.\n *\n * **Algorithm**: For each place, compute the minimal siphon containing it via\n * fixed-point expansion. For each siphon, find the maximal trap within it\n * (fixed-point contraction). If every siphon contains an initially-marked\n * trap, deadlock-freedom is proven structurally — no SMT query needed.\n *\n * Limited to nets with ≤50 places to bound enumeration cost.\n */\nimport type { FlatNet } from '../encoding/flat-net.js';\nimport type { MarkingState } from '../marking-state.js';\n\nconst MAX_PLACES_FOR_SIPHON_ANALYSIS = 50;\n\n/**\n * Result of structural deadlock check using siphon/trap analysis.\n */\nexport type StructuralCheckResult =\n | { readonly type: 'no-potential-deadlock' }\n | { readonly type: 'potential-deadlock'; readonly siphon: ReadonlySet<number> }\n | { readonly type: 'inconclusive'; readonly reason: string };\n\n/**\n * Structural deadlock pre-check using siphon/trap analysis.\n *\n * Commoner's theorem: a Petri net is deadlock-free if every siphon\n * contains a marked trap.\n *\n * A siphon is a set of places S such that every transition with\n * an output in S also has an input in S. Once empty, a siphon stays empty.\n *\n * A trap is a set of places S such that every transition with\n * an input in S also has an output in S. Once marked, a trap stays marked.\n */\nexport function structuralCheck(flatNet: FlatNet, initialMarking: MarkingState): StructuralCheckResult {\n const P = flatNet.places.length;\n\n if (P === 0) {\n return { type: 'no-potential-deadlock' };\n }\n\n if (P > MAX_PLACES_FOR_SIPHON_ANALYSIS) {\n return { type: 'inconclusive', reason: `Net has ${P} places, siphon enumeration skipped` };\n }\n\n const siphons = findMinimalSiphons(flatNet);\n\n if (siphons.length === 0) {\n return { type: 'no-potential-deadlock' };\n }\n\n for (const siphon of siphons) {\n const trap = findMaximalTrapIn(flatNet, siphon);\n\n if (trap.size === 0 || !isMarked(trap, flatNet, initialMarking)) {\n return { type: 'potential-deadlock', siphon };\n }\n }\n\n return { type: 'no-potential-deadlock' };\n}\n\n/**\n * Finds minimal siphons by checking all non-empty subsets of deadlock-enabling places.\n * Uses a fixed-point approach: start from each place and grow the siphon.\n */\nexport function findMinimalSiphons(flatNet: FlatNet): ReadonlySet<number>[] {\n const P = flatNet.places.length;\n const siphons: Set<number>[] = [];\n\n // Pre-compute: for each place, which transitions have it as output?\n const placeAsOutput: number[][] = [];\n for (let p = 0; p < P; p++) {\n placeAsOutput.push([]);\n }\n\n for (let t = 0; t < flatNet.transitions.length; t++) {\n const ft = flatNet.transitions[t]!;\n for (let p = 0; p < P; p++) {\n if (ft.postVector[p]! > 0) {\n placeAsOutput[p]!.push(t);\n }\n }\n }\n\n for (let startPlace = 0; startPlace < P; startPlace++) {\n const siphon = computeSiphonContaining(startPlace, flatNet, placeAsOutput);\n if (siphon !== null && siphon.size > 0) {\n let isMinimal = true;\n const toRemove: number[] = [];\n for (let i = 0; i < siphons.length; i++) {\n const existing = siphons[i]!;\n if (setsEqual(existing, siphon)) {\n isMinimal = false;\n break;\n }\n if (isSubsetOf(existing, siphon)) {\n isMinimal = false;\n break;\n }\n if (isSubsetOf(siphon, existing)) {\n toRemove.push(i);\n }\n }\n for (let i = toRemove.length - 1; i >= 0; i--) {\n siphons.splice(toRemove[i]!, 1);\n }\n if (isMinimal) {\n siphons.push(siphon);\n }\n }\n }\n\n return siphons;\n}\n\nfunction computeSiphonContaining(\n startPlace: number,\n flatNet: FlatNet,\n placeAsOutput: number[][],\n): Set<number> | null {\n const siphon = new Set<number>();\n siphon.add(startPlace);\n\n let changed = true;\n while (changed) {\n changed = false;\n const snapshot = [...siphon];\n\n for (const p of snapshot) {\n for (const t of placeAsOutput[p]!) {\n const ft = flatNet.transitions[t]!;\n\n let hasInputInSiphon = false;\n for (let q = 0; q < flatNet.places.length; q++) {\n if (ft.preVector[q]! > 0 && siphon.has(q)) {\n hasInputInSiphon = true;\n break;\n }\n }\n\n if (!hasInputInSiphon) {\n let added = false;\n for (let q = 0; q < flatNet.places.length; q++) {\n if (ft.preVector[q]! > 0) {\n if (!siphon.has(q)) {\n siphon.add(q);\n changed = true;\n }\n added = true;\n break;\n }\n }\n if (!added) {\n return null;\n }\n }\n }\n }\n }\n\n return siphon;\n}\n\n/**\n * Finds the maximal trap within a given set of places.\n * Uses fixed-point: start with the full set and remove places that violate the trap condition.\n */\nexport function findMaximalTrapIn(flatNet: FlatNet, places: ReadonlySet<number>): ReadonlySet<number> {\n const trap = new Set(places);\n\n let changed = true;\n while (changed) {\n changed = false;\n const toRemove: number[] = [];\n\n for (const p of trap) {\n let satisfies = true;\n for (let t = 0; t < flatNet.transitions.length; t++) {\n const ft = flatNet.transitions[t]!;\n if (ft.preVector[p]! > 0) {\n let outputsToTrap = false;\n for (const q of trap) {\n if (ft.postVector[q]! > 0) {\n outputsToTrap = true;\n break;\n }\n }\n if (!outputsToTrap) {\n satisfies = false;\n break;\n }\n }\n }\n if (!satisfies) {\n toRemove.push(p);\n }\n }\n\n if (toRemove.length > 0) {\n for (const p of toRemove) trap.delete(p);\n changed = true;\n }\n }\n\n return trap;\n}\n\nfunction isMarked(placeIndices: ReadonlySet<number>, flatNet: FlatNet, marking: MarkingState): boolean {\n for (const idx of placeIndices) {\n const place = flatNet.places[idx]!;\n if (marking.tokens(place) > 0) return true;\n }\n return false;\n}\n\nfunction setsEqual(a: ReadonlySet<number>, b: ReadonlySet<number>): boolean {\n if (a.size !== b.size) return false;\n for (const v of a) {\n if (!b.has(v)) return false;\n }\n return true;\n}\n\nfunction isSubsetOf(sub: ReadonlySet<number>, sup: ReadonlySet<number>): boolean {\n if (sub.size > sup.size) return false;\n for (const v of sub) {\n if (!sup.has(v)) return false;\n }\n return true;\n}\n","import type { Place } from '../core/place.js';\n\n/**\n * Safety properties that can be verified via IC3/PDR.\n *\n * Each property is encoded as an error condition: if a reachable state\n * violates the property, Spacer finds a counterexample. If no violation\n * is reachable, the property is proven.\n */\nexport type SmtProperty = DeadlockFree | MutualExclusion | PlaceBound | Unreachable;\n\n/** Deadlock-freedom: no reachable marking has all transitions disabled. */\nexport interface DeadlockFree {\n readonly type: 'deadlock-free';\n}\n\n/** Mutual exclusion: two places never have tokens simultaneously. */\nexport interface MutualExclusion {\n readonly type: 'mutual-exclusion';\n readonly p1: Place<any>;\n readonly p2: Place<any>;\n}\n\n/** Place bound: a place never exceeds a given token count. */\nexport interface PlaceBound {\n readonly type: 'place-bound';\n readonly place: Place<any>;\n readonly bound: number;\n}\n\n/** Unreachability: the given places never all have tokens simultaneously. */\nexport interface Unreachable {\n readonly type: 'unreachable';\n readonly places: ReadonlySet<Place<any>>;\n}\n\n// Factory functions\n\nexport function deadlockFree(): DeadlockFree {\n return { type: 'deadlock-free' };\n}\n\nexport function mutualExclusion(p1: Place<any>, p2: Place<any>): MutualExclusion {\n return { type: 'mutual-exclusion', p1, p2 };\n}\n\nexport function placeBound(place: Place<any>, bound: number): PlaceBound {\n return { type: 'place-bound', place, bound };\n}\n\nexport function unreachable(places: ReadonlySet<Place<any>>): Unreachable {\n return { type: 'unreachable', places: new Set(places) };\n}\n\n/** Human-readable description of a property. */\nexport function propertyDescription(prop: SmtProperty): string {\n switch (prop.type) {\n case 'deadlock-free':\n return 'Deadlock-freedom';\n case 'mutual-exclusion':\n return `Mutual exclusion of ${prop.p1.name} and ${prop.p2.name}`;\n case 'place-bound':\n return `Place ${prop.place.name} bounded by ${prop.bound}`;\n case 'unreachable':\n return `Unreachability of marking with tokens in {${[...prop.places].map(p => p.name).join(', ')}}`;\n }\n}\n","import type { MarkingState } from './marking-state.js';\nimport type { PInvariant } from './invariant/p-invariant.js';\n\n/**\n * Verification verdict.\n */\nexport type Verdict = Proven | Violated | Unknown;\n\n/** Property proven safe. No reachable state violates it. */\nexport interface Proven {\n readonly type: 'proven';\n readonly method: string;\n readonly inductiveInvariant: string | null;\n}\n\n/** Property violated. A counterexample trace is available. */\nexport interface Violated {\n readonly type: 'violated';\n}\n\n/** Could not determine. */\nexport interface Unknown {\n readonly type: 'unknown';\n readonly reason: string;\n}\n\n/**\n * Solver statistics.\n */\nexport interface SmtStatistics {\n readonly places: number;\n readonly transitions: number;\n readonly invariantsFound: number;\n readonly structuralResult: string;\n}\n\n/**\n * Result of SMT-based verification.\n */\nexport interface SmtVerificationResult {\n readonly verdict: Verdict;\n readonly report: string;\n readonly invariants: readonly PInvariant[];\n readonly discoveredInvariants: readonly string[];\n readonly counterexampleTrace: readonly MarkingState[];\n readonly counterexampleTransitions: readonly string[];\n readonly elapsedMs: number;\n readonly statistics: SmtStatistics;\n}\n\nexport function isProven(result: SmtVerificationResult): boolean {\n return result.verdict.type === 'proven';\n}\n\nexport function isViolated(result: SmtVerificationResult): boolean {\n return result.verdict.type === 'violated';\n}\n","import { init } from 'z3-solver';\nimport type { Bool, Expr, FuncDecl } from 'z3-solver';\n\n/**\n * Result of a Spacer query.\n */\nexport type QueryResult = QueryProven | QueryViolated | QueryUnknown;\n\n/** Property proven: no reachable error state (UNSAT). */\nexport interface QueryProven {\n readonly type: 'proven';\n readonly invariantFormula: string | null;\n readonly levelInvariants: readonly string[];\n}\n\n/** Counterexample found (SAT). The answer is the derivation tree. */\nexport interface QueryViolated {\n readonly type: 'violated';\n readonly answer: Expr | null;\n}\n\n/** Solver could not determine (timeout, resource limit). */\nexport interface QueryUnknown {\n readonly type: 'unknown';\n readonly reason: string;\n}\n\n/**\n * The Z3 context and helpers returned by SpacerRunner.create().\n * Exposes the context object for building expressions.\n */\nexport interface SpacerContext {\n /** The Z3 high-level context for building expressions. */\n readonly ctx: ReturnType<Awaited<ReturnType<typeof init>>['Context']>;\n /** The Z3 Fixedpoint solver instance (Spacer engine). Z3 types are complex; using any. */\n readonly fp: any;\n\n /** Queries whether the error state is reachable. */\n query(errorExpr: Bool, reachableDecl?: FuncDecl): Promise<QueryResult>;\n\n /** Releases Z3 resources. */\n dispose(): void;\n}\n\n// Use a type alias for the Z3 context to avoid the deep inference\ntype Z3Context = ReturnType<Awaited<ReturnType<typeof init>>['Context']>;\n\n/**\n * Creates a Spacer runner with the given timeout.\n *\n * Uses Z3's Spacer engine (CHC solver based on IC3/PDR) to prove or\n * disprove safety properties.\n */\nexport async function createSpacerRunner(timeoutMs: number): Promise<SpacerContext> {\n const { Context } = await init();\n const ctx = new Context('main') as Z3Context;\n const fp = new (ctx as any).Fixedpoint() as any;\n\n // Configure Spacer engine\n fp.set('engine', 'spacer');\n fp.set('spacer.global', true);\n fp.set('spacer.use_bg_invs', true);\n if (timeoutMs > 0) {\n fp.set('timeout', Math.min(timeoutMs, 2147483647));\n }\n\n async function query(errorExpr: Bool, reachableDecl?: FuncDecl): Promise<QueryResult> {\n try {\n const status = await fp.query(errorExpr);\n\n if (status === 'unsat') {\n let invariantFormula: string | null = null;\n const levelInvariants: string[] = [];\n\n try {\n const answer = fp.getAnswer();\n if (answer != null) {\n invariantFormula = answer.toString();\n }\n } catch {\n // Some configurations don't produce answers\n }\n\n if (reachableDecl != null) {\n try {\n const levels = fp.getNumLevels(reachableDecl);\n for (let i = 0; i < levels; i++) {\n const cover = fp.getCoverDelta(i, reachableDecl);\n if (cover != null && !(ctx as any).isTrue(cover)) {\n levelInvariants.push(`Level ${i}: ${cover.toString()}`);\n }\n }\n } catch {\n // Level queries may not be available\n }\n }\n\n return { type: 'proven', invariantFormula, levelInvariants };\n }\n\n if (status === 'sat') {\n let answer: Expr | null = null;\n try {\n answer = fp.getAnswer();\n } catch {\n // Some configurations don't produce answers\n }\n return { type: 'violated', answer };\n }\n\n // unknown\n return { type: 'unknown', reason: fp.getReasonUnknown() };\n } catch (e: any) {\n return { type: 'unknown', reason: `Z3 exception: ${e.message ?? e}` };\n }\n }\n\n function dispose(): void {\n try {\n fp.release();\n } catch {\n // ignore\n }\n }\n\n return {\n ctx,\n fp,\n query,\n dispose,\n } as SpacerContext;\n}\n","/**\n * @module smt-encoder\n *\n * Encodes a flattened Petri net as Constrained Horn Clauses (CHC) for Z3's Spacer engine.\n *\n * **CHC encoding strategy**: The net's state space is modeled as integer vectors\n * (one variable per place = token count). Three rule types:\n *\n * 1. **Init**: `Reachable(M0)` — the initial marking is reachable\n * 2. **Transition**: `Reachable(M') :- Reachable(M) ∧ enabled(M,t) ∧ fire(M,M',t)` —\n * one rule per flat transition (XOR branches are separate transitions)\n * 3. **Error**: `Error() :- Reachable(M) ∧ violation(M)` — safety property violation\n *\n * Transition rules include: non-negativity constraints on M', P-invariant strengthening\n * clauses, and environment bounds for bounded analysis.\n *\n * Z3 types are complex and partially untyped; the ctx/fp parameters use `any`.\n */\nimport type { Arith, Bool, FuncDecl } from 'z3-solver';\nimport type { FlatNet } from '../encoding/flat-net.js';\nimport type { FlatTransition } from '../encoding/flat-transition.js';\nimport type { MarkingState } from '../marking-state.js';\nimport type { SmtProperty } from '../smt-property.js';\nimport type { PInvariant } from '../invariant/p-invariant.js';\nimport { flatNetIndexOf } from '../encoding/flat-net.js';\n\n/** Z3 high-level context. Typed as `any` because z3-solver's TS types are incomplete. */\ntype Z3Context = any;\n/** Z3 Fixedpoint solver instance. Typed as `any` because z3-solver's TS types are incomplete. */\ntype Z3Fixedpoint = any;\n\n/**\n * Result of CHC encoding.\n */\nexport interface EncodingResult {\n readonly errorExpr: Bool;\n readonly reachableDecl: FuncDecl;\n}\n\n/**\n * Encodes a flattened Petri net as Constrained Horn Clauses (CHC) for Z3's Spacer engine.\n *\n * CHC rules:\n * - Reachable(M0) — initial state is reachable\n * - Reachable(M') :- Reachable(M) AND enabled(M,t) AND fire(M,M',t) — transition rules\n * - Error() :- Reachable(M) AND property_violation(M) — safety property\n */\nexport function encode(\n ctx: Z3Context,\n fp: Z3Fixedpoint,\n flatNet: FlatNet,\n initialMarking: MarkingState,\n property: SmtProperty,\n invariants: readonly PInvariant[],\n): EncodingResult {\n const P = flatNet.places.length;\n const Int = ctx.Int;\n const Bool_ = ctx.Bool;\n\n // Create sorts array for function declaration\n const intSort = Int.sort();\n const boolSort = Bool_.sort();\n const markingSorts: any[] = new Array(P).fill(intSort);\n\n // Create the Reachable relation: (Int, Int, ...) -> Bool\n const reachable: FuncDecl = ctx.Function.declare('Reachable', ...markingSorts, boolSort);\n fp.registerRelation(reachable);\n\n // Create the Error relation: () -> Bool\n const error: FuncDecl = ctx.Function.declare('Error', boolSort);\n fp.registerRelation(error);\n\n // === Rule 1: Initial state ===\n // Reachable(m0_0, m0_1, ..., m0_{P-1})\n const m0Args: Arith[] = [];\n for (let i = 0; i < P; i++) {\n const tokens = initialMarking.tokens(flatNet.places[i]!);\n m0Args.push(Int.val(tokens));\n }\n const initFact = (reachable as any).call(...m0Args) as Bool;\n fp.addRule(initFact, 'init');\n\n // === Rule 2: Transition rules ===\n for (let t = 0; t < flatNet.transitions.length; t++) {\n const ft = flatNet.transitions[t]!;\n encodeTransitionRule(ctx, fp, reachable, ft, flatNet, invariants, P);\n }\n\n // === Rule 3: Error rule (property violation) ===\n encodeErrorRule(ctx, fp, reachable, error, flatNet, property, P);\n\n return {\n errorExpr: (error as any).call() as Bool,\n reachableDecl: reachable,\n };\n}\n\nfunction encodeTransitionRule(\n ctx: Z3Context,\n fp: Z3Fixedpoint,\n reachable: FuncDecl,\n ft: FlatTransition,\n flatNet: FlatNet,\n invariants: readonly PInvariant[],\n P: number,\n): void {\n const Int = ctx.Int;\n\n // Create named variables for current and next marking\n const mVars: Arith[] = [];\n const mPrimeVars: Arith[] = [];\n for (let i = 0; i < P; i++) {\n mVars.push(Int.const(`m${i}`));\n mPrimeVars.push(Int.const(`mp${i}`));\n }\n\n // Body: Reachable(M) AND enabled(M,t) AND fire(M,M',t) AND non-negativity(M') AND invariants(M') AND env bounds(M')\n const reachBody = (reachable as any).call(...mVars) as Bool;\n const enabled = encodeEnabled(ctx, ft, flatNet, mVars, P);\n const fireRelation = encodeFire(ctx, ft, flatNet, mVars, mPrimeVars, P);\n\n // Non-negativity of M'\n let nonNeg: Bool = ctx.Bool.val(true);\n for (let i = 0; i < P; i++) {\n nonNeg = ctx.And(nonNeg, mPrimeVars[i]!.ge(0));\n }\n\n // P-invariant constraints on M'\n const invConstraints = encodeInvariantConstraints(ctx, invariants, mPrimeVars, P);\n\n // Environment bounds on M'\n let envBounds: Bool = ctx.Bool.val(true);\n for (const [name, bound] of flatNet.environmentBounds) {\n const idx = flatNet.placeIndex.get(name);\n if (idx != null) {\n envBounds = ctx.And(envBounds, mPrimeVars[idx]!.le(bound));\n }\n }\n\n // Body conjunction\n const body = ctx.And(reachBody, enabled, fireRelation, nonNeg, invConstraints, envBounds);\n\n // Head: Reachable(M')\n const head = (reachable as any).call(...mPrimeVars) as Bool;\n\n // Rule: forall M, M'. body => head\n const allVars = [...mVars, ...mPrimeVars];\n const rule = ctx.Implies(body, head);\n const qRule = ctx.ForAll(allVars, rule);\n\n fp.addRule(qRule, `t_${ft.name}`);\n}\n\nfunction encodeEnabled(\n ctx: Z3Context,\n ft: FlatTransition,\n _flatNet: FlatNet,\n mVars: Arith[],\n P: number,\n): Bool {\n let result: Bool = ctx.Bool.val(true);\n\n // Input requirements: M[p] >= pre[p]\n for (let p = 0; p < P; p++) {\n if (ft.preVector[p]! > 0) {\n result = ctx.And(result, mVars[p]!.ge(ft.preVector[p]!));\n }\n }\n\n // Read arcs: M[p] >= 1\n for (const p of ft.readPlaces) {\n result = ctx.And(result, mVars[p]!.ge(1));\n }\n\n // Inhibitor arcs: M[p] == 0\n for (const p of ft.inhibitorPlaces) {\n result = ctx.And(result, mVars[p]!.eq(0));\n }\n\n // Non-negativity of current marking\n for (let p = 0; p < P; p++) {\n result = ctx.And(result, mVars[p]!.ge(0));\n }\n\n return result;\n}\n\nfunction encodeFire(\n ctx: Z3Context,\n ft: FlatTransition,\n _flatNet: FlatNet,\n mVars: Arith[],\n mPrimeVars: Arith[],\n P: number,\n): Bool {\n let result: Bool = ctx.Bool.val(true);\n\n for (let p = 0; p < P; p++) {\n const isReset = ft.resetPlaces.includes(p);\n\n if (isReset || ft.consumeAll[p]) {\n // Reset/consumeAll: M'[p] = post[p]\n result = ctx.And(result, mPrimeVars[p]!.eq(ft.postVector[p]!));\n } else {\n // Standard: M'[p] = M[p] - pre[p] + post[p]\n const delta = ft.postVector[p]! - ft.preVector[p]!;\n if (delta === 0) {\n result = ctx.And(result, mPrimeVars[p]!.eq(mVars[p]!));\n } else {\n result = ctx.And(result, mPrimeVars[p]!.eq(mVars[p]!.add(delta)));\n }\n }\n }\n\n return result;\n}\n\nfunction encodeErrorRule(\n ctx: Z3Context,\n fp: Z3Fixedpoint,\n reachable: FuncDecl,\n error: FuncDecl,\n flatNet: FlatNet,\n property: SmtProperty,\n P: number,\n): void {\n const Int = ctx.Int;\n\n // Create variables for the error rule\n const mVars: Arith[] = [];\n for (let i = 0; i < P; i++) {\n mVars.push(Int.const(`em${i}`));\n }\n\n const reachBody = (reachable as any).call(...mVars) as Bool;\n const violation = encodePropertyViolation(ctx, flatNet, property, mVars, P);\n\n const head = (error as any).call() as Bool;\n const body = ctx.And(reachBody, violation);\n const rule = ctx.Implies(body, head);\n const qRule = ctx.ForAll(mVars, rule);\n\n fp.addRule(qRule, `error_${property.type}`);\n}\n\nfunction encodePropertyViolation(\n ctx: Z3Context,\n flatNet: FlatNet,\n property: SmtProperty,\n mVars: Arith[],\n P: number,\n): Bool {\n switch (property.type) {\n case 'deadlock-free':\n return encodeDeadlock(ctx, flatNet, mVars, P);\n\n case 'mutual-exclusion': {\n const idx1 = flatNetIndexOf(flatNet, property.p1);\n const idx2 = flatNetIndexOf(flatNet, property.p2);\n if (idx1 < 0) throw new Error(`MutualExclusion references unknown place: ${property.p1.name}`);\n if (idx2 < 0) throw new Error(`MutualExclusion references unknown place: ${property.p2.name}`);\n return ctx.And(mVars[idx1]!.ge(1), mVars[idx2]!.ge(1));\n }\n\n case 'place-bound': {\n const idx = flatNetIndexOf(flatNet, property.place);\n if (idx < 0) throw new Error(`PlaceBound references unknown place: ${property.place.name}`);\n return mVars[idx]!.gt(property.bound);\n }\n\n case 'unreachable': {\n let allMarked: Bool = ctx.Bool.val(true);\n for (const place of property.places) {\n const idx = flatNetIndexOf(flatNet, place);\n if (idx >= 0) {\n allMarked = ctx.And(allMarked, mVars[idx]!.ge(1));\n }\n }\n return allMarked;\n }\n }\n}\n\n/** Encodes the deadlock condition: no transition is enabled. */\nfunction encodeDeadlock(\n ctx: Z3Context,\n flatNet: FlatNet,\n mVars: Arith[],\n P: number,\n): Bool {\n let deadlock: Bool = ctx.Bool.val(true);\n\n for (const ft of flatNet.transitions) {\n const enabled = encodeEnabled(ctx, ft, flatNet, mVars, P);\n deadlock = ctx.And(deadlock, ctx.Not(enabled));\n }\n\n return deadlock;\n}\n\nfunction encodeInvariantConstraints(\n ctx: Z3Context,\n invariants: readonly PInvariant[],\n mVars: Arith[],\n P: number,\n): Bool {\n let result: Bool = ctx.Bool.val(true);\n\n for (const inv of invariants) {\n // sum(y_i * M[i]) == constant\n let sum: Arith = ctx.Int.val(0);\n for (const idx of inv.support) {\n if (idx < P) {\n sum = sum.add(mVars[idx]!.mul(inv.weights[idx]!));\n }\n }\n result = ctx.And(result, sum.eq(inv.constant));\n }\n\n return result;\n}\n","import type { Expr } from 'z3-solver';\nimport { MarkingState } from '../marking-state.js';\nimport type { FlatNet } from '../encoding/flat-net.js';\n\n/**\n * Result of counterexample decoding.\n */\nexport interface DecodedTrace {\n readonly trace: readonly MarkingState[];\n readonly transitions: readonly string[];\n}\n\n/**\n * Decodes Z3 Spacer counterexample answers into Petri net marking traces.\n *\n * When Spacer finds a counterexample (property violation), it produces\n * a derivation tree showing how the error state is reachable. This function\n * extracts the marking at each step to produce a human-readable trace.\n */\nexport function decode(ctx: any, answer: Expr | null, flatNet: FlatNet): DecodedTrace {\n const trace: MarkingState[] = [];\n const transitions: string[] = [];\n\n if (answer == null) {\n return { trace, transitions };\n }\n\n try {\n extractTrace(ctx, answer, flatNet, trace, transitions);\n } catch {\n // Z3 answer format varies; gracefully degrade\n }\n\n return { trace, transitions };\n}\n\n/**\n * Recursively traverses the Z3 proof tree to extract marking states.\n */\nfunction extractTrace(\n ctx: any,\n expr: any,\n flatNet: FlatNet,\n trace: MarkingState[],\n transitions: string[],\n): void {\n if (expr == null) return;\n\n // Check if this is a function application\n if (!ctx.isApp(expr)) return;\n\n let name: string;\n try {\n const decl = expr.decl();\n name = String(decl.name());\n } catch {\n return;\n }\n\n // Check if this is a Reachable application with integer arguments\n const P = flatNet.places.length;\n if (name === 'Reachable') {\n const numArgs = expr.numArgs();\n if (numArgs === P) {\n const marking = extractMarking(ctx, expr, flatNet);\n if (marking != null) {\n trace.push(marking);\n }\n }\n }\n\n // Recurse into children to find the derivation chain\n try {\n const numArgs = expr.numArgs();\n for (let i = 0; i < numArgs; i++) {\n const child = expr.arg(i);\n extractTrace(ctx, child, flatNet, trace, transitions);\n }\n } catch {\n // Not all expressions support arg()\n }\n\n // Try to extract transition name from rule application\n if (name.startsWith('t_')) {\n transitions.push(name.substring(2));\n }\n}\n\n/**\n * Extracts a MarkingState from a Reachable(...) application.\n */\nfunction extractMarking(ctx: any, reachableApp: any, flatNet: FlatNet): MarkingState | null {\n const P = flatNet.places.length;\n if (reachableApp.numArgs() !== P) return null;\n\n const builder = MarkingState.builder();\n for (let i = 0; i < P; i++) {\n const arg = reachableApp.arg(i);\n if (ctx.isIntVal(arg)) {\n const tokens = Number(arg.value());\n if (tokens > 0) {\n builder.tokens(flatNet.places[i]!, tokens);\n }\n } else {\n // Non-concrete value in counterexample\n return null;\n }\n }\n return builder.build();\n}\n","import type { PetriNet } from '../core/petri-net.js';\nimport type { EnvironmentPlace } from '../core/place.js';\nimport { MarkingState, MarkingStateBuilder } from './marking-state.js';\nimport type { SmtProperty } from './smt-property.js';\nimport { deadlockFree, propertyDescription } from './smt-property.js';\nimport type { SmtVerificationResult, SmtStatistics, Verdict } from './smt-verification-result.js';\nimport type { PInvariant } from './invariant/p-invariant.js';\nimport type { FlatNet } from './encoding/flat-net.js';\nimport { flatten, type EnvironmentAnalysisMode, unbounded } from './encoding/net-flattener.js';\nimport { IncidenceMatrix } from './encoding/incidence-matrix.js';\nimport { computePInvariants, isCoveredByInvariants } from './invariant/p-invariant-computer.js';\nimport { structuralCheck } from './invariant/structural-check.js';\nimport { createSpacerRunner } from './z3/spacer-runner.js';\nimport { encode } from './z3/smt-encoder.js';\nimport { decode } from './z3/counterexample-decoder.js';\n\n/**\n * IC3/PDR-based safety verifier for Petri nets using Z3's Spacer engine.\n *\n * Proves safety properties (especially deadlock-freedom) without\n * enumerating all reachable states. IC3 constructs inductive invariants\n * incrementally, which works well for bounded nets.\n *\n * Key design decisions:\n * - Operates on the marking projection (integer vectors) — no timing\n * - An untimed deadlock-freedom proof is stronger than needed\n * (timing can only restrict behavior)\n * - Guards are ignored — over-approximation is sound for safety properties\n * - If a counterexample is found, it may be spurious in timed/guarded\n * semantics — the report notes this\n *\n * Verification Pipeline:\n * 1. Flatten — expand XOR, index places, build pre/post vectors\n * 2. Structural pre-check — siphon/trap analysis (may prove early)\n * 3. P-invariants — compute conservation laws for strengthening\n * 4. SMT encode + query — IC3/PDR via Z3 Spacer\n * 5. Decode result — proof or counterexample trace\n */\nexport class SmtVerifier {\n private _initialMarking: MarkingState = MarkingState.empty();\n private _property: SmtProperty = deadlockFree();\n private readonly _environmentPlaces = new Set<EnvironmentPlace<any>>();\n private _environmentMode: EnvironmentAnalysisMode = unbounded();\n private _timeoutMs: number = 60_000;\n\n private constructor(private readonly net: PetriNet) {}\n\n static forNet(net: PetriNet): SmtVerifier {\n return new SmtVerifier(net);\n }\n\n initialMarking(marking: MarkingState): this;\n initialMarking(configurator: (builder: MarkingStateBuilder) => void): this;\n initialMarking(arg: MarkingState | ((builder: MarkingStateBuilder) => void)): this {\n if (arg instanceof MarkingState) {\n this._initialMarking = arg;\n } else {\n const builder = MarkingState.builder();\n arg(builder);\n this._initialMarking = builder.build();\n }\n return this;\n }\n\n property(property: SmtProperty): this {\n this._property = property;\n return this;\n }\n\n environmentPlaces(...places: EnvironmentPlace<any>[]): this {\n for (const p of places) this._environmentPlaces.add(p);\n return this;\n }\n\n environmentMode(mode: EnvironmentAnalysisMode): this {\n this._environmentMode = mode;\n return this;\n }\n\n timeout(ms: number): this {\n this._timeoutMs = ms;\n return this;\n }\n\n /**\n * Runs the verification pipeline.\n */\n async verify(): Promise<SmtVerificationResult> {\n const start = performance.now();\n const report: string[] = [];\n report.push('=== IC3/PDR SAFETY VERIFICATION ===\\n');\n report.push(`Net: ${this.net.name}`);\n report.push(`Property: ${propertyDescription(this._property)}`);\n report.push(`Timeout: ${(this._timeoutMs / 1000).toFixed(0)}s\\n`);\n\n // Phase 1: Flatten\n report.push('Phase 1: Flattening net...');\n const flatNet = flatten(this.net, this._environmentPlaces, this._environmentMode);\n report.push(` Places: ${flatNet.places.length}`);\n report.push(` Transitions (expanded): ${flatNet.transitions.length}`);\n if (flatNet.environmentBounds.size > 0) {\n report.push(` Environment bounds: ${flatNet.environmentBounds.size} places`);\n }\n report.push('');\n\n // Phase 2: Structural pre-check\n report.push('Phase 2: Structural pre-check (siphon/trap)...');\n const structResult = structuralCheck(flatNet, this._initialMarking);\n let structResultStr: string;\n switch (structResult.type) {\n case 'no-potential-deadlock':\n structResultStr = 'no potential deadlock';\n break;\n case 'potential-deadlock':\n structResultStr = `potential deadlock (siphon: {${[...structResult.siphon].join(',')}})`;\n break;\n case 'inconclusive':\n structResultStr = `inconclusive (${structResult.reason})`;\n break;\n }\n report.push(` Result: ${structResultStr}\\n`);\n\n // If structural check proves deadlock-freedom for DeadlockFree property\n if (\n this._property.type === 'deadlock-free' &&\n structResult.type === 'no-potential-deadlock'\n ) {\n report.push('=== RESULT ===\\n');\n report.push('PROVEN (structural): Deadlock-freedom verified by Commoner\\'s theorem.');\n report.push(' All siphons contain initially marked traps.');\n return buildResult(\n { type: 'proven', method: 'structural', inductiveInvariant: null },\n report.join('\\n'), [], [], [], [],\n performance.now() - start,\n { places: flatNet.places.length, transitions: flatNet.transitions.length, invariantsFound: 0, structuralResult: structResultStr },\n );\n }\n\n // Phase 3: P-invariants\n report.push('Phase 3: Computing P-invariants...');\n const matrix = IncidenceMatrix.from(flatNet);\n const invariants = computePInvariants(matrix, flatNet, this._initialMarking);\n report.push(` Found: ${invariants.length} P-invariant(s)`);\n const structurallyBounded = isCoveredByInvariants(invariants, flatNet.places.length);\n report.push(` Structurally bounded: ${structurallyBounded ? 'YES' : 'NO'}`);\n for (const inv of invariants) {\n report.push(` ${formatInvariant(inv, flatNet)}`);\n }\n report.push('');\n\n // Phase 4: SMT encode + query via Spacer\n report.push('Phase 4: IC3/PDR verification via Z3 Spacer...');\n\n let runner;\n try {\n runner = await createSpacerRunner(this._timeoutMs);\n } catch (e: any) {\n report.push(` ERROR: ${e.message ?? e}\\n`);\n report.push('=== RESULT ===\\n');\n report.push(`UNKNOWN: Z3 initialization error: ${e.message ?? e}`);\n return buildResult(\n { type: 'unknown', reason: `Z3 init error: ${e.message ?? e}` },\n report.join('\\n'), invariants, [], [], [],\n performance.now() - start,\n { places: flatNet.places.length, transitions: flatNet.transitions.length, invariantsFound: invariants.length, structuralResult: structResultStr },\n );\n }\n\n try {\n const encoding = encode(runner.ctx, runner.fp, flatNet, this._initialMarking, this._property, invariants);\n const queryResult = await runner.query(encoding.errorExpr, encoding.reachableDecl);\n\n switch (queryResult.type) {\n case 'proven': {\n report.push(' Status: UNSAT (property holds)\\n');\n\n // Decode IC3-synthesized invariants with place name substitution\n const discoveredInvariants: string[] = [];\n if (queryResult.invariantFormula != null) {\n discoveredInvariants.push(substituteNames(queryResult.invariantFormula, flatNet));\n }\n for (const level of queryResult.levelInvariants) {\n discoveredInvariants.push(substituteNames(level, flatNet));\n }\n\n // Phase 5: Inductive invariant\n if (discoveredInvariants.length > 0) {\n report.push('Phase 5: Inductive invariant (discovered by IC3)');\n report.push(` Spacer synthesized: ${discoveredInvariants[0]}`);\n report.push(' This formula is INDUCTIVE: preserved by all transitions.');\n if (discoveredInvariants.length > 1) {\n report.push(' Per-level clauses:');\n for (let i = 1; i < discoveredInvariants.length; i++) {\n report.push(` ${discoveredInvariants[i]}`);\n }\n }\n report.push('');\n }\n\n report.push('=== RESULT ===\\n');\n report.push(`PROVEN (IC3/PDR): ${propertyDescription(this._property)}`);\n report.push(' Z3 Spacer proved no reachable state violates the property.');\n report.push(' NOTE: Verification ignores timing constraints and JS guards.');\n report.push(' An untimed proof is STRONGER than a timed one (timing only restricts behavior).');\n\n return buildResult(\n {\n type: 'proven',\n method: 'IC3/PDR',\n inductiveInvariant: queryResult.invariantFormula != null\n ? substituteNames(queryResult.invariantFormula, flatNet)\n : null,\n },\n report.join('\\n'), invariants, discoveredInvariants, [], [],\n performance.now() - start,\n { places: flatNet.places.length, transitions: flatNet.transitions.length, invariantsFound: invariants.length, structuralResult: structResultStr },\n );\n }\n\n case 'violated': {\n report.push(' Status: SAT (counterexample found)\\n');\n\n const decoded = decode(runner.ctx, queryResult.answer, flatNet);\n\n report.push('=== RESULT ===\\n');\n report.push(`VIOLATED: ${propertyDescription(this._property)}`);\n if (decoded.trace.length > 0) {\n report.push(` Counterexample trace (${decoded.trace.length} states):`);\n for (let i = 0; i < decoded.trace.length; i++) {\n report.push(` ${i}: ${decoded.trace[i]}`);\n }\n }\n if (decoded.transitions.length > 0) {\n report.push(` Firing sequence: ${decoded.transitions.join(' -> ')}`);\n }\n report.push('\\n WARNING: This counterexample is in UNTIMED semantics.');\n report.push(' It may be spurious if timing constraints prevent this sequence.');\n report.push(' JS guards are also ignored in this analysis.');\n\n return buildResult(\n { type: 'violated' },\n report.join('\\n'), invariants, [], decoded.trace as MarkingState[], decoded.transitions as string[],\n performance.now() - start,\n { places: flatNet.places.length, transitions: flatNet.transitions.length, invariantsFound: invariants.length, structuralResult: structResultStr },\n );\n }\n\n case 'unknown': {\n report.push(` Status: UNKNOWN (${queryResult.reason})\\n`);\n report.push('=== RESULT ===\\n');\n report.push(`UNKNOWN: Could not determine ${propertyDescription(this._property)}`);\n report.push(` Reason: ${queryResult.reason}`);\n\n return buildResult(\n { type: 'unknown', reason: queryResult.reason },\n report.join('\\n'), invariants, [], [], [],\n performance.now() - start,\n { places: flatNet.places.length, transitions: flatNet.transitions.length, invariantsFound: invariants.length, structuralResult: structResultStr },\n );\n }\n }\n } catch (e: any) {\n report.push(` ERROR: ${e.message ?? e}\\n`);\n report.push('=== RESULT ===\\n');\n report.push(`UNKNOWN: Z3 solver error: ${e.message ?? e}`);\n\n return buildResult(\n { type: 'unknown', reason: `Z3 error: ${e.message ?? e}` },\n report.join('\\n'), invariants, [], [], [],\n performance.now() - start,\n { places: flatNet.places.length, transitions: flatNet.transitions.length, invariantsFound: invariants.length, structuralResult: structResultStr },\n );\n } finally {\n runner.dispose();\n }\n }\n}\n\n/**\n * Substitutes Z3 variable names (m0, m1, ...) with place names in a formula string.\n */\nfunction substituteNames(formula: string, flatNet: FlatNet): string {\n // Replace from highest index first to avoid m1 matching inside m10\n for (let i = flatNet.places.length - 1; i >= 0; i--) {\n formula = formula.replace(new RegExp(`\\\\bm${i}\\\\b`, 'g'), flatNet.places[i]!.name);\n }\n return formula;\n}\n\nfunction formatInvariant(inv: PInvariant, flatNet: FlatNet): string {\n const parts: string[] = [];\n for (const idx of inv.support) {\n if (inv.weights[idx] !== 1) {\n parts.push(`${inv.weights[idx]}*${flatNet.places[idx]!.name}`);\n } else {\n parts.push(flatNet.places[idx]!.name);\n }\n }\n return `${parts.join(' + ')} = ${inv.constant}`;\n}\n\nfunction buildResult(\n verdict: Verdict,\n report: string,\n invariants: readonly PInvariant[],\n discoveredInvariants: readonly string[],\n trace: readonly MarkingState[],\n transitions: readonly string[],\n elapsedMs: number,\n statistics: SmtStatistics,\n): SmtVerificationResult {\n return { verdict, report, invariants, discoveredInvariants, counterexampleTrace: trace, counterexampleTransitions: transitions, elapsedMs, statistics };\n}\n"],"mappings":";;;;;;AAGA,IAAM,oBAAoB,uBAAO,uBAAuB;AAQjD,IAAM,eAAN,MAAM,cAAa;AAAA,EACP;AAAA,EACA;AAAA;AAAA,EAGjB,YAAY,KAAa,aAAkC,cAAuC;AAChG,QAAI,QAAQ,kBAAmB,OAAM,IAAI,MAAM,gDAAgD;AAC/F,SAAK,cAAc;AACnB,SAAK,eAAe;AAAA,EACtB;AAAA;AAAA,EAGA,OAAO,OAA2B;AAChC,WAAO,KAAK,YAAY,IAAI,MAAM,IAAI,KAAK;AAAA,EAC7C;AAAA;AAAA,EAGA,UAAU,OAA4B;AACpC,WAAO,KAAK,OAAO,KAAK,IAAI;AAAA,EAC9B;AAAA;AAAA,EAGA,eAAe,QAAuC;AACpD,eAAW,KAAK,QAAQ;AACtB,UAAI,KAAK,UAAU,CAAC,EAAG,QAAO;AAAA,IAChC;AACA,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,mBAAiC;AAC/B,WAAO,CAAC,GAAG,KAAK,aAAa,OAAO,CAA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AAO;AACT;AAEA,SAAS,gBAAgB,KAAiB,SAA0B;AAClE,QAAM,QAAkB,CAAC;AACzB,aAAW,OAAO,IAAI,SAAS;AAC7B,QAAI,IAAI,QAAQ,GAAG,MAAM,GAAG;AAC1B,YAAM,KAAK,GAAG,IAAI,QAAQ,GAAG,CAAC,IAAI,QAAQ,OAAO,GAAG,EAAG,IAAI,EAAE;AAAA,IAC/D,OAAO;AACL,YAAM,KAAK,QAAQ,OAAO,GAAG,EAAG,IAAI;AAAA,IACtC;AAAA,EACF;AACA,SAAO,GAAG,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,QAAQ;AAC/C;AAEA,SAAS,YACP,SACA,QACA,YACA,sBACA,OACA,aACA,WACA,YACuB;AACvB,SAAO,EAAE,SAAS,QAAQ,YAAY,sBAAsB,qBAAqB,OAAO,2BAA2B,aAAa,WAAW,WAAW;AACxJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/verification/marking-state.ts","../../src/verification/encoding/flat-transition.ts","../../src/verification/encoding/flat-net.ts","../../src/verification/encoding/incidence-matrix.ts","../../src/verification/encoding/net-flattener.ts","../../src/verification/invariant/p-invariant.ts","../../src/verification/invariant/p-invariant-computer.ts","../../src/verification/invariant/structural-check.ts","../../src/verification/smt-property.ts","../../src/verification/smt-verification-result.ts","../../src/verification/z3/spacer-runner.ts","../../src/verification/z3/smt-encoder.ts","../../src/verification/z3/counterexample-decoder.ts","../../src/verification/smt-verifier.ts"],"sourcesContent":["import type { Place } from '../core/place.js';\n\n/** @internal Symbol key restricting construction to the builder and factory methods. */\nconst MARKING_STATE_KEY = Symbol('MarkingState.internal');\n\n/**\n * Immutable snapshot of a Petri net marking for state space analysis.\n *\n * Maps places (by name) to integer token counts. Only stores places with count > 0.\n * Used for invariant computation and structural verification, not runtime execution.\n */\nexport class MarkingState {\n private readonly tokenCounts: ReadonlyMap<string, number>;\n private readonly placesByName: ReadonlyMap<string, Place<any>>;\n\n /** @internal Use {@link MarkingState.builder} or {@link MarkingState.empty} to create instances. */\n constructor(key: symbol, tokenCounts: Map<string, number>, placesByName: Map<string, Place<any>>) {\n if (key !== MARKING_STATE_KEY) throw new Error('Use MarkingState.builder() to create instances');\n this.tokenCounts = tokenCounts;\n this.placesByName = placesByName;\n }\n\n /** Returns the token count for a place (0 if absent). */\n tokens(place: Place<any>): number {\n return this.tokenCounts.get(place.name) ?? 0;\n }\n\n /** Checks if a place has at least one token. */\n hasTokens(place: Place<any>): boolean {\n return this.tokens(place) > 0;\n }\n\n /** Checks if any of the given places has tokens. */\n hasTokensInAny(places: Iterable<Place<any>>): boolean {\n for (const p of places) {\n if (this.hasTokens(p)) return true;\n }\n return false;\n }\n\n /** Returns all places with tokens > 0. */\n placesWithTokens(): Place<any>[] {\n return [...this.placesByName.values()];\n }\n\n /** Returns the total number of tokens. */\n totalTokens(): number {\n let sum = 0;\n for (const count of this.tokenCounts.values()) sum += count;\n return sum;\n }\n\n /** Checks if no tokens exist anywhere. */\n isEmpty(): boolean {\n return this.tokenCounts.size === 0;\n }\n\n toString(): string {\n if (this.tokenCounts.size === 0) return '{}';\n const entries = [...this.tokenCounts.entries()]\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([name, count]) => `${name}:${count}`);\n return `{${entries.join(', ')}}`;\n }\n\n static empty(): MarkingState {\n return new MarkingState(MARKING_STATE_KEY, new Map(), new Map());\n }\n\n static builder(): MarkingStateBuilder {\n return new MarkingStateBuilder();\n }\n}\n\nexport class MarkingStateBuilder {\n private readonly tokenCounts = new Map<string, number>();\n private readonly placesByName = new Map<string, Place<any>>();\n\n /** Sets the token count for a place. */\n tokens(place: Place<any>, count: number): this {\n if (count < 0) throw new Error(`Token count cannot be negative: ${count}`);\n if (count > 0) {\n this.tokenCounts.set(place.name, count);\n this.placesByName.set(place.name, place);\n } else {\n this.tokenCounts.delete(place.name);\n this.placesByName.delete(place.name);\n }\n return this;\n }\n\n /** Adds tokens to a place. */\n addTokens(place: Place<any>, count: number): this {\n if (count < 0) throw new Error(`Token count cannot be negative: ${count}`);\n if (count > 0) {\n const current = this.tokenCounts.get(place.name) ?? 0;\n this.tokenCounts.set(place.name, current + count);\n this.placesByName.set(place.name, place);\n }\n return this;\n }\n\n build(): MarkingState {\n return new MarkingState(MARKING_STATE_KEY, new Map(this.tokenCounts), new Map(this.placesByName));\n }\n}\n","import type { Transition } from '../../core/transition.js';\n\n/**\n * A flattened transition with pre/post vectors for SMT encoding.\n *\n * Each Transition with XOR outputs is expanded into multiple FlatTransitions\n * (one per branch). Non-XOR transitions map 1:1.\n */\nexport interface FlatTransition {\n /** Display name (e.g. \"Search_b0\", \"Search_b1\"). */\n readonly name: string;\n /** The original transition. */\n readonly source: Transition;\n /** Which XOR branch (-1 if no XOR). */\n readonly branchIndex: number;\n /** Tokens consumed per place (indexed by place index). */\n readonly preVector: readonly number[];\n /** Tokens produced per place (indexed by place index). */\n readonly postVector: readonly number[];\n /** Place indices where inhibitor arcs block firing. */\n readonly inhibitorPlaces: readonly number[];\n /** Place indices requiring a token without consuming. */\n readonly readPlaces: readonly number[];\n /** Place indices set to 0 on firing. */\n readonly resetPlaces: readonly number[];\n /** True at index i means place i uses All/AtLeast semantics. */\n readonly consumeAll: readonly boolean[];\n}\n\nexport function flatTransition(\n name: string,\n source: Transition,\n branchIndex: number,\n preVector: number[],\n postVector: number[],\n inhibitorPlaces: number[],\n readPlaces: number[],\n resetPlaces: number[],\n consumeAll: boolean[],\n): FlatTransition {\n return {\n name,\n source,\n branchIndex,\n preVector,\n postVector,\n inhibitorPlaces,\n readPlaces,\n resetPlaces,\n consumeAll,\n };\n}\n","import type { Place } from '../../core/place.js';\nimport type { FlatTransition } from './flat-transition.js';\n\n/**\n * A flattened Petri net with indexed places and XOR-expanded transitions.\n *\n * Intermediate representation between the high-level PetriNet and Z3 CHC encoding.\n */\nexport interface FlatNet {\n /** Ordered list of places (index = position). */\n readonly places: readonly Place<any>[];\n /** Reverse lookup: place name -> index. */\n readonly placeIndex: ReadonlyMap<string, number>;\n /** XOR-expanded flat transitions. */\n readonly transitions: readonly FlatTransition[];\n /** For bounded environment places: place name -> max tokens. */\n readonly environmentBounds: ReadonlyMap<string, number>;\n}\n\nexport function flatNetPlaceCount(net: FlatNet): number {\n return net.places.length;\n}\n\nexport function flatNetTransitionCount(net: FlatNet): number {\n return net.transitions.length;\n}\n\nexport function flatNetIndexOf(net: FlatNet, place: Place<any>): number {\n return net.placeIndex.get(place.name) ?? -1;\n}\n","import type { FlatNet } from './flat-net.js';\n\n/**\n * Incidence matrix for a flattened Petri net.\n *\n * The incidence matrix C is defined as C[t][p] = post[t][p] - pre[t][p].\n * It captures the net effect of each transition on each place.\n *\n * P-invariants are solutions to y^T * C = 0, found via null space\n * computation on C^T.\n */\nexport class IncidenceMatrix {\n private readonly _pre: readonly (readonly number[])[];\n private readonly _post: readonly (readonly number[])[];\n private readonly _incidence: readonly (readonly number[])[];\n private readonly _numTransitions: number;\n private readonly _numPlaces: number;\n\n private constructor(\n pre: number[][],\n post: number[][],\n incidence: number[][],\n numTransitions: number,\n numPlaces: number,\n ) {\n this._pre = pre;\n this._post = post;\n this._incidence = incidence;\n this._numTransitions = numTransitions;\n this._numPlaces = numPlaces;\n }\n\n /**\n * Computes the incidence matrix from a FlatNet.\n */\n static from(flatNet: FlatNet): IncidenceMatrix {\n const T = flatNet.transitions.length;\n const P = flatNet.places.length;\n\n const pre: number[][] = [];\n const post: number[][] = [];\n const incidence: number[][] = [];\n\n for (let t = 0; t < T; t++) {\n const ft = flatNet.transitions[t]!;\n const preRow = new Array<number>(P);\n const postRow = new Array<number>(P);\n const incRow = new Array<number>(P);\n\n for (let p = 0; p < P; p++) {\n preRow[p] = ft.preVector[p]!;\n postRow[p] = ft.postVector[p]!;\n incRow[p] = postRow[p]! - preRow[p]!;\n }\n\n pre.push(preRow);\n post.push(postRow);\n incidence.push(incRow);\n }\n\n return new IncidenceMatrix(pre, post, incidence, T, P);\n }\n\n /**\n * Returns C^T (transpose of incidence matrix), dimensions [P][T].\n * Used for P-invariant computation: null space of C^T gives P-invariants.\n */\n transposedIncidence(): number[][] {\n const ct: number[][] = [];\n for (let p = 0; p < this._numPlaces; p++) {\n const row = new Array<number>(this._numTransitions);\n for (let t = 0; t < this._numTransitions; t++) {\n row[t] = this._incidence[t]![p]!;\n }\n ct.push(row);\n }\n return ct;\n }\n\n /** Returns the pre-matrix (tokens consumed). T×P. */\n pre(): readonly (readonly number[])[] { return this._pre; }\n\n /** Returns the post-matrix (tokens produced). T×P. */\n post(): readonly (readonly number[])[] { return this._post; }\n\n /** Returns the incidence matrix C[t][p] = post - pre. T×P. */\n incidence(): readonly (readonly number[])[] { return this._incidence; }\n\n numTransitions(): number { return this._numTransitions; }\n numPlaces(): number { return this._numPlaces; }\n}\n","/**\n * @module net-flattener\n *\n * Flattens a PetriNet into integer-indexed pre/post vectors for SMT encoding.\n *\n * **XOR expansion**: Transitions with XOR output specs are expanded into multiple\n * flat transitions — one per deterministic branch. Each branch produces tokens to\n * exactly one XOR child's places. This converts non-deterministic output routing\n * into separate transitions that the SMT solver can reason about independently.\n *\n * **Vector construction**: For each flat transition, builds:\n * - `preVector[p]`: tokens consumed from place p (input cardinality)\n * - `postVector[p]`: tokens produced to place p (from the selected branch)\n * - `consumeAll[p]`: true for `all`/`at-least` inputs (consume everything)\n * - Index arrays for inhibitor, read, and reset arcs\n *\n * Places are sorted by name for stable, deterministic indexing across runs.\n */\nimport type { PetriNet } from '../../core/petri-net.js';\nimport type { Place, EnvironmentPlace } from '../../core/place.js';\nimport type { Out } from '../../core/out.js';\nimport type { FlatNet } from './flat-net.js';\nimport { flatTransition } from './flat-transition.js';\nimport { enumerateBranches, allPlaces as outAllPlaces } from '../../core/out.js';\n\n/**\n * How to treat environment places during analysis.\n */\nexport type EnvironmentAnalysisMode =\n | { readonly type: 'unbounded' }\n | { readonly type: 'bounded'; readonly maxTokens: number };\n\nexport function unbounded(): EnvironmentAnalysisMode {\n return { type: 'unbounded' };\n}\n\nexport function bounded(maxTokens: number): EnvironmentAnalysisMode {\n return { type: 'bounded', maxTokens };\n}\n\n/**\n * Flattens a PetriNet into a FlatNet suitable for SMT encoding.\n *\n * Flattening involves:\n * 1. Assigning each place a stable integer index (sorted by name)\n * 2. Expanding XOR outputs into separate flat transitions (one per branch)\n * 3. Building pre/post vectors from input/output specs\n * 4. Recording inhibitor, read, and reset arcs\n * 5. Setting environment bounds for bounded analysis mode\n */\nexport function flatten(\n net: PetriNet,\n environmentPlaces: Set<EnvironmentPlace<any>> = new Set(),\n environmentMode: EnvironmentAnalysisMode = unbounded(),\n): FlatNet {\n // 1. Collect ALL places\n const allPlacesSet = new Map<string, Place<any>>();\n for (const p of net.places) {\n allPlacesSet.set(p.name, p);\n }\n for (const t of net.transitions) {\n for (const inSpec of t.inputSpecs) {\n allPlacesSet.set(inSpec.place.name, inSpec.place);\n }\n if (t.outputSpec !== null) {\n for (const p of outAllPlaces(t.outputSpec)) {\n allPlacesSet.set(p.name, p);\n }\n }\n for (const arc of t.inhibitors) allPlacesSet.set(arc.place.name, arc.place);\n for (const arc of t.reads) allPlacesSet.set(arc.place.name, arc.place);\n for (const arc of t.resets) allPlacesSet.set(arc.place.name, arc.place);\n }\n\n // Sort by name for stable indexing\n const places = [...allPlacesSet.values()].sort((a, b) => a.name.localeCompare(b.name));\n\n const placeIndex = new Map<string, number>();\n for (let i = 0; i < places.length; i++) {\n placeIndex.set(places[i]!.name, i);\n }\n\n // 2. Compute environment bounds\n const environmentBounds = new Map<string, number>();\n if (environmentMode.type === 'bounded') {\n for (const ep of environmentPlaces) {\n environmentBounds.set(ep.place.name, environmentMode.maxTokens);\n }\n }\n\n // 3. Expand transitions\n const n = places.length;\n const flatTransitions = [];\n\n for (const transition of net.transitions) {\n const branches = enumerateOutputBranches(transition);\n\n for (let branchIdx = 0; branchIdx < branches.length; branchIdx++) {\n const branchPlaces = branches[branchIdx]!;\n const name = branches.length > 1\n ? `${transition.name}_b${branchIdx}`\n : transition.name;\n\n // Build pre-vector and consumeAll flags\n const preVector = new Array<number>(n).fill(0);\n const consumeAll = new Array<boolean>(n).fill(false);\n\n for (const inSpec of transition.inputSpecs) {\n const idx = placeIndex.get(inSpec.place.name);\n if (idx === undefined) continue;\n\n switch (inSpec.type) {\n case 'one':\n preVector[idx] = 1;\n break;\n case 'exactly':\n preVector[idx] = inSpec.count;\n break;\n case 'all':\n preVector[idx] = 1;\n consumeAll[idx] = true;\n break;\n case 'at-least':\n preVector[idx] = inSpec.minimum;\n consumeAll[idx] = true;\n break;\n }\n }\n\n // Build post-vector from branch output places\n const postVector = new Array<number>(n).fill(0);\n for (const p of branchPlaces) {\n const idx = placeIndex.get(p.name);\n if (idx !== undefined) {\n postVector[idx] = 1;\n }\n }\n\n // Inhibitor places\n const inhibitorPlaces = transition.inhibitors\n .map(arc => placeIndex.get(arc.place.name))\n .filter((idx): idx is number => idx !== undefined);\n\n // Read places\n const readPlaces = transition.reads\n .map(arc => placeIndex.get(arc.place.name))\n .filter((idx): idx is number => idx !== undefined);\n\n // Reset places\n const resetPlaces = transition.resets\n .map(arc => placeIndex.get(arc.place.name))\n .filter((idx): idx is number => idx !== undefined);\n\n flatTransitions.push(flatTransition(\n name,\n transition,\n branches.length > 1 ? branchIdx : -1,\n preVector,\n postVector,\n inhibitorPlaces,\n readPlaces,\n resetPlaces,\n consumeAll,\n ));\n }\n }\n\n return {\n places,\n placeIndex,\n transitions: flatTransitions,\n environmentBounds,\n };\n}\n\nfunction enumerateOutputBranches(t: { outputSpec: Out | null }): ReadonlySet<Place<any>>[] {\n if (t.outputSpec !== null) {\n return enumerateBranches(t.outputSpec) as ReadonlySet<Place<any>>[];\n }\n // No outputs (sink transition)\n return [new Set()];\n}\n","/**\n * A P-invariant (place invariant) of a Petri net.\n *\n * A P-invariant is a vector y such that y^T * C = 0, where C is the\n * incidence matrix. This means that for any reachable marking M:\n * sum(y_i * M_i) = constant, where constant = sum(y_i * M0_i).\n *\n * P-invariants provide structural bounds on places and are used as\n * strengthening lemmas for the IC3/PDR engine.\n */\nexport interface PInvariant {\n /** Weight vector (one entry per place index). */\n readonly weights: readonly number[];\n /** The invariant value sum(y_i * M0_i). */\n readonly constant: number;\n /** Set of place indices where weight != 0. */\n readonly support: ReadonlySet<number>;\n}\n\nexport function pInvariant(weights: number[], constant: number, support: Set<number>): PInvariant {\n return { weights, constant, support };\n}\n\nexport function pInvariantToString(inv: PInvariant): string {\n const parts: string[] = [];\n for (const i of inv.support) {\n if (inv.weights[i] !== 1) {\n parts.push(`${inv.weights[i]}*p${i}`);\n } else {\n parts.push(`p${i}`);\n }\n }\n return `PInvariant[${parts.join(' + ')} = ${inv.constant}]`;\n}\n","/**\n * @module p-invariant-computer\n *\n * Computes P-invariants of a Petri net via integer Gaussian elimination (Farkas' algorithm).\n *\n * **Algorithm**: A P-invariant is a non-negative integer vector y such that y^T · C = 0\n * (where C is the incidence matrix). This expresses a conservation law: the weighted\n * token sum Σ(y_i · M[i]) is constant across all reachable markings.\n *\n * **Farkas variant**: Constructs the augmented matrix [C^T | I_P] and row-reduces\n * the C^T portion to zero using integer elimination (no floating point). Rows where\n * the C^T part becomes all-zero yield invariant vectors from the identity part.\n * Row normalization by GCD keeps values small during elimination.\n *\n * **Integer Gaussian elimination**: Each elimination step multiplies rows by pivot\n * coefficients (a·row - b·pivotRow) to avoid fractions. This preserves integer\n * arithmetic throughout, critical for exact invariant computation.\n *\n * Invariants are used to strengthen SMT queries (added as constraints on M').\n */\nimport type { FlatNet } from '../encoding/flat-net.js';\nimport type { IncidenceMatrix } from '../encoding/incidence-matrix.js';\nimport type { MarkingState } from '../marking-state.js';\nimport type { PInvariant } from './p-invariant.js';\nimport { pInvariant } from './p-invariant.js';\n\n/**\n * Computes P-invariants of a Petri net via integer Gaussian elimination.\n *\n * P-invariants are non-negative integer vectors y where y^T * C = 0.\n * They express conservation laws: the weighted token sum is constant\n * across all reachable markings.\n *\n * Algorithm: compute the null space of C^T using integer row reduction\n * with an augmented identity matrix (Farkas' algorithm variant).\n */\nexport function computePInvariants(\n matrix: IncidenceMatrix,\n flatNet: FlatNet,\n initialMarking: MarkingState,\n): PInvariant[] {\n const P = matrix.numPlaces();\n const T = matrix.numTransitions();\n\n if (P === 0 || T === 0) return [];\n\n // We want to find y such that y^T * C = 0, i.e., C^T * y = 0\n // Start with augmented matrix [C^T | I_P]\n // Row-reduce C^T part to zero; the I_P part gives the invariant vectors.\n const ct = matrix.transposedIncidence(); // P × T\n\n // Augmented matrix: P rows, T + P columns\n // Use regular numbers (safe for nets with < ~50 places/transitions)\n const cols = T + P;\n const augmented: number[][] = [];\n for (let i = 0; i < P; i++) {\n const row = new Array<number>(cols).fill(0);\n for (let j = 0; j < T; j++) {\n row[j] = ct[i]![j]!;\n }\n row[T + i] = 1; // identity part\n augmented.push(row);\n }\n\n // Integer Gaussian elimination on the C^T part (columns 0..T-1)\n let pivotRow = 0;\n for (let col = 0; col < T && pivotRow < P; col++) {\n // Find pivot (non-zero entry in this column)\n let pivot = -1;\n for (let row = pivotRow; row < P; row++) {\n if (augmented[row]![col] !== 0) {\n pivot = row;\n break;\n }\n }\n if (pivot === -1) continue; // free variable\n\n // Swap pivot row\n if (pivot !== pivotRow) {\n const tmp = augmented[pivotRow]!;\n augmented[pivotRow] = augmented[pivot]!;\n augmented[pivot] = tmp;\n }\n\n // Eliminate this column in all other rows\n for (let row = 0; row < P; row++) {\n if (row === pivotRow || augmented[row]![col] === 0) continue;\n\n const a = augmented[pivotRow]![col]!;\n const b = augmented[row]![col]!;\n\n // row = a*row - b*pivotRow (keeps integers, eliminates col)\n for (let c = 0; c < cols; c++) {\n augmented[row]![c] = a * augmented[row]![c]! - b * augmented[pivotRow]![c]!;\n }\n\n // Normalize by GCD to keep values small\n normalizeRow(augmented[row]!, cols);\n }\n\n pivotRow++;\n }\n\n // Extract invariants: rows where C^T part is all zeros\n const invariants: PInvariant[] = [];\n for (let row = 0; row < P; row++) {\n let isZero = true;\n for (let col = 0; col < T; col++) {\n if (augmented[row]![col] !== 0) {\n isZero = false;\n break;\n }\n }\n if (!isZero) continue;\n\n // Extract the weight vector from the identity part\n const weights = new Array<number>(P);\n let allNonNegative = true;\n let hasPositive = false;\n\n for (let i = 0; i < P; i++) {\n weights[i] = augmented[row]![T + i]!;\n if (weights[i]! < 0) {\n allNonNegative = false;\n break;\n }\n if (weights[i]! > 0) hasPositive = true;\n }\n\n // We want semi-positive invariants (all weights >= 0, at least one > 0)\n if (!allNonNegative) {\n // Try negating\n let allNonPositive = true;\n for (let i = 0; i < P; i++) {\n if (augmented[row]![T + i]! > 0) {\n allNonPositive = false;\n break;\n }\n }\n if (allNonPositive) {\n for (let i = 0; i < P; i++) {\n weights[i] = -augmented[row]![T + i]!;\n }\n hasPositive = true;\n allNonNegative = true;\n }\n }\n\n if (!allNonNegative || !hasPositive) continue;\n\n // Normalize: divide by GCD of weights\n let g = 0;\n for (const w of weights) {\n if (w > 0) g = gcd(g, w);\n }\n if (g > 1) {\n for (let i = 0; i < P; i++) {\n weights[i] = weights[i]! / g;\n }\n }\n\n // Compute support and constant\n const support = new Set<number>();\n let constant = 0;\n for (let i = 0; i < P; i++) {\n if (weights[i] !== 0) {\n support.add(i);\n const place = flatNet.places[i]!;\n constant += weights[i]! * initialMarking.tokens(place);\n }\n }\n\n invariants.push(pInvariant(weights, constant, support));\n }\n\n return invariants;\n}\n\n/**\n * Checks if every place is covered by at least one P-invariant.\n * If true, the net is structurally bounded.\n */\nexport function isCoveredByInvariants(invariants: readonly PInvariant[], numPlaces: number): boolean {\n const covered = new Array<boolean>(numPlaces).fill(false);\n for (const inv of invariants) {\n for (const idx of inv.support) {\n if (idx < numPlaces) covered[idx] = true;\n }\n }\n return covered.every(c => c);\n}\n\nfunction normalizeRow(row: number[], cols: number): void {\n let g = 0;\n for (let c = 0; c < cols; c++) {\n if (row[c] !== 0) {\n g = gcd(g, Math.abs(row[c]!));\n }\n }\n if (g > 1) {\n for (let c = 0; c < cols; c++) {\n row[c] = row[c]! / g;\n }\n }\n}\n\nfunction gcd(a: number, b: number): number {\n while (b !== 0) {\n const t = b;\n b = a % b;\n a = t;\n }\n return a;\n}\n","/**\n * @module structural-check\n *\n * Structural deadlock pre-check using siphon/trap analysis (Commoner's theorem).\n *\n * **Commoner's theorem**: A Petri net is deadlock-free if every siphon contains\n * an initially marked trap.\n *\n * **Siphon**: A set of places S where every transition that outputs to S also\n * inputs from S. Key property: once all places in a siphon become empty,\n * they can never be re-marked. An empty siphon can cause deadlock.\n *\n * **Trap**: A set of places S where every transition that inputs from S also\n * outputs to S. Key property: once any place in a trap is marked,\n * the trap remains marked forever.\n *\n * **Algorithm**: For each place, compute the minimal siphon containing it via\n * fixed-point expansion. For each siphon, find the maximal trap within it\n * (fixed-point contraction). If every siphon contains an initially-marked\n * trap, deadlock-freedom is proven structurally — no SMT query needed.\n *\n * Limited to nets with ≤50 places to bound enumeration cost.\n */\nimport type { FlatNet } from '../encoding/flat-net.js';\nimport type { MarkingState } from '../marking-state.js';\n\nconst MAX_PLACES_FOR_SIPHON_ANALYSIS = 50;\n\n/**\n * Result of structural deadlock check using siphon/trap analysis.\n */\nexport type StructuralCheckResult =\n | { readonly type: 'no-potential-deadlock' }\n | { readonly type: 'potential-deadlock'; readonly siphon: ReadonlySet<number> }\n | { readonly type: 'inconclusive'; readonly reason: string };\n\n/**\n * Structural deadlock pre-check using siphon/trap analysis.\n *\n * Commoner's theorem: a Petri net is deadlock-free if every siphon\n * contains a marked trap.\n *\n * A siphon is a set of places S such that every transition with\n * an output in S also has an input in S. Once empty, a siphon stays empty.\n *\n * A trap is a set of places S such that every transition with\n * an input in S also has an output in S. Once marked, a trap stays marked.\n */\nexport function structuralCheck(flatNet: FlatNet, initialMarking: MarkingState): StructuralCheckResult {\n const P = flatNet.places.length;\n\n if (P === 0) {\n return { type: 'no-potential-deadlock' };\n }\n\n if (P > MAX_PLACES_FOR_SIPHON_ANALYSIS) {\n return { type: 'inconclusive', reason: `Net has ${P} places, siphon enumeration skipped` };\n }\n\n const siphons = findMinimalSiphons(flatNet);\n\n if (siphons.length === 0) {\n return { type: 'no-potential-deadlock' };\n }\n\n for (const siphon of siphons) {\n const trap = findMaximalTrapIn(flatNet, siphon);\n\n if (trap.size === 0 || !isMarked(trap, flatNet, initialMarking)) {\n return { type: 'potential-deadlock', siphon };\n }\n }\n\n return { type: 'no-potential-deadlock' };\n}\n\n/**\n * Finds minimal siphons by checking all non-empty subsets of deadlock-enabling places.\n * Uses a fixed-point approach: start from each place and grow the siphon.\n */\nexport function findMinimalSiphons(flatNet: FlatNet): ReadonlySet<number>[] {\n const P = flatNet.places.length;\n const siphons: Set<number>[] = [];\n\n // Pre-compute: for each place, which transitions have it as output?\n const placeAsOutput: number[][] = [];\n for (let p = 0; p < P; p++) {\n placeAsOutput.push([]);\n }\n\n for (let t = 0; t < flatNet.transitions.length; t++) {\n const ft = flatNet.transitions[t]!;\n for (let p = 0; p < P; p++) {\n if (ft.postVector[p]! > 0) {\n placeAsOutput[p]!.push(t);\n }\n }\n }\n\n for (let startPlace = 0; startPlace < P; startPlace++) {\n const siphon = computeSiphonContaining(startPlace, flatNet, placeAsOutput);\n if (siphon !== null && siphon.size > 0) {\n let isMinimal = true;\n const toRemove: number[] = [];\n for (let i = 0; i < siphons.length; i++) {\n const existing = siphons[i]!;\n if (setsEqual(existing, siphon)) {\n isMinimal = false;\n break;\n }\n if (isSubsetOf(existing, siphon)) {\n isMinimal = false;\n break;\n }\n if (isSubsetOf(siphon, existing)) {\n toRemove.push(i);\n }\n }\n for (let i = toRemove.length - 1; i >= 0; i--) {\n siphons.splice(toRemove[i]!, 1);\n }\n if (isMinimal) {\n siphons.push(siphon);\n }\n }\n }\n\n return siphons;\n}\n\nfunction computeSiphonContaining(\n startPlace: number,\n flatNet: FlatNet,\n placeAsOutput: number[][],\n): Set<number> | null {\n const siphon = new Set<number>();\n siphon.add(startPlace);\n\n let changed = true;\n while (changed) {\n changed = false;\n const snapshot = [...siphon];\n\n for (const p of snapshot) {\n for (const t of placeAsOutput[p]!) {\n const ft = flatNet.transitions[t]!;\n\n let hasInputInSiphon = false;\n for (let q = 0; q < flatNet.places.length; q++) {\n if (ft.preVector[q]! > 0 && siphon.has(q)) {\n hasInputInSiphon = true;\n break;\n }\n }\n\n if (!hasInputInSiphon) {\n let added = false;\n for (let q = 0; q < flatNet.places.length; q++) {\n if (ft.preVector[q]! > 0) {\n if (!siphon.has(q)) {\n siphon.add(q);\n changed = true;\n }\n added = true;\n break;\n }\n }\n if (!added) {\n return null;\n }\n }\n }\n }\n }\n\n return siphon;\n}\n\n/**\n * Finds the maximal trap within a given set of places.\n * Uses fixed-point: start with the full set and remove places that violate the trap condition.\n */\nexport function findMaximalTrapIn(flatNet: FlatNet, places: ReadonlySet<number>): ReadonlySet<number> {\n const trap = new Set(places);\n\n let changed = true;\n while (changed) {\n changed = false;\n const toRemove: number[] = [];\n\n for (const p of trap) {\n let satisfies = true;\n for (let t = 0; t < flatNet.transitions.length; t++) {\n const ft = flatNet.transitions[t]!;\n if (ft.preVector[p]! > 0) {\n let outputsToTrap = false;\n for (const q of trap) {\n if (ft.postVector[q]! > 0) {\n outputsToTrap = true;\n break;\n }\n }\n if (!outputsToTrap) {\n satisfies = false;\n break;\n }\n }\n }\n if (!satisfies) {\n toRemove.push(p);\n }\n }\n\n if (toRemove.length > 0) {\n for (const p of toRemove) trap.delete(p);\n changed = true;\n }\n }\n\n return trap;\n}\n\nfunction isMarked(placeIndices: ReadonlySet<number>, flatNet: FlatNet, marking: MarkingState): boolean {\n for (const idx of placeIndices) {\n const place = flatNet.places[idx]!;\n if (marking.tokens(place) > 0) return true;\n }\n return false;\n}\n\nfunction setsEqual(a: ReadonlySet<number>, b: ReadonlySet<number>): boolean {\n if (a.size !== b.size) return false;\n for (const v of a) {\n if (!b.has(v)) return false;\n }\n return true;\n}\n\nfunction isSubsetOf(sub: ReadonlySet<number>, sup: ReadonlySet<number>): boolean {\n if (sub.size > sup.size) return false;\n for (const v of sub) {\n if (!sup.has(v)) return false;\n }\n return true;\n}\n","import type { Place } from '../core/place.js';\n\n/**\n * Safety properties that can be verified via IC3/PDR.\n *\n * Each property is encoded as an error condition: if a reachable state\n * violates the property, Spacer finds a counterexample. If no violation\n * is reachable, the property is proven.\n */\nexport type SmtProperty = DeadlockFree | MutualExclusion | PlaceBound | Unreachable;\n\n/** Deadlock-freedom: no reachable marking has all transitions disabled. */\nexport interface DeadlockFree {\n readonly type: 'deadlock-free';\n}\n\n/** Mutual exclusion: two places never have tokens simultaneously. */\nexport interface MutualExclusion {\n readonly type: 'mutual-exclusion';\n readonly p1: Place<any>;\n readonly p2: Place<any>;\n}\n\n/** Place bound: a place never exceeds a given token count. */\nexport interface PlaceBound {\n readonly type: 'place-bound';\n readonly place: Place<any>;\n readonly bound: number;\n}\n\n/** Unreachability: the given places never all have tokens simultaneously. */\nexport interface Unreachable {\n readonly type: 'unreachable';\n readonly places: ReadonlySet<Place<any>>;\n}\n\n// Factory functions\n\nexport function deadlockFree(): DeadlockFree {\n return { type: 'deadlock-free' };\n}\n\nexport function mutualExclusion(p1: Place<any>, p2: Place<any>): MutualExclusion {\n return { type: 'mutual-exclusion', p1, p2 };\n}\n\nexport function placeBound(place: Place<any>, bound: number): PlaceBound {\n return { type: 'place-bound', place, bound };\n}\n\nexport function unreachable(places: ReadonlySet<Place<any>>): Unreachable {\n return { type: 'unreachable', places: new Set(places) };\n}\n\n/** Human-readable description of a property. */\nexport function propertyDescription(prop: SmtProperty): string {\n switch (prop.type) {\n case 'deadlock-free':\n return 'Deadlock-freedom';\n case 'mutual-exclusion':\n return `Mutual exclusion of ${prop.p1.name} and ${prop.p2.name}`;\n case 'place-bound':\n return `Place ${prop.place.name} bounded by ${prop.bound}`;\n case 'unreachable':\n return `Unreachability of marking with tokens in {${[...prop.places].map(p => p.name).join(', ')}}`;\n }\n}\n","import type { MarkingState } from './marking-state.js';\nimport type { PInvariant } from './invariant/p-invariant.js';\n\n/**\n * Verification verdict.\n */\nexport type Verdict = Proven | Violated | Unknown;\n\n/** Property proven safe. No reachable state violates it. */\nexport interface Proven {\n readonly type: 'proven';\n readonly method: string;\n readonly inductiveInvariant: string | null;\n}\n\n/** Property violated. A counterexample trace is available. */\nexport interface Violated {\n readonly type: 'violated';\n}\n\n/** Could not determine. */\nexport interface Unknown {\n readonly type: 'unknown';\n readonly reason: string;\n}\n\n/**\n * Solver statistics.\n */\nexport interface SmtStatistics {\n readonly places: number;\n readonly transitions: number;\n readonly invariantsFound: number;\n readonly structuralResult: string;\n}\n\n/**\n * Result of SMT-based verification.\n */\nexport interface SmtVerificationResult {\n readonly verdict: Verdict;\n readonly report: string;\n readonly invariants: readonly PInvariant[];\n readonly discoveredInvariants: readonly string[];\n readonly counterexampleTrace: readonly MarkingState[];\n readonly counterexampleTransitions: readonly string[];\n readonly elapsedMs: number;\n readonly statistics: SmtStatistics;\n}\n\nexport function isProven(result: SmtVerificationResult): boolean {\n return result.verdict.type === 'proven';\n}\n\nexport function isViolated(result: SmtVerificationResult): boolean {\n return result.verdict.type === 'violated';\n}\n","import { init } from 'z3-solver';\nimport type { Bool, Expr, FuncDecl } from 'z3-solver';\n\n/**\n * Result of a Spacer query.\n */\nexport type QueryResult = QueryProven | QueryViolated | QueryUnknown;\n\n/** Property proven: no reachable error state (UNSAT). */\nexport interface QueryProven {\n readonly type: 'proven';\n readonly invariantFormula: string | null;\n readonly levelInvariants: readonly string[];\n}\n\n/** Counterexample found (SAT). The answer is the derivation tree. */\nexport interface QueryViolated {\n readonly type: 'violated';\n readonly answer: Expr | null;\n}\n\n/** Solver could not determine (timeout, resource limit). */\nexport interface QueryUnknown {\n readonly type: 'unknown';\n readonly reason: string;\n}\n\n/**\n * The Z3 context and helpers returned by SpacerRunner.create().\n * Exposes the context object for building expressions.\n */\nexport interface SpacerContext {\n /** The Z3 high-level context for building expressions. */\n readonly ctx: ReturnType<Awaited<ReturnType<typeof init>>['Context']>;\n /** The Z3 Fixedpoint solver instance (Spacer engine). Z3 types are complex; using any. */\n readonly fp: any;\n\n /** Queries whether the error state is reachable. */\n query(errorExpr: Bool, reachableDecl?: FuncDecl): Promise<QueryResult>;\n\n /** Releases Z3 resources. */\n dispose(): void;\n}\n\n// Use a type alias for the Z3 context to avoid the deep inference\ntype Z3Context = ReturnType<Awaited<ReturnType<typeof init>>['Context']>;\n\n/**\n * Creates a Spacer runner with the given timeout.\n *\n * Uses Z3's Spacer engine (CHC solver based on IC3/PDR) to prove or\n * disprove safety properties.\n */\nexport async function createSpacerRunner(timeoutMs: number): Promise<SpacerContext> {\n const { Context } = await init();\n const ctx = new Context('main') as Z3Context;\n const fp = new (ctx as any).Fixedpoint() as any;\n\n // Configure Spacer engine\n fp.set('engine', 'spacer');\n fp.set('spacer.global', true);\n fp.set('spacer.use_bg_invs', true);\n if (timeoutMs > 0) {\n fp.set('timeout', Math.min(timeoutMs, 2147483647));\n }\n\n async function query(errorExpr: Bool, reachableDecl?: FuncDecl): Promise<QueryResult> {\n try {\n const status = await fp.query(errorExpr);\n\n if (status === 'unsat') {\n let invariantFormula: string | null = null;\n const levelInvariants: string[] = [];\n\n try {\n const answer = fp.getAnswer();\n if (answer != null) {\n invariantFormula = answer.toString();\n }\n } catch {\n // Some configurations don't produce answers\n }\n\n if (reachableDecl != null) {\n try {\n const levels = fp.getNumLevels(reachableDecl);\n for (let i = 0; i < levels; i++) {\n const cover = fp.getCoverDelta(i, reachableDecl);\n if (cover != null && !(ctx as any).isTrue(cover)) {\n levelInvariants.push(`Level ${i}: ${cover.toString()}`);\n }\n }\n } catch {\n // Level queries may not be available\n }\n }\n\n return { type: 'proven', invariantFormula, levelInvariants };\n }\n\n if (status === 'sat') {\n let answer: Expr | null = null;\n try {\n answer = fp.getAnswer();\n } catch {\n // Some configurations don't produce answers\n }\n return { type: 'violated', answer };\n }\n\n // unknown\n return { type: 'unknown', reason: fp.getReasonUnknown() };\n } catch (e: any) {\n return { type: 'unknown', reason: `Z3 exception: ${e.message ?? e}` };\n }\n }\n\n function dispose(): void {\n try {\n fp.release();\n } catch {\n // ignore\n }\n }\n\n return {\n ctx,\n fp,\n query,\n dispose,\n } as SpacerContext;\n}\n","/**\n * @module smt-encoder\n *\n * Encodes a flattened Petri net as Constrained Horn Clauses (CHC) for Z3's Spacer engine.\n *\n * **CHC encoding strategy**: The net's state space is modeled as integer vectors\n * (one variable per place = token count). Three rule types:\n *\n * 1. **Init**: `Reachable(M0)` — the initial marking is reachable\n * 2. **Transition**: `Reachable(M') :- Reachable(M) ∧ enabled(M,t) ∧ fire(M,M',t)` —\n * one rule per flat transition (XOR branches are separate transitions)\n * 3. **Error**: `Error() :- Reachable(M) ∧ violation(M)` — safety property violation\n *\n * Transition rules include: non-negativity constraints on M', P-invariant strengthening\n * clauses, and environment bounds for bounded analysis.\n *\n * Z3 types are complex and partially untyped; the ctx/fp parameters use `any`.\n */\nimport type { Arith, Bool, FuncDecl } from 'z3-solver';\nimport type { FlatNet } from '../encoding/flat-net.js';\nimport type { FlatTransition } from '../encoding/flat-transition.js';\nimport type { MarkingState } from '../marking-state.js';\nimport type { SmtProperty } from '../smt-property.js';\nimport type { PInvariant } from '../invariant/p-invariant.js';\nimport type { Place } from '../../core/place.js';\nimport { flatNetIndexOf } from '../encoding/flat-net.js';\n\n/** Z3 high-level context. Typed as `any` because z3-solver's TS types are incomplete. */\ntype Z3Context = any;\n/** Z3 Fixedpoint solver instance. Typed as `any` because z3-solver's TS types are incomplete. */\ntype Z3Fixedpoint = any;\n\n/**\n * Result of CHC encoding.\n */\nexport interface EncodingResult {\n readonly errorExpr: Bool;\n readonly reachableDecl: FuncDecl;\n}\n\n/**\n * Encodes a flattened Petri net as Constrained Horn Clauses (CHC) for Z3's Spacer engine.\n *\n * CHC rules:\n * - Reachable(M0) — initial state is reachable\n * - Reachable(M') :- Reachable(M) AND enabled(M,t) AND fire(M,M',t) — transition rules\n * - Error() :- Reachable(M) AND property_violation(M) — safety property\n */\nexport function encode(\n ctx: Z3Context,\n fp: Z3Fixedpoint,\n flatNet: FlatNet,\n initialMarking: MarkingState,\n property: SmtProperty,\n invariants: readonly PInvariant[],\n sinkPlaces: ReadonlySet<Place<any>> = new Set(),\n): EncodingResult {\n const P = flatNet.places.length;\n const Int = ctx.Int;\n const Bool_ = ctx.Bool;\n\n // Create sorts array for function declaration\n const intSort = Int.sort();\n const boolSort = Bool_.sort();\n const markingSorts: any[] = new Array(P).fill(intSort);\n\n // Create the Reachable relation: (Int, Int, ...) -> Bool\n const reachable: FuncDecl = ctx.Function.declare('Reachable', ...markingSorts, boolSort);\n fp.registerRelation(reachable);\n\n // Create the Error relation: () -> Bool\n const error: FuncDecl = ctx.Function.declare('Error', boolSort);\n fp.registerRelation(error);\n\n // === Rule 1: Initial state ===\n // Reachable(m0_0, m0_1, ..., m0_{P-1})\n const m0Args: Arith[] = [];\n for (let i = 0; i < P; i++) {\n const tokens = initialMarking.tokens(flatNet.places[i]!);\n m0Args.push(Int.val(tokens));\n }\n const initFact = (reachable as any).call(...m0Args) as Bool;\n fp.addRule(initFact, 'init');\n\n // === Rule 2: Transition rules ===\n for (let t = 0; t < flatNet.transitions.length; t++) {\n const ft = flatNet.transitions[t]!;\n encodeTransitionRule(ctx, fp, reachable, ft, flatNet, invariants, P);\n }\n\n // === Rule 3: Error rule (property violation) ===\n encodeErrorRule(ctx, fp, reachable, error, flatNet, property, sinkPlaces, P);\n\n return {\n errorExpr: (error as any).call() as Bool,\n reachableDecl: reachable,\n };\n}\n\nfunction encodeTransitionRule(\n ctx: Z3Context,\n fp: Z3Fixedpoint,\n reachable: FuncDecl,\n ft: FlatTransition,\n flatNet: FlatNet,\n invariants: readonly PInvariant[],\n P: number,\n): void {\n const Int = ctx.Int;\n\n // Create named variables for current and next marking\n const mVars: Arith[] = [];\n const mPrimeVars: Arith[] = [];\n for (let i = 0; i < P; i++) {\n mVars.push(Int.const(`m${i}`));\n mPrimeVars.push(Int.const(`mp${i}`));\n }\n\n // Body: Reachable(M) AND enabled(M,t) AND fire(M,M',t) AND non-negativity(M') AND invariants(M') AND env bounds(M')\n const reachBody = (reachable as any).call(...mVars) as Bool;\n const enabled = encodeEnabled(ctx, ft, flatNet, mVars, P);\n const fireRelation = encodeFire(ctx, ft, flatNet, mVars, mPrimeVars, P);\n\n // Non-negativity of M'\n let nonNeg: Bool = ctx.Bool.val(true);\n for (let i = 0; i < P; i++) {\n nonNeg = ctx.And(nonNeg, mPrimeVars[i]!.ge(0));\n }\n\n // P-invariant constraints on M'\n const invConstraints = encodeInvariantConstraints(ctx, invariants, mPrimeVars, P);\n\n // Environment bounds on M'\n let envBounds: Bool = ctx.Bool.val(true);\n for (const [name, bound] of flatNet.environmentBounds) {\n const idx = flatNet.placeIndex.get(name);\n if (idx != null) {\n envBounds = ctx.And(envBounds, mPrimeVars[idx]!.le(bound));\n }\n }\n\n // Body conjunction\n const body = ctx.And(reachBody, enabled, fireRelation, nonNeg, invConstraints, envBounds);\n\n // Head: Reachable(M')\n const head = (reachable as any).call(...mPrimeVars) as Bool;\n\n // Rule: forall M, M'. body => head\n const allVars = [...mVars, ...mPrimeVars];\n const rule = ctx.Implies(body, head);\n const qRule = ctx.ForAll(allVars, rule);\n\n fp.addRule(qRule, `t_${ft.name}`);\n}\n\nfunction encodeEnabled(\n ctx: Z3Context,\n ft: FlatTransition,\n _flatNet: FlatNet,\n mVars: Arith[],\n P: number,\n): Bool {\n let result: Bool = ctx.Bool.val(true);\n\n // Input requirements: M[p] >= pre[p]\n for (let p = 0; p < P; p++) {\n if (ft.preVector[p]! > 0) {\n result = ctx.And(result, mVars[p]!.ge(ft.preVector[p]!));\n }\n }\n\n // Read arcs: M[p] >= 1\n for (const p of ft.readPlaces) {\n result = ctx.And(result, mVars[p]!.ge(1));\n }\n\n // Inhibitor arcs: M[p] == 0\n for (const p of ft.inhibitorPlaces) {\n result = ctx.And(result, mVars[p]!.eq(0));\n }\n\n // Non-negativity of current marking\n for (let p = 0; p < P; p++) {\n result = ctx.And(result, mVars[p]!.ge(0));\n }\n\n return result;\n}\n\nfunction encodeFire(\n ctx: Z3Context,\n ft: FlatTransition,\n _flatNet: FlatNet,\n mVars: Arith[],\n mPrimeVars: Arith[],\n P: number,\n): Bool {\n let result: Bool = ctx.Bool.val(true);\n\n for (let p = 0; p < P; p++) {\n const isReset = ft.resetPlaces.includes(p);\n\n if (isReset || ft.consumeAll[p]) {\n // Reset/consumeAll: M'[p] = post[p]\n result = ctx.And(result, mPrimeVars[p]!.eq(ft.postVector[p]!));\n } else {\n // Standard: M'[p] = M[p] - pre[p] + post[p]\n const delta = ft.postVector[p]! - ft.preVector[p]!;\n if (delta === 0) {\n result = ctx.And(result, mPrimeVars[p]!.eq(mVars[p]!));\n } else {\n result = ctx.And(result, mPrimeVars[p]!.eq(mVars[p]!.add(delta)));\n }\n }\n }\n\n return result;\n}\n\nfunction encodeErrorRule(\n ctx: Z3Context,\n fp: Z3Fixedpoint,\n reachable: FuncDecl,\n error: FuncDecl,\n flatNet: FlatNet,\n property: SmtProperty,\n sinkPlaces: ReadonlySet<Place<any>>,\n P: number,\n): void {\n const Int = ctx.Int;\n\n // Create variables for the error rule\n const mVars: Arith[] = [];\n for (let i = 0; i < P; i++) {\n mVars.push(Int.const(`em${i}`));\n }\n\n const reachBody = (reachable as any).call(...mVars) as Bool;\n const violation = encodePropertyViolation(ctx, flatNet, property, sinkPlaces, mVars, P);\n\n const head = (error as any).call() as Bool;\n const body = ctx.And(reachBody, violation);\n const rule = ctx.Implies(body, head);\n const qRule = ctx.ForAll(mVars, rule);\n\n fp.addRule(qRule, `error_${property.type}`);\n}\n\nfunction encodePropertyViolation(\n ctx: Z3Context,\n flatNet: FlatNet,\n property: SmtProperty,\n sinkPlaces: ReadonlySet<Place<any>>,\n mVars: Arith[],\n P: number,\n): Bool {\n switch (property.type) {\n case 'deadlock-free': {\n const deadlock = encodeDeadlock(ctx, flatNet, mVars, P);\n if (sinkPlaces.size > 0) {\n // Deadlock is only a violation if NOT at any expected sink place\n let notAtSink: Bool = ctx.Bool.val(true);\n for (const sink of sinkPlaces) {\n const idx = flatNetIndexOf(flatNet, sink);\n if (idx >= 0) {\n notAtSink = ctx.And(notAtSink, mVars[idx]!.eq(0));\n }\n }\n return ctx.And(deadlock, notAtSink);\n }\n return deadlock;\n }\n\n case 'mutual-exclusion': {\n const idx1 = flatNetIndexOf(flatNet, property.p1);\n const idx2 = flatNetIndexOf(flatNet, property.p2);\n if (idx1 < 0) throw new Error(`MutualExclusion references unknown place: ${property.p1.name}`);\n if (idx2 < 0) throw new Error(`MutualExclusion references unknown place: ${property.p2.name}`);\n return ctx.And(mVars[idx1]!.ge(1), mVars[idx2]!.ge(1));\n }\n\n case 'place-bound': {\n const idx = flatNetIndexOf(flatNet, property.place);\n if (idx < 0) throw new Error(`PlaceBound references unknown place: ${property.place.name}`);\n return mVars[idx]!.gt(property.bound);\n }\n\n case 'unreachable': {\n let allMarked: Bool = ctx.Bool.val(true);\n for (const place of property.places) {\n const idx = flatNetIndexOf(flatNet, place);\n if (idx >= 0) {\n allMarked = ctx.And(allMarked, mVars[idx]!.ge(1));\n }\n }\n return allMarked;\n }\n }\n}\n\n/** Encodes the deadlock condition: no transition is enabled. */\nfunction encodeDeadlock(\n ctx: Z3Context,\n flatNet: FlatNet,\n mVars: Arith[],\n P: number,\n): Bool {\n let deadlock: Bool = ctx.Bool.val(true);\n\n for (const ft of flatNet.transitions) {\n const enabled = encodeEnabled(ctx, ft, flatNet, mVars, P);\n deadlock = ctx.And(deadlock, ctx.Not(enabled));\n }\n\n return deadlock;\n}\n\nfunction encodeInvariantConstraints(\n ctx: Z3Context,\n invariants: readonly PInvariant[],\n mVars: Arith[],\n P: number,\n): Bool {\n let result: Bool = ctx.Bool.val(true);\n\n for (const inv of invariants) {\n // sum(y_i * M[i]) == constant\n let sum: Arith = ctx.Int.val(0);\n for (const idx of inv.support) {\n if (idx < P) {\n sum = sum.add(mVars[idx]!.mul(inv.weights[idx]!));\n }\n }\n result = ctx.And(result, sum.eq(inv.constant));\n }\n\n return result;\n}\n","import type { Expr } from 'z3-solver';\nimport { MarkingState } from '../marking-state.js';\nimport type { FlatNet } from '../encoding/flat-net.js';\n\n/**\n * Result of counterexample decoding.\n */\nexport interface DecodedTrace {\n readonly trace: readonly MarkingState[];\n readonly transitions: readonly string[];\n}\n\n/**\n * Decodes Z3 Spacer counterexample answers into Petri net marking traces.\n *\n * When Spacer finds a counterexample (property violation), it produces\n * a derivation tree showing how the error state is reachable. This function\n * extracts the marking at each step to produce a human-readable trace.\n */\nexport function decode(ctx: any, answer: Expr | null, flatNet: FlatNet): DecodedTrace {\n const trace: MarkingState[] = [];\n const transitions: string[] = [];\n\n if (answer == null) {\n return { trace, transitions };\n }\n\n try {\n extractTrace(ctx, answer, flatNet, trace, transitions);\n } catch {\n // Z3 answer format varies; gracefully degrade\n }\n\n return { trace, transitions };\n}\n\n/**\n * Recursively traverses the Z3 proof tree to extract marking states.\n */\nfunction extractTrace(\n ctx: any,\n expr: any,\n flatNet: FlatNet,\n trace: MarkingState[],\n transitions: string[],\n): void {\n if (expr == null) return;\n\n // Check if this is a function application\n if (!ctx.isApp(expr)) return;\n\n let name: string;\n try {\n const decl = expr.decl();\n name = String(decl.name());\n } catch {\n return;\n }\n\n // Check if this is a Reachable application with integer arguments\n const P = flatNet.places.length;\n if (name === 'Reachable') {\n const numArgs = expr.numArgs();\n if (numArgs === P) {\n const marking = extractMarking(ctx, expr, flatNet);\n if (marking != null) {\n trace.push(marking);\n }\n }\n }\n\n // Recurse into children to find the derivation chain\n try {\n const numArgs = expr.numArgs();\n for (let i = 0; i < numArgs; i++) {\n const child = expr.arg(i);\n extractTrace(ctx, child, flatNet, trace, transitions);\n }\n } catch {\n // Not all expressions support arg()\n }\n\n // Try to extract transition name from rule application\n if (name.startsWith('t_')) {\n transitions.push(name.substring(2));\n }\n}\n\n/**\n * Extracts a MarkingState from a Reachable(...) application.\n */\nfunction extractMarking(ctx: any, reachableApp: any, flatNet: FlatNet): MarkingState | null {\n const P = flatNet.places.length;\n if (reachableApp.numArgs() !== P) return null;\n\n const builder = MarkingState.builder();\n for (let i = 0; i < P; i++) {\n const arg = reachableApp.arg(i);\n if (ctx.isIntVal(arg)) {\n const tokens = Number(arg.value());\n if (tokens > 0) {\n builder.tokens(flatNet.places[i]!, tokens);\n }\n } else {\n // Non-concrete value in counterexample\n return null;\n }\n }\n return builder.build();\n}\n","import type { PetriNet } from '../core/petri-net.js';\nimport type { EnvironmentPlace, Place } from '../core/place.js';\nimport { MarkingState, MarkingStateBuilder } from './marking-state.js';\nimport type { SmtProperty } from './smt-property.js';\nimport { deadlockFree, propertyDescription } from './smt-property.js';\nimport type { SmtVerificationResult, SmtStatistics, Verdict } from './smt-verification-result.js';\nimport type { PInvariant } from './invariant/p-invariant.js';\nimport type { FlatNet } from './encoding/flat-net.js';\nimport { flatten, type EnvironmentAnalysisMode, unbounded } from './encoding/net-flattener.js';\nimport { IncidenceMatrix } from './encoding/incidence-matrix.js';\nimport { computePInvariants, isCoveredByInvariants } from './invariant/p-invariant-computer.js';\nimport { structuralCheck } from './invariant/structural-check.js';\nimport { createSpacerRunner } from './z3/spacer-runner.js';\nimport { encode } from './z3/smt-encoder.js';\nimport { decode } from './z3/counterexample-decoder.js';\n\n/**\n * IC3/PDR-based safety verifier for Petri nets using Z3's Spacer engine.\n *\n * Proves safety properties (especially deadlock-freedom) without\n * enumerating all reachable states. IC3 constructs inductive invariants\n * incrementally, which works well for bounded nets.\n *\n * Key design decisions:\n * - Operates on the marking projection (integer vectors) — no timing\n * - An untimed deadlock-freedom proof is stronger than needed\n * (timing can only restrict behavior)\n * - Guards are ignored — over-approximation is sound for safety properties\n * - If a counterexample is found, it may be spurious in timed/guarded\n * semantics — the report notes this\n *\n * Verification Pipeline:\n * 1. Flatten — expand XOR, index places, build pre/post vectors\n * 2. Structural pre-check — siphon/trap analysis (may prove early)\n * 3. P-invariants — compute conservation laws for strengthening\n * 4. SMT encode + query — IC3/PDR via Z3 Spacer\n * 5. Decode result — proof or counterexample trace\n */\nexport class SmtVerifier {\n private _initialMarking: MarkingState = MarkingState.empty();\n private _property: SmtProperty = deadlockFree();\n private readonly _environmentPlaces = new Set<EnvironmentPlace<any>>();\n private readonly _sinkPlaces = new Set<Place<any>>();\n private _environmentMode: EnvironmentAnalysisMode = unbounded();\n private _timeoutMs: number = 60_000;\n\n private constructor(private readonly net: PetriNet) {}\n\n static forNet(net: PetriNet): SmtVerifier {\n return new SmtVerifier(net);\n }\n\n initialMarking(marking: MarkingState): this;\n initialMarking(configurator: (builder: MarkingStateBuilder) => void): this;\n initialMarking(arg: MarkingState | ((builder: MarkingStateBuilder) => void)): this {\n if (arg instanceof MarkingState) {\n this._initialMarking = arg;\n } else {\n const builder = MarkingState.builder();\n arg(builder);\n this._initialMarking = builder.build();\n }\n return this;\n }\n\n property(property: SmtProperty): this {\n this._property = property;\n return this;\n }\n\n environmentPlaces(...places: EnvironmentPlace<any>[]): this {\n for (const p of places) this._environmentPlaces.add(p);\n return this;\n }\n\n environmentMode(mode: EnvironmentAnalysisMode): this {\n this._environmentMode = mode;\n return this;\n }\n\n /**\n * Declares expected sink (terminal) places for deadlock-freedom analysis.\n * Markings where any sink place has a token are not considered deadlocks.\n */\n sinkPlaces(...places: Place<any>[]): this {\n for (const p of places) this._sinkPlaces.add(p);\n return this;\n }\n\n timeout(ms: number): this {\n this._timeoutMs = ms;\n return this;\n }\n\n /**\n * Runs the verification pipeline.\n */\n async verify(): Promise<SmtVerificationResult> {\n const start = performance.now();\n const report: string[] = [];\n report.push('=== IC3/PDR SAFETY VERIFICATION ===\\n');\n report.push(`Net: ${this.net.name}`);\n const propDesc = this._sinkPlaces.size === 0\n ? propertyDescription(this._property)\n : `${propertyDescription(this._property)} (sinks: ${[...this._sinkPlaces].map(p => p.name).join(', ')})`;\n report.push(`Property: ${propDesc}`);\n report.push(`Timeout: ${(this._timeoutMs / 1000).toFixed(0)}s\\n`);\n\n // Phase 1: Flatten\n report.push('Phase 1: Flattening net...');\n const flatNet = flatten(this.net, this._environmentPlaces, this._environmentMode);\n report.push(` Places: ${flatNet.places.length}`);\n report.push(` Transitions (expanded): ${flatNet.transitions.length}`);\n if (flatNet.environmentBounds.size > 0) {\n report.push(` Environment bounds: ${flatNet.environmentBounds.size} places`);\n }\n report.push('');\n\n // Phase 2: Structural pre-check\n report.push('Phase 2: Structural pre-check (siphon/trap)...');\n const structResult = structuralCheck(flatNet, this._initialMarking);\n let structResultStr: string;\n switch (structResult.type) {\n case 'no-potential-deadlock':\n structResultStr = 'no potential deadlock';\n break;\n case 'potential-deadlock':\n structResultStr = `potential deadlock (siphon: {${[...structResult.siphon].join(',')}})`;\n break;\n case 'inconclusive':\n structResultStr = `inconclusive (${structResult.reason})`;\n break;\n }\n report.push(` Result: ${structResultStr}\\n`);\n\n // If structural check proves deadlock-freedom for DeadlockFree property\n // (only valid when no sink places — structural check doesn't account for sinks)\n if (\n this._property.type === 'deadlock-free' &&\n this._sinkPlaces.size === 0 &&\n structResult.type === 'no-potential-deadlock'\n ) {\n report.push('=== RESULT ===\\n');\n report.push('PROVEN (structural): Deadlock-freedom verified by Commoner\\'s theorem.');\n report.push(' All siphons contain initially marked traps.');\n return buildResult(\n { type: 'proven', method: 'structural', inductiveInvariant: null },\n report.join('\\n'), [], [], [], [],\n performance.now() - start,\n { places: flatNet.places.length, transitions: flatNet.transitions.length, invariantsFound: 0, structuralResult: structResultStr },\n );\n }\n\n // Phase 3: P-invariants\n report.push('Phase 3: Computing P-invariants...');\n const matrix = IncidenceMatrix.from(flatNet);\n const invariants = computePInvariants(matrix, flatNet, this._initialMarking);\n report.push(` Found: ${invariants.length} P-invariant(s)`);\n const structurallyBounded = isCoveredByInvariants(invariants, flatNet.places.length);\n report.push(` Structurally bounded: ${structurallyBounded ? 'YES' : 'NO'}`);\n for (const inv of invariants) {\n report.push(` ${formatInvariant(inv, flatNet)}`);\n }\n report.push('');\n\n // Phase 4: SMT encode + query via Spacer\n report.push('Phase 4: IC3/PDR verification via Z3 Spacer...');\n\n let runner;\n try {\n runner = await createSpacerRunner(this._timeoutMs);\n } catch (e: any) {\n report.push(` ERROR: ${e.message ?? e}\\n`);\n report.push('=== RESULT ===\\n');\n report.push(`UNKNOWN: Z3 initialization error: ${e.message ?? e}`);\n return buildResult(\n { type: 'unknown', reason: `Z3 init error: ${e.message ?? e}` },\n report.join('\\n'), invariants, [], [], [],\n performance.now() - start,\n { places: flatNet.places.length, transitions: flatNet.transitions.length, invariantsFound: invariants.length, structuralResult: structResultStr },\n );\n }\n\n try {\n const encoding = encode(runner.ctx, runner.fp, flatNet, this._initialMarking, this._property, invariants, this._sinkPlaces);\n const queryResult = await runner.query(encoding.errorExpr, encoding.reachableDecl);\n\n switch (queryResult.type) {\n case 'proven': {\n report.push(' Status: UNSAT (property holds)\\n');\n\n // Decode IC3-synthesized invariants with place name substitution\n const discoveredInvariants: string[] = [];\n if (queryResult.invariantFormula != null) {\n discoveredInvariants.push(substituteNames(queryResult.invariantFormula, flatNet));\n }\n for (const level of queryResult.levelInvariants) {\n discoveredInvariants.push(substituteNames(level, flatNet));\n }\n\n // Phase 5: Inductive invariant\n if (discoveredInvariants.length > 0) {\n report.push('Phase 5: Inductive invariant (discovered by IC3)');\n report.push(` Spacer synthesized: ${discoveredInvariants[0]}`);\n report.push(' This formula is INDUCTIVE: preserved by all transitions.');\n if (discoveredInvariants.length > 1) {\n report.push(' Per-level clauses:');\n for (let i = 1; i < discoveredInvariants.length; i++) {\n report.push(` ${discoveredInvariants[i]}`);\n }\n }\n report.push('');\n }\n\n report.push('=== RESULT ===\\n');\n report.push(`PROVEN (IC3/PDR): ${propDesc}`);\n report.push(' Z3 Spacer proved no reachable state violates the property.');\n report.push(' NOTE: Verification ignores timing constraints and JS guards.');\n report.push(' An untimed proof is STRONGER than a timed one (timing only restricts behavior).');\n\n return buildResult(\n {\n type: 'proven',\n method: 'IC3/PDR',\n inductiveInvariant: queryResult.invariantFormula != null\n ? substituteNames(queryResult.invariantFormula, flatNet)\n : null,\n },\n report.join('\\n'), invariants, discoveredInvariants, [], [],\n performance.now() - start,\n { places: flatNet.places.length, transitions: flatNet.transitions.length, invariantsFound: invariants.length, structuralResult: structResultStr },\n );\n }\n\n case 'violated': {\n report.push(' Status: SAT (counterexample found)\\n');\n\n const decoded = decode(runner.ctx, queryResult.answer, flatNet);\n\n report.push('=== RESULT ===\\n');\n report.push(`VIOLATED: ${propDesc}`);\n if (decoded.trace.length > 0) {\n report.push(` Counterexample trace (${decoded.trace.length} states):`);\n for (let i = 0; i < decoded.trace.length; i++) {\n report.push(` ${i}: ${decoded.trace[i]}`);\n }\n }\n if (decoded.transitions.length > 0) {\n report.push(` Firing sequence: ${decoded.transitions.join(' -> ')}`);\n }\n report.push('\\n WARNING: This counterexample is in UNTIMED semantics.');\n report.push(' It may be spurious if timing constraints prevent this sequence.');\n report.push(' JS guards are also ignored in this analysis.');\n\n return buildResult(\n { type: 'violated' },\n report.join('\\n'), invariants, [], decoded.trace as MarkingState[], decoded.transitions as string[],\n performance.now() - start,\n { places: flatNet.places.length, transitions: flatNet.transitions.length, invariantsFound: invariants.length, structuralResult: structResultStr },\n );\n }\n\n case 'unknown': {\n report.push(` Status: UNKNOWN (${queryResult.reason})\\n`);\n report.push('=== RESULT ===\\n');\n report.push(`UNKNOWN: Could not determine ${propDesc}`);\n report.push(` Reason: ${queryResult.reason}`);\n\n return buildResult(\n { type: 'unknown', reason: queryResult.reason },\n report.join('\\n'), invariants, [], [], [],\n performance.now() - start,\n { places: flatNet.places.length, transitions: flatNet.transitions.length, invariantsFound: invariants.length, structuralResult: structResultStr },\n );\n }\n }\n } catch (e: any) {\n report.push(` ERROR: ${e.message ?? e}\\n`);\n report.push('=== RESULT ===\\n');\n report.push(`UNKNOWN: Z3 solver error: ${e.message ?? e}`);\n\n return buildResult(\n { type: 'unknown', reason: `Z3 error: ${e.message ?? e}` },\n report.join('\\n'), invariants, [], [], [],\n performance.now() - start,\n { places: flatNet.places.length, transitions: flatNet.transitions.length, invariantsFound: invariants.length, structuralResult: structResultStr },\n );\n } finally {\n runner.dispose();\n }\n }\n}\n\n/**\n * Substitutes Z3 variable names (m0, m1, ...) with place names in a formula string.\n */\nfunction substituteNames(formula: string, flatNet: FlatNet): string {\n // Replace from highest index first to avoid m1 matching inside m10\n for (let i = flatNet.places.length - 1; i >= 0; i--) {\n formula = formula.replace(new RegExp(`\\\\bm${i}\\\\b`, 'g'), flatNet.places[i]!.name);\n }\n return formula;\n}\n\nfunction formatInvariant(inv: PInvariant, flatNet: FlatNet): string {\n const parts: string[] = [];\n for (const idx of inv.support) {\n if (inv.weights[idx] !== 1) {\n parts.push(`${inv.weights[idx]}*${flatNet.places[idx]!.name}`);\n } else {\n parts.push(flatNet.places[idx]!.name);\n }\n }\n return `${parts.join(' + ')} = ${inv.constant}`;\n}\n\nfunction buildResult(\n verdict: Verdict,\n report: string,\n invariants: readonly PInvariant[],\n discoveredInvariants: readonly string[],\n trace: readonly MarkingState[],\n transitions: readonly string[],\n elapsedMs: number,\n statistics: SmtStatistics,\n): SmtVerificationResult {\n return { verdict, report, invariants, discoveredInvariants, counterexampleTrace: trace, counterexampleTransitions: transitions, elapsedMs, statistics };\n}\n"],"mappings":";;;;;;AAGA,IAAM,oBAAoB,uBAAO,uBAAuB;AAQjD,IAAM,eAAN,MAAM,cAAa;AAAA,EACP;AAAA,EACA;AAAA;AAAA,EAGjB,YAAY,KAAa,aAAkC,cAAuC;AAChG,QAAI,QAAQ,kBAAmB,OAAM,IAAI,MAAM,gDAAgD;AAC/F,SAAK,cAAc;AACnB,SAAK,eAAe;AAAA,EACtB;AAAA;AAAA,EAGA,OAAO,OAA2B;AAChC,WAAO,KAAK,YAAY,IAAI,MAAM,IAAI,KAAK;AAAA,EAC7C;AAAA;AAAA,EAGA,UAAU,OAA4B;AACpC,WAAO,KAAK,OAAO,KAAK,IAAI;AAAA,EAC9B;AAAA;AAAA,EAGA,eAAe,QAAuC;AACpD,eAAW,KAAK,QAAQ;AACtB,UAAI,KAAK,UAAU,CAAC,EAAG,QAAO;AAAA,IAChC;AACA,WAAO;AAAA,EACT;AAAA;AAAA,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YAAY,sBAAsB,qBAAqB,OAAO,2BAA2B,aAAa,WAAW,WAAW;AACxJ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libpetri",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "Coloured Time Petri Net engine — TypeScript port",
|
|
5
5
|
"homepage": "https://libpetri.org",
|
|
6
6
|
"repository": {
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
"url": "https://github.com/debe/libpetri/issues"
|
|
13
13
|
},
|
|
14
14
|
"license": "Apache-2.0",
|
|
15
|
-
"files": [
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
16
18
|
"type": "module",
|
|
17
19
|
"exports": {
|
|
18
20
|
".": {
|