Shadowing
The later and the inner hide the earlier and the outer
One rule
When Formall has to choose among several visible things that fit, it takes the nearest: a later one hides an earlier one in the same block, and one in an inner block hides one in an outer block. It is the rule of local variables in programming languages, and it is the same for names, for the facts a proof substitutes, and for the facts a call finds for the conditions of a theorem.
The order of the search is fixed: the current block from its end, then the enclosing block from its end, and so on outward to the top level of the file and the modules it imports. A label given explicitly comes before all of them.
Names
An inner for hides an atom of the same name declared outside (Atoms):
An inner atom hides an outer one
Facts in prove
Without a label, <e> takes the first statement with left side e in the search order. Other statements about e are not an error: in a proof by contradiction the hypothesis X -> false of the inner if stands beside the outer fact X -> true, and the hypothesis is the one meant.
The nearest fact
In the full code the outer if carries the label X1.
Conditions of a call
A theorem's if conditions are patterns; a call matches them against the visible statements to infer the arguments not given (calls). When the conditions can be met in several ways, each way uses one statement per condition, and one way shadows another when each of its statements is the same or nearer, at least one nearer. The ways nobody shadows must give the same result. Two conditions may take the same statement, and the names of the theorem's parameters play no part:
Each condition takes its nearest fact
Unique is an axiom of a lock here only to keep the example short; a uniqueness theorem is applied the same way.
When neither way shadows the other — one is nearer in one condition and farther in another — the call stops and shows both. Here P := A uses the earlier ⇔(A, B) -> ✔ and the later A -> ✔; P := C the other way round:
Neither choice shadows the other
A fact label or an argument such as P := A settles it.
Expected error: Ambiguous arguments of the call
In other systems
Lean's assumption takes the latest matching hypothesis of the local context, and Isabelle's assumption tries the premises in turn; for one condition this is the same rule. Formall extends it to several conditions at once without preferring any of them, so an ambiguity that depends on the order of conditions is reported instead of being decided silently.