Skip to content

Commit 9503afb

Browse files
committed
add more fields to structures table, remove functors table (WIP)
the fields source, target, left_adjoint are moved to the structures table, which makes the functors table redundant. this might be useful later when adding, say, monoidal functors, where source refers to a monoidal category then. also, it justifies more the existence of the source_assumptions table for general implications. on the other hand, this yields many NULL columns for categories. I am not sure if I should keep it.
1 parent 93d16a4 commit 9503afb

12 files changed

Lines changed: 115 additions & 137 deletions

File tree

databases/catdat/schema/001_structures.sql

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ CREATE TABLE structures (
1313
notation TEXT NOT NULL,
1414
description TEXT,
1515
nlab_link TEXT CHECK (nlab_link IS NULL OR nlab_link like 'https://%'),
16-
dual_structure_id TEXT,
16+
dual_structure_id TEXT, -- e.g. for categories
17+
source TEXT, -- e.g. for functors
18+
target TEXT, -- e.g. for functors
19+
left_adjoint TEXT, -- e.g. for functors
1720
UNIQUE (id, type),
1821
FOREIGN KEY (type) REFERENCES structure_types (type) ON DELETE RESTRICT,
19-
FOREIGN KEY (dual_structure_id, type) REFERENCES structures (id, type) ON DELETE RESTRICT
22+
FOREIGN KEY (dual_structure_id, type) REFERENCES structures (id, type) ON DELETE RESTRICT,
23+
FOREIGN KEY (source) REFERENCES structures (id),
24+
FOREIGN KEY (target) REFERENCES structures (id),
25+
FOREIGN KEY (left_adjoint) REFERENCES structures (id)
2026
);
2127

2228
CREATE UNIQUE INDEX structures_lower_id_unique ON structures (lower(id));
@@ -39,6 +45,4 @@ CREATE TABLE structure_comments (
3945
FOREIGN KEY (structure_id) REFERENCES structures (id) ON DELETE CASCADE
4046
);
4147

42-
CREATE INDEX idx_structure_comments ON structure_comments (structure_id);
43-
44-
48+
CREATE INDEX idx_structure_comments ON structure_comments (structure_id);

databases/catdat/schema/004_categories.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,19 @@ BEGIN
1414
(SELECT type FROM structures WHERE id = NEW.id) != 'category'
1515
THEN RAISE(ABORT, 'Categories must have type "category"')
1616
END;
17+
END;
18+
19+
CREATE TRIGGER trg_category_insert_check
20+
BEFORE INSERT ON structures
21+
WHEN NEW.type = 'category'
22+
BEGIN
23+
SELECT CASE
24+
WHEN NEW.source IS NOT NULL
25+
THEN RAISE(ABORT, 'Categories cannot have a source')
26+
END;
27+
28+
SELECT CASE
29+
WHEN NEW.target IS NOT NULL
30+
THEN RAISE(ABORT, 'Categories cannot have a target')
31+
END;
1732
END;
Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
1-
CREATE TABLE functors (
2-
id TEXT PRIMARY KEY,
3-
source TEXT NOT NULL,
4-
target TEXT NOT NULL,
5-
FOREIGN KEY (source) REFERENCES categories (id) ON DELETE CASCADE,
6-
FOREIGN KEY (target) REFERENCES categories (id) ON DELETE CASCADE,
7-
FOREIGN KEY (id) REFERENCES structures (id) ON DELETE CASCADE
8-
);
9-
10-
CREATE TRIGGER trg_functor_type_check
11-
BEFORE INSERT ON functors
1+
CREATE TRIGGER trg_functor_insert_check
2+
BEFORE INSERT ON structures
3+
WHEN NEW.type = 'functor'
124
BEGIN
13-
SELECT
14-
CASE
15-
WHEN
16-
(SELECT type FROM structures WHERE id = NEW.id) != 'functor'
17-
THEN RAISE(ABORT, 'Functors must have type "functor"')
18-
END;
19-
END;
5+
SELECT CASE
6+
WHEN NEW.source IS NULL
7+
THEN RAISE(ABORT, 'Functor source must be defined')
8+
END;
9+
10+
SELECT CASE
11+
WHEN NEW.target IS NULL
12+
THEN RAISE(ABORT, 'Functor target must be defined')
13+
END;
14+
15+
SELECT CASE
16+
WHEN NOT EXISTS (
17+
SELECT 1
18+
FROM structures
19+
WHERE id = NEW.source AND type = 'category'
20+
)
21+
THEN RAISE(ABORT, 'Functor source must reference an existing category')
22+
END;
23+
24+
SELECT CASE
25+
WHEN NOT EXISTS (
26+
SELECT 1
27+
FROM structures
28+
WHERE id = NEW.target AND type = 'category'
29+
)
30+
THEN RAISE(ABORT, 'Functor target must reference an existing category')
31+
END;
32+
END;
33+
34+
-- TODO: add trigger that checks that adjoint functors behave as expected

