SCORE language #
This file defines SCORE, a minimal reversible programming language designed as a reversible adaptation of LOOP. SCORE can be understood as an extension of SRL [Mat03] that operates on variables represented by stacks of integers.
Notations #
[x ↦ v]stands forupdate emp x vwhereempis the emptyStore(set the value ofxtovinemp).σ[x ↦ v]stands forupdate σ x v(set the value ofxtovinσ).
Consecutive updates can be concatenated as σ[x ↦ v₁][x ↦ v₂].
P⁻¹stands forinv P(the inverse program ofP).
Updates a Store by mapping the register identified by x to a new value v.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Updating a variable to its current value produces no change.
Alternative version of update_no_update that considers the structure of the list.
Equations
- SCORE.State.«term⊥» = Lean.ParserDescr.node `SCORE.State.term⊥ 1024 (Lean.ParserDescr.symbol "⊥")
Instances For
A SCORE program is a sequence of commands chosen from skip, extending a stack, decreasing a stack, incrementing the top of a stack, decrementing the top of a stack, composing two commands, and iterating over a finite number of steps.
- SKIP: SCORE.Com
- CON: Ident → SCORE.Com
- NOC: Ident → SCORE.Com
- DEC: Ident → SCORE.Com
- INC: Ident → SCORE.Com
- SEQ: SCORE.Com → SCORE.Com → SCORE.Com
- FOR: Ident → SCORE.Com → SCORE.Com
Instances For
Equations
- SCORE.Com.«term_;;_» = Lean.ParserDescr.trailingNode `SCORE.Com.term_;;_ 80 81 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol ";;") (Lean.ParserDescr.cat `term 80))
Instances For
Computes the string representation of a LOOP command.
Equations
- One or more equations did not get rendered due to their size.
- SCORE.Com.comToString indLv SCORE.Com.SKIP = toString "" ++ toString (SCORE.Com.comToString.ind indLv) ++ toString "SKIP"
- SCORE.Com.comToString indLv (SCORE.Com.CON x) = toString "" ++ toString (SCORE.Com.comToString.ind indLv) ++ toString "CON " ++ toString x ++ toString ""
- SCORE.Com.comToString indLv (SCORE.Com.NOC x) = toString "" ++ toString (SCORE.Com.comToString.ind indLv) ++ toString "NOC " ++ toString x ++ toString ""
- SCORE.Com.comToString indLv (SCORE.Com.DEC x) = toString "" ++ toString (SCORE.Com.comToString.ind indLv) ++ toString "DEC " ++ toString x ++ toString ""
- SCORE.Com.comToString indLv (SCORE.Com.INC x) = toString "" ++ toString (SCORE.Com.comToString.ind indLv) ++ toString "INC " ++ toString x ++ toString ""
- SCORE.Com.comToString indLv (P_2;;Q) = toString "" ++ toString (SCORE.Com.comToString indLv P_2) ++ toString ";\n" ++ toString (SCORE.Com.comToString indLv Q) ++ toString ""
Instances For
Equations
Instances For
Equations
- SCORE.Com.instToString = { toString := SCORE.Com.comToString 0 }
Equations
- SCORE.Com.SKIP⁻¹ = SCORE.Com.SKIP
- (SCORE.Com.CON x)⁻¹ = SCORE.Com.NOC x
- (SCORE.Com.NOC x)⁻¹ = SCORE.Com.CON x
- (SCORE.Com.DEC x)⁻¹ = SCORE.Com.INC x
- (SCORE.Com.INC x)⁻¹ = SCORE.Com.DEC x
- (P_2;;Q)⁻¹ = Q⁻¹;;P_2⁻¹
- (SCORE.Com.FOR x P_2)⁻¹ = SCORE.Com.FOR x P_2⁻¹
Instances For
Equations
- SCORE.«term_⁻¹» = Lean.ParserDescr.trailingNode `SCORE.term_⁻¹ 1024 1024 (Lean.ParserDescr.symbol "⁻¹")
Instances For
Interpreter #
Interpreter for SCORE. The interpreter takes as input a Com and an evaluation State and
outputs the resulting State obtained by applying the command to the initial state.
Equations
- One or more equations did not get rendered due to their size.
- SCORE.eval P none = none
- SCORE.eval SCORE.Com.SKIP (some σ) = some σ
- SCORE.eval (SCORE.Com.CON x) (some σ) = some (σ[x ↦ 0 :: σ x])
- SCORE.eval (SCORE.Com.NOC x) (some σ) = match (σ x).head? with | some 0 => some (σ[x ↦ (σ x).tail]) | x => none
- SCORE.eval (SCORE.Com.DEC x) (some σ) = match (σ x).head? with | some v => some (σ[x ↦ (v - 1) :: (σ x).tail]) | none => none
- SCORE.eval (SCORE.Com.INC x) (some σ) = match (σ x).head? with | some v => some (σ[x ↦ (v + 1) :: (σ x).tail]) | none => none
- SCORE.eval (P_2;;Q) (some σ) = SCORE.eval Q (SCORE.eval P_2 (some σ))