tla-ts 0.0.2 → 0.0.3-dev.a50fc89

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.
@@ -0,0 +1,76 @@
1
+ // tlapm's proof IR (P_t).
2
+
3
+ import type { Bound, Defn, Expr, Locus, Sequent } from "./obligation-expression";
4
+
5
+ export type StepNumber =
6
+ | { kind: "Named"; level: number; label: string; isAnonymous: boolean }
7
+ | { kind: "Unnamed"; level: number; id: number };
8
+
9
+ export type UseDef = ({ kind: "Dvar"; name: string } | { kind: "Dx"; index: number }) & {
10
+ location?: Locus;
11
+ };
12
+
13
+ export interface Usable {
14
+ facts: Expr[];
15
+ defs: UseDef[];
16
+ }
17
+
18
+ type Omission = "Implicit" | "Explicit" | "Elsewhere";
19
+
20
+ export type ObligationKind =
21
+ | { kind: "Main" }
22
+ | { kind: "Support" }
23
+ | { kind: "Error"; message: string }
24
+ | { kind: "Omitted"; omission: Omission };
25
+
26
+ export interface Obligation {
27
+ sequent: Sequent;
28
+ location: Locus | undefined;
29
+ kind: ObligationKind;
30
+ }
31
+
32
+ interface ProofProps {
33
+ location?: Locus;
34
+ step?: StepNumber;
35
+ isSuppressed?: boolean;
36
+ obligations?: Obligation[];
37
+ }
38
+
39
+ export type Proof = ProofCore & ProofProps;
40
+
41
+ type ProofCore =
42
+ | { kind: "Obvious" }
43
+ | { kind: "Omitted"; omission: Omission }
44
+ | { kind: "By"; usable: Usable; isOnly: boolean }
45
+ | { kind: "Steps"; steps: Step[]; qed: QedStep }
46
+ | { kind: "Error"; message: string };
47
+
48
+ interface QedStep extends ProofProps {
49
+ proof: Proof;
50
+ }
51
+
52
+ export type Step = StepCore & ProofProps;
53
+
54
+ type StepCore =
55
+ | { kind: "Hide"; usable: Usable }
56
+ | { kind: "Define"; definitions: Defn[] }
57
+ | { kind: "Assert"; sequent: Sequent; proof: Proof }
58
+ | { kind: "Suffices"; sequent: Sequent; proof: Proof }
59
+ | { kind: "Pcase"; expression: Expr; proof: Proof }
60
+ | { kind: "Pick"; bounds: Bound[]; expression: Expr; proof: Proof }
61
+ | { kind: "Use"; usable: Usable; isOnly: boolean }
62
+ | { kind: "Have"; expression: Expr }
63
+ | { kind: "Take"; bounds: Bound[] }
64
+ | { kind: "Witness"; expressions: Expr[] }
65
+ | { kind: "Forget"; count: number };
66
+
67
+ export const getStepName = (step: StepNumber) =>
68
+ step.kind === "Named" ? `<${step.level}>${step.label}` : `<${step.level}>`;
69
+
70
+ // Std.unique: one counter for the whole run, shared by the parser, anonymization, and
71
+ // simplification, so anonymous step names match tlapm's.
72
+ export interface Counter {
73
+ value: number;
74
+ }
75
+
76
+ export const getUnique = (counter: Counter) => ++counter.value;