Playground Documentation Challenges Full Docs

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 -> (when notation("default", …) is declared) the statement gets the default value of its type: if(P) is if(P -> ✔).
hypothesisLabel
Optional: a label on if holds 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 if command IS the scope where its statements live. A label on if captures its assumptions and is scoped to the if scope.
Creates scope
Yes.
Mechanism
Parses the argument string as a list of statements separated by ;. Each entry follows the format expression -> expression. Left-hand sides that share the right-hand side are separated by commas: if(P, Q -> true; R -> false) is equivalent to if(P -> true; Q -> true; R -> false). All resulting statements are introduced as assumptions inside the if scope.

Basic examples

Inside an if scope, the assumed statements are available:

Basic if usage

▶ Run

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

▶ Run

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

▶ Run

Case Analysis

Use nested if commands for case analysis (proof by cases):

Case analysis

▶ Run

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.

▶ Run

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.

▶ Run

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:

  1. The assumed statement's value is flipped (by the schemas of the enumeration type(bool = false | true), from which the lemma is proved)
  2. The flipped statement becomes proven in the outer scope
  3. The if scope typically immediately closes (as continuing within a contradictory scope is pointless — from a contradiction, anything can be proven)
⚠
The 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.