NLA-lib Explorer

Worked instance: a loop with early exit, ended by its test and by its cap

Library · Source module

Worked instance: a loop with early exit, ended by its test and by its cap

The tree NLAlib.Ops.Examples.countdown moves a counter from one cell to another, one unit in each round, for at most five rounds, testing before each round whether the counter is zero. It is run on natural-number words from the counters 2 (the test ends the loop) and 7 (the cap ends it). The two runs fix what a loop with early exit is charged, and in particular the convention at the exit (docs/design/Ops-ReferenceReview.md): leaving the loop is charged the address of the operand of the test once, whether or not a test is made there.

The runs are evaluated: the final memory and the whole count are computed by the evaluator and transferred to the execution rules (NLAlib.Ops.Reference.execution_iff_exec). The count is stated as the list of instructions in the order of execution.

Expected, from scripts/worked_instances.py (EarlyExit):

* from 2: the cells (0, 2), 2 decrements, 2 increments and 3 tests; * from 7: the cells (2, 5), 5 decrements, 5 increments and 5 tests.

The operand resolutions (11 and 26) follow the convention above: one for each test made, four in each round, and one more at the cap, where no test is made. They and the totals of 37 and 81 instructions are regression values.

Main definitions

* NLAlib.Ops.Examples.WorkedInstances.EarlyExit.stopTrace, NLAlib.Ops.Examples.WorkedInstances.EarlyExit.capTrace: the instructions of the two runs. * NLAlib.Ops.Examples.WorkedInstances.EarlyExit.tallies: decrements, increments, tests, operand resolutions and total of a count.

Main results

* NLAlib.Ops.Examples.WorkedInstances.EarlyExit.stop_run, NLAlib.Ops.Examples.WorkedInstances.EarlyExit.cap_run: the two runs.

Declarations