if
Introducing assumptions and conditional reasoning
Overview
The if command introduces assumptions (hypotheses) that hold within its scope. It's the primary way to work with conditional statements in Formall.
if(expression -> expression) { ... }if(leftExpression1 -> rightExpression1; leftExpression2 -> rightExpression2; ...) { ... }+hypothesisLabel: if(expression -> expression) { ... }if(expression) // with notation("default", ✔): if(expression -> ✔)leftExpression -> rightExpression, …- The assumptions: statements that hold inside the block. Without
->(whennotation("default", …)is declared) the statement gets the default value of its type:if(P)isif(P -> ✔). hypothesisLabel- Optional: a label on
ifholds the assumptions themselves — to name them in hints and as facts of calls. { … }- The block where the assumptions hold. Without braces
if(…)is a header of the next command, or with;a declaration to the end of the enclosing block.
Command Properties
- Group
- Context
- Produces
- Statements (assumptions)
- Delivery & Label
- Into itself — the
ifcommand IS the scope where its statements live. A label onifcaptures its assumptions and is scoped to theifscope. - Creates scope
- Yes.
- Mechanism
- Parses the argument string as a list of statements separated by
;. Each entry follows the formatexpression -> expression. Left-hand sides that share the right-hand side are separated by commas:if(P, Q -> true; R -> false)is equivalent toif(P -> true; Q -> true; R -> false). All resulting statements are introduced as assumptions inside theifscope.
Basic examples
Inside an if scope, the assumed statements are available:
Basic if usage
Details
With notation("default", "true") in scope, a statement without -> means -> true: if(p) is if(p -> true).
Multiple Statements
You can introduce multiple statements at once, separated by ;; a comma joins left-hand sides that share the right-hand side (if(P, Q -> true; R -> false)):
Multiple assumptions
Proof by Contradiction
The most common pattern: assume the opposite, derive a contradiction, and call contradict (the lemma of the library, logic/bool.fl) to flip the assumption:
Proof by contradiction
Case Analysis
Use nested if commands for case analysis (proof by cases):
Case analysis
If without Block
Without braces, if still creates a scope — it just contains only the next command (and its scope):
Chained if
contradict[] only closes the nearest (inner) if. The outer if then simply completes.
Labels and Scope: if Delivers into Itself
Since if delivers its statements into its own scope, a label placed on if captures those assumptions. This label can then be used inside the scope — or passed out to commands that operate at other levels:
Labels on if: scoping and usage
Label A is declared at the if level and captures its assumption. It is accessible inside the block and in nested blocks.
How contradict works with if
contradict[| S] is a call that takes the if it stands in: its lock axiom asks for two values of one expression under the assumption. When it succeeds inside an if scope:
- The assumed statement's value is flipped (by the schemas of the enumeration
type(bool = false | true), from which the lemma is proved) - The flipped statement becomes proven in the outer scope
- The
ifscope typically immediately closes (as continuing within a contradictory scope is pointless — from a contradiction, anything can be proven)
if command must have exactly one statement for contradict to flip it: the axiom of the lemma asks for an if of one condition. Multiple statements in one if cannot be flipped at once.