In the formal languages used in mathematical logic and computer science, a **well-formed formula** or simply **formula**^{[2]} (often abbreviated **wff**, pronounced "wiff" or "wuff") is an idea, abstraction or concept which is expressed using the symbols and formation rules (also called the formal grammar) of a particular formal language. To say that a string of symbols is a wff with respect to a given formal grammar is equivalent to saying that belongs to the language generated by . A formal language can be identified with the set of its wffs.

Although the term "well-formed formula" is commonly used to refer to the written marks, for instance, on a piece of paper or chalkboard which are being used to express an idea; it is more precisely understood as the idea being expressed and the marks as a token instance of the well formed formula. Two different strings of marks may be tokens of the same well-formed formula. This is to say that there may be many different formulations of the same the idea.

There are also well-formed formulas for which there are no tokens. Formal languages may have an infinite number of well-formed formula, regardless of whether there actually exist any token instances of them.

The set of well-formed formulas of a particular formal language is determined by a fiat of its creator, who simply lays down what things are to be wffs of his language. Usually this is done by specifying a set of symbols, and a set of formation rules.

A key use of wffs is in propositional logic and predicate logics such as first-order logic. In those contexts, a formula is a string of symbols φ for which it makes sense to ask "is φ true?", once any free variables in φ have been instantiated.

In formal logic, proofs can be represented by sequences of wffs with certain properties, and the final wff in the sequence is what is proven. This final wff is called a theorem when it plays a significant role in the theory being developed, or a lemma when it plays an accessory role in the proof of a theorem.

The well-formed formulae of the propositional calculus are recursively defined as follows:

- Each propositional variable is, on its own, a formula.
- If φ is a formula, then is a formula.
- If φ and ψ are formulas, and • is any binary connective, then ( φ • ψ) is a formula. Here • could be ∨, ∧, →, or ↔.

This definition can also be written as a formal grammar in Backus–Naur form:

- <alpha set> ::= p | q | r | s | t | u | ... (arbitrary finite set of propositional variables)
- <wff> ::= <alpha set> | <wff> | (<wff><wff>) | (<wff><wff>) | (<wff><wff>) | (<wff><wff>)

Using this grammar, the sequence of symbols

- (((
*p**q*) (*r**s*)) (*q**s*))

is a WFF because it is grammatically correct. The sequence of symbols

- ((
*p**q*)(*qq*))*p*))

is not a WFF, because it does not conform to the grammar of .

Note that sometimes WFF may become very hard to read, owing to, for example, the proliferation of parentheses. To alleviate this last phenomenon, precedence rules are assumed among the operators, making some operators more binding than others. For example, assuming the precedence (from most binding to least binding) 1. 2. 3. 4. , the above correct expression may be written as:

*p**q**r**s**q**s*

This is, however, only a convention used to simplify the written representation of a WFF (commonly used in programming languages).

The definition of a formula in first-order logic is relative to the signature of the theory at hand. This signature specifies the constant symbols, relation symbols, and function symbols of the theory at hand, along with the arities of the function and relation symbols.

The definition of a formula comes in several parts. First, the set of **terms** is defined recursively. Terms, informally, are expressions that represent objects from the domain of discourse.

- Any variable is a term.
- Any constant symbol from the signature is a term
- an expression of the form
*f*(*t*_{1},...,*t*_{n}), where*f*is an*n*-ary function symbol, and*t*_{1},...,*t*_{n}are terms, is again a term.

The next step is to define the atomic formulas.

- If
*t*_{1}and*t*_{2}are terms then*t*_{1}=*t*_{2}is an atomic formula - If
*R*is an*n*-ary relation symbol, and*t*_{1},...,*t*_{n}are terms, then*R*(*t*_{1},...,*t*_{n}) is an atomic formula

Finally, the set of WFFs is defined to be the smallest set containing the set of atomic WFFs such that the following holds:

- is a WFF when is a WFF
- and are WFFs when and are WFFs;
- is a WFF when
*x*is a variable and is a WFF; - is a WFF when is a variable and is a WFF (alternatively, could be defined as an abbreviation for ).

If a formula has no occurrences of or , for any variable , then it is called *quantifier-free*. An *existential formula* is a string of existential quantification followed by a quantifier-free formula.

*WFF* is part of an esoteric pun used in the name of "WFF 'N PROOF: The Game of Modern Logic," by Layman Allen^{[3]}, developed while he was at Yale Law School (he was later a professor at the University of Michigan). The suite of games is designed to teach the principles of symbolic logic to children (in Polish notation)^{[4]}. Its name is a pun on *whiffenpoof*, a nonsense word used as a cheer at Yale University made popular in *The Whiffenpoof Song* and The Whiffenpoofs^{[5]}.