[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlaplus] Generating a set of structs where each key ranges over a distinct set

Your definition is not even syntactically well formed. If I understand correctly, you would like to define the set of all records whose fields are those of your prototype record and such that the value of each field is contained in the interval between 0 and the number that the prototype assigns to the field. This can be defined as

AllPossibleShipments ==
  { f \in [DOMAIN Inventory -> Nat] : 
      \A item \in DOMAIN Inventory : f[item] \in 0 .. Inventory[item] }

However, TLC will be unable to evaluate this definition because the base set of the set comprehension, i.e.

  [DOMAIN Inventory -> Nat]

is infinite. The cheap ways around this are to either introduce a constant MAX as an upper bound on the stocks of each item and replace `Nat' by `0 .. MAX' or to redefine Nat to an interval such as `0 .. 10' (Advanced Options -> Definition Override in the model checking pane of the Toolbox). If you want to be more sophisticated, you can write

AllPossibleShipments ==
  LET fields == DOMAIN Inventory
      bounds == { Inventory[item] : item \in fields }
      max == CHOOSE b \in bounds : \A bb \in bounds : bb <= b
  IN  { f \in [fields -> (0 .. max)] : 
          \A item \in fields : f[item] \in 0 .. Inventory[item] }

Disclaimer: I haven't actually checked these definitions, they may contain typos.


On 5 Feb 2019, at 07:57, yati sagade <yati....@xxxxxxxxx> wrote:

Given a structure like this:

   Inventory == [foo |-> 3, bar |-> 2, baz |-> 5] \* How much of an item do we have in store

I'd like to generate the set of structures

   AllPossibleShipments ==
       [foo: 0..3, bar: 0..2, baz: 0..5]

But of course without re-enumerating the items by hand. The most natural thing that came to mind is:

   AllPossibleShipments ==
       [item \in DOMAIN Inventory : 0..Inventory[item]]

That does not work. Any ideas?

You received this message because you are subscribed to the Google Groups "tlaplus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tlaplus+u...@xxxxxxxxxxxxxxxx.
To post to this group, send email to tla...@xxxxxxxxxxxxxxxx.
Visit this group at https://groups.google.com/group/tlaplus.
For more options, visit https://groups.google.com/d/optout.