Concurrent program extraction
Ulrich Berger and Hideki Tsuiki CCC 2017, June 26-30, 2030, Loria, Nancy
1 / 25
Concurrent program extraction Ulrich Berger and Hideki Tsuiki CCC - - PowerPoint PPT Presentation
Concurrent program extraction Ulrich Berger and Hideki Tsuiki CCC 2017, June 26-30, 2030, Loria, Nancy 1 / 25 Question? There are two doors. You know that you can get a treasure from at least one of the doors, but do not know which
1 / 25
◮ There are two doors. ◮ You know that you can get a
◮ If you find a treasure, you can
◮ What shall you do?
2 / 25
◮ Duplicate yourself!
3 / 25
◮ Duplicate yourself! ◮ Search concurrently.
3 / 25
◮ Duplicate yourself! ◮ Search concurrently. ◮ If one of them finds a
3 / 25
◮ Duplicate yourself! ◮ Search concurrently. ◮ If one of them finds a
3 / 25
◮ Duplicate yourself! ◮ Search concurrently. ◮ If one of them finds a
3 / 25
4 / 25
4 / 25
◮ Amb: McCarthy’s nondeterministic bottom-avoiding choice operator. ◮ Amb x y =
◮ Here, ⊥ means that computation does not terminate. ◮ It returns x when y = ⊥. ◮ It returns y when x = ⊥. ◮ It may return x or y nondeterministically when both x and y are not
◮ Compute x and y in parallel, and return the one obtained first. ◮ We want to extract a program that uses the Amb operator from a
5 / 25
◮ We extend the realizability theory IFP(Intuitionistic Fixed Point Logic)
◮ TCF and Minlog [Schwichtenberg 1991]. ◮ q-realizability of [Tatsuta 1998]
◮ Logic: Extension of first-order predicate logic by least and greatest
◮ Program: Untyped programs. We allow unrestricted recursion and
◮ As the space of programs, consider the Scott domain D defined by a
◮ + : separated sum. ◮ Nil, Left, Right, . . . : constructors. ◮ All the elements except for ⊥ are constructor terms like
Left..., Pair(..., ...), Fun(λd....).
◮ We write Def(b) to express that b is not ⊥. 6 / 25
◮ Formulae are divided into two categories: computational and
◮ For a formula A and c ∈ D, we define the predicate c r A, which
◮ c r A Def
◮ c r (A ∨ B) Def
◮ c r (A → B) Def
◮ From a derivation of a formula A in IFP, one can extract a program
7 / 25
◮ We add a new formula Sn(A) which means that the computational
◮ We consider a new constructor Amb which means the Amb operator
◮ Note: We do not consider a power domain. Amb([d1, . . . , dn]) is a
8 / 25
◮ First candidate (it is not valid):
◮ If B holds, b will produce A. ◮ If C holds, c will produce A. ◮ If B or C holds. ◮ Therefore, by executing b and c in parallel, we obtain A. ◮ However, this reasoning is not valid.
9 / 25
◮
◮ c returns with a treasure.
10 / 25
◮
◮ b returns with a treasure. ◮ ◮ ◮ ◮
11 / 25
◮
◮ b returns with a treasure. ◮ No information about C.
◮ ◮ ◮
11 / 25
◮
◮ b returns with a treasure. ◮ No information about C.
◮ c may return with a
◮ ◮
11 / 25
◮
◮ b returns with a treasure. ◮ No information about C.
◮ c may return with a
◮ However, c may return
◮
11 / 25
◮
◮ b returns with a treasure. ◮ No information about C.
◮ c may return with a
◮ However, c may return
◮ If c returns fast,...
11 / 25
◮
◮ b returns with a treasure. ◮ No information about C.
◮ c may return with a
◮ However, c may return
◮ If c returns fast,...
11 / 25
◮ Sn(A)
◮ a r Sn(A)
Def
= ∃m (1 ≤ m ≤ n ∧ a = Amb([a1, . . . , am])∧ ∃i ≤ m (Def(ai))∧ ∀i ≤ m (Def(ai) → ai r A)) .
◮ A |
◮ a r (A |
| B)
Def
= (B → Def(a)) ∧ (Def(a) → a r A).
◮ (We only consider the case B is nc.)
◮ Bounded non-determinism and restriction:
12 / 25
◮
◮
◮
◮
13 / 25
◮
◮
◮
◮
◮ A |
◮
◮
14 / 25
◮ If B holds, a r A0 ∨ A1 and obviously a r A0 ∨ A1 |
◮ If B does not hold, then a may be anything.
◮ If a does not have the form Left b or Right b, then ⊥ r A0 ∨ A1 |
| B.
◮ if a has the form Left b or Right b, then LeftNil or RightNil realizes
A0 ∨ A1 because A0 and A1 are both true.
15 / 25
◮
◮
16 / 25
◮ A (closed) value is an intro program (i.e., weak head normal form).
◮ We define a bigstep reduction relation M → v between (closed)
◮ A data is a term defined inductively only with Nil, Left, Right, Pair. ◮ The printing relation M =
◮ It is a multi-valued relation. Amb[bot, 1, 2] =
◮ We define data(a) for a ∈ D as the set of values obtained by
◮ [Computational Adequacy] For every closed term M,
17 / 25
◮ For any formula A of CFP without restriction(|
◮ A data formula is a formula without implications. ◮ If A is a realizable data formula of CFP, A− is realizable in IFP though
◮ [Program Extraction] From a proof of A in CFP, one can extract a
18 / 25
◮ data D = Nil + Left D + . . . + Amb([D]) is a Haskell datatype. ◮ Our realizers are Haskell programs. ◮ From a proof, we hand-extract a haskell program of type D. ◮ “Value” is a weak head normal form and our bigstep reduction is
◮ “Printing relation” on Amb is implemented in (concurrent) haskell
◮ It uses forkIO (spawn a concurrent process) and MVar (mutable
19 / 25
20 / 25
◮ Gray-code of real number (on the unit interval [-1, 1]) is a
◮ At most one ⊥ is included in each code. ◮ It is equivalent to signed digit. ◮ Let ONEBOT be the set of {0, 1, ⊥}-sequences with at most one ⊥. ◮ SDtoGRAY : {−1, 0, 1}ω → ONEBOT. ◮ GRAYtoSD : ONEBOT → {−1, 0, 1}ω. ◮ SDtoGRAY can be written in Haskell. (Haskell list type contain partial
◮ For GRAYtoSD, we need to read in a one-bottom sequence. ◮ To read a one-bottom sequence, one needs to evaluate two cells in
21 / 25
◮ SD Def
◮ I
Def
◮ C(x) ν
◮ C2(x) ν
◮ D(x) Def
◮ G(x) ν
◮ We proved ∀x(C(x) → G(x)). The extracted program is a Haskell
◮ We proved ∀x(G(x) → C2(x)). The extracted program produces a
22 / 25
Def
µ
Def
24 / 25
25 / 25