databases/catdat/schema/008_adjoint-functors.sql

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

databases/catdat/schema/009_implications.sql renamed to databases/catdat/schema/008_implications.sql

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,34 @@ CREATE TABLE conclusions (
3737
REFERENCES properties (id, type) ON DELETE CASCADE
3838
);
3939

40-
-- property of source category of a functor (can be generalized when required)
40+
-- property of the source structure (e.g. of a functor)
4141
CREATE TABLE source_assumptions (
4242
implication_id TEXT NOT NULL,
4343
property_id TEXT NOT NULL,
44-
type TEXT NOT NULL CHECK (type = 'functor'),
45-
property_type TEXT NOT NULL CHECK (property_type = 'category'),
44+
type TEXT NOT NULL,
45+
property_type TEXT NOT NULL,
4646
PRIMARY KEY (implication_id, property_id),
4747
FOREIGN KEY (implication_id, type)
4848
REFERENCES implications (id, type) ON DELETE CASCADE,
4949
FOREIGN KEY (property_id, property_type)
5050
REFERENCES properties (id, type) ON DELETE CASCADE
5151
);
5252

53-
-- property of target category of a functor (can be generalized when required)
53+
-- properties of the target structure (e.g. of a functor)
5454
CREATE TABLE target_assumptions (
5555
implication_id TEXT NOT NULL,
5656
property_id TEXT NOT NULL,
57-
type TEXT NOT NULL CHECK (type = 'functor'),
58-
property_type TEXT NOT NULL CHECK (property_type = 'category'),
57+
type TEXT NOT NULL,
58+
property_type TEXT NOT NULL,
5959
PRIMARY KEY (implication_id, property_id),
6060
FOREIGN KEY (implication_id, type)
6161
REFERENCES implications (id, type) ON DELETE CASCADE,
6262
FOREIGN KEY (property_id, property_type)
6363
REFERENCES properties (id, type) ON DELETE CASCADE
6464
);
6565

66+
-- TODO: add left_adjoint_assumptions and right_adjoint_assumptions tables
67+
6668
CREATE INDEX idx_assumptions_property ON assumptions (property_id);
6769

6870
CREATE INDEX idx_conclusions_property ON conclusions (property_id);

