Library / Notational Engineering DPF
Jump to passage
In this reading

Link to current text

Published source confirmed at last check

Source changed 2026-10-03 11:52:20 UTC · snapshot created 2026-10-03 11:53:41 UTC · last check 2026-10-03 12:25:14 UTC

NOT.2:5.1 - A sum with a local index and an external parameter

A team is designing a compact notation for repeated addition. Its proposed expression is:

sum i=1..2 of i + p

The notation has not specified where the summation body ends. At external parameter p = 10, two readings give different results: (1 + 10) + (2 + 10) = 23, or (1 + 2) + 10 = 13.

Choose a constructor sum(index, lower, upper, body). It introduces the index only within body; bounds use the surrounding context. Choose add(left, right) for addition. These rules express the first reading as:

sum(i, 1, 2, add(i, p))

The occurrence of i in add(i, p) reaches the local index declaration. The occurrence of p has no local declaration and uses the external value 10. Substituting the two index values gives 11 and 12, then 23. The second reading has a different construction:

add(sum(i, 1, 2, i), p)

Its outer operation adds the external parameter once and gives 13. The notation now makes the two operand structures recoverable.

Naming also matters. The expression sum(p, 1, 2, add(p, p)) is a valid expression under the chosen lexical rule, but both occurrences in its body refer to the index. It gives 6 and no longer uses the external parameter. To rename the index while preserving that parameter, choose a name such as j that does not capture it: sum(j, 1, 2, add(j, p)) still gives 23. This example identifies the binding condition; NOT.4 supplies the general transformation method.