You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
4.3 KiB

  1. --------------------------- MODULE Apalache -----------------------------------
  2. (*
  3. * This is a standard module for use with the Apalache model checker.
  4. * The meaning of the operators is explained in the comments.
  5. * Many of the operators serve as additional annotations of their arguments.
  6. * As we like to preserve compatibility with TLC and TLAPS, we define the
  7. * operator bodies by erasure. The actual interpretation of the operators is
  8. * encoded inside Apalache. For the moment, these operators are mirrored in
  9. * the class at.forsyte.apalache.tla.lir.oper.ApalacheOper.
  10. *
  11. * Igor Konnov, Jure Kukovec, Informal Systems 2020-2021
  12. *)
  13. (**
  14. * An assignment of an expression e to a state variable x. Typically, one
  15. * uses the non-primed version of x in the initializing predicate Init and
  16. * the primed version of x (that is, x') in the transition predicate Next.
  17. * Although TLA+ does not have a concept of a variable assignment, we find
  18. * this concept extremely useful for symbolic model checking. In pure TLA+,
  19. * one would simply write x = e, or x \in {e}.
  20. *
  21. * Apalache automatically converts some expressions of the form
  22. * x = e or x \in {e} into assignments. However, if you like to annotate
  23. * assignments by hand, you can use this operator.
  24. *
  25. * For a further discussion on that matter, see:
  26. * https://github.com/informalsystems/apalache/blob/ik/idiomatic-tla/docs/idiomatic/assignments.md
  27. *)
  28. x := e == x = e
  29. (**
  30. * A generator of a data structure. Given a positive integer `bound`, and
  31. * assuming that the type of the operator application is known, we
  32. * recursively generate a TLA+ data structure as a tree, whose width is
  33. * bound by the number `bound`.
  34. *
  35. * The body of this operator is redefined by Apalache.
  36. *)
  37. Gen(size) == {}
  38. (**
  39. * Convert a set of pairs S to a function F. Note that if S contains at least
  40. * two pairs <<x, y>> and <<u, v>> such that x = u and y /= v,
  41. * then F is not uniquely defined. We use CHOOSE to resolve this ambiguity.
  42. * Apalache implements a more efficient encoding of this operator
  43. * than the default one.
  44. *
  45. * @type: Set(<<a, b>>) => (a -> b);
  46. *)
  47. SetAsFun(S) ==
  48. LET Dom == { x: <<x, y>> \in S }
  49. Rng == { y: <<x, y>> \in S }
  50. IN
  51. [ x \in Dom |-> CHOOSE y \in Rng: <<x, y>> \in S ]
  52. (**
  53. * As TLA+ is untyped, one can use function- and sequence-specific operators
  54. * interchangeably. However, to maintain correctness w.r.t. our type-system,
  55. * an explicit cast is needed when using functions as sequences.
  56. *)
  57. LOCAL INSTANCE Sequences
  58. FunAsSeq(fn, maxSeqLen) == SubSeq(fn, 1, maxSeqLen)
  59. (**
  60. * Annotating an expression \E x \in S: P as Skolemizable. That is, it can
  61. * be replaced with an expression c \in S /\ P(c) for a fresh constant c.
  62. * Not every exisential can be replaced with a constant, this should be done
  63. * with care. Apalache detects Skolemizable expressions by static analysis.
  64. *)
  65. Skolem(e) == e
  66. (**
  67. * A hint to the model checker to expand a set S, instead of dealing
  68. * with it symbolically. Apalache finds out which sets have to be expanded
  69. * by static analysis.
  70. *)
  71. Expand(S) == S
  72. (**
  73. * A hint to the model checker to replace its argument Cardinality(S) >= k
  74. * with a series of existential quantifiers for a constant k.
  75. * Similar to Skolem, this has to be done carefully. Apalache automatically
  76. * places this hint by static analysis.
  77. *)
  78. ConstCardinality(cardExpr) == cardExpr
  79. (**
  80. * The folding operator, used to implement computation over a set.
  81. * Apalache implements a more efficient encoding than the one below.
  82. * (from the community modules).
  83. *)
  84. RECURSIVE FoldSet(_,_,_)
  85. FoldSet( Op(_,_), v, S ) == IF S = {}
  86. THEN v
  87. ELSE LET w == CHOOSE x \in S: TRUE
  88. IN LET T == S \ {w}
  89. IN FoldSet( Op, Op(v,w), T )
  90. (**
  91. * The folding operator, used to implement computation over a sequence.
  92. * Apalache implements a more efficient encoding than the one below.
  93. * (from the community modules).
  94. *)
  95. RECURSIVE FoldSeq(_,_,_)
  96. FoldSeq( Op(_,_), v, seq ) == IF seq = <<>>
  97. THEN v
  98. ELSE FoldSeq( Op, Op(v,Head(seq)), Tail(seq) )
  99. ===============================================================================