ArticleslgStudy

computer science

Janus (reversible computing programming language)

Janus (reversible computing programming language) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Janus (reversible computing programming language) rather than just read about it. In short: Janus is a reversible programming language written at Caltech in 1982. 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.

Key takeaways

  • Janus (reversible computing programming language) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Janus (reversible computing programming language) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Janus (reversible computing programming language) from memory before moving on to harder problems.

Reference excerpt

Janus is a reversible programming language written at Caltech in 1982. 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. A Janus inverter and interpreter is made freely available by the TOPPS research group at DIKU. Another Janus interpreter was implemented in Prolog in 2009. An optimizing compiler has been developed in the RC3 research group. The below summarises the language presented in the 2007 paper. Janus is a structured imperative programming language that operates on a global store without heap allocation and does not support dynamic data structures. As a reversible programming language, Janus performs deterministic computations in both forward and backward directions. An extension of Janus features procedure parameters and local variable declarations (local-delocal). Additionally, other variants of Janus support dynamic data structures such as lists.

Syntax We specify the syntax of Janus using Backus–Naur form. A Janus program is a sequence of one or more variable declarations, followed by a sequence of one or more procedure declarations:

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. A program that does nothing is trivially invertible, and not interesting in practice. A variable declaration defines either a variable or a one-dimensional array:

Note, variable declarations carry no type information. This is because all values (and all constants) in Janus are non-negative 32-bit integers, so all values are between 0 and 232 − 1 = 4294967295. Note however, that the Janus interpreter hosted by TOPPS uses regular two's complement 32-bit integers, so all values there are between −231 = −2147483648 and 231 − 1 = 2147483647. All variables are initialized to the value 0. There are no theoretical bounds to the sizes of arrays, but the said interpreter demands a size of at least 1. A procedure declaration consists of the keyword procedure, followed by a unique procedure identifier and a statement:

The entry point of a Janus program is a procedure named main. If no such procedure exists, the last procedure in the program text is the entry point. 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:

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. (Note, array cell assignment has an expression on both sides of the assignment.) A swap (<x> "<=>" <x>) is trivially reversible. For conditionals to be reversible, we provide both a test (the <e> after "if") and an assertion (the <e> after "fi"). The semantics is that the test must hold before the execution of the then-branch, and the assertion must hold after it. Conversely, the test must not hold before the execution of the else-branch, and the assertion must not hold after it. In the inverted program, the assertion becomes the test, and the test becomes the assertion. (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 <e> after "from") and a test (the <e> after "until"). 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. In the inverted program, the assertion becomes the test, and the test becomes the assertion. An additional <e> after "loop" allows to perform work after the test is evaluated to false. The work should ensure that the assertion is false subsequently. A procedure call executes the statements of a procedure in a forward direction. A procedure uncall executes the statements of a procedure in the backward direction. There are no parameters to procedures, so all variable passing is done by side-effects on the global store. 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. 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, λ v ′ . ⊕ ( v ′ , v ) {\displaystyle \lambda v'.\oplus \left(v',v\right)} is a bijective function, and hence invertible, where ⊕ {\displaystyle \oplus } is a modification operator:

The inverse functions are "-", "+", and "^", respectively. 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.

Semantics The language Janus was initially conceived at Caltech in 1982. Subsequent work formalized the language semantics in the form of natural semantics and the denotational semantics. The semantics of purely reversible programming languages can also be treated reversibly at the meta level.

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 nth Fibonacci number. i is an iterator variable that goes from n to 2. As i is decremented in every iteration, the assumption (i = n) is only true prior to the first iteration. The test is (i = 2) is only true after the last iteration of the loop (assuming n > 2). 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. The inverse of fib is:

procedure fib from i = 2 do i += 1 x1 <=> x2 x1 -= x2 loop until i = n

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Janus (reversible computing programming language)

Start with the simplest possible case. Write down what Janus (reversible computing programming language) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Janus (reversible computing programming language) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Janus (reversible computing programming language) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Janus (reversible computing programming language)

In research
Janus (reversible computing programming language) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Janus (reversible computing programming language) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Janus (reversible computing programming language) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Programming languages, Reversible computing, so understanding it makes those chapters shorter.
In everyday life
Look for Janus (reversible computing programming language) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Janus (reversible computing programming language) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Janus (reversible computing programming language) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Janus (reversible computing programming language) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Janus (reversible computing programming language) in simple terms?

Janus is a reversible programming language written at Caltech in 1982. 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.

Why does Janus (reversible computing programming language) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Janus (reversible computing programming language)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Janus (reversible computing programming language).

Tags

  • Programming languages
  • Reversible computing

Keep exploring