| 1 | {{{ |
| 2 | A rough set of examples (using the refined 'chr-based' algorithm) |
| 3 | |
| 4 | |
| 5 | Assuming a normal form of equations, it is sufficient to apply |
| 6 | the following 'FD'-rule step. |
| 7 | |
| 8 | e1: F t1 = t2 |
| 9 | |
| 10 | e2: F t1 = t3 |
| 11 | |
| 12 | ==> |
| 13 | |
| 14 | e1: F t1 = t2 |
| 15 | e2: F t1 = t3 |
| 16 | e3: t2 = t3 |
| 17 | |
| 18 | where e3 = (sym e1) trans e2 |
| 19 | |
| 20 | |
| 21 | Here are some examples: |
| 22 | |
| 23 | EXAMPLE 1 |
| 24 | |
| 25 | Assume (given) |
| 26 | |
| 27 | g : forall a. S [a] = [S a] -- axiom |
| 28 | |
| 29 | d1 : T Int = Int -- local equations |
| 30 | d2 : T [Int] = S [Int] |
| 31 | d3 : T Int = S Int |
| 32 | |
| 33 | |
| 34 | wanted |
| 35 | |
| 36 | ? : T [Int] = [Int] |
| 37 | |
| 38 | |
| 39 | Step 1: Normalize (local and wanted) equations |
| 40 | (also applies to axioms but we skip this step here) |
| 41 | |
| 42 | g : forall a. S [a] = [S a] (0) |
| 43 | |
| 44 | |
| 45 | g1 : T Int = Int (1) |
| 46 | g2 : T [Int] = a (2) |
| 47 | g3 : S [Int] = a (3) |
| 48 | g4 : T Int = b (4) |
| 49 | g5 : S Int = b (5) |
| 50 | |
| 51 | |
| 52 | ? : T [Int] = [Int] (6) |
| 53 | |
| 54 | Reduction steps: |
| 55 | |
| 56 | |
| 57 | 2+6 => ?' : a = [Int] |
| 58 | |
| 59 | ? = g2 trans ?' |
| 60 | |
| 61 | 03 from 0+3 => |
| 62 | g03 : a = [S Int] |
| 63 | g03 = (sym g3) trans (g Int) |
| 64 | |
| 65 | 503 from 5+03 => |
| 66 | g503 : a = [b] |
| 67 | g503 = g03 trans ([] g5) |
| 68 | |
| 69 | 14 from 1+4 => |
| 70 | g14 : b = Int |
| 71 | g14 = (sym g4) trans g1 |
| 72 | |
| 73 | Apply 14 on 503 => |
| 74 | g' : a = [Int] |
| 75 | g' = g503 trans ([] g14) |
| 76 | |
| 77 | We found a match for the (reduced) wanted constraint. |
| 78 | |
| 79 | ? = g2 trans ?' |
| 80 | = g2 trans (g503 trans ([] g14)) |
| 81 | = g2 trans ((g03 trans ([] g5)) trans ([] g14)) |
| 82 | = g2 trans ((((sym g3) trans (g Int)) trans ([] g5)) trans ([] g14)) |
| 83 | |
| 84 | How to map back to the original (given) local equations? |
| 85 | |
| 86 | |
| 87 | The same calculation using the original (given) local equations. |
| 88 | |
| 89 | g : forall a. S [a] = [S a] (0) -- axiom |
| 90 | |
| 91 | d1 : T Int = Int (1) -- local equations |
| 92 | d2 : T [Int] = S [Int] (2) |
| 93 | d3 : T Int = S Int (3) |
| 94 | |
| 95 | wanted: |
| 96 | d4 : T [Int] = [Int] (4) |
| 97 | |
| 98 | Reduction steps: |
| 99 | |
| 100 | 24: 2+4 => |
| 101 | d24 : S [Int] = [Int] |
| 102 | d4 = d2 trans d24 -- wanted, we're interested how to construct d4! |
| 103 | |
| 104 | 024: 0+24 => |
| 105 | d024 : [S Int] = [Int] |
| 106 | d24 = (sym (g Int)) trans d024 |
| 107 | |
| 108 | deompose => |
| 109 | d024' : S Int = Int |
| 110 | d024 = [] d024' |
| 111 | |
| 112 | 13 : 1+3 => |
| 113 | d13 : S Int = Int |
| 114 | d13 = (sym d3) trans d1 |
| 115 | |
| 116 | |
| 117 | We found a match for the (reduced) wanted constraint. |
| 118 | |
| 119 | d024' = d13 |
| 120 | = (sym d3) trans d1 |
| 121 | |
| 122 | Thus, |
| 123 | |
| 124 | d4 = d2 trans d24 |
| 125 | = d2 trans ((sym (g Int)) trans d024) |
| 126 | = d2 trans ((sym (g Int)) trans ([] d024')) |
| 127 | = d2 trans ((sym (g Int)) trans ([] ((sym d3) trans d1))) |
| 128 | |
| 129 | |
| 130 | Compare the normalized result |
| 131 | |
| 132 | g2 trans ((((sym g3) trans (g Int)) trans ([] g5)) trans ([] g14)) |
| 133 | |
| 134 | against the 'unnormalized' result |
| 135 | |
| 136 | d2 trans ((sym (g Int)) trans ([] ((sym d3) trans d1))) |
| 137 | |
| 138 | |
| 139 | EXAMPLE 2 |
| 140 | |
| 141 | no axioms involved |
| 142 | |
| 143 | given: |
| 144 | d1 : G Int = Bool |
| 145 | d2 : F (G Int) = Int |
| 146 | |
| 147 | wanted: |
| 148 | |
| 149 | d : F Bool = Int |
| 150 | |
| 151 | clearly d = (sym (F d1)) trans d2 |
| 152 | |
| 153 | |
| 154 | The normalized case: |
| 155 | |
| 156 | g1 : G Int = Bool (1) |
| 157 | g2 : G Int = a (2) |
| 158 | g3 : F a = Int (3) |
| 159 | |
| 160 | Reductions: |
| 161 | |
| 162 | 12 from 1 + 2 => |
| 163 | g12 : a = Bool |
| 164 | g12 = (sym g2) trans g1 |
| 165 | |
| 166 | apply 12 on g3: |
| 167 | |
| 168 | g3' : F Bool = Int |
| 169 | g3' = (sym (F g12)) trans g3 |
| 170 | |
| 171 | Match found, we find |
| 172 | |
| 173 | d = (sym (F g12)) trans g3 |
| 174 | = (sym (F ((sym g2) trans g1))) trans g3 |
| 175 | |
| 176 | compare with |
| 177 | |
| 178 | (sym (F d1)) trans d2 |
| 179 | }}} |