Skip to content

Commit e9a95cf

Browse files
committed
add JSdocs
1 parent c9b88fb commit e9a95cf

6 files changed

Lines changed: 114 additions & 0 deletions

scripts/deduce-category-implications.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,27 @@ import dotenv from 'dotenv'
44

55
dotenv.config({ quiet: true })
66

7+
/**
8+
* Deduces implications from given ones.
9+
*/
710
export async function deduce_category_implications(db: Client) {
811
await clear_deduced_category_implications(db)
912
await create_dualized_category_implications(db)
1013
await create_self_dual_category_implications(db)
1114
}
1215

16+
/**
17+
* Clears all deduced implications. This is done as a first step.
18+
*/
1319
async function clear_deduced_category_implications(db: Client) {
1420
await db.execute(`DELETE FROM implications WHERE is_deduced = TRUE`)
1521
}
1622

23+
/**
24+
* Dualizes all implications by dualizing the involved properties
25+
* (in case they have a dual). For example, if P ===> Q holds,
26+
* then P^op ===> Q^op holds as well.
27+
*/
1728
async function create_dualized_category_implications(db: Client) {
1829
const res = await db.execute(`
1930
SELECT
@@ -91,6 +102,10 @@ async function create_dualized_category_implications(db: Client) {
91102
console.info(`Dualized ${dualizable_implications.length} category implications`)
92103
}
93104

105+
/**
106+
* Creates all trivial implications of the form
107+
* self-dual + P ===> P^op
108+
*/
94109
async function create_self_dual_category_implications(db: Client) {
95110
const { rows } = await db.execute(`
96111
INSERT INTO implication_input (

scripts/deduce-category-properties.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ type CategoryMeta = {
1515
dual_category_id: string | null
1616
}
1717

18+
/**
19+
* Deduce properties of categories from given ones
20+
* by using the list of implications.
21+
*/
1822
export async function deduce_category_properties(db: Client) {
1923
const tx = await db.transaction()
2024

@@ -53,6 +57,20 @@ export async function deduce_category_properties(db: Client) {
5357
}
5458
}
5559

60+
/**
61+
* Implications have the form:
62+
*
63+
* P_1 + ... + P_n ----> Q_1 + ... + Q_m
64+
*
65+
* or
66+
*
67+
* P_1 + ... + P_n <---> Q_1 + ... + Q_m
68+
*
69+
* This function decomposes them into normalized implications,
70+
* which have the form:
71+
*
72+
* P_1 + ... + P_n ----> Q
73+
*/
5674
async function get_normalized_category_implications(
5775
tx: Transaction,
5876
): Promise<NormalizedCategoryImplication[]> {
@@ -113,6 +131,9 @@ async function get_normalized_category_implications(
113131
return implications
114132
}
115133

134+
/**
135+
* Returns the list of categories saved in the database.
136+
*/
116137
async function get_categories(tx: Transaction) {
117138
const res = await tx.execute(`
118139
SELECT id, name, dual_category_id
@@ -121,6 +142,10 @@ async function get_categories(tx: Transaction) {
121142
return res.rows as unknown as CategoryMeta[]
122143
}
123144

145+
/**
146+
* Clears all the deduced properties.
147+
* This runs before the deduction starts.
148+
*/
124149
async function delete_deduced_category_properties(tx: Transaction, category_id: string) {
125150
await tx.execute({
126151
sql: `
@@ -131,6 +156,10 @@ async function delete_deduced_category_properties(tx: Transaction, category_id:
131156
})
132157
}
133158

159+
/**
160+
* Returns the list of properties that are satisfied or unsatisfied
161+
* for a given category.
162+
*/
134163
async function get_decided_properties(
135164
tx: Transaction,
136165
category_id: string,
@@ -148,6 +177,10 @@ async function get_decided_properties(
148177
return new Set(res.rows.map((row) => row.property_id) as string[])
149178
}
150179

180+
/**
181+
* Deduce satisfied properties for a given category from given ones
182+
* by using the list of normalized implications.
183+
*/
151184
async function deduce_satisfied_category_properties(
152185
tx: Transaction,
153186
category_id: string,
@@ -208,6 +241,10 @@ async function deduce_satisfied_category_properties(
208241
)
209242
}
210243

244+
/**
245+
* Deduce unsatisfied properties for a given category from given ones
246+
* by using the satisfied properties and the list of normalized implications.
247+
*/
211248
async function deduce_unsatisfied_category_properties(
212249
tx: Transaction,
213250
category_id: string,
@@ -287,6 +324,10 @@ async function deduce_unsatisfied_category_properties(
287324
)
288325
}
289326

327+
/**
328+
* Assign dual properties to dual categories:
329+
* If C has property P, then C^op has property P^op (if defined).
330+
*/
290331
async function deduce_dual_category_properties(tx: Transaction, category: CategoryMeta) {
291332
const res = await tx.execute({
292333
sql: `

scripts/deduce-functor-implications.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,27 @@ dotenv.config({ quiet: true })
66

77
// TODO: remove code duplication with category implication deduction script
88

9+
/**
10+
* Deduces functor implications from given ones.
11+
*/
912
export async function deduce_functor_implications(db: Client) {
1013
await clear_deduced_functor_implications(db)
1114
await create_dualized_functor_implications(db)
1215
}
1316

17+
/**
18+
* Clears all deduced functor implications. This is done as a first step.
19+
*/
1420
async function clear_deduced_functor_implications(db: Client) {
1521
await db.execute(`DELETE FROM functor_implications WHERE is_deduced = TRUE`)
1622
}
1723

24+
/**
25+
* Dualizes all functor implications by dualizing the involved properties
26+
* (in case they have a dual). For example, if P ===> Q holds,
27+
* then P^op ===> Q^op holds as well. The assumptions of source and target
28+
* categories (if any) need to be dualized as well.
29+
*/
1830
async function create_dualized_functor_implications(db: Client) {
1931
const res = await db.execute(`
2032
SELECT

scripts/deduce-functor-properties.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ type FunctorMeta = {
2121
// TODO: remove code duplication with category deduction script
2222
// (not quite the same because we need source and target assumptions)
2323

24+
/**
25+
* Deduce properties of functor from given ones
26+
* by using the list of functor implications.
27+
*/
2428
export async function deduce_functor_properties(db: Client) {
2529
const tx = await db.transaction()
2630

@@ -43,6 +47,20 @@ export async function deduce_functor_properties(db: Client) {
4347
}
4448
}
4549

50+
/**
51+
* Implications have the form:
52+
*
53+
* P_1 + ... + P_n ----> Q_1 + ... + Q_m
54+
*
55+
* or
56+
*
57+
* P_1 + ... + P_n <---> Q_1 + ... + Q_m
58+
*
59+
* This function decomposes them into normalized implications,
60+
* which have the form:
61+
*
62+
* P_1 + ... + P_n ----> Q
63+
*/
4664
async function get_normalized_functor_implications(
4765
tx: Transaction,
4866
): Promise<NormalizedFunctorImplication[]> {
@@ -113,6 +131,10 @@ async function get_normalized_functor_implications(
113131
return implications
114132
}
115133

134+
/**
135+
* Returns the list of functors saved in the database along with
136+
* the satisfied properties of their source and target category.
137+
*/
116138
async function get_functors(tx: Transaction) {
117139
const res = await tx.execute(`
118140
SELECT
@@ -148,6 +170,10 @@ async function get_functors(tx: Transaction) {
148170
})) as FunctorMeta[]
149171
}
150172

173+
/**
174+
* Clears all the deduced functor properties.
175+
* This runs before the deduction starts.
176+
*/
151177
async function delete_deduced_functor_properties(tx: Transaction, functor: FunctorMeta) {
152178
await tx.execute({
153179
sql: `
@@ -158,6 +184,10 @@ async function delete_deduced_functor_properties(tx: Transaction, functor: Funct
158184
})
159185
}
160186

187+
/**
188+
* Returns the list of properties that are satisfied or unsatisfied
189+
* for a given functor.
190+
*/
161191
async function get_decided_functor_properties(
162192
tx: Transaction,
163193
functor_id: string,
@@ -175,6 +205,10 @@ async function get_decided_functor_properties(
175205
return new Set(res.rows.map((row) => row.property_id) as string[])
176206
}
177207

208+
/**
209+
* Deduce satisfied properties for a given functor from given ones
210+
* by using the list of normalized implications.
211+
*/
178212
async function deduce_satisfied_functor_properties(
179213
tx: Transaction,
180214
functor: FunctorMeta,
@@ -235,6 +269,10 @@ async function deduce_satisfied_functor_properties(
235269
)
236270
}
237271

272+
/**
273+
* Deduce unsatisfied properties for a given functor from given ones
274+
* by using the satisfied properties and the list of normalized implications.
275+
*/
238276
async function deduce_unsatisfied_functor_properties(
239277
tx: Transaction,
240278
functor: FunctorMeta,

scripts/deduce-special-morphisms.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export async function deduce_special_morphisms(db: Client) {
77
// e.g. regular monomorphisms = same as monomorphisms in mono-regular categories,
88
}
99

10+
/**
11+
* Deduce special morphisms in dual categories.
12+
* For example, monomorphisms in C describe epimorphisms in C^op.
13+
*/
1014
async function deduce_special_morphisms_of_dual_categories(db: Client) {
1115
const res = await db.execute(`
1216
INSERT INTO special_morphisms (category_id, type, description, reason)

scripts/deduce-special-objects.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ export async function deduce_special_objects(db: Client) {
44
await deduce_special_objects_of_dual_categories(db)
55
}
66

7+
/**
8+
* Deduce special objects in dual categories.
9+
* For example, initial objects in C describe the terminal objects in C^op.
10+
*/
711
async function deduce_special_objects_of_dual_categories(db: Client) {
812
const res = await db.execute(`
913
INSERT INTO special_objects (category_id, type, description)

0 commit comments

Comments
 (0)