Skip to content

Commit 4b5a4cc

Browse files
authored
Merge pull request #405 from crlf0710/book-and-readme
Copy chalk related content from rustc-dev-guide to chalk-book.
2 parents 27a9850 + 6e5af0a commit 4b5a4cc

21 files changed

+3329
-207
lines changed

GLOSSARY.md

Lines changed: 1 addition & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -1,203 +1,3 @@
11
# Glossary
2-
This is a glossary of terminology (possibly) used in the chalk crate.
32

4-
## Binary connective
5-
There are sixteen logical connectives on two boolean variables. The most
6-
interesting in this context are listed below. There is also a truth table given
7-
which encodes the possible results of the operations like this
8-
9-
```
10-
f(false, false) f(false, true) f(true, false) f(true, true).
11-
```
12-
13-
As a shorthand the resulting truth table is encoded with `true = 1` and `false =
14-
0`.
15-
16-
| Truth table | Operator symbol | Common name |
17-
|-------------|-----------------|----------------------------------|
18-
| 0001 | && | Conjunction; and |
19-
| 1001 | <=> | Equivalence; if and only if; iff |
20-
| 1101 | => | Implication; if ... then |
21-
22-
## Binder
23-
A binder is an expression that binds a literal to a certain expression.
24-
Examples for binders:
25-
26-
- The universal quantifier `forall(a)` states that a certain condition holds for
27-
all allowed values for `a`.
28-
- A function definition `f(x) = a * x` is a binder for the variable `x` whereas
29-
`a` is a free variable.
30-
- A sum `\sum_n x_n` binds the index variable `n`.
31-
32-
## Canonical Form
33-
A formula in canonical form has the property that its DeBruijn indices are
34-
minimized. For example when the formula `forall<0, 1> { 0: A && 1: B }` is
35-
processed, both "branches" `0: A` and `1: B` are processed individually. The
36-
first branch would be in canonical form, the second branch not since the
37-
occurring DeBruijn index `1` could be replaced with `0`.
38-
39-
## Clause
40-
In the A clause is the disjunction of several expressions. For example the clause
41-
`condition_1 || condition_2 || ...` states that at least one of the conditions
42-
holds.
43-
44-
There are two notable special cases of clauses. A *Horn clause* has at most one
45-
positive literal. A *Definite clause* has exactly one positive literal.
46-
47-
*Horn clauses* can be written in the form `A || !B || !C || ...` with `A` being
48-
the optional positive literal. Due to the equivalence `(P => Q) <=> (!P || Q)`
49-
the clause can be expressed as `B && C && ... => A` which means that A is true
50-
if `B`, `C`, etc. are all true. All rules in chalk are in this form. For example
51-
52-
```
53-
struct A<T> {}
54-
impl<T> B for A<T> where T: C + D {}
55-
```
56-
57-
is expressed as the *Horn clause* `(T: C) && (T: D) => (A<T>: B)`. This formula
58-
has to hold for all values of `T`. The second example
59-
60-
```
61-
struct A {}
62-
impl B for A {}
63-
impl C for A {}
64-
```
65-
66-
is expressed as the *Horn clause* `(A: B) && (A: C)`. Note the missing
67-
consequence.
68-
69-
## DeBruijn Index
70-
DeBruijn indices numerate literals that are bound in an unambiguous way. The
71-
literal is given the number of its binder. The indices start at zero from the
72-
innermost binder increasing from the inside out.
73-
74-
Given the example `forall<T> { exists<U> { T: Foo<Item=U> } }` the
75-
literal names `U` and `T` are replaced with `0` and `1` respectively and the names are erased from the binders: `forall<_>
76-
{ exists<_> { 1: Foo<Item=0> } }`.
77-
78-
## Formula
79-
A formula is a logical expression consisting of literals and constants connected
80-
by logical operators.
81-
82-
## Goal
83-
With a set of type variables, given types, traits and impls, a goal specifies a
84-
problem which is solved by finding types for the type variables that satisfy the
85-
formula. For example the goal `exists<T> { T: u32 }` can be solved with `T =
86-
u32`.
87-
88-
## Literal
89-
A literal is an atomic element of a formula together with the constants `true`
90-
and `false`. It is equivalent to a variable in an algebraic expressions. Note
91-
that literals are *not* the same as the type variables used in specifying a
92-
goal.
93-
94-
## Normal form
95-
To say that a statement is in a certain *normal form* means that the pattern in
96-
which the subformulas are arranged fulfil certain rules. The individual patterns
97-
have different advantages for their manipulation.
98-
99-
### Conjunctive normal form (CNF)
100-
A formula in CNF is a conjunction of disjunctions. For example `(x1 || x2 ||
101-
x3) && (x4 || x5 || x6)` is in CNF.
102-
103-
### Disjunctive normal form (DNF)
104-
A formula in DNF is a disjunction of conjunctions. For example `(x1 && x2 &&
105-
x3) || (x4 && x5 && x6)` is in DNF.
106-
107-
### Negation normal form (NNF)
108-
A formula in NNF consists only of literals, the connectives `&&` and `||` and
109-
`true` and `false`.
110-
111-
### Prenex normal form (PNF)
112-
All quantifiers are on the highest level of a formula and do not occur inside
113-
the subformulas of the expression.
114-
115-
- `forall(x). exists(y). forall(z). P(x) && P(y) => P(z)` is in PNF.
116-
- `(exists(x). P(x)) => exists(y). P(y) && forall(z). P(z)` is *not* in PNF.
117-
118-
## Normalization
119-
Normalization is the process of converting an associated type to a concrete
120-
type. In the case of an iterator this would mean that the associated `Item` type
121-
is replaced with something more meaningful with respect to the individual
122-
context (e.g. `u32`).
123-
124-
## Projection
125-
Projection is the reference to a field or (in the context of Rust) to a type
126-
from another type.
127-
128-
## Satisfiability
129-
A formula is satisfiable iff there is a valuation for the atoms inside the
130-
formula that makes it true.
131-
132-
## Unification
133-
Unification is the process of solving a formula. That means unification finds
134-
values for all the free literals of the formula that satisfy it. In the context
135-
of chalk the values refer to types.
136-
137-
## Universe
138-
A universe sets the scope in which a particular variable name is bound. (See
139-
*Binder*.) A universe can encapsulate other universes. A universe can
140-
be contained by only one parent universe. Universes have therefore a tree-like
141-
structure. A universe can access the variable names of itself and the parent
142-
universes but not of the sibling universes.
143-
144-
## Well-formed
145-
A formula is well-formed if it is constructed according to a predefined set of
146-
syntactic rules.
147-
148-
In the context of the Rust type system this means that basic rules for type
149-
construction have to be met. Two examples: 1) Given a struct definition
150-
151-
```rust
152-
struct HashSet<T: Hash>
153-
```
154-
then a type `HashSet<i32>` is well-formed since `i32` implements `Hash`. A type
155-
`HashSet<NoHash>` with a type `NoHash` that does not implement the `Hash` trait
156-
is not well-formed.
157-
158-
2) If a trait demands by its definition the implementation of further traits
159-
for a certain type then these secondary traits have to be implemented as well.
160-
If a type `Foo` implements `trait Eq: PartialEq` then this type has to implement
161-
`trait PartialEq` as well. If it does not, then the type `Foo: Eq` is not well
162-
formed according to Rust type building rules.
163-
164-
## Quantifier
165-
166-
### Existential quantifier
167-
A formula with the existential quantifier `exists(x). P(x)` is satisfiable if
168-
and only if there exists at least one value for all possible values of x which
169-
satisfies the subformula `P(x)`.
170-
171-
In the context of chalk, the existential quantifier usually demands the
172-
existence of exactly one instance (i.e. type) that satisfies the formula (i.e.
173-
type constraints). More than one instance means that the result is ambiguous.
174-
175-
### Universal quantifier
176-
A formula with the universal quantifier `forall(x). P(x)` is satisfiable
177-
if and only if the subformula `P(x)` is true for all possible values for x.
178-
179-
### Helpful equivalences
180-
- `not(forall(x). P(x)) <=> exists(x). not(P(x))`
181-
- `not(exists(x). P(x)) <=> forall(x). not(P(x))`
182-
183-
## Skolemization
184-
Skolemization is a technique of transferring a logical formula with existential
185-
quantifiers to a statement without them. The resulting statement is in general
186-
not equivalent to the original statement but equisatisfiable.
187-
188-
## Validity
189-
An argument (*premise* therefore *conclusion*) is valid iff there is no
190-
valuation which makes the premise true and the conclusion false.
191-
192-
Valid: `A && B therefore A || B`. Invalid: `A || B therefore A && B` because the
193-
valuation `A = true, B = false` makes the premise true and the conclusion false.
194-
195-
## Valuation
196-
A valuation is an assignment of values to all variables inside a logical
197-
formula.
198-
199-
# Literature
200-
- Offline
201-
- "Introduction to Formal Logic", Peter Smith
202-
- "Handbook of Practical Logic and Automated Reasoning", John Harrison
203-
- "Types and Programming Languages", Benjamin C. Pierce
3+
Please see [Appendix A: Glossary and terminology](`http://rust-lang.github.io/chalk/book/glossary.html`) in Chalk book.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[![Build Status](https://github.com/rust-lang/chalk/workflows/CI/badge.svg)](https://github.com/rust-lang/chalk/actions?workflow=CI)
2+
[![Chalk Book](https://img.shields.io/badge/book-chalk-blue.svg)](https://rust-lang.github.io/chalk/book/)
3+
[![Rust Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://rust-lang.github.io/chalk/chalk/)
24

35
# chalk
46

book/src/SUMMARY.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,21 @@
1414
- [Fold and the Folder trait](./types/operations/fold.md)
1515
- [Representing traits, impls, and other parts of Rust programs](./rust_ir.md)
1616
- [Lowering Rust IR to logic](./clauses.md)
17-
- [Unification and type equality](./clauses/type_equality.md)
17+
- [Goals and clauses](./clauses/goals_and_clauses.md)
18+
- [Type equality and unification](./clauses/type_equality.md)
19+
- [Implied bounds](./clauses/implied_bounds.md)
20+
- [Lowering rules](./clauses/lowering_rules.md)
21+
- [Well-formedness checking](./clauses/wf.md)
22+
- [Canonical queries](./canonical_queries.md)
23+
- [Canonicalization](./canonical_queries/canonicalization.md)
1824
- [How does the engine work](./engine.md)
1925
- [Major concepts](./engine/major_concepts.md)
2026
- [Logic](./engine/logic.md)
2127
- [Coinduction](./engine/logic/coinduction.md)
22-
- [Glossary and terminology](./glossary.md)
28+
- [SLG Solver](./engine/slg.md)
29+
30+
---
31+
32+
[Appendix A: Glossary and terminology](./glossary.md)
33+
[Appendix B: Bibliography](./bibliography.md)
34+
[Appendix C: Incomplete chapters](./todo.md)

book/src/bibliography.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Bibliography
2+
3+
If you'd like to read more background material, here are some
4+
recommended texts and papers:
5+
6+
## Blog Posts
7+
8+
* [Lowering Rust traits to logic](http://smallcultfollowing.com/babysteps/blog/2017/01/26/lowering-rust-traits-to-logic/)
9+
* [Unification in Chalk, part 1](http://smallcultfollowing.com/babysteps/blog/2017/03/25/unification-in-chalk-part-1/)
10+
* [Unification in Chalk, part 2](http://smallcultfollowing.com/babysteps/blog/2017/04/23/unification-in-chalk-part-2/)
11+
* [Negative reasoning in Chalk](https://aturon.github.io/blog/2017/04/24/negative-chalk/)
12+
* [Query structure in chalk](http://smallcultfollowing.com/babysteps/blog/2017/05/25/query-structure-in-chalk/)
13+
* [Cyclic queries in chalk](http://smallcultfollowing.com/babysteps/blog/2017/09/12/tabling-handling-cyclic-queries-in-chalk/)
14+
* [An on-demand SLG solver for chalk](http://smallcultfollowing.com/babysteps/blog/2018/01/31/an-on-demand-slg-solver-for-chalk/)
15+
16+
## Papers
17+
18+
<a name="pphhf"></a>
19+
20+
["A proof procedure for the logic of Hereditary Harrop formulas"][pphhf],
21+
by Gopalan Nadathur. This paper covers the basics of universes,
22+
environments, and Lambda Prolog-style proof search. Quite readable.
23+
24+
[pphhf]: https://dl.acm.org/citation.cfm?id=868380
25+
26+
<a name="slg"></a>
27+
28+
["A new formulation of tabled resolution with delay"][nftrd], by
29+
Theresa Swift. This paper gives a kind of abstract treatment of the
30+
SLG formulation that is the basis for our on-demand solver.
31+
32+
[nftrd]: https://dl.acm.org/citation.cfm?id=651202
33+
34+
35+
## Books
36+
* "Introduction to Formal Logic", Peter Smith
37+
* "Handbook of Practical Logic and Automated Reasoning", John Harrison
38+
* "Types and Programming Languages", Benjamin C. Pierce
39+
* [Programming with Higher-order Logic][phl], by Dale Miller and Gopalan
40+
Nadathur, covers the key concepts of Lambda prolog. Although it's a
41+
slim little volume, it's the kind of book where you learn something
42+
new every time you open it.
43+
44+
[phl]: https://www.amazon.com/Programming-Higher-Order-Logic-Dale-Miller/dp/052187940X
45+

0 commit comments

Comments
 (0)