databases/catdat/scripts/restrict-functor-properties.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ export function restrict_representable_functors() {
2121
check_redundancy
2222
)
2323
SELECT
24-
f.id,
24+
s.id,
2525
'representable',
2626
'functor',
2727
FALSE,
2828
'The target category is not $\\Set$.',
2929
FALSE,
3030
FALSE
31-
FROM functors f
32-
WHERE f.target <> 'Set'
31+
FROM structures s
32+
WHERE s.type = 'functor' AND s.target <> 'Set'
3333
ON CONFLICT (structure_id, property_id) DO NOTHING`,
3434
)
3535
.run()

databases/catdat/scripts/seed.ts

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type {
44
CategoryYaml,
55
ConfigYaml,
66
ImplicationYaml,
7-
FunctorYaml,
87
PropertyEntry,
98
StructureYaml,
109
PropertyYaml,
@@ -34,7 +33,7 @@ function seed() {
3433

3534
seed_properties({ type: 'functor', folder: 'functor-properties' })
3635
seed_implications({ type: 'functor', folder: 'functor-implications' })
37-
seed_structures({ type: 'functor', folder: 'functors', extra: insert_functor })
36+
seed_structures({ type: 'functor', folder: 'functors' })
3837
}
3938

4039
/**
@@ -68,7 +67,6 @@ function clear_all_tables() {
6867

6968
db.prepare(`DELETE FROM source_assumptions`).run()
7069
db.prepare(`DELETE FROM target_assumptions`).run()
71-
db.prepare(`DELETE FROM adjoint_functors`).run()
7270

7371
db.prepare(`DELETE FROM assumptions`).run()
7472
db.prepare(`DELETE FROM conclusions`).run()
@@ -162,9 +160,9 @@ function seed_structures<T extends StructureYaml>({
162160
const structure_insert = db.prepare(
163161
`INSERT INTO structures (
164162
id, type, name, notation, description, nlab_link,
165-
dual_structure_id
163+
dual_structure_id, source, target, left_adjoint
166164
)
167-
VALUES (?, ?, ?, ?, ?, ?, ?)`,
165+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
168166
)
169167

170168
const tag_insert = db.prepare(
@@ -214,6 +212,9 @@ function seed_structures<T extends StructureYaml>({
214212
structure.description,
215213
structure.nlab_link,
216214
structure[`dual_${type}`] || null,
215+
structure.source || null,
216+
structure.target || null,
217+
structure.left_adjoint || null,
217218
)
218219

219220
for (const tag of structure.tags) {
@@ -274,27 +275,6 @@ function insert_category(category: CategoryYaml) {
274275
}
275276
}
276277

277-
/**
278-
* Inserts the data of a functor that is specific to functors.
279-
*/
280-
function insert_functor(functor: FunctorYaml) {
281-
const functor_insert = db.prepare(
282-
`INSERT INTO functors (id, source, target) VALUES (?, ?, ?)`,
283-
)
284-
285-
const adjoint_insert = db.prepare(
286-
`INSERT INTO adjoint_functors (left_adjoint, right_adjoint)
287-
VALUES (?, ?)
288-
ON CONFLICT (left_adjoint, right_adjoint) DO NOTHING`,
289-
)
290-
291-
functor_insert.run(functor.id, functor.source, functor.target)
292-
293-
if (functor.left_adjoint) {
294-
adjoint_insert.run(functor.left_adjoint, functor.id)
295-
}
296-
}
297-
298278
/**
299279
* Seeds all properties of a given type from YAML files.
300280
*/

databases/catdat/scripts/seed.types.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ export type StructureYaml = {
3737
notation: string
3838
description?: string | null
3939
nlab_link?: string
40-
left_adjoint?: string
4140
tags: string[]
41+
source?: string
42+
target?: string
43+
left_adjoint?: string
4244
related_categories?: string[] // TODO: improve this
4345
related_functors?: string[]
4446
dual_category?: string // TODO: improve this
45-
dual_functor?: string
47+
dual_functor?: string // TODO: improve this
4648
satisfied_properties: PropertyEntry[]
4749
unsatisfied_properties: PropertyEntry[]
4850
undecidable_properties?: PropertyEntry[]
@@ -52,17 +54,10 @@ export type StructureYaml = {
5254
export type CategoryYaml = StructureYaml & {
5355
objects: string
5456
morphisms: string
55-
dual_category?: string | null
5657
special_objects: Record<string, ObjectEntry | undefined>
5758
special_morphisms: Record<string, MorphismEntry | undefined>
5859
}
5960

60-
export type FunctorYaml = StructureYaml & {
61-
source: string
62-
target: string
63-
left_adjoint?: string
64-
}
65-
6661
export type PropertyYaml = {
6762
id: string
6863
relation: string

databases/catdat/scripts/utils/functors.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ export function get_functors(db: Database): FunctorMeta[] {
2828
}
2929
>(
3030
`SELECT
31-
f.id,
31+
s.id,
3232
s.name,
33-
f.source,
34-
f.target,
33+
s.source,
34+
s.target,
3535
(
3636
SELECT json_group_array(property_id) FROM (
3737
SELECT property_id
3838
FROM property_assignments
3939
WHERE
4040
type = 'category'
41-
AND structure_id = f.source
41+
AND structure_id = s.source
4242
AND is_satisfied = TRUE
4343
)
4444
) AS source_props,
@@ -48,12 +48,12 @@ export function get_functors(db: Database): FunctorMeta[] {
4848
FROM property_assignments
4949
WHERE
5050
type = 'category'
51-
AND structure_id = f.target
51+
AND structure_id = s.target
5252
AND is_satisfied = TRUE
5353
)
5454
) AS target_props
55-
FROM functors f
56-
INNER JOIN structures s ON s.id = f.id
55+
FROM structures s
56+
WHERE s.type = 'functor'
5757
ORDER BY lower(s.name)`,
5858
)
5959
.all()

src/lib/commons/types.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,17 @@ export type CategorySpecificDisplay = {
3131

3232
export type FunctorSpecificDisplay = {
3333
source: string
34-
target: string
3534
source_name: string
36-
target_name: string
3735
source_notation: string
36+
target: string
37+
target_name: string
3838
target_notation: string
39+
left_adjoint: string | null
40+
left_adjoint_name: string | null
41+
left_adjoint_notation: string | null
42+
right_adjoint: string | null
43+
right_adjoint_name: string | null
44+
right_adjoint_notation: string | null
3945
}
4046

4147
export type TagObject = { tag: string }

0 commit comments

Comments
 (0)