encyclopegia.org

Janus (reversible computing programming language)

Janus is a reversible programming language written at Caltech in 1982.[src] The operational semantics of the language were formally specified, together with a program inverter and an invertible self-interpreter, in 2007 by Tetsuo Yokoyama and Robert Glück.[src] A Janus inverter and interpreter is made freely available by the TOPPS research group at DIKU.[src] Another Janus interpreter was implemented in Prolog in 2009.[src] An optimizing compiler has been developed in the RC3 research group.[src] The below summarises the language presented in the 2007 paper.[src] Janus is a structured imperative programming language that operates on a global store without heap allocation and does not support dynamic data structures.[src] As a reversible programming language, Janus performs deterministic computations in both forward and backward directions.[src] An extension of Janus features procedure parameters and local variable declarations (local-delocal).[src] Additionally, other variants of Janus support dynamic data structures such as lists.[src]

Janus is a reversible programming language written at Caltech in 1982.[src] The operational semantics of the language were formally specified, together with a program inverter and an invertible self-interpreter, in 2007 by Tetsuo Yokoyama and Robert Glück.[src] A Janus inverter and interpreter is made freely available by the TOPPS research group at DIKU.[src] Another Janus interpreter was implemented in Prolog in 2009.[src] An optimizing compiler has been developed in the RC3 research group.[src] The below summarises the language presented in the 2007 paper.[src] Janus is a structured imperative programming language that operates on a global store without heap allocation and does not support dynamic data structures.[src] As a reversible programming language, Janus performs deterministic computations in both forward and backward directions.[src] An extension of Janus features procedure parameters and local variable declarations (local-delocal).[src] Additionally, other variants of Janus support dynamic data structures such as lists.[src] ::= ::= | "" ::= | "" Note, Janus as specified in the 2007 paper, allows zero or more variables, but a program that starts with an empty store, produces an empty store.[src] A program that does nothing is trivially invertible, and not interesting in practice.[src] A variable declaration defines either a variable or a one-dimensional array: ::= | "[" "]" Note, variable declarations carry no type information.[src] This is because all values (and all constants) in Janus are non-negative 32-bit integers, so all values are between 0 and 2 32 − 1 = 4294967295.[src] Note however, that the Janus interpreter hosted by TOPPS uses regular two's complement 32-bit integers, so all values there are between −2 31 = −2147483648 and 2 31 − 1 = 2147483647.[src] All variables are initialized to the value 0.[src] There are no theoretical bounds to the sizes of arrays, but the said interpreter demands a size of at least 1.[src] A procedure declaration consists of the keyword procedure , followed by a unique procedure identifier and a statement: ::= "procedure" The entry point of a Janus program is a procedure named main .[src] If no such procedure exists, the last procedure in the program text is the entry point.[src] A statement is either an assignment, a swap, an if-then-else, a loop, a procedure call, a procedure uncall, a skip, or a sequence of statements: := "=" | "[" "]" "=" | " " | "if" "then" "else" "fi" | "from" "do" "loop" "until" | "call" | "uncall" | "skip" | For assignments to be reversible, it is demanded that the variable on the left-hand side does not appear in the expressions on either side of the assignment.[src] (Note, array cell assignment has an expression on both sides of the assignment.) A swap ( " " ) is trivially reversible.[src] For conditionals to be reversible, we provide both a test (the after "if" ) and an assertion (the after "fi" ).[src] The semantics is that the test must hold before the execution of the then-branch, and the assertion must hold after it.[src] Conversely, the test must not hold before the execution of the else-branch, and the assertion must not hold after it.[src] In the inverted program, the assertion becomes the test, and the test becomes the assertion.[src] (Since all values in Janus are integers, the usual C-semantics that 0 indicates false are employed.) For loops to be reversible, we similarly provide an assertion (the after "from" ) and a test (the after "until" ).[src] The semantics is that the assertion must hold only on entry to the loop, and the test must hold only on exit from the loop.[src] In the inverted program, the assertion becomes the test, and the test becomes the assertion.[src] An additional after "loop" allows to perform work after the test is evaluated to false.[src] The work should ensure that the assertion is false subsequently.[src] A procedure call executes the statements of a procedure in a forward direction.[src] A procedure uncall executes the statements of a procedure in the backward direction.[src] There are no parameters to procedures, so all variable passing is done by side-effects on the global store.[src] An expression is a constant (integer), a variable, an indexed variable, or an application of a binary operation: ::= | | "[" "]" | The constants in Janus (and the Janus interpreter hosted by TOPPS) have already been discussed above.[src] A binary operator is one of the following, having semantics similar to their C counterparts: ::= "+" | "-" | "^" | "*" | "/" | "%" | "&" | "|" | "&&" | "||" | ">" | " =" The modification operators are a subset of the binary operators such that for all v, \lambda v'.\oplus\left(v',v\right) is a bijective function, and hence invertible, where \oplus is a modification operator: ::= "+" | "-" | "^" The inverse functions are "-" , "+" , and "^" , respectively.[src] The restriction that the variable assigned to does not appear in an expression on either side of the assignment allows us to prove that the inference system of Janus is forward and backward deterministic.[src] ==Example== We write a Janus procedure fib to find the n-th Fibonacci number, for n>2, i=n, x1=1, and x2=1: procedure fib from i = n do x1 += x2 x1 x2 i -= 1 until i = 2 Upon termination, x1 is the (n−1)-th Fibonacci number and x2 is the n th Fibonacci number.[src] i is an iterator variable that goes from to 2.[src] As i is decremented in every iteration, the assumption ( i = n ) is only true prior to the first iteration.[src] The test is ( i = 2 ) is only true after the last iteration of the loop (assuming > 2).[src] Assuming the following prelude to the procedure, we end up with the 4th Fibonacci number in x2 : i n x1 x2 procedure main n += 4 i += n x1 += 1 x2 += 1 call fib Note, our main would have to do a bit more work if we were to make it handle n≤2, especially negative integers.[src] The inverse of fib is: procedure fib from i = 2 do i += 1 x1 x2 x1 -= x2 loop until i = n As you can see, Janus programs can be transformed by local inversion, where the loop test and assertion are swapped, the order of statements is reversed, and every statement in the loop is itself reversed.[src] The inverse program can be used to find when is the (n-1) th and is the n th Fibonacci number.[src] ==References==[src]

54 sentences · 54 cited inline · 0 references stored

References

No reference rows published for this article.

Cite this article

MLA

"Janus (reversible computing programming language)." encyclopegia.org, 2026, https://encyclopegia.org/wiki/janus-reversible-computing-programming-language. Accessed 26 November 2026.

Chicago

"Janus (reversible computing programming language)." encyclopegia.org. Accessed November 26, 2026. https://encyclopegia.org/wiki/janus-reversible-computing-programming-language.

APA

encyclopegia.org. (2026). Janus (reversible computing programming language). Retrieved November 26, 2026, from https://encyclopegia.org/wiki/janus-reversible-computing-programming-language

Accessed November 26, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Air-Gapped Computing

article · references available

Janus Cornarius

stub · references available

Association for Computing Machinery

stub · references available

IEEE Transactions on Mobile Computing

stub · references available

16-bit computing

stub · references available

Janus

stub · references available

ACM Computing Classification System

stub · references available

Temple of Janus

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1369582644 · 0.5 · snapshot enwiki-001369582644

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.