In formal reasoning, in particular in
mathematical logic
Mathematical logic is the study of formal logic within mathematics. Major subareas include model theory, proof theory, set theory, and recursion theory. Research in mathematical logic commonly addresses the mathematical properties of formal ...
,
computer algebra
In mathematics and computer science, computer algebra, also called symbolic computation or algebraic computation, is a scientific area that refers to the study and development of algorithms and software for manipulating mathematical expression ...
, and
automated theorem proving
Automated theorem proving (also known as ATP or automated deduction) is a subfield of automated reasoning and mathematical logic dealing with proving mathematical theorems by computer programs. Automated reasoning over mathematical proof was ...
, a fresh variable is a variable that did not occur in the context considered so far.
The concept is often used without explanation.
Fresh variables may be used to replace other variables, to eliminate
variable shadowing
In computer programming, variable shadowing occurs when a variable declared within a certain scope (decision block, method, or inner class) has the same name as a variable declared in an outer scope. At the level of identifiers (names, rather than ...
or capture. For instance, in
alpha-conversion, the processing of terms in the
lambda calculus
Lambda calculus (also written as ''λ''-calculus) is a formal system in mathematical logic for expressing computation based on function abstraction and application using variable binding and substitution. It is a universal model of computation t ...
into equivalent terms with renamed variables, replacing variables with fresh variables can be helpful as a way to avoid accidentally capturing variables that should be
free
Free may refer to:
Concept
* Freedom, having the ability to do something, without having to obey anyone/anything
* Freethought, a position that beliefs should be formed only on the basis of logic, reason, and empiricism
* Emancipate, to procur ...
. Another use for fresh variables involves the development of
loop invariant
In computer science, a loop invariant is a property of a program loop that is true before (and after) each iteration. It is a logical assertion, sometimes checked within the code by an assertion call. Knowing its invariant(s) is essential in ...
s in
formal program verification, where it is sometimes useful to replace constants by newly introduced fresh variables.
Example
For example, in
term rewriting
In mathematics, computer science, and logic, rewriting covers a wide range of methods of replacing subterms of a formula with other terms. Such methods may be achieved by rewriting systems (also known as rewrite systems, rewrite engines, or red ...
, before applying a rule
to a given term
, each variable in
should be replaced by a fresh one to avoid clashes with variables occurring in
.
Given the rule
:
and the term
:
,
attempting to find a matching substitution of the rule's left-hand side,
, within
will fail, since
cannot match
.
However, if the rule is replaced by a ''fresh copy''
:
before, matching will succeed with the answer substitution
.
Notes
References
{{logic-stub
Rewriting systems
Automated theorem proving
Computer algebra
Variables (mathematics)