0

Let me just say that this is for a university project. I do not expect an answer but more of a "hint".

I have a schema of a Supermarket that holds a sequence of queues:

+-- Supermarket-------
|queues: seq Queue
----------------------

And here is how I've defined a queue:

+-- Queue ----------
|length: ℕ
--------------------

I wish to define a schema that returns the total number of customers, waiting in line. Thus far I have:

+--TotalQueueCustomers----
|Ξsupermarket: Supermarket
|totalCustomers!: ℕ
|-------------------------
|totalCustomers = total θ supermarket
--------------------------

I'm struggling with defining the total function. It needs to "loop" every customer in every queue and sum their lengths. Here is what I have so far: total = q: Queue ⦁ q.length ↦ q.length

Any idea?

tdranv
  • 1,140
  • 11
  • 38

1 Answers1

0

You can define the function inductively by having a base case (no queues) and specifying how an additional queue is computed:

total: seq Queue → ℕ
---
total(∅) = 0
∀ q: Queue; qs: seq Queue ⦁ total( <q> ^ qs ) = q.length + total(qs)

<q> is the sequence having a single element q, a ^ b denotes the sequence concatenation operator (Section 4.5 of the Z reference manual).

(Please note: I did not check this example with a Z type checker, so it probably contains some kind of syntax error - but the idea should be clear)

danielp
  • 1,179
  • 11
  • 26