<s>
Janus	B-Application
is	O
a	O
time-reversible	B-Application
programming	O
language	O
written	O
at	O
Caltech	O
in	O
1982	O
.	O
</s>
<s>
A	O
Janus	B-Application
inverter	O
and	O
interpreter	O
is	O
made	O
freely	O
available	O
by	O
the	O
TOPPS	O
research	O
group	O
at	O
DIKU	O
.	O
</s>
<s>
Another	O
Janus	B-Application
interpreter	O
was	O
implemented	O
in	O
Prolog	B-Language
in	O
2009	O
.	O
</s>
<s>
Janus	B-Application
is	O
an	O
imperative	B-Application
programming	I-Application
language	I-Application
with	O
a	O
global	O
store	O
(	O
there	O
is	O
no	O
stack	O
or	O
heap	O
allocation	O
)	O
.	O
</s>
<s>
Janus	B-Application
is	O
a	O
reversible	B-Application
programming	I-Application
language	I-Application
,	O
i.e.	O
</s>
<s>
We	O
specify	O
the	O
syntax	O
of	O
Janus	B-Application
using	O
Backus	O
–	O
Naur	O
form	O
.	O
</s>
<s>
A	O
Janus	B-Application
program	O
is	O
a	O
sequence	O
of	O
one	O
or	O
more	O
variable	O
declarations	O
,	O
followed	O
by	O
a	O
sequence	O
of	O
one	O
or	O
more	O
procedure	O
declarations	O
:	O
</s>
<s>
Note	O
,	O
Janus	B-Application
as	O
specified	O
in	O
the	O
2007	O
paper	O
,	O
allows	O
zero	O
or	O
more	O
variables	O
,	O
but	O
a	O
program	O
that	O
starts	O
with	O
an	O
empty	O
store	O
,	O
produces	O
an	O
empty	O
store	O
.	O
</s>
<s>
This	O
is	O
because	O
all	O
values	O
(	O
and	O
all	O
constants	O
)	O
in	O
Janus	B-Application
are	O
non-negative	O
32-bit	O
integers	O
,	O
so	O
all	O
values	O
are	O
between	O
0	O
and	O
232	O
−	O
1	O
=	O
4294967295	O
.	O
</s>
<s>
Note	O
however	O
,	O
that	O
the	O
Janus	B-Application
interpreter	O
hosted	O
by	O
TOPPS	O
uses	O
regular	O
two	B-General_Concept
's	I-General_Concept
complement	I-General_Concept
32-bit	O
integers	O
,	O
so	O
all	O
values	O
there	O
are	O
between	O
−231	O
=	O
−2147483648	O
and	O
231	O
−	O
1	O
=	O
2147483647	O
.	O
</s>
<s>
The	O
entry	O
point	O
of	O
a	O
Janus	B-Application
program	O
is	O
a	O
procedure	O
named	O
main	O
.	O
</s>
<s>
For	O
assignments	O
to	O
be	O
reversible	B-Application
,	O
it	O
is	O
demanded	O
that	O
the	O
variable	O
on	O
the	O
left-hand	O
side	O
does	O
not	O
appear	O
in	O
the	O
expressions	O
on	O
either	O
side	O
of	O
the	O
assignment	O
.	O
</s>
<s>
A	O
swap	O
(	O
<x> "<=>" <x>	O
)	O
is	O
trivially	O
reversible	B-Application
.	O
</s>
<s>
For	O
conditionals	O
to	O
be	O
reversible	B-Application
,	O
we	O
provide	O
both	O
a	O
test	O
(	O
the	O
<e> after "if" )  and an assertion (the <e>	O
after	O
"	O
fi	O
"	O
)	O
.	O
</s>
<s>
(	O
Since	O
all	O
values	O
in	O
Janus	B-Application
are	O
integers	O
,	O
the	O
usual	O
C-semantics	O
that	O
0	O
indicates	O
false	O
are	O
employed	O
.	O
)	O
</s>
<s>
For	O
loops	O
to	O
be	O
reversible	B-Application
,	O
we	O
similarly	O
provide	O
an	O
assertion	O
(	O
the	O
<e> after "from" )  and a test (the <e>	O
after	O
"	O
until	O
"	O
)	O
.	O
</s>
<s>
The	O
constants	O
in	O
Janus	B-Application
(	O
and	O
the	O
Janus	B-Application
interpreter	O
hosted	O
by	O
TOPPS	O
)	O
have	O
already	O
been	O
discussed	O
above	O
.	O
</s>
<s>
The	O
restriction	O
that	O
the	O
variable	O
assigned	O
to	O
does	O
not	O
appear	O
in	O
an	O
expression	O
on	O
either	O
side	O
of	O
the	O
assignment	O
allows	O
us	O
to	O
prove	O
that	O
the	O
inference	O
system	O
of	O
Janus	B-Application
is	O
forward	O
and	O
backward	O
deterministic	O
.	O
</s>
<s>
We	O
write	O
a	O
Janus	B-Application
procedure	O
fib	O
to	O
find	O
the	O
n-th	O
Fibonacci	B-Algorithm
number	I-Algorithm
,	O
for	O
n>2	O
,	O
i	O
=	O
n	O
,	O
x1	O
=	O
1	O
,	O
and	O
x2	O
=	O
1	O
:	O
</s>
<s>
Upon	O
termination	O
,	O
x1	O
is	O
the	O
(	O
n−1	O
)	O
-th	O
Fibonacci	B-Algorithm
number	I-Algorithm
and	O
x2	O
is	O
the	O
nth	O
Fibonacci	B-Algorithm
number	I-Algorithm
.	O
</s>
<s>
Assuming	O
the	O
following	O
prelude	O
to	O
the	O
procedure	O
,	O
we	O
end	O
up	O
with	O
the	O
4th	O
Fibonacci	B-Algorithm
number	I-Algorithm
in	O
x2	O
:	O
</s>
<s>
As	O
you	O
can	O
see	O
,	O
Janus	B-Application
performs	O
local	O
inversion	O
,	O
where	O
the	O
loop	O
test	O
and	O
assertion	O
are	O
swapped	O
,	O
the	O
order	O
of	O
statements	O
is	O
reversed	O
,	O
and	O
every	O
statement	O
in	O
the	O
loop	O
is	O
itself	O
reversed	O
.	O
</s>
<s>
The	O
reverse	O
program	O
can	O
be	O
used	O
to	O
find	O
n	O
when	O
x1	O
is	O
the	O
(	O
n-1	O
)	O
th	O
and	O
x2	O
is	O
the	O
nth	O
Fibonacci	B-Algorithm
number	I-Algorithm
.	O
</s>
