|  | 
|  | 1 | +(use-macros "../milkyway/prelude.sg") | 
|  | 2 | + | 
|  | 3 | +''' ============================================ ''' | 
|  | 4 | +''' MULTIPLICATIVE LINEAR LOGIC PROOF-STRUCTURES ''' | 
|  | 5 | +''' ============================================ ''' | 
|  | 6 | +' MLL proof-structures is a representation of mathematical proofs | 
|  | 7 | +' for an elementary fragment of logic dealing with the most | 
|  | 8 | +' elementary mechanisms of logical implication. | 
|  | 9 | +' | 
|  | 10 | +' They are graphs with natural numbers as vertices which are linked | 
|  | 11 | +' by the following constructors: | 
|  | 12 | +' | 
|  | 13 | +'     ax | 
|  | 14 | +'     __     (axiom)                 (cut) | 
|  | 15 | +'    /  \                    \__/ | 
|  | 16 | +'                             cut | 
|  | 17 | +' | 
|  | 18 | +' | 
|  | 19 | +'     \ /                    \ / | 
|  | 20 | +'      ⊗     (tensor)         ⅋      (par) | 
|  | 21 | +'      |                      | | 
|  | 22 | +' | 
|  | 23 | +' | 
|  | 24 | +' Proof-structures can be executed by a graph-contraction | 
|  | 25 | +' procedure called "cut-elimination" using two rules: | 
|  | 26 | +' | 
|  | 27 | +'     ax | 
|  | 28 | +'     __   2 | 
|  | 29 | +'    /  \__/       ~~ax/cut~~>   1 | 
|  | 30 | +'    1   cut | 
|  | 31 | +' | 
|  | 32 | +'    contracting two vertices | 
|  | 33 | +' | 
|  | 34 | +'    1 2    3  4               1 2    3  4 | 
|  | 35 | +'    \ /     \ /               | |    |  | | 
|  | 36 | +'     ⅋       ⊗    ~~⅋/⊗~~>    \ \____/__/ | 
|  | 37 | +'      \_____/                  \    / cut | 
|  | 38 | +'        cut                     \__/ | 
|  | 39 | +'                                cut | 
|  | 40 | +' | 
|  | 41 | +'   rewiring the connections upward (left input with | 
|  | 42 | +'   left input and right with right). | 
|  | 43 | + | 
|  | 44 | +''' ======================================================== ''' | 
|  | 45 | +''' ENCODING ''' | 
|  | 46 | +''' ======================================================== ''' | 
|  | 47 | +' The idea is that an axiom between a and b will be a | 
|  | 48 | +' binary positive star: | 
|  | 49 | +[(+a X) (+b X)] | 
|  | 50 | + | 
|  | 51 | +' A cut between vertices a and b will be binary negative star: | 
|  | 52 | +[(-a X) (-b X)] | 
|  | 53 | + | 
|  | 54 | +' A proof of (a ⅋ b) coming from a proof v is obtained by turning rays | 
|  | 55 | +(+a X) (+b X) | 
|  | 56 | +' of the constellation corresponding to v into | 
|  | 57 | +(+(⅋ a b) [l|X]) (+(⅋ a b) [r|X]) | 
|  | 58 | + | 
|  | 59 | +' A proof of (a ⅋ b) coming from proofs va and vb is obtained by turning rays | 
|  | 60 | +(+a X) | 
|  | 61 | +' of the constellation corresponding to va into | 
|  | 62 | +(+(⊗ a b) [l|X]) | 
|  | 63 | +' and turning rays | 
|  | 64 | +(+b X) | 
|  | 65 | +' of the constellation corresponding to vb into | 
|  | 66 | +(+(⊗ a b) [r|X]) | 
|  | 67 | + | 
|  | 68 | + | 
|  | 69 | +''' ======================================================== ''' | 
|  | 70 | +''' EXAMPLE ''' | 
|  | 71 | +''' ======================================================== ''' | 
|  | 72 | +' | 
|  | 73 | +'   ax   ax   ax | 
|  | 74 | +'   _    __   __ | 
|  | 75 | +'  / \  /  \ /  \ | 
|  | 76 | +'  1 2  3  4 5  6 | 
|  | 77 | +'  \ /     \ / | 
|  | 78 | +'   ⅋       ⊗ | 
|  | 79 | +'   |_______| | 
|  | 80 | +'      cut | 
|  | 81 | + | 
|  | 82 | +'    becomes | 
|  | 83 | + | 
|  | 84 | +(:= x { | 
|  | 85 | +  [(+(⅋ 1 2) [l|X]) (+(⅋ 1 2) [r|X])] | 
|  | 86 | +  [(+3 X) (+(⊗ 4 5) [l|X])] | 
|  | 87 | +  [(+(⊗ 4 5) [r|X]) (+6 X)] | 
|  | 88 | +  [(-(⅋ 1 2) X) (-(⊗ 4 5) X)] | 
|  | 89 | +}) | 
|  | 90 | + | 
|  | 91 | +' by cut-elimination, it is evaluated into | 
|  | 92 | +' | 
|  | 93 | +'   ax    ax    ax | 
|  | 94 | +'   __    __    __ | 
|  | 95 | +'  /  \  /  \  /  \ | 
|  | 96 | +'  1  2  3  4  5  6 | 
|  | 97 | +'  \   \____/__/ | 
|  | 98 | +'   \   cut/ | 
|  | 99 | +'    \____/ | 
|  | 100 | +'     cut | 
|  | 101 | +' | 
|  | 102 | +'    then | 
|  | 103 | +' | 
|  | 104 | +'   [1, 2]  [3, 4]  [5, 6] | 
|  | 105 | +'    \   \______/____/ | 
|  | 106 | +'     \________/ | 
|  | 107 | +' | 
|  | 108 | +'    then | 
|  | 109 | +' | 
|  | 110 | +'   [1, 6]  [3, 4] | 
|  | 111 | +'    \          / | 
|  | 112 | +'     \________/ | 
|  | 113 | +' | 
|  | 114 | +'    then | 
|  | 115 | +' | 
|  | 116 | +'   [3, 6] | 
|  | 117 | +' | 
|  | 118 | +' This corresponds to the following executio in stellogen | 
|  | 119 | +' in which [] is a way to initiate a starting point in computation | 
|  | 120 | +(:= comp (exec #x @[(-3 X) (+3 X)])) | 
|  | 121 | +(:= res { [(+3 X9) (+6 X9)] }) | 
|  | 122 | +' (== #comp #res) | 
|  | 123 | + | 
|  | 124 | +' as for the proof of identity (A ⊗ B) -o (A ⊗ B): | 
|  | 125 | +' | 
|  | 126 | +'   ax   ax | 
|  | 127 | +'   _    _ | 
|  | 128 | +'  / \  / \ | 
|  | 129 | +'  1 2  3 4 | 
|  | 130 | +'  \ /  \ / | 
|  | 131 | +'   ⅋    ⊗ | 
|  | 132 | +'   |____| | 
|  | 133 | +'     cut | 
|  | 134 | +' | 
|  | 135 | +'   it becomes | 
|  | 136 | +(:= proof? { | 
|  | 137 | +  [(+(⅋ 1 2) [l|X]) (+(⊗ 3 4) [l|X])] | 
|  | 138 | +  [(+(⅋ 1 2) [r|X]) (+(⊗ 3 4) [r|X])] | 
|  | 139 | +}) | 
|  | 140 | + | 
|  | 141 | +' Actually, all rays could have a unique natural number as head symbol and | 
|  | 142 | +' it would still work the same | 
|  | 143 | + | 
|  | 144 | +''' ======================================================== ''' | 
|  | 145 | +''' SUCCESSFUL TYPING ''' | 
|  | 146 | +''' ======================================================== ''' | 
|  | 147 | +' We want to check that we have a proof of identity | 
|  | 148 | +' (A ⊗ B) -o (A ⊗ B) | 
|  | 149 | +' with the previous constellation | 
|  | 150 | +#proof? | 
|  | 151 | + | 
|  | 152 | +' We do it in two steps. | 
|  | 153 | +' 1. checking the structure of the candidate | 
|  | 154 | +' 2. checking that the duality of variables is coherent | 
|  | 155 | + | 
|  | 156 | +' Specification with tests returning [ok] when interacting | 
|  | 157 | +' with a constellation having the shape of a proof of | 
|  | 158 | +' (_ ⊗ _) -o (_ ⊗ _) | 
|  | 159 | +(spec (-o (⊗ A B) (⊗ C D)) { | 
|  | 160 | +  [+testrl [ | 
|  | 161 | +    [-(var A) -(var B) +(⊗ A B)] | 
|  | 162 | +    [-(var C)] [-(var D) +(⅋ C D)] | 
|  | 163 | +    [-(⊗ A B) +concl] [-(⅋ C D)] | 
|  | 164 | +    @[-concl ok]]] | 
|  | 165 | +  [+testrr [ | 
|  | 166 | +    [-(var A) -(var B) +(⊗ A B)] | 
|  | 167 | +    [-(var C)] [-(var D) +(⅋ C D)] | 
|  | 168 | +    [-(⊗ A B)] [+concl -(⅋ C D)] | 
|  | 169 | +    @[-concl ok]]] | 
|  | 170 | +  [+testll [ | 
|  | 171 | +    [-(var A) -(var B) +(⊗ A B)] | 
|  | 172 | +    [-(var D)] [-(var C) +(⅋ C D)] | 
|  | 173 | +    [-(⊗ A B) +concl] [-(⅋ C D)] | 
|  | 174 | +    @[-concl ok]]] | 
|  | 175 | +  [+testlr [ | 
|  | 176 | +    [-(var A) -(var B) +(⊗ A B)] | 
|  | 177 | +    [-(var D)] [-(var C) +(⅋ C D)] | 
|  | 178 | +    [-(⊗ A B)] [+concl -(⅋ C D)] | 
|  | 179 | +    @[-concl ok]]]}) | 
|  | 180 | + | 
|  | 181 | +' Check if proof? satisfies the test-based specification | 
|  | 182 | +(:= adapters { | 
|  | 183 | +  [(-(⅋ 1 2) [l|X]) +(var 1)] | 
|  | 184 | +  [(-(⅋ 1 2) [r|X]) +(var 2)] | 
|  | 185 | +  [(-(⊗ 3 4) [l|X]) +(var 3)] | 
|  | 186 | +  [(-(⊗ 3 4) [r|X]) +(var 4)] | 
|  | 187 | +}) | 
|  | 188 | +(:= proof?+adapters (exec @#proof? #adapters)) | 
|  | 189 | +'(:: proof? (-o (⊗ 1 2) (⊗ 3 4)) | 
|  | 190 | + | 
|  | 191 | +' Check if duality is coherent | 
|  | 192 | +' TODO | 
|  | 193 | + | 
|  | 194 | +''' ======================================================== ''' | 
|  | 195 | +''' FAILING TYPING ''' | 
|  | 196 | +''' ======================================================== ''' | 
|  | 197 | + | 
|  | 198 | +(spec (⊗ A B) { | 
|  | 199 | +  [-(var A) -(var B) +(⊗ A B)] | 
|  | 200 | +  @[-(⊗ A B) ok] | 
|  | 201 | +}) | 
|  | 202 | + | 
|  | 203 | +' To avoid unecessary infinite loop, | 
|  | 204 | +' we use a linear type assertion | 
|  | 205 | +(macro (::lin Tested Test) (== @(fire #Tested #Test) ok)) | 
|  | 206 | + | 
|  | 207 | +(:= proof? [(+1 X) (+2 X)]) | 
|  | 208 | +(:= adapters { [(-1 X) +(var 1)] [(-2 X) +(var 2)] }) | 
|  | 209 | +(:= proof?+adapters (exec @#proof? #adapters)) | 
|  | 210 | +'(::lin proof?+adapters (⊗ 1 2)) ' does not typecheck | 
|  | 211 | + | 
|  | 212 | +''' ======================================================== ''' | 
|  | 213 | +''' COMPRESSED TESTS ''' | 
|  | 214 | +''' ======================================================== ''' | 
|  | 215 | +' Actually, constellations corresponding to proofs | 
|  | 216 | +' have internal connections which could be compressed | 
|  | 217 | +' by pre-executing them, thus avoiding unecessary computation. | 
|  | 218 | +' The two specifications above become: | 
|  | 219 | + | 
|  | 220 | +(spec (comp-o (⊗ A B) (⊗ C D)) { | 
|  | 221 | +  [+testrl [ | 
|  | 222 | +    [-(var A) -(var B) +concl] [-(var C)] [-(var D)] | 
|  | 223 | +    @[-concl ok]]] | 
|  | 224 | +  [+testrr [ | 
|  | 225 | +    [-(var A) -(var B)] [-(var C)] [-(var D) +concl] | 
|  | 226 | +    @[-concl ok]]] | 
|  | 227 | +  [+testll [ | 
|  | 228 | +    [-(var A) -(var B) +concl] [-(var D)] [-(var C)] | 
|  | 229 | +    @[-concl ok]]] | 
|  | 230 | +  [+testlr [ | 
|  | 231 | +    [-(var A) -(var B)] [-(var D)] [-(var C +concl)] | 
|  | 232 | +    @[-concl ok]]]}) | 
|  | 233 | + | 
|  | 234 | +(spec (⊗ A B) @[-A -B ok]) | 
0 commit comments