Fresh variable

From HandWiki

In formal reasoning, in particular in mathematical logic, computer algebra, and automated theorem proving, a fresh variable is a variable that did not occur in the context considered so far.[1][citation needed] The concept is often used without explanation.[2][citation needed]

Fresh variables may be used to replace other variables, to eliminate variable shadowing or capture. For instance, in alpha-conversion, the processing of terms in the lambda calculus 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.[3] Another use for fresh variables involves the development of loop invariants in formal program verification, where it is sometimes useful to replace constants by newly introduced fresh variables.[4]

Example

For example, in term rewriting, before applying a rule [math]\displaystyle{ l \to r }[/math] to a given term [math]\displaystyle{ t }[/math], each variable in [math]\displaystyle{ l \to r }[/math] should be replaced by a fresh one to avoid clashes with variables occurring in [math]\displaystyle{ t }[/math].[citation needed] Given the rule

[math]\displaystyle{ append(cons(x,y),z) \to cons(x,append(y,z)) }[/math]

and the term

[math]\displaystyle{ append(cons(x,cons(y,nil)),cons(3,nil)) }[/math],

attempting to find a matching substitution of the rule's left-hand side, [math]\displaystyle{ append(cons(x,y),z) }[/math], within [math]\displaystyle{ append(cons(x,cons(y,nil)),cons(3,nil)) }[/math] will fail, since [math]\displaystyle{ y }[/math] cannot match [math]\displaystyle{ cons(y,nil) }[/math]. However, if the rule is replaced by a fresh copy[lower-alpha 1]

[math]\displaystyle{ append(cons(v_1,v_2),v_3) \to cons(v_1,append(v_2,v_3)) }[/math]

before, matching will succeed with the answer substitution [math]\displaystyle{ \{ v_2 \mapsto x, \; v_2 \mapsto cons(y,nil), \; v_3 \mapsto cons(3,nil) \} }[/math].

Notes

  1. that is, a copy with each variable consistently replaced by a fresh variable

References

  1. Carmen Bruni (2018). Predicate Logic: Natural Deduction (Lecture Slides). https://cs.uwaterloo.ca/~cbruni/CS245Resources/lectures/2018_Fall/13_Predicate_Logic_Natural_Deduction_post.pdf.  Here: slide 13/26.
  2. Michael Färber (Feb 2023). Denotational Semantics and a Fast Interpreter for jq (Technical Report).  Here: p.4.
  3. Gordon, Andrew D.; Melham, Thomas F. (1996). "Five axioms of alpha-conversion". in von Wright, Joakim; Grundy, Jim; Harrison, John. Theorem Proving in Higher Order Logics, 9th International Conference, TPHOLs'96, Turku, Finland, August 26-30, 1996, Proceedings. Lecture Notes in Computer Science. 1125. Springer. pp. 173–190. doi:10.1007/BFB0105404. 
  4. Cohen, Edward (1990). "Loops B — On replacing constants by fresh variables". Programming in the 1990s. Monographs in Computer Science. New York: Springer. pp. 149–194. doi:10.1007/978-1-4613-9706-9. ISBN 9781461397069.