|
10 | 10 | \forall T, \ T \leq \top \quad \text{and} \quad \forall T, \ \bot \leq T |
11 | 11 | $$ |
12 | 12 |
|
| 13 | +## The Subsumption Rule |
| 14 | + |
| 15 | +In a type system with subtyping, a type \( A \) can be considered a **subtype** of another type \( B \) if \( A \) satisfies all the constraints and properties of \( B \), and possibly some additional ones. The subsumption rule formalizes this idea by allowing expressions of a more specific type to be treated as expressions of a more general type. |
| 16 | + |
| 17 | +The subsumption rule can be expressed as: |
| 18 | + |
| 19 | +\[ |
| 20 | +\frac{A \leq B \quad \Gamma \vdash e : A}{\Gamma \vdash e : B} |
| 21 | +\] |
| 22 | + |
| 23 | +This means that if we have an expression \( e \) of type \( A \), and we know that \( A \) is a subtype of \( B \) (denoted \( A \leq B \)), then we can treat \( e \) as an expression of type \( B \) without any further checks. |
| 24 | + |
13 | 25 | ## Basic Subtype Relationships |
14 | 26 |
|
15 | 27 | ### Reflexivity of Subtyping |
@@ -239,138 +251,107 @@ For example: |
239 | 251 |
|
240 | 252 |
|
241 | 253 |
|
| 254 | +## Subtyping for Recursive Type |
242 | 255 |
|
243 | | - |
244 | | - |
| 256 | +$$ |
| 257 | +\frac{ |
| 258 | +\Gamma \vdash T : \mathcal{U} \quad \Gamma, x : T \vdash \sigma \leq T |
| 259 | +}{ |
| 260 | +\Gamma \vdash \mu (x : T) . \sigma \leq T |
| 261 | +} |
| 262 | +$$ |
245 | 263 |
|
246 | 264 |
|
247 | 265 |
|
248 | 266 | ## Dependent Types |
249 | 267 |
|
250 | 268 | Dependent types extend the expressive power of type systems by allowing types to depend on values or other types. Algebraic subtyping supports dependent types, incorporating union and intersection constructs to define relationships between dependent types effectively. |
251 | 269 |
|
252 | | -### Intersection of Dependent \( \Pi \)-Types |
| 270 | +### Subtyping Relationships |
253 | 271 |
|
254 | | -#### Type Formation Rule for Intersection of Dependent \( \Pi \)-Types |
| 272 | +#### Dependent $\Pi$-Type |
255 | 273 |
|
256 | | -Dependent \( \Pi \)-types are function-like types where the codomain depends on the specific value of the domain. For the intersection of such types: |
| 274 | +The dependent $\Pi$-type rule for subtyping is given by: |
257 | 275 |
|
258 | 276 | $$ |
259 | 277 | \frac{ |
260 | | -\Gamma \vdash A_1 : \mathcal{U} \quad \Gamma \vdash A_2 : \mathcal{U} \quad \Gamma, x:A_1 \vdash B_1(x) : \mathcal{U} \quad \Gamma, x:A_2 \vdash B_2(x) : \mathcal{U} |
| 278 | +\Gamma \vdash A_2 \leq A_1 \quad \Gamma, x:A_1 \vdash B_1(x) \quad \Gamma, x:A_2 \vdash B_1(x) \leq B_2(x) |
261 | 279 | }{ |
262 | | -\Gamma \vdash \Pi(x:A_1). B_1(x) \cap \Pi(x:A_2). B_2(x) : \mathcal{U} |
| 280 | +\Gamma \vdash \Pi(x:A_1). B_1(x) \leq \Pi(x:A_2). B_2(x) |
263 | 281 | } |
264 | 282 | $$ |
265 | 283 |
|
266 | | -Refinement ensures that \( x \) must be in both \( A_1 \) and \( A_2 \), producing: |
| 284 | +#### Dependent $\Sigma$-Type |
| 285 | + |
| 286 | +The dependent $\Sigma$-type rule for subtyping is given by: |
267 | 287 |
|
268 | 288 | $$ |
269 | 289 | \frac{ |
270 | | -\Gamma \vdash A = A_1 \cap A_2 : \mathcal{U} \quad \Gamma, x:A \vdash B(x) = B_1(x) \cap B_2(x) : \mathcal{U} |
| 290 | +\Gamma \vdash A_1 \leq A_2 \quad \Gamma, x:A_1 \vdash B_1(x) \leq B_2(x) |
271 | 291 | }{ |
272 | | -\Gamma \vdash \Pi(x:A). B(x) : \mathcal{U} |
| 292 | +\Gamma \vdash \Sigma(x:A_1). B_1(x) \leq \Sigma(x:A_2). B_2(x) |
273 | 293 | } |
274 | 294 | $$ |
275 | 295 |
|
276 | | -#### Subtyping Rule for Intersection of Dependent \( \Pi \)-Types |
| 296 | +### Intersection of Dependent \( \Pi \)-Types |
| 297 | + |
| 298 | +#### Type Formation Rule for Intersection of Dependent \( \Pi \)-Types |
277 | 299 |
|
278 | | -Subtyping for dependent \( \Pi \)-types follows: |
| 300 | +Dependent \( \Pi \)-types are function-like types where the codomain depends on the specific value of the domain. For the intersection of such types: |
279 | 301 |
|
280 | 302 | $$ |
281 | 303 | \frac{ |
282 | | -\Gamma \vdash A_2 \leq A_1 \quad \Gamma \vdash B_1(x) \leq B_2(x) \quad \Gamma \vdash B_2(x) \leq B_1(x) |
| 304 | +\Gamma \vdash A_1 : \mathcal{U} \quad \Gamma \vdash A_2 : \mathcal{U} \quad \Gamma, x:A_1 \vdash B_1(x) : \mathcal{U} \quad \Gamma, x:A_2 \vdash B_2(x) : \mathcal{U} |
283 | 305 | }{ |
284 | | -\Gamma \vdash \Pi(x : A_1). B_1(x) \cap \Pi(x : A_2). B_2(x) \leq \Pi(x : A_2). B_2(x) |
| 306 | +\Gamma \vdash \Pi(x:A_1). B_1(x) \cap \Pi(x:A_2). B_2(x) : \mathcal{U} |
285 | 307 | } |
286 | 308 | $$ |
287 | 309 |
|
288 | | -### Union of Dependent \( \Pi \)-Types |
289 | | - |
290 | | -#### Type Formation Rule for Union of Dependent \( \Pi \)-Types |
291 | | - |
292 | | -For unions of dependent \( \Pi \)-types, a sum type representation is used: |
293 | | - |
294 | | -$$ |
295 | | -\Pi(x : A_1). B_1(x) \cup \Pi(x : A_2). B_2(x) \equiv \text{inl}(\Pi(x : A_1). B_1(x)) \cup \text{inr}(\Pi(x : A_2). B_2(x)) |
296 | | -$$ |
297 | | - |
298 | | -Where \( \text{inl} \) and \( \text{inr} \) represent injections into the left and right components. |
299 | | - |
300 | | -#### Typing Rule |
301 | | - |
302 | | -A term \( f \) of either constituent type satisfies: |
| 310 | +Refinement ensures that \( x \) must be in both \( A_1 \) and \( A_2 \), producing: |
303 | 311 |
|
304 | 312 | $$ |
305 | 313 | \frac{ |
306 | | -\Gamma \vdash f : \Pi(x : A_1). B_1(x) |
307 | | -}{ |
308 | | -\Gamma \vdash f : \Pi(x : A_1). B_1(x) \cup \Pi(x : A_2). B_2(x) |
309 | | -} |
310 | | -\quad \text{or} \quad |
311 | | -\frac{ |
312 | | -\Gamma \vdash f : \Pi(x : A_2). B_2(x) |
| 314 | +\Gamma \vdash A = A_1 \cap A_2 : \mathcal{U} \quad \Gamma, x:A \vdash B(x) = B_1(x) \cap B_2(x) : \mathcal{U} |
313 | 315 | }{ |
314 | | -\Gamma \vdash f : \Pi(x : A_1). B_1(x) \cup \Pi(x : A_2). B_2(x) |
| 316 | +\Gamma \vdash \Pi(x:A). B(x) : \mathcal{U} |
315 | 317 | } |
316 | 318 | $$ |
317 | 319 |
|
318 | | -#### Subtyping Rule for Union of Dependent \( \Pi \)-Types |
| 320 | +#### Type Formation Rule for Intersection of Dependent \( \Sigma \)-Types |
319 | 321 |
|
320 | | -Subtyping ensures inclusion and equivalence between unions and their constituents: |
| 322 | +Dependent \( \Sigma \)-types represent dependent pairs, where the type of the second component depends on the value of the first. The intersection of such types is defined as: |
321 | 323 |
|
322 | 324 | $$ |
323 | 325 | \frac{ |
324 | | -\Gamma \vdash \Pi(x : A_1). B_1(x) \leq \Pi(x : A_1). B_1(x) \cup \Pi(x : A_2). B_2(x) |
| 326 | +\Gamma \vdash A_1 : \mathcal{U} \quad \Gamma \vdash A_2 : \mathcal{U} \quad \Gamma, x:A_1 \vdash B_1(x) : \mathcal{U} \quad \Gamma, x:A_2 \vdash B_2(x) : \mathcal{U} |
325 | 327 | }{ |
326 | | -\Gamma \vdash \Pi(x : A_1). B_1(x) \cup \Pi(x : A_2). B_2(x) \leq \Pi(x : A_1). B_1(x) |
| 328 | +\Gamma \vdash \Sigma(x:A_1). B_1(x) \cap \Sigma(x:A_2). B_2(x) : \mathcal{U} |
327 | 329 | } |
328 | 330 | $$ |
329 | 331 |
|
330 | | -A similar rule applies for the second component of the union. |
331 | | - |
332 | | -### Intersection of Dependent \( \Sigma \)-Types |
333 | | - |
334 | | -#### Type Formation Rule for Intersection of Dependent \( \Sigma \)-Types |
335 | | - |
336 | | -For dependent \( \Sigma \)-types, intersections represent the set of pairs satisfying constraints for both components: |
337 | | - |
338 | | -$$ |
339 | | -\Sigma(x : A_1). B_1(x) \cap \Sigma(x : A_2). B_2(x) \equiv \Sigma(x : A_1 \cap A_2). (B_1(x) \cap B_2(x)) |
340 | | -$$ |
| 332 | +### Union of Dependent \( \Pi \)-Types |
341 | 333 |
|
342 | | -#### Subtyping Rule for Intersection of Dependent \( \Sigma \)-Types |
| 334 | +#### Type Formation Rule for Union of Dependent \( \Pi \)-Types |
343 | 335 |
|
344 | | -The subtyping rule for intersected \( \Sigma \)-types is: |
| 336 | +The union of dependent \( \Pi \)-types combines the domains and codomains of the respective types: |
345 | 337 |
|
346 | 338 | $$ |
347 | 339 | \frac{ |
348 | | -\Gamma \vdash A_2 \leq A_1 \quad \Gamma \vdash B_1(x) \leq B_2(x) \quad \Gamma \vdash B_2(x) \leq B_1(x) |
| 340 | +\Gamma \vdash A_1 : \mathcal{U} \quad \Gamma \vdash A_2 : \mathcal{U} \quad \Gamma, x:A_1 \vdash B_1(x) : \mathcal{U} \quad \Gamma, x:A_2 \vdash B_2(x) : \mathcal{U} |
349 | 341 | }{ |
350 | | -\Gamma \vdash \Sigma(x : A_1). B_1(x) \cap \Sigma(x : A_2). B_2(x) \leq \Sigma(x : A_2). B_2(x) |
| 342 | +\Gamma \vdash \Pi(x:A_1). B_1(x) \cup \Pi(x:A_2). B_2(x) : \mathcal{U} |
351 | 343 | } |
352 | 344 | $$ |
353 | 345 |
|
354 | | -### Union of Dependent \( \Sigma \)-Types |
355 | | - |
356 | 346 | #### Type Formation Rule for Union of Dependent \( \Sigma \)-Types |
357 | 347 |
|
358 | | -Unions of dependent \( \Sigma \)-types follow a sum-type structure: |
359 | | - |
360 | | -$$ |
361 | | -\Sigma(x : A_1). B_1(x) \cup \Sigma(x : A_2). B_2(x) \equiv \text{inl}(\Sigma(x : A_1). B_1(x)) \cup \text{inr}(\Sigma(x : A_2). B_2(x)) |
362 | | -$$ |
363 | | - |
364 | | -Here, \( \text{inl} \) and \( \text{inr} \) designate the left and right components. |
365 | | - |
366 | | -#### Typing Rule |
367 | | - |
368 | | -Subtyping for unions of \( \Sigma \)-types maintains compatibility: |
| 348 | +The union of dependent \( \Sigma \)-types combines the types of the first and second components: |
369 | 349 |
|
370 | 350 | $$ |
371 | 351 | \frac{ |
372 | | -\Gamma \vdash (a, b) : \Sigma(x : A_1). B_1(x) |
| 352 | +\Gamma \vdash A_1 : \mathcal{U} \quad \Gamma \vdash A_2 : \mathcal{U} \quad \Gamma, x:A_1 \vdash B_1(x) : \mathcal{U} \quad \Gamma, x:A_2 \vdash B_2(x) : \mathcal{U} |
373 | 353 | }{ |
374 | | -\Gamma \vdash (a, b) : \Sigma(x : A_1). B_1(x) \cup \Sigma(x : A_2). B_2(x) |
| 354 | +\Gamma \vdash \Sigma(x:A_1). B_1(x) \cup \Sigma(x:A_2). B_2(x) : \mathcal{U} |
375 | 355 | } |
376 | 356 | $$ |
| 357 | + |
0 commit comments