Skip to content

Commit b13376d

Browse files
committed
Update examples (proofnets)
1 parent cb5364e commit b13376d

File tree

6 files changed

+143
-119
lines changed

6 files changed

+143
-119
lines changed

examples/mll.sg

Lines changed: 0 additions & 61 deletions
This file was deleted.

examples/proofnets/fomll.sg

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
(use-macros "../milkyway/prelude.sg")
2+
3+
''' ======================================================== '''
4+
''' FIRST-ORDER MULTIPLICATIVE LINEAR LOGIC PROOF-STRUCTURES '''
5+
''' ======================================================== '''
6+
' FOMLL proof-structures are MLL proof-structures
7+
' (cf. examples/proofnets/mll.sg) which contain only cut and axiom
8+
' constructors.
9+
'
10+
' An axiom between vertices x and y becomes the binary postive star
11+
[+x +y]
12+
'
13+
' A cut between vertices y and z becomes the binary negative star
14+
' which will link two axioms
15+
[-y -z]
16+
17+
''' ======================================================== '''
18+
''' FOR EXAMPLE '''
19+
''' ======================================================== '''
20+
' MLL proof-structures with only cuts and axioms yield partitions
21+
' corresponding to axiom links with links between natural numbers.
22+
'
23+
' ax ax ax
24+
' __ __ __
25+
' / \ / \ / \
26+
' 1 2 3 4 5 6
27+
' \ \____/__/
28+
' \ cut/
29+
' \____/
30+
' cut
31+
'
32+
' becomes
33+
'
34+
' [1, 2] [3, 4] [5, 6]
35+
' \ \______/____/
36+
' \________/
37+
'
38+
' corresponding to the constellation
39+
(:= x {
40+
[+1 +2] [+3 +4] [+5 +6]
41+
[-1 -4] [-2 -5]
42+
})
43+
' which evaluates into
44+
'
45+
' [1, 6] [3, 4]
46+
' \ /
47+
' \________/
48+
'
49+
' then
50+
51+
' [3, 6]
52+
'
53+
' This corresponds to the following execution in stellogen
54+
' in which [-3 +3] is a way to initiate a starting point in computation
55+
(:= comp (exec #x @[-3 +3]))
56+
(:= res { [+3 +6] })
57+
(== #comp #res)
58+
59+
60+
''' ======================================================== '''
61+
''' SUCCESSFUL TYPING '''
62+
''' ======================================================== '''
63+
' We want to check that we have a proof of identity
64+
' (A ⊗ B) -o (A ⊗ B)
65+
' with the following constellation (two axioms)
66+
(:= proof? { [+1 +3] [+2 +4]})
67+
68+
' We do it in two steps.
69+
' 1. checking the structure of the candidate
70+
' 2. checking that the duality of variables is coherent
71+
72+
' Specification with tests returning [ok] when interacting
73+
' with a constellation having the shape of a proof of
74+
' (_ ⊗ _) -o (_ ⊗ _)
75+
(spec (-o (⊗ A B) (⊗ C D)) {
76+
[+testrl [
77+
[-A -B +(⊗ A B)]
78+
[-C] [-D +(⅋ C D)]
79+
[-(⊗ A B) +concl] [-(⅋ C D)]
80+
@[-concl ok]]]
81+
[+testrr [
82+
[-A -B +(⊗ A B)]
83+
[-C] [-D +(⅋ C D)]
84+
[-(⊗ A B)] [+concl -(⅋ C D)]
85+
@[-concl ok]]]
86+
[+testll [
87+
[-A -B +(⊗ A B)]
88+
[-D] [-C +(⅋ C D)]
89+
[-(⊗ A B) +concl] [-(⅋ C D)]
90+
@[-concl ok]]]
91+
[+testlr [
92+
[-A -B +(⊗ A B)]
93+
[-D] [-C +(⅋ C D)]
94+
[-(⊗ A B)] [+concl -(⅋ C D)]
95+
@[-concl ok]]]})
96+
97+
' Check if proof? satisfies the test-based specification
98+
'(:: proof? (-o (⊗ 1 2) (⊗ 3 4))
99+
100+
' Check if duality is coherent
101+
' TODO
102+
103+
''' ======================================================== '''
104+
''' FAILING TYPING '''
105+
''' ======================================================== '''
106+
107+
(spec (⊗ A B) {
108+
[-A -B +(⊗ A B)]
109+
@[-(⊗ A B) ok]
110+
})
111+
112+
' To avoid unecessary infinite loop,
113+
' we use a linear type assertion
114+
(macro (::lin Tested Test) (== @(fire #Tested #Test) ok))
115+
116+
(:= proof? [+1 +2])
117+
' (::lin proof? (⊗ 1 2)) ' does not typecheck
118+
119+
''' ======================================================== '''
120+
''' COMPRESSED TESTS '''
121+
''' ======================================================== '''
122+
' Actually, have internal connections which could be compressed
123+
' by pre-executing them, thus avoiding unecessary computation.
124+
' The two specifications above become:
125+
126+
(spec (comp-o (⊗ A B) (⊗ C D)) {
127+
[+testrl [
128+
[-A -B +concl] [-C] [-D]
129+
@[-concl ok]]]
130+
[+testrr [
131+
[-A -B] [-C] [-D +concl]
132+
@[-concl ok]]]
133+
[+testll [
134+
[-A -B +concl] [-D] [-C]
135+
@[-concl ok]]]
136+
[+testlr [
137+
[-A -B] [-D] [-C +concl]
138+
@[-concl ok]]]})
139+
140+
(spec (⊗ A B) @[-A -B ok])
File renamed without changes.

examples/smll.sg

Lines changed: 0 additions & 56 deletions
This file was deleted.

test/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
(glob_files ./syntax/*.sg)
66
(glob_files ./errors/*.sg)
77
(glob_files ../examples/*.sg)
8+
(glob_files ../examples/proofnets/*.sg)
89
(glob_files ../examples/milkyway/*.sg)
910
(glob_files ../exercises/solutions/*.sg)
1011
(package stellogen)))

test/examples.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ Linear lambda example:
3333
{}
3434

3535
MALL (multiplicative-additive linear logic) example:
36-
$ sgen run ../examples/mall.sg
36+
$ sgen run ../examples/proofnets/mall.sg
3737
{ [(-3 (%cons r (%cons l X4))) (-3 (%cons r (%cons r X4))) || (slice c b)] [(c X11) (d X11) || (slice c a)] }
3838

3939
MLL (multiplicative linear logic) example:
40-
$ sgen run ../examples/mll.sg
40+
$ sgen run ../examples/proofnets/mll.sg
4141
{}
4242

4343
Natural numbers example:

0 commit comments

Comments
 (0)