207 index.rss.xml dan-0001 index.xml Lîm Tsú-thuàn dannypsnl

This blog majorly writes about computer science and mathematic, also is my personal public notes.

• Mail
• Sourcehut/GitHub
• pgp: 196576B231622B8F

1 208 posts.rss.xml posts posts.xml Blog Posts false 209 210 math-003I.rss.xml Definition math-003I math-003I.xml 2023 11 29 Lîm Tsú-thuàn Boolean algebra

A Boolean algebra is a complemented distributive lattice.

211 math-003L.rss.xml Proposition math-003L math-003L.xml 2023 11 29 Lîm Tsú-thuàn <tex>{x^ \mathsf {c}}^ \mathsf {c} = x</tex>

In boolean algebra, the complement of complement of x is x.

Proof.

This is a direct result from at most one complement. 212 math-003M.rss.xml Proposition math-003M math-003M.xml 2023 11 29 Lîm Tsú-thuàn <tex>x \sqcap y = 0</tex> if and only if <tex>y \sqsubseteq x^{ \mathsf {c}}</tex>

In boolean algebra, the problem can be expressed categorical: x \times y = 0 iff y \to x^{ \mathsf {c}}.

Proof. We have product x \leftarrow 0 \rightarrow y, and the y \to 1 (terminal rule), but complement x^ \mathsf {c} existed and x + y has no need to be 1, so somewhere between y \to 1 has a x^ \mathsf {c}. 213 math-003N.rss.xml Proposition math-003N math-003N.xml 2023 11 29 Lîm Tsú-thuàn <tex>x \sqsubseteq y</tex> if and only if <tex>y^ \mathsf {c} \sqsubseteq x^ \mathsf {c}</tex>

In boolean algebra, the problem can be expressed categorical: x \to y iff y^ \mathsf {c} \to x^ \mathsf {c}.

Proof.

By applying proposition: x \sqcap y = 0 iff y \sqsubseteq x^{ \mathsf {c}}, with fact that x \to y, we know y^ \mathsf {c} \sqcap x = 0 Apply proposition again, we can see the goal existed. 214 math-003O.rss.xml Proposition math-003O math-003O.xml 2023 11 29 Lîm Tsú-thuàn <tex>(x \sqcap y)^ \mathsf {c} = x^ \mathsf {c} \sqcup y^ \mathsf {c}</tex>

In boolean algebra, we can rewrite it categorical: (x \times y)^ \mathsf {c} = x^ \mathsf {c} + y^ \mathsf {c}.

Proof. By removing the thing we no need, we can see that (x \times y)^ \mathsf {c} = x^ \mathsf {c} + y^ \mathsf {c}. 215 math-003P.rss.xml Proposition math-003P math-003P.xml 2023 11 29 Lîm Tsú-thuàn <tex>(x \sqcup y)^ \mathsf {c} = x^ \mathsf {c} \sqcap y^ \mathsf {c}</tex>

In boolean algebra, we can rewrite in categorical language: (x + y)^ \mathsf {c} = x^ \mathsf {c} \times y^ \mathsf {c}.

Proof. 216 math-003J.rss.xml math-003J math-003J.xml 2022 2 16 Lîm Tsú-thuàn Indexing boolean algebra

Boolean algebra can be encoded by indexing, for example, a venn diagram for two sets A, B divide diagram to four parts: 1, 2, 3, 4. Thus

1. A = \{ 1, 2 \}
2. B = \{ 1, 3 \}
3. A \cup B = \{ 1, 2, 3 \}
4. A \cap B = \{ 1 \}
5. (A \cup B)^{ \mathsf {c}} = \{ 4 \}

The benefit of the encoding is the encoding let any sets can be treated as finite sets operation. So for any set check a boolean algebra is valid, indexing helps you check them by computer.

217 cs-000J.rss.xml cs-000J cs-000J.xml 2022 2 16 Lîm Tsú-thuàn Encode to program

Here is the racket program.

(define I (set 1 2 3 4))
(define A (set 1 2))
(define B (set 1 3))
(define ∅ (set))
(define ∩ set-intersect)
(define ∪ set-union)
(define (not S)
(set-subtract I S))
(define (→ A B)
(∪ (not A) B))
(define (- A B)
(∩ A (not B)))
(define (≡ A B)
(∪ (∩ A B) (∩ (not A) (not B))))

218 cs-000K.rss.xml cs-000K cs-000K.xml 2022 2 16 Lîm Tsú-thuàn Checking based on encoding

Now, you can check A \to B = (A - B)^{ \mathsf {c}} by the following program.

(equal? (→ A B) (not (- A B)))


And you will know (A \cap (A - B)^{ \mathsf {c}}) = \emptyset is invalid since the following program returns false.

(equal? (∩ A (not (- A B))) ∅)


You can even extend this method for sets A, B, C, for sets A, B, C, D and so on, but then that's too far for this article.

219 math-003K.rss.xml Theorem math-003K math-003K.xml 2023 11 29 Lîm Tsú-thuàn Each element of distributive lattice has at most one complement

In a distributive lattice each element has at most one complement, which means y, z are complements of x implies y = z.

Proof.
The proof use category language, \sqcap (product) and \sqcup (coproduct).

Assuming there have two complements y, z for an element x, then x + y = x + z = 1 and x \times y = x \times z = 0. By distributive law we have below diagram Then we use x + y = x + z = 1 to reduce it and get Since there has at most one path, the diagram commute, hence y = z. 220 math-0032.rss.xml math-0032 math-0032.xml 2023 11 27 Lîm Tsú-thuàn Soundness 與 completeness

221 math-0035.rss.xml Definition math-0035 math-0035.xml 2023 11 27 Lîm Tsú-thuàn Classical logic

The twelve forms, where \alpha , \beta , \gamma denotes arbitrary sentences, are axioms of classical logic.

• \alpha \supset ( \alpha \land \alpha )
• ( \alpha \land \beta ) \supset ( \beta \land \alpha )
• ( \alpha \supset \beta ) \supset (( \alpha \land \gamma ) \supset ( \beta \land \gamma ))
• (( \alpha \supset \beta ) \land ( \beta \supset \gamma )) \supset ( \alpha \supset \gamma )
• \beta \supset ( \alpha \supset \beta )
• ( \alpha \land ( \alpha \supset \beta )) \supset \beta
• \alpha \supset ( \alpha \lor \beta )
• ( \alpha \lor \beta ) \supset ( \beta \lor \alpha )
• (( \alpha \supset \gamma ) \land ( \beta \supset \gamma )) \supset (( \alpha \lor \beta ) \supset \gamma )
• \sim \alpha \supset ( \alpha \supset \beta )
• (( \alpha \supset \beta ) \land ( \alpha \supset \sim \beta )) \supset \sim \alpha
• \alpha \lor \sim \alpha

with single rule of inference.

Rule of Detachment

From \alpha and \alpha \supset \beta, the sentence \beta may be derived. Denote derivable formula \vdash _{cl} \alpha, we can rewrite rule of detachment to \frac { \vdash _{cl} \alpha \ \ \ \ \vdash _{cl} ( \alpha \supset \beta ) }{ \vdash _{cl} \beta }

222 math-0033.rss.xml Theorem math-0033 math-0033.xml 2023 11 27 Lîm Tsú-thuàn Classical logic's soundness

If \vdash _{cl} \alpha, then \alpha is classically valid.

223 math-0034.rss.xml Theorem math-0034 math-0034.xml 2023 11 27 Lîm Tsú-thuàn Classical logic's completeness

If \alpha is classically valid, then \vdash _{cl} \alpha.

224 cs-000I.rss.xml Example cs-000I cs-000I.xml 2023 11 27 Lîm Tsú-thuàn 靜態分析中的 sound 與 complete

225 math-0036.rss.xml Conclusion math-0036 math-0036.xml 2023 11 27 Lîm Tsú-thuàn 如何使用 soundness 與 completeness

226 math-002Z.rss.xml Theorem math-002Z math-002Z.xml 2023 11 23 Lîm Tsú-thuàn A space is Hausdorff iff its diagonal map is closed

The proposition says a space is Hausdorff if and only if its diagonal map \Delta : X \to X \times X to product space is closed, which given an alternative definition. Notice that close means its complement \Delta ^ \mathsf {c} is open. The definition of \Delta is \Delta = \{ (x, x) \mid x \in X \}

Proof.

The first direction is Hausdorff implies diagonal map is closed. Hausdorff means every two different points has a pair of disjoint neighborhoods (U \in \mathcal {N} _x, V \in \mathcal {N} _y), where x \in U and y \in V. therefore, every pair (x, y) not line on the diagonal has U \times V cover them. The union of all these open sets U \times V indeed covers \Delta ^ \mathsf {c}, so the complement \Delta is closed.

The second direction is diagonal map is closed implies Hausdorff. Since \Delta ^ \mathsf {c} = \{ (x, y) \mid x, y \in X (x \ne y) \} is open, which implies for all x, y the pair (x, y) \in \Delta ^ \mathsf {c}. Since \mathcal {N} _{(x, y)} = \mathcal {N} _x \times \mathcal {N} _y, this implies the fact that \Delta ^ \mathsf {c} \in \mathcal {N} _x \times \mathcal {N} _y. Also, for all U \in \mathcal {N} _x and V \in \mathcal {N} _y, it's natural that U \times V \subseteq \Delta ^ \mathsf {c}, since the open set U \times V at most cover \Delta ^ \mathsf {c}. Consider that reversely again, that means for all (x, x) \in \Delta, pair (x, x) \notin U \times V (U \times V will not cover any part of diagonal), that implies U \cap V = \emptyset as desired.

227 math-001K.rss.xml math-001K math-001K.xml 2023 10 24 Lîm Tsú-thuàn Understanding <tex>F</tex>-algebra

To understand F-algebra, we will need some observations, the first one is we can summarize an algebra with a signature. For example, monoid has a signature:

\begin {cases} 1 : 1 \to m \\ \cdot : m \times m \to m \end {cases}

or we can say ring is:

\begin {cases} 0 : 1 \to m \\ 1 : 1 \to m \\ + : m \times m \to m \\ \times : m \times m \to m \\ - : m \to m \end {cases}

The next observation is we can consider these m as objects in a proper category C, at here is a cartesian closed category. For example

• monoid is a C-morphism 1 + m \times m \to m
• ring is a C-morphism 1 + 1 + m \times m + m \times m + m \to m

Now, we generalize algebra's definition.

228 math-001L.rss.xml Definition math-001L math-001L.xml 2023 10 24 Lîm Tsú-thuàn <tex>F</tex>-algebra (algebra for an endofunctor)

With a proper category C which can encode the signature of F(-), and an endofunctor F : C \to C, the F-algebra is a triple: (F, x, \alpha ) where \alpha : F \; x \to x is a C-morphism.

With the definition of F-algebra, we wondering if F-algebras of a fixed F form a category, and the answer is yes.

229 math-001M.rss.xml Definition math-001M math-001M.xml 2023 10 24 Lîm Tsú-thuàn Category of <tex>F</tex>-algebras

For a fixed endofunctor F in a proper category C (below notations omit fixed F),

1. the F-algebras (x, \alpha ) form the objects of the category,
2. morphisms are homomorphisms of objects (x, \alpha ) \xrightarrow {F \; m} (y, \beta ), composition is given by functor laws.
A homomorphism is a C-morphism m makes below diagram commutes. We can extra check identity indeed works. There is a theorem about the initial object of the category.

230 math-001N.rss.xml Theorem math-001N math-001N.xml 2023 10 24 Lîm Tsú-thuàn Lambek's

The evaluator j of an initial algebra (F, i, j) is an isomorphism.

Proof.

Let F \; i be an initial in the F-algebra category, the following diagram commutes for any C-object a Now, replace a with F \; i, we have commute diagram Then we consider a trivial commute diagram by duplicating the path F \; i \to i Combine two diagrams, then we get another commute diagram By definition now we know j \circ m is a homomorphism, and since F \; i is an initial, we must have F \; j \circ F \; m = 1_{Fi}

Therefore, we also have j \circ m = 1_i so m is the inverse of j, proves j is an isomorphism.
231 math-001P.rss.xml math-001P math-001P.xml 2023 10 24 Lîm Tsú-thuàn Catamorphism

The theorem actually proves the corresponding C-object i of initial algebra (F, i, j) is a fixed point of F. By reversing j with its inverse, we get a commute diagram below. In Haskell, we are able to define initial algebra

newtype Fix f = Fix (f (Fix f))

unFix :: Fix f -> f (Fix f)
unFix (Fix x) = x


View j as constructor Fix, j^{-1} as unFix, then we can define m = alg . fmap m . unFix. Since m :: Fix f -> a, we have definition of catamorphism.

cata :: Functor f => (f a -> a) -> Fix f -> a
cata alg = alg . fmap (cata alg) . unFix


An usual example is foldr, a convenient specialization of catamorphism.

232 math-001Q.rss.xml math-001Q math-001Q.xml 2023 10 24 Lîm Tsú-thuàn Anamorphism

As a dual concept, we can draw coalgebra diagram and define anamorphism as well.

ana :: Functor f => (a -> f a) -> a -> Fix f
ana coalg = Fix . fmap (ana coalg) . coalg

233 math-001R.rss.xml math-001R math-001R.xml 2023 10 25 Lîm Tsú-thuàn Conclusion

I mostly learn F-algebras from Category Theory for Programmers, and take a while to express the core idea in details with my voice with a lot practicing. The article answered some questions, but we always with more. What's an algebra of monad? What's an algebra of a programming language (usually has a recursive syntax tree)? Hope you also understand it well through the article and practicing.

234 math-0012.rss.xml math-0012 math-0012.xml 2023 10 11 Lîm Tsú-thuàn Lawvere's fixed point theorem

235 math-0013.rss.xml Theorem math-0013 math-0013.xml 2023 10 11 Lîm Tsú-thuàn Lawvere's fixed point http://tac.mta.ca/tac/reprints/articles/15/tr15.pdf

Proof. 首先畫出交換圖 其中 \delta 的定義是 c \mapsto \langle c, c \rangle，所以對 1 \xrightarrow {p} A 來說 \delta \circ p = \langle p, p \rangle。沿著這個定義，我們知道 ( \phi \times 1_A) \circ \delta \circ p = \langle \phi \circ p, p \rangle。根據 point-surjective 我們知道 \phi \circ p 對每個 p 來說都是唯一確定的。現在把往下方 Bev 也畫出，即可得出等式： f \circ ev \circ \langle \phi \circ p, p \rangle = ev \circ \langle \phi \circ p, p \rangle 換句話說 B \xrightarrow {f} B 的不動點即是 ev \circ \langle \phi \circ p, p \rangle
236 math-001S.rss.xml Example math-001S math-001S.xml 2023 10 26 Lîm Tsú-thuàn 應用到 lambda calculus

237 math-0016.rss.xml Example math-0016 math-0016.xml 2023 10 11 Lîm Tsú-thuàn 應用到 Cantor's theorem

238 math-0017.rss.xml Lemma math-0017 math-0017.xml 2023 10 11 Lîm Tsú-thuàn No point-surjective morphism

If there exists B \xrightarrow {f} B such that f \circ b \ne b for all 1 \xrightarrow {b} B, then there has no point-surjective morphism can exist for A \xrightarrow {g} B^A.

This is a reversed version of Lawvere's fixed point theorem, no need an extra proof.
Proof. 存在 2 \xrightarrow { \text {not}} 2 令所有 1 \xrightarrow {b} 2 都滿足 \text {not} \circ b \ne b，所以對任何集合 A 都不存在 A \to 2^Apoint-surjective 函數，因此也不存在 A \cong 2^A

239 math-000U.rss.xml math-000U math-000U.xml 2023 10 3 Lîm Tsú-thuàn Understand comma category

Comma category is generated by two functors, denoted (T \downarrow S).

To understand the idea, we can start from slice & co-slice category, which is a special case of comma category. In co-slice category, we have objects \langle f, c \rangle where x \xrightarrow {f} c, and morphism \langle f, c \rangle \xrightarrow {h} \langle f', c' \rangle where below diagram commutes: We give another denotation (x \downarrow C) for object x and its category C for this concept, and (C \downarrow x) for the dual.

If we generalize the idea, by replacing category C with a functor S : D \to C, then we get a category (x \downarrow S) with

• objects \langle f, d \rangle where x \xrightarrow {f} Sd
• morphisms h : \langle f, d \rangle \to \langle f', d' \rangle where below diagram commutes: If we replace object x to another functor T? It's the full picture of comma category:

240 math-000V.rss.xml Definition math-000V math-000V.xml 2023 10 3 Lîm Tsú-thuàn Comma category

Given categories and functors The comma category (T \downarrow S) (or (T,S)) has

• objects \langle e,d,f \rangle where e \in E, d \in D, and T(e) \xrightarrow {f} S(d)
• morphisms \langle k,h \rangle : \langle e,d,f \rangle \to \langle e',d',f' \rangle where below commutes: 241 math-000W.rss.xml Example math-000W math-000W.xml 2023 10 3 Lîm Tsú-thuàn Slice category as comma category

With the definition, now we can see how slice & co-slice category is a special case of comma category:

• Replace object x with a functor T : 1 \to C, it will exactly pick a certain object, in case is x
• Replace functor S : D \to C with identity functor of C, and hence, it's the category itself
Then we get a co-slice category.

242 math-002K.rss.xml Example math-002K math-002K.xml 2023 10 3 Lîm Tsú-thuàn All morphisms of <tex>C</tex>

Take T = S = 1_C, then (C \downarrow C) is C^2 (all morphisms of C)

243 tt-000F.rss.xml tt-000F tt-000F.xml 2023 9 23 Lîm Tsú-thuàn cmj 子類型與多型（泛型）

244 question-0001.rss.xml question-0001 question-0001.xml 2023 9 23 cmj Golang 為什麼要有泛型？ https://g0v.social/@cmj/111106397553350393

245 tt-000D.rss.xml tt-000D tt-000D.xml 2023 9 23 Lîm Tsú-thuàn Go 的 interface

Go 語言的 interface，範例如下

type Abser interface {
Abs() float64
}


type A interface {
F(C) D
}
type B interface {
F(C) D
}


246 tt-000E.rss.xml tt-000E tt-000E.xml 2023 9 23 Lîm Tsú-thuàn Java 的 interface 與 bounded polymorphism (bounded quantification)

interface Comparable<T> {
int compareTo(T other);
}


<S extends Comparable> S min(S a, S b)


247 tt-000G.rss.xml tt-000G tt-000G.xml 2023 9 23 Lîm Tsú-thuàn 問題所在

interface 是一種子類型關係，換句話說當 T 實現 A 我們就說 T \le A，在每個要求 A 的位置都可以用 T 取代。

248 tt-0005.rss.xml tt-0005 tt-0005.xml 2023 9 15 Lîm Tsú-thuàn Pattern matching on Types: An indirected universe

By introduce a indirect level of universe \mathcal {U} ^-, such that a subtype of normal universe \mathcal {U}, and allows pattern matching. By restricting it can only be used at inductive type definitions' dependent position, it preserves parametricity, solves the problem easier compare with subscripting universe. In this setup, every defined type has type \mathcal {U} ^- first, and hence

• \mathbb {N} : \mathcal {U} ^-
• \mathbb {B} : \mathcal {U} ^-
• \mathbb {L} : \mathcal {U} \to \mathcal {U} ^-

\mathbb {L} didn't depend on \mathcal {U} ^-, so we keep using tagless encoding to explain

data Term Type
| ℕ => add (Term ℕ) (Term ℕ)
| 𝔹 => eq (Term ℕ) (Term ℕ)
| a => if (Term 𝔹) (Term a) (Term a)
| a => lit a


We have \text {Term} : \mathcal {U} ^- \to \mathcal {U} ^-, and then, if one wants List (Term Nat) it still work since \mathcal {U} ^- \le \mathcal {U}. But if one tries to define code below:

inductive Split Type^
| Nat => nat
| Bool => bool
| _ => else

def id (A : Type) (x : A) : A =>
match Split A
| nat => 0
| bool => false
| _ => x


Since the \mathcal {U} isn't the subtype of \mathcal {U} ^-, program Split A won't type check, the definition will not work as intended. This is indeed more boring than subscripting universe, but easier to check it does't break parametricity.

Till now, I haven't start to check the pattern of type, except the primitive exact value, if I'm going to push this further, a good example is:
inductive K Type^
| List a => hi a
| _ => he

This is quite intuitive since in implementation inductive types' head are also rigid values, just like constructors.
249 tt-0003.rss.xml tt-0003 tt-0003.xml 2023 9 14 Lîm Tsú-thuàn Subscripting Universe

This is an extension means to solve pattern matching on type's problem. We start from my old idea, an extension of inductive types.

250 tt-0009.rss.xml tt-0009 tt-0009.xml 2023 9 14 Lîm Tsú-thuàn Subscripting <em>Inductive types</em>

An intutive extension of inductive types is, let constructor be subscripting set of the inductive type. For example, a type with definition

inductive Nat
| zero
| suc Nat


A type Nat[suc] means only suc ... is a term, zero cannot have type Nat[suc]. It's easy to see NatNonZero = Nat[suc], this can also apply to

• List1 = List[cons]
• Int is also a good motive example
    inductive Int
| 0
| + Int[+, zero]
| - Int[-, zero]
Int[+] is positive, Int[-] is negative. The diagram in its syntactic category: To ensure this, if the following syntax of each constructor c is a list of argument types Ti ..., we say the type of constructor of type T is Ti ... -> T[c]. The corresponding part is pattern matching's type rules will refine type T with the pattern matched constructor c, below marks all binder's refined type. The type T[c, ...] is a subtype of T.

def foo : Int -> Int
| 0 => 0
| + p =>
-- p : Int[+, 0]
p
| - n =>
-- n : Int[-, 0]
n

An obvious problem is
def neg : Int -> Int
| 0 => 0
| + p => - (neg p)
| - n => + (neg p)

We can see that the type information is squeezed, the second and third case need type casting. A potential solution is case type, and hence, neg has type like: neg : \begin {cases} Int_{} \to Int_{} \\ Int_{[+]} \to Int_{[-]} \\ Int_{[-]} \to Int_{[+]} \end {cases} But then what's the type rule of it? Will need some time to explore.
251 tt-000A.rss.xml tt-000A tt-000A.xml 2023 9 14 Lîm Tsú-thuàn Extend to Universe

To extend this on to universe type Type, we say if there is an inductive family T

inductive T (xi : Xi) ...
| ci Ti ...
| ...


, there is a binding T : Xi ... -> Type[T]. As usual, Type[T, ...] is a subtype of Type. Therefore, in this configuration, writes down id : {A : Type} -> A -> A still has the only one implementation! And we can do type pattern matching if we have subscriptings. Consider

• \mathcal {U} as Type
• \mathbb {N} as Nat
• \mathbb {B} as Bool
• L as List

we have an example diagram as below A motive example is the tagless encoding:

data Term Type
| ℕ => add (Term ℕ) (Term ℕ)
| 𝔹 => eq (Term ℕ) (Term ℕ)
| a => if (Term 𝔹) (Term a) (Term a)
| a => lit a

The final we can consider subtyping more, should we generally introduce subset of subscriptings as super type? In this setup then Type[Nat, Bool] <: Type[Nat] <: Type.

However, this is an over complicated idea, I prefer indirected universe more.

252 math-0007.rss.xml math-0007 math-0007.xml 2023 9 12 Lîm Tsú-thuàn Generalize concept of element

Element or member is a natural concept in set theory, one can use x \in A to denote x is an element of A. We can extend the idea from view it in the category \bold {Sets}:

Each element x of a set A corresponding to a function \{ \bullet \} \xrightarrow {x} A

Therefore, if we admit a category \mathcal {C} has a terminal object 1, we say an element x of object A \in Ob( \mathcal {C}) is a morphism 1 \xrightarrow {x} A.

NOTE: A terminal object 1 has exact only one morphism from elsewhere, it's a proper corresponding to one element.
253 math-0008.rss.xml Theorem math-0008 math-0008.xml 2023 9 12 Lîm Tsú-thuàn Equal Arrow

If A \xrightarrow {f} B and A \xrightarrow {g} B are morphisms in the category \mathcal {C} then f = g if and only if for every object X and every morphisms X \xrightarrow {x} A we have f x = g x

Proof. The f = g leads to f x = g x is obvious. Conversely, we already have f x = g x for all objects and morphisms. Let X = A, by premise we got a commute diagram: By diagram we got f = f \circ 1_A = g \circ 1_A = g.
254 tt-0001.rss.xml tt-0001 tt-0001.xml 2023 9 10 Lîm Tsú-thuàn Pattern matching on type & following problems

I'm considering a weird way to build inductive types, it's start on Zhang's idea, do pattern matching to get constructors.

255 tt-0006.rss.xml tt-0006 tt-0006.xml 2021 12 Lîm Tsú-thuàn Zhang's idea

The idea is coming from Zhang's paper, a simpler encoding of indexed types. An example is Vec in Agda

data Vec (A : Set a) : ℕ → Set a where
[]  : Vec A zero
_∷_ : ∀ (x : A) (xs : Vec A n) → Vec A (suc n)


One can still try [] : Vec A 10, although the type check failed, it need a sophisticated unification check. With Zhang's idea, we can do:

data Vec (A : Set a) : ℕ → Set a where
zero => []
suc n => _∷_ A (Vec A n)


Now, [] : Vec A n where n \ne 0 is impossible to write down as usual, but now it's an easier unification! Since there has no constructor [] for type Vec A n where n \ne 0. Another good example is finite set:

data Fin (n : N)
| suc _ => fzero
| suc n => fsuc (Fin n)


It requires overlapping pattern. One more last, we cannot define usual equality type here (please check)

data Id (A : Type ℓ) (x : A) : A → Type ℓ where
idp : Id A x x

Paper: Simpler indexed type essentially simplifies the problem of constructor selection just by turning the term-match-term problem to a term-match-pattern problem, which rules out numerous complication but also loses the benefit of general indexed types.
256 tt-0007.rss.xml tt-0007 tt-0007.xml 2022 12 Lîm Tsú-thuàn The encoding problem of Zhang's idea

The benefit of the idea is clear, but it disallows definition like tagless interpreter:

data Term : Set → Set1 where
lit : ∀ {a} → a → Term a
add : Term ℕ → Term ℕ → Term ℕ
eq : Term ℕ → Term ℕ → Term 𝔹
if : ∀ {a} → Term 𝔹 → Term a → Term a → Term a

eval : ∀ {a} → Term a → a
eval (lit x) = x
eval (add x y) = eval x + eval y
eval (eq x y) = eval x == eval y
eval (if c t e) with eval c
eval (if c t e) | true = eval t
eval (if c t e) | false = eval e

NOTE: There is a workaround in paper, and hence, the problem is inconvenience instead of impossible.
257 tt-0008.rss.xml tt-0008 tt-0008.xml 2023 1 Lîm Tsú-thuàn Pattern matching on Type as a solution

If I simply allow pattern matching on "Type", it's able to restore encoding from the problem:

data Term Type
| ℕ => add (Term ℕ) (Term ℕ)
| 𝔹 => eq (Term ℕ) (Term ℕ)
| a => if (Term 𝔹) (Term a) (Term a)
| a => lit a


But then it breaks parametricity! One now can read what is a polymorphic type concretely:

data C (A : Type)
| ℕ => c1
| 𝔹 => c2
| _ => c3

id : {A : Type} -> C A -> A -> A
id c1 x = 3
id c2 x = false
id _ x = x

The first simple idea in my mind is forbidding C P where
1. P is a type
2. C destruct a P position
3. P is a polymorphic type variable
The question is, does this enough?
258 math-002L.rss.xml math-002L math-002L.xml 2023 3 20 Lîm Tsú-thuàn Cones, their category, and limit

In category theory, cone is a kind of natural transformation, to describe a diagram formally. The setup of cone is starting from a diagram, which we will define it as a category \mathcal {D} (usually is a finite one but no need to be) with two functors to the target category \mathcal {C}. The two functors are

• \Delta _c takes all objects of \mathcal {D} to a certain \mathcal {C}-object c, and all morphisms to the identity 1_c
• F sends the diagram \mathcal {D} entirely into \mathcal {C}

The first functor is very clear, we always can do that for any category; the second functor will need \mathcal {C} has that diagram. Consider \mathcal {D} as below If such diagram exists in \mathcal {C}, then we have a proper way to define F, there can have many such diagram in \mathcal {C}, we denote them as \mathcal {C} ( \mathcal {D} ). Now consider if there is a morphism from c to all objects in \mathcal {C} ( \mathcal {D} ), that lift a natural transformation from \Delta _c \to F. We say c is an apex and the \mathcal {C} ( \mathcal {D} ) is a plane in this sense, thus, such a natural transformation gives concept cone. With a fixed functor F (we also abuse language to say F is the diagram), varies \Delta _c bring different cones! When I get this, the picture in my mind is: Image the head is apex and the body is the fixed diagram F, you will also get the idea slowly.

To describe above idea, we make another category! By picking all apex of cone as objects, and picking morphism between apex in \mathcal {C} as morphisms, this is the category of cones (please check it does really a category).

259 math-002M.rss.xml Definition math-002M math-002M.xml 2023 3 20 Lîm Tsú-thuàn Category of (co)cones

With a fixed diagram \mathcal {D} \xrightarrow {F} \mathcal {C}, and natural transformations \Delta _c \to F (from different \Delta _c), we get a category that consituited by

• objects: all cone objects c above the fixed diagram (via \Delta _c functor).
• morphisms: \mathcal {C}-morphisms between cones.

Dual natural transformations F \xrightarrow { \beta } \Delta _c form cocones and a dual category.

The funny part we care here, is the terminal object of the category of cones, that is the next section. A limit or universal cone is a terminal object of category of cones. If you consider it carefully, and you will find this is the best cone of cones, because every other cones can be represented by composition of an addition morphism from itself to the limit!

260 math-002N.rss.xml Definition math-002N math-002N.xml 2023 3 20 Lîm Tsú-thuàn Limit (universal cone) and colimit

With a fixed diagram \mathcal {D} \xrightarrow {F} \mathcal {C}, a limit is a terminal of the category of cones, denoted as \text {Lim} F.

• notice that we can freely abuse language and say a \mathcal {C}-diagram is a functor target to \mathcal {C}
• Limit might not exist, so you have to ensure there has one.

The dual concept colimit is an initial of category of cocones.

With concept of cone and limit, you might already find there has some concept can be replaced by cone and limit, you're right and that would be fun to rewrite them in this new sense. Have a nice day.

261 cs-000F.rss.xml cs-000F cs-000F.xml 2018 9 3 Lîm Tsú-thuàn Mark sweep GC

Mark-Sweep is a classic GC algorithm, it's combined with two parts, mark and sweep.

mark(root):
if not marked?(root):
mark(root)
for obj in knowns(root):
mark(obj)

sweep(heap):
for obj in heap:
if marked?(obj):
unmark(obj)
else:
release(obj)


If we run collection (mark-sweep), then since each object is reachable from root, so no one would be released. After do some executions, obj1 don't need obj3 anymore, so it became: Now when we run collection, obj3 is unreachable from root, so it won't be marked! When running to sweep, it will be dropped.

2 421 notes.rss.xml notes notes.xml Notes false 422 423 math-003A.rss.xml Definition math-003A math-003A.xml 2023 11 29 Lîm Tsú-thuàn Lattice

A lattice is a poset such that any two elements x, y of it have

• A greatest lower bound x \sqcap y (also called meet, or categorical product)
• A least upper bound x \sqcup y (also called join, or categorical coproduct)
424 math-003B.rss.xml Definition math-003B math-003B.xml 2023 11 29 Lîm Tsú-thuàn Lattice (bounded)

A lattice is bounded if it has both initial and terminal.

425 math-003C.rss.xml Proposition math-003C math-003C.xml 2023 11 29 Lîm Tsú-thuàn Lattice always has pullbacks and pushouts

For any two elements of lattice, there is a pullback and pushout.

Proof.

Any two elements has a product and coproduct, which means below diagram exists and just like preorder pullbacks are products reason, there has at most one x \sqcap y \to x \sqcup y, so this diagram must be a pullback square, and must also be a pushout square.

426 math-003D.rss.xml Example math-003D math-003D.xml 2023 11 29 Lîm Tsú-thuàn Powerset and lattice

Powersets \mathscr {P}(A) of a set A with \subseteq relation is a lattice, where

• join of x, y is their union x \cup y
• meet of x, y is their interesection x \cap y
• unit is the set A
• zero is \emptyset
427 math-003E.rss.xml Example math-003E math-003E.xml 2023 11 29 Lîm Tsú-thuàn Topology and lattice

Let I be a topological space, its open sets \Theta with \subseteq forms a lattice ( \Theta , \subseteq ) just like powerset example, since open sets \Theta will be a sub collection of \mathscr {P}(I).

428 math-003F.rss.xml Definition math-003F math-003F.xml 2023 11 29 Lîm Tsú-thuàn Lattice (distributive)

A lattice A is said to be distributive if admits the following law

x \sqcap (y \sqcup z) = (x \sqcap y) \sqcup (x \sqcap z)

for all x, y, z \in A, or equivalent version is x \sqcup (y \sqcap z) = (x \sqcup y) \sqcap (x \sqcup z).

429 math-003G.rss.xml Definition math-003G math-003G.xml 2023 11 29 Lîm Tsú-thuàn Complement in lattice

In a bounded lattice, y is a complement of x if x \sqcup y = 1 and x \sqcap y = 0. A bounded lattice is complemented if each of its element has a complement in the lattice.

430 math-003H.rss.xml Collary math-003H math-003H.xml 2023 11 29 Lîm Tsú-thuàn Recheck lattice's example
• powerset with subset relation is complemented for instance.
• compare with powerset example, topology with subset relation is complemented only when each open set A is closed, this is because the A^{ \mathsf {c}} \in \Theta iff A is closed.
431 math-0038.rss.xml Proposition math-0038 math-0038.xml 2023 11 28 Lîm Tsú-thuàn All preorder pullbacks are products

The proposition is saying the preorder diagram below is a pullback square if and only if p is a product of a and b. Proof.

The proof is easy, in preorder at most one arrow a \to b for all objects a, b. Therefore, we can make below diagram commutes 432 math-0039.rss.xml Definition math-0039 math-0039.xml 2023 11 28 Lîm Tsú-thuàn Pullback and pushout

A pullback is a limit of \bullet \rightarrow \bullet \leftarrow \bullet; a pushout is a colimit of \bullet \leftarrow \bullet \rightarrow \bullet.

pullback square pushout square 433 math-0037.rss.xml Definition math-0037 math-0037.xml 2023 11 27 Lîm Tsú-thuàn Skeletal category

If in a category, every isomorphism is identical, then the category is skeletal. For example, skeletal preorder is poset.

434 software-000J.rss.xml software-000J software-000J.xml 2023 11 24 Lîm Tsú-thuàn Git send-email setup with Protonmail

In the original setup I already explain the configuration, to do the same with Protonmail will need to install Proton Mail Bridge, then with configuration as below.

[sendemail]
smtpEncryption = STARTTLS
smtpServer = 127.0.0.1
smtpServerPort = 1025

435 math-0030.rss.xml Definition math-0030 math-0030.xml 2023 11 24 Lîm Tsú-thuàn Mono and epi arrows
• An arrow f : A \to B is mono if it's left-cancelable: f \circ x_1 = f \circ x_2 \implies x_1 = x_2
• An arrow f : A \to B is epi if it's right-cancelable: x_1 \circ f = x_2 \circ f \implies x_1 = x_2
436 math-0031.rss.xml Definition math-0031 math-0031.xml 2023 11 24 Lîm Tsú-thuàn Split mono and epi arrows
• An arrow f : A \to B is split mono if there is an post-inverse arrow k : B \to A such that k \circ f = id_A
• An arrow f : A \to B is split epi if there is an pre-inverse arrow h : B \to A such that f \circ h = id_B
437 math-002X.rss.xml Example math-002X math-002X.xml 2023 11 22 Lîm Tsú-thuàn <tex>\pi : [0, 1] \to S^1</tex>

The map \pi : [0,1] \to S^1 defined by \pi (t) = ( \cos (2 \pi t), \sin (2 \pi t)) is a quotient map.

438 math-002Y.rss.xml Definition math-002Y math-002Y.xml 2023 11 22 Lîm Tsú-thuàn Product topology

For two topological spaces X, Y, their product topological space X \times Y is cartesian product of sets X and Y, where open sets are cartesian product U \times V of all open sets U \subset X, V \subset Y.

439 math-002W.rss.xml Definition math-002W math-002W.xml 2023 11 21 Lîm Tsú-thuàn Simplicial set

A simplicial set is a presheaf over the category \Delta, denote sSet = \widehat \Delta for the category of simplicial sets.

440 math-002T.rss.xml Definition math-002T math-002T.xml 2023 11 14 Lîm Tsú-thuàn Subspace

A set of vectors is a subspace if all linear combinations of vectors still stay in the subspace.

441 math-002P.rss.xml Definition math-002P math-002P.xml 2023 11 12 Lîm Tsú-thuàn Equalizer

An equalizer is a limit of the diagram Therefore, for two morphisms f, g : A \to B in a category C, their equalizer (if existed) is an object eq(f, g) with a morphism eq(f, g) \xrightarrow {e} A, such that f \circ e = g \circ e, and given any h : C \to A satisfy f \circ h = g \circ h, then there is a unique morphism k let h = e \circ k.

442 math-002S.rss.xml Proposition math-002S math-002S.xml 2023 11 12 Lîm Tsú-thuàn Equalizer is monomorphism

If E \xrightarrow {e} A is an equalizer, then e is a monomorphism.

Proof.

If there is any f, g : C \to E, due to C \to A has a unique C \to E, therefore, f = g must be true.

443 math-002Q.rss.xml Proposition math-002Q math-002Q.xml 2023 11 12 Lîm Tsú-thuàn With binary product and pullback admits equalizer

A category with binary product and pullback admits equalizer.

Proof. We don't have to denote it as eq(f,g). Anyway, it's a pullback means (f,g) \circ e = (1_B, 1_B) \circ e , which admits f \circ e = g \circ e.

444 math-002R.rss.xml Proposition math-002R math-002R.xml 2023 11 12 Lîm Tsú-thuàn With equalizer, finite product admits all finite limits

If a category has equalizers, finite products then it has finite limits.

Proof.

TODO

445 math-002O.rss.xml Definition math-002O math-002O.xml 2023 11 12 Lîm Tsú-thuàn Ideal

A subset \mathfrak {c} of ring R is an ideal of R if

• u, v \in \mathfrak {c} then u + v \in \mathfrak {c}
• u \in \mathfrak {c} and r \in \R then ru \in \mathfrak {c}
446 tt-000W.rss.xml Definition tt-000W tt-000W.xml 2023 11 11 Lîm Tsú-thuàn Categories with attributes

A category with attributes consists of:

• A small category \mathbb {C} with a terminal object \diamond
• Each object \Gamma of \mathbb {C} has a set \text {Ty}( \Gamma )
• For each \Gamma and each A \in \text {Ty}( \Gamma ), there is an \mathbb {C}-object \Gamma .A and a \mathbb {C}-morphism p_A : \Gamma .A \to \Gamma
• For each \sigma : \Delta \to \Gamma in \mathbb {C}, a function (-)[ \sigma ] : \text {Ty}( \Gamma ) \to \text {Ty}( \Delta ) and a morphism \Delta .A[ \sigma ] \xrightarrow { \sigma .A} \Gamma .A
such that satisfy below pullback and equations • A[1_ \Gamma ] = A
• A[ \sigma \circ \tau ] = A[ \sigma ][ \tau ] for each \Theta \xrightarrow { \tau } \Delta \xrightarrow { \sigma } \Gamma
• ( \sigma \circ \tau ).A = ( \sigma .A) \circ ( \tau .A[ \sigma ]) for each \Theta \xrightarrow { \tau } \Delta \xrightarrow { \sigma } \Gamma
447 tt-000X.rss.xml Collary tt-000X tt-000X.xml 2023 11 11 Lîm Tsú-thuàn Dependent type in categories with attributes

Depedent types in context \Gamma are elements of \text {Ty}( \Gamma ); object \Gamma .A represents the result of extending the context \Gamma by the type A. Terms \Gamma \vdash a : A are interpreted as sections of map \Gamma .A \xrightarrow {p_A} \Gamma

448 tt-000Y.rss.xml Collary tt-000Y tt-000Y.xml 2023 11 11 Lîm Tsú-thuàn Rewrite equations to diagrams

Of course, equations can also rewrite to diagrams: and composition of substituions 449 tt-000Z.rss.xml Definition tt-000Z tt-000Z.xml 2023 11 11 Lîm Tsú-thuàn Categories with families 450 tt-0011.rss.xml Definition tt-0011 tt-0011.xml 2023 11 12 Lîm Tsú-thuàn Families

\bold {Fam} is a category of families of small sets, consists with

• objects: pair \langle I, (A_i)_{i \in I} \rangle, consisting of a set I and an I-indexed family of sets (A_i)_{i \in I}
• morphisms: a pair of function f : I \to J and I-indexed family of functions A_i \xrightarrow {g_i} B_{f(i)}, denote as \langle f, (g_i)_{i \in I} \rangle : \langle I, (A_i)_{i \in I} \rangle \to \langle J, (B_j)_{j \in J} \rangle

A category with families is a category \mathbb {C} with a distinguished terminal object \diamond, and the following

• A functor T : \mathbb {C} ^{op} \to \bold {Fam}, such that T( \Gamma ) = \langle \text {Ty}( \Gamma ) , \text {Tm}( \Gamma , A ) _{A \in \text {Ty}( \Gamma )} \rangle and denote \langle A[ \sigma ], a[ \sigma ] \rangle \text { where } A[ \sigma ] \in \text {Ty}( \Delta ) \ \text {and} \ a[ \sigma ] \in \text {Tm}( \Delta , A[ \sigma ] ) as the result of applying T( \sigma : \Delta \to \Gamma ) to \langle A, a \rangle \text { where } A \in \text {Ty}( \Gamma ) \ \text {and} \ a \in \text {Tm}( \Gamma , A ) , recursively.
• For each \Gamma and each type A \in \text {Ty}( \Gamma ), there is an \mathbb {C}-object \Gamma .A, a \mathbb {C}-morphism \Gamma .A \xrightarrow {p_A} \Gamma and an element q_A \in \text {Ty}( \Gamma .A, A[p_A] )

such that for any two contexts \Gamma, \Delta and morphism of them \Delta \xrightarrow { \sigma } \Gamma satisfy 451 tt-0010.rss.xml Collary tt-0010 tt-0010.xml 2023 11 12 Lîm Tsú-thuàn Dependent type in categories with families

Each element A \in \text {Ty}( \Gamma ) is a dependent type \Gamma \vdash A, and each element a \in \text {Tm}( \Gamma , A ) is a term \Gamma \vdash a : A.

452 math-002F.rss.xml Definition math-002F math-002F.xml 2023 11 3 Lîm Tsú-thuàn Initial and terminal (category theory)

An object I of \mathbb {C} is initial if for any other object A, there is an unique morphism I \to A.

An object T of \mathbb {C} is terminal if for any other object A, there is an unique morphism A \to T.

453 math-002D.rss.xml Definition math-002D math-002D.xml 2023 11 3 Lîm Tsú-thuàn Internal language of topos

Mitchell-Benabou language, also known as internal language of topos, every term can be interpreted as a morphism in the topos (in multiple ways), such that the final target is its type.

1. For every object A of a topos \mathbb {C} there has an infinite list a_0, a_1, ... called variables over A, we denote a_i.A for a_i is a variable of type A.
2. If A \xrightarrow {f} B is a \mathbb {C}-morphism, and s is a term of type A, then f \ s is a term of type B.
3. \mathbb {C}-morphism 1 \xrightarrow {c} A is considered as a term of type A, we also say such c is a constant of type A.
4. For every term s_1 of type A and s_2 of type B, there is a term \langle s_1, s_2 \rangle of type A \times B. Notice that \langle s_1, s_2 \rangle need not been a morphism.
5. For every term t of type B and a variable a.A, there is a term ( \lambda a . A) s of type B^A.
454 math-002G.rss.xml Definition math-002G math-002G.xml 2023 11 3 Lîm Tsú-thuàn Simplicial category (simplex category)

The simplicial category is formed by

• objects: [n] = ( \{ 0, 1, ..., n \} , \le ), the \le is standard order of n \in \N
• morphisms: monotone maps [m] \to [n] such that for every pair i, j \in [0, 1, ..., m], if i \le j then f(i) \le f(j)

we denote this category as \Delta.

455 math-002E.rss.xml Definition math-002E math-002E.xml 2023 11 3 Lîm Tsú-thuàn Small-complete

A category \mathbb {C} is small-complete if for all small category \mathbb {S}, the functor \mathbb {S} \to \mathbb {C} has a limit. We can narrow it to finite complete.

456 math-001Z.rss.xml Definition math-001Z math-001Z.xml 2023 10 29 Lîm Tsú-thuàn Finitely-complete

A category C is finitely complete if it admits all finite limits, that means all limits for any diagrams F : J \to C, where J is a finite category.

457 tt-000R.rss.xml Definition tt-000R tt-000R.xml 2023 11 3 Lîm Tsú-thuàn Syntactic category (category of contexts)

Given a type theory T, a syntactic category \text {Con}(T) given by

• Objects are contexts in the type theory,
• Morphisms are substitutions between contexts.

Let \Gamma and \Delta be contexts of a type theory T \Gamma = x_0 : A_0, x_1 : A_1( \vec {x_0}), x_2 : A_2( \vec {x_{1}}), ..., x_n : A_n( \vec {x_{n-1}}) and \Gamma = y_0 : B_0, y_1 : B_1( \vec {y_0}), y_2 : B_2( \vec {y_{1}}), ..., y_m : B_m( \vec {y_{m-1}}) The \vec {x_n} notation expanded to x_0, ..., x_n that represents types can depends on eariler variables.

Then a morphism \Gamma \to \Delta is a sequence of terms \begin {aligned} & \Gamma \vdash \sigma _0 : B_0 \\ & \Gamma \vdash \sigma _1 : B_1( \vec { \sigma _0}) \\ &... \\ & \Gamma \vdash \sigma _m : B_m( \vec { \sigma _{m-1}}) \end {aligned} So a morphism of contexts is a sequence of terms satisfying requirement of target context \Delta, where we should be able to construct these terms from source context \Gamma. The abbreviation of these terms are \sigma = ( \sigma _0, ..., \sigma _m). For any context with size n, the identity substitution is obvious: its variables x_0, ..., x_n.

458 tt-000S.rss.xml Collary tt-000S tt-000S.xml 2023 11 3 Lîm Tsú-thuàn Empty context

The empty context is denoted as \bullet, it's the terminal object of the category, this is obvious since only one way to satisfy the empty context: do nothing.

459 tt-000U.rss.xml Definition tt-000U tt-000U.xml 2023 11 3 Lîm Tsú-thuàn Closed types and closed terms

If a type A is derivable from empty context \bullet, then it's a closed type.

\bullet \vdash A \text { type}

Any closed type can be viewed as a context by concat it back to empty context \bullet , (_ : A) = (_ : A), abusing the notation, we also say it's a context A. In this sense, a closed term is a morphism \bullet \to A, where A is a closed type.

460 tt-000T.rss.xml Example tt-000T tt-000T.xml 2023 11 3 Lîm Tsú-thuàn

If a type theory T has a closed type \N, \bullet \xrightarrow {(1,1)} (m : \N , n : \N ) \xrightarrow {m + n} \N the composition above is 2 : \bullet \to \N.

461 tt-000V.rss.xml tt-000V tt-000V.xml 2023 11 5 Lîm Tsú-thuàn Relation with classifying category

Syntactic category is highly related to classifying categories, which is focusing on type's signature. If we must find a different, classifying categories are not with any fixed judgement rules, so they can be shared by different type theories. In fact, if a classifying category with axioms, denote as Cl( \Sigma , \mathcal {A}), I believe it's the syntactic category here, since a type theory is made by signature and axioms (equation rules).

462 cs-000H.rss.xml cs-000H cs-000H.xml 2023 11 1 Lîm Tsú-thuàn Unification

Unification is an usual operation in logic programming language and type system, for example, one can say "I let a is b" then ask "Is b equals to a?". This is very common thing, in polymorphic type system, we want to avoid type application again and again, especially when it's trivial to find. That's why we have unification algorithm. In polymorphic type system, we want to have a property: If A \cong B, I can use A as B and vice versa. Therefore, an unification algorithm will receive a question like:

Is \text {List Nat} \cong \text {List } a? (In the sense that a is a type variable.)
By structural recursion rule, that question can be break down to
If \text {Nat} \cong a, then \text {List Nat} \cong \text {List } a
By primitive rule, any variable is similar to anything with the same type, at here they both with type \text {Type}, so a : \text {Type} \cong \text {Nat} : \text {Type} Then the unification algorithm will judge they are the same type, then user of the language can pass \text {List Nat} as \text {List } a.

463 math-0025.rss.xml Definition math-0025 math-0025.xml 2023 10 31 Lîm Tsú-thuàn Kernel

The kernel of \varphi : G \to G' is a special kind subgroup of G such that \text {ker } \varphi \ \dot {=} \ \{ g \in G \mid \varphi (g) \in 1_{G'} \} = \varphi ^{-1}(1_{G'})

464 math-0026.rss.xml Proposition math-0026 math-0026.xml 2023 10 31 Lîm Tsú-thuàn

Let \varphi : G \to G' be a homomorphism, for any trivial map \varphi \circ \alpha, the inclusion map \text {ker } \varphi from the kernel to G, below diagram commutes Proof. If \varphi \circ \alpha is a trivial map, then for all k \in K \varphi \circ \alpha (k) = \varphi ( \alpha (k)) = 1_{G'} Since \alpha will go to 1_G' with composition automatically, then it must already send every thing to \varphi ^{-1}(1_{G'})! Therefore, the unique \bar \alpha is the \alpha itself.
465 math-0027.rss.xml Definition math-0027 math-0027.xml 2023 10 31 Lîm Tsú-thuàn Normal subgroup

A subgroup N is normal subgroup of G if for all g \in G and n \in N the condition holds

gng^{-1} \in N 466 math-0028.rss.xml Lemma math-0028 math-0028.xml 2023 10 31 Lîm Tsú-thuàn Kernel is normal subgroup

The kernel \text {ker } \varphi is a normal subgroup of G.

Proof. Since for all n \in \text {ker } \varphi has \varphi (n) = 1_{G'}, we know that for any element g \in G \varphi (gng^{-1}) = \varphi (g) 1_{G'} \varphi (g^{-1}) = 1_{G'} implies gng^{-1} \in \text {ker } \varphi.
467 math-002C.rss.xml Definition math-002C math-002C.xml 2023 10 31 Lîm Tsú-thuàn Presheaf

A presheaf F of a small category C is a functor F : C^{op} \to \bold {Sets}.

• Since they are functors, presheaves form a functor category \bold {Sets}^{C^{op}}, we also denoted \bold {Sets}^{C^{op}} as \widehat C.
• If replace \bold {Sets} with V, we also say F : C^{op} \to V is a V-valued presheaf.
468 math-002V.rss.xml Collary math-002V math-002V.xml 2023 11 21 Lîm Tsú-thuàn Fibre and section

The set X_a via a presheaf X evaluates at an object a is sometimes called the fibre, the elements of X_a thus named sections of X over a.

469 math-0029.rss.xml Definition math-0029 math-0029.xml 2023 10 31 Lîm Tsú-thuàn Subgroup

A group H is called a subgroup of G if there is an inclusion function i : H \hookrightarrow G is a group homomorphism.

470 math-0023.rss.xml Proposition math-0023 math-0023.xml 2023 10 31 Lîm Tsú-thuàn Condition of subset is a subgroup

A nonempty subset H of a group G is a subgroup (shares G's operation) if and only if \forall a, b \in H . \; ab^{-1} \in H

Proof. If H is a subgroup, the element calculus of course closed under H. Now, prove the oppsite that condition hold implies H is a subgroup. Since H is nonempty, there is an element h \in H, by condition, we know 1_G = hh^{-1} \in H thus H has an identity. Let a = 1_G and b = h, then we have h^{-1} = 1_Gh^{-1} \in H thus H have inverses of its elements. Let a = x and b = y^{-1}, get x y = x (y^{-1})^{-1} \in H thus H is closed under the operation. Finally, since H shares G's operation, the associative is preserved, proves H is a group.
471 tt-000O.rss.xml Definition tt-000O tt-000O.xml 2023 10 29 Lîm Tsú-thuàn Classifying category (term model)

A classifying category (or term model) Cl( \Sigma ) is a category generated by term calculus on a signature \Sigma.

• objects: variable context \Gamma = (v_1 : T_1, ..., v_n : T_n)
• morphisms: \Gamma \to \Delta is a m-tuples (M_1, ..., M_m) of terms such that we can derive \Gamma \vdash M_i : T_i where \Delta = (v_1 : T_1, ..., v_m : T_m)

Identity is ensured by use variables of the context as terms. Composition is a k-tuples (L_1, ..., L_k) defined by simultaneous substitution L_i = N_i[M_1/v_1, ..., M_m/v_m]

472 tt-000P.rss.xml Proposition tt-000P tt-000P.xml 2023 10 29 Lîm Tsú-thuàn Classifying category has finite products

For any two contexts \Gamma and \Delta, the concatenation \Gamma , \Delta is the product of them. 473 math-001X.rss.xml Definition math-001X math-001X.xml 2023 10 29 Lîm Tsú-thuàn Elementary topos (plural topoi)

A topos \xi is a category with all finite limits, equipped with an object \Omega, and for each \xi-object A, there is an isomorphism for subobjects of A and morphisms from A \to \Omega. \text {Sub}_{ \xi }( A ) \cong \text {Hom}_{ \xi }( A , \Omega ) The condition ensures \Omega is a subobject classifier. Then, a functor P : \xi ^{op} \to \xi with condition \text {Hom}_{ \xi }( B \times A , \Omega ) \cong \text {Hom}_{ \xi }( A , PB ) This also tells PB = \Omega ^B. We can combine them into one condition. \text {Sub}_{ \xi }( B \times A ) \cong \text {Hom}_{ \xi }( A , \Omega ^B )

474 math-002J.rss.xml Definition math-002J math-002J.xml 2023 11 4 Lîm Tsú-thuàn Another topos definition

We can also define topos as a cartesian closed category with a subobject classifier. This version is not that essential but convenience to work with, also

475 tt-000Q.rss.xml Definition tt-000Q tt-000Q.xml 2023 10 29 Lîm Tsú-thuàn Models of signature and their category

A model of many-typed signature \Sigma in a category B with finite products, is a functor from classifying category to B Cl( \Sigma ) \xrightarrow { \mathcal {M}} B preserving finite products. Natural transformations between models \mathcal {M}, \mathcal {N} : Cl( \Sigma ) \to B form a category of B-models.

476 math-001Y.rss.xml Definition math-001Y math-001Y.xml 2023 10 29 Lîm Tsú-thuàn Subobject classifier

A subobject classifier in a category C with finite limits is a monic true : 1 \to \Omega, such that for every monic m : S \rightarrowtail A there is a unique morphism \phi forms a pullback square. By abuse of language, a subobject of A is an object S that with a monic m : S \rightarrowtail A, or the monic m. The class of subobjects of A is \text {Sub}_{ C }( A ).

477 math-001W.rss.xml math-001W math-001W.xml 2023 10 28 Lîm Tsú-thuàn Category of span

A span is a \mathcal {C}-diagram A \leftarrow C \rightarrow B, there is a category of span with fixed \mathbb {C}-objects A, B is:

• objects: A \leftarrow C \rightarrow B
• morphisms: given by the below diagram, the red-colored morphism h The product A \times B is a terminal of this category.

478 math-001V.rss.xml Definition math-001V math-001V.xml 2023 10 28 Lîm Tsú-thuàn Product and coproduct (category theory)

A product of two C-object a, b is an object p with a pair of morphisms a \xleftarrow { \pi _1} p \xrightarrow { \pi _2} b , makes below diagram commutes , and the dashed line is unique. We usually denoted product as a \times b. The dual coproduct is an object c with a pair of morphisms a \xrightarrow {inj_1} c \xleftarrow {inj_2} b , makes below diagram commutes , and the dashed line is unique. We usually denoted coproduct as a + b.

479 math-001W.rss.xml math-001W math-001W.xml 2023 10 28 Lîm Tsú-thuàn Category of span

A span is a \mathcal {C}-diagram A \leftarrow C \rightarrow B, there is a category of span with fixed \mathbb {C}-objects A, B is:

• objects: A \leftarrow C \rightarrow B
• morphisms: given by the below diagram, the red-colored morphism h The product A \times B is a terminal of this category.

480 math-001T.rss.xml Definition math-001T math-001T.xml 2023 10 27 Lîm Tsú-thuàn Functor

A functor F is a tranformation between two categories C, D, which

• assigns each C-object c an D-object Fc,
• assigns each C-morphism f a D-morphism Ff.
and requires equations
1. identity F(1_c) = 1_{Fc}
2. composition F (a \circ b) = Fa \circ Fb

481 math-002A.rss.xml Collary math-002A math-002A.xml 2023 10 27 Lîm Tsú-thuàn Endofunctor

C \to C functor is called endofunctor.

482 math-001U.rss.xml Definition math-001U math-001U.xml 2023 10 27 Lîm Tsú-thuàn Weakly initial

An object x is weakly initial if for every other object y there is a morphism x \to y.

483 math-001O.rss.xml Definition math-001O math-001O.xml 2023 10 24 Lîm Tsú-thuàn Initial algebra

F-algebra (F, i, j) is an initial algebra if and only if F \ i is an initial object of the category of F-algebras.

484 cs-000D.rss.xml cs-000D cs-000D.xml 2023 10 23 Lîm Tsú-thuàn Derive Y combinator

Consider F is a fixed point we are seeking, then F' = \lambda f. F(f \; f) is a variant version of F, by f \; f = f and F \; x = x we believing. Now, using substitution we can obtain F' F' = F(F' F'), which means F' F' is the fixed point of F. Therefore, we derived ( \lambda f. F(f \; f)) ( \lambda f. F(f \; f)) and the Y combinator is \lambda F. ( \lambda f. F(f \; f)) ( \lambda f. F(f \; f))

485 math-001H.rss.xml Proposition math-001H math-001H.xml 2023 10 23 Lîm Tsú-thuàn Preserve finite order

If g \in G is an element of finite order, and \varphi : G \to H is a homomorphism, then | \varphi (g) | divides |g|.

Proof. Let n be the order of g, then \varphi (g)^n = \varphi (g^n) = \varphi (1_G) = 1_H By lemma we know | \varphi (g)| divides |g|.
486 math-001D.rss.xml Definition math-001D math-001D.xml 2023 10 22 Lîm Tsú-thuàn Hausdorff space (<tex>T_2</tex> space)

A space X is Hausdorff if and only if for every two points x, y \in X (where x \ne y), there exist disjoint open sets U and V with x \in U and y \in V.

487 math-001E.rss.xml Example math-001E math-001E.xml 2023 10 22 Lîm Tsú-thuàn Metric spaces are Hausdorff

Let x, y be points in a metric space, we will get a distance d(x, y) > 0 if x \ne y, then pick two open balls B(x, \frac {d(x,y)}{2}) and B(y, \frac {d(x,y)}{2}) are indeed disjoint.

488 math-0019.rss.xml Definition math-0019 math-0019.xml 2023 10 19 Lîm Tsú-thuàn Category <tex>\text {Grp}</tex>

The category \text {Grp}'s objects are formed by all groups, and morphisms are group homomorphism.

489 math-0018.rss.xml Definition math-0018 math-0018.xml 2023 10 19 Lîm Tsú-thuàn Group homomorphism

• 一個底層集合 G
• 一個滿足特定要求的二元運算 m_G : G \times G \to G 490 math-001A.rss.xml Proposition math-001A math-001A.xml 2023 10 19 Lîm Tsú-thuàn The unit and inverse are preserved via group homomorphism

The statement can be expressed as: Let \varphi : G \to H be a group homomorphism, then

• \varphi (1_G) = 1_H
• and \forall g \in G, \varphi (g^{-1}) = \varphi (g)^{-1}.

Proof.

For the first property, we use 1_H \cdot \varphi (1_G) = \varphi (1_G) = \varphi (1_G \cdot 1_G) = \varphi (1_G) \cdot \varphi (1_G) as the lemma, by cancel \varphi (1_G) we get 1_H = \varphi (1_G).

For the second part, we use \varphi (a) \cdot \varphi (a)^{-1} = 1 = \varphi (1) = \varphi (a \cdot a^{-1}) = \varphi (a) \cdot \varphi (a^{-1}) as the lemma, by cancel \varphi (a) we get \varphi (a)^{-1} = \varphi (a^{-1}).

491 math-001B.rss.xml math-001B math-001B.xml 2023 10 20 Lîm Tsú-thuàn Formalization in lean

Before we start to prove the proposition, we have to define is_hom for what's a homomorphism

def is_hom [Group G] [Group H] [MulHomClass F G H]
(φ : F) : Prop := ∀ a b : G, φ (a * b) = φ (a) * φ (b)


Then below code proves the proposition

theorem preserve_identity [Group G] [Group H] [MulHomClass F G H]
(φ : F) : is_hom φ → 1 = φ 1 := by
intro H
have inner_one : φ 1 = φ (1 * 1) := by
refine Eq.symm (FunLike.congr_arg φ ?h₂)
exact one_mul 1
have lem : 1 * φ 1 = φ 1 * φ 1 := by
rw [one_mul <| φ 1, ← H]
exact inner_one
apply mul_right_cancel (a := 1) (b := φ 1) (c := φ 1) lem

theorem preserve_inv [Group G] [Group H] [MulHomClass F G H]
(φ : F) : is_hom φ → ∀ a : G, (φ a)⁻¹ = φ a⁻¹ := by
intro H a
have lem : φ a * (φ a)⁻¹ = φ a * φ a⁻¹ := by
refine Iff.mpr mul_left_cancel_iff ?_
refine DivisionMonoid.inv_eq_of_mul (φ a) (φ a⁻¹) ?_
rw [← H, mul_right_inv a]
exact Eq.symm (preserve_identity φ H)
exact mul_left_cancel (a := φ a) (b := (φ a)⁻¹) (c := φ a⁻¹) lem

imports
import Mathlib.Algebra.Group.Defs
import Mathlib.Algebra.Hom.Group.Defs

492 cs-000C.rss.xml cs-000C cs-000C.xml 2023 10 18 Lîm Tsú-thuàn 量子位元基本運算
• 第一種運算是 NOT \oplus，會把量子位元中的左 |0 \rangle 與右 |1 \rangle 互換
• 第二種運算 HAD \fbox {H} 會把疊加態均分，但在初始為偏右時會旋轉右的相位。另外，與 NOT 相同的是套用兩次同樣會回到原本的狀態
493 software-0009.rss.xml software-0009 software-0009.xml 2023 10 11 Lîm Tsú-thuàn Nix 指令更新

494 math-0014.rss.xml Definition math-0014 math-0014.xml 2023 10 11 Lîm Tsú-thuàn Point surjective

A morphism A \xrightarrow { \phi } B is point-surjective iff for every point 1 \xrightarrow {q} B, there exists a point 1 \xrightarrow {p} A that lifts q (satisfy \phi \circ p = q).

495 software-000A.rss.xml software-000A software-000A.xml 2023 10 11 Lîm Tsú-thuàn Proof search in Lean4 https://proofassistants.stackexchange.com/a/415/302

With below line in Lean prover

import Mathlib.Tactic.LibrarySearch


One can use exact?, apply? tactics to search in Lean4 library.

496 math-0015.rss.xml Definition math-0015 math-0015.xml 2023 10 11 Lîm Tsú-thuàn Weakly point surjective

A morphism \phi : B \to C^A is weakly point surjective, iff for every A \xrightarrow {f} C there is 1 \xrightarrow {x} B such that for every 1 \xrightarrow {a} A, we have commute diagram The C^A \to C^A \times A is given by This is a weaker version of point-surjective.

497 cs-0006.rss.xml cs-0006 cs-0006.xml 2023 10 10 Lîm Tsú-thuàn Lazy lambda calculus reduction model & computation resource https://golem.ph.utexas.edu/category/2015/05/a_2categorical_approach_to_the.html 498 cs-0007.rss.xml cs-0007 cs-0007.xml 2023 10 10 Lîm Tsú-thuàn The algebra of term constructors

A functor LC : Set \to Set takes any set of variables V to the set of term T = LC(V), this is the term constructors' algebra. \begin {aligned} &- : &V \to T \quad & \text {mbox variable} \\ &-(-) : &T \times T \to T \quad & \text {mbox abstraction} \\ & \lambda : &V \times T \to T \quad & \text {mbox application} \\ \end {aligned}

499 cs-0008.rss.xml cs-0008 cs-0008.xml 2023 10 10 Lîm Tsú-thuàn Infinite loop

Consider \Omega = \omega ( \omega ) where \omega = \lambda x. x(x), it's easier to verify \Omega \downarrow _{ \beta } \Omega, an infinite loop. Now think about ( \lambda x. \lambda y. x)( \lambda x. x)( \Omega ), this example is interesting if we consider eager/lazy semantic. In the eager semantic, the result is stuck due to \Omega, because we calculate \Omega before we use it as an argument. In the lazy semantic, the result is identity function \lambda x.x.

500 cs-0009.rss.xml cs-0009 cs-0009.xml 2023 10 10 Lîm Tsú-thuàn The idea of the post

The key point of the post is about: when \beta-reduction can happend anywhere in the term, there are too many 2-morphisms to model lazy lambda calculus. Therefore, the post suggests introducing reduction context [-] : T \to T into the algebra above, for marking where we can do \beta-reduction. The new rules are

1. Propagates the reduction context to the head position of the term. [t(t')] \downarrow _{ \text {ctx}} [[t] (t')]
2. Restrict \beta-reduction to a reduciton context. [[ \lambda x. t] (t')] \downarrow _{ \beta } [t] \{ t'/ x \}
The rules correctly works on the above example \begin {aligned} & \quad \quad \quad [( \lambda x. \lambda y. x)( \lambda x. x)( \Omega )] \\ & \downarrow _{ \text {ctx}} \quad [[( \lambda x. \lambda y. x) ( \lambda x. x)] ( \Omega )] \\ & \downarrow _{ \text {ctx}} \quad [[[ \lambda x. \lambda y. x] ( \lambda x. x)] ( \Omega )] \\ & \downarrow _{ \beta } \quad \; \; [[ \lambda y. ( \lambda x. x)] ( \Omega )] \\ & \downarrow _{ \beta } \quad \; \; [ \lambda x. x] \end {aligned}

501 cs-000A.rss.xml cs-000A cs-000A.xml 2023 10 10 Lîm Tsú-thuàn Reuse the idea to limit computation

The post also suggests if we replace rule [t(t')] \downarrow _{ \text {ctx}} [[t] (t')] with [t(t')] \downarrow _{ \text {ctx}} [t] (t') the number of occurences of [ - ] will never increase. Then [[ \cdots [t] \cdots ] ] the number of \beta-reductions are bound. In the paper, they reuse this way to represent a processor or computer in a network.

Below implements a part of the system.

inductive Tm : Type where
| var : String → Tm
| app : Tm → Tm → Tm
| lam : String → Tm → Tm
| ctx : Tm → Tm

def Tm.subst (t : Tm) (s : Tm) (x : String) : Tm :=
match t with
| .var y => if x == y then s else .var y
| .app t u => .app (t.subst s x) (u.subst s x)
| .lam y b => if x == y then .lam y b else .lam y (b.subst s x)
| .ctx t => .ctx (t.subst s x)

def Tm.r : Tm → Tm
| .ctx (.app t t') => .ctx (.app (.ctx t |> r) t')
| t => t
def Tm.β : Tm → Tm
| .ctx (.app (.ctx (.lam x t)) t') => subst (.ctx t) t' x
| .ctx t => .ctx (t.β)
| .app t t' => .app t.β t'
| t => t

def ω : Tm := .lam "x" (.app (.var "x") (.var "x"))
def Ω : Tm := (.app ω ω)
def e : Tm :=
(.ctx (.app (.app (.lam "x" (.lam "y" (.var "x")))
(.lam "x" (.var "x")))
Ω))

#eval e
#eval e.r
#eval e.r.β
#eval e.r.β.β

502 software-0008.rss.xml software-0008 software-0008.xml 2023 10 10 Lîm Tsú-thuàn 用 quarto 產出 reveal.js 簡報

Quarto 這個工具有相當多功能，我只是想要移植以往放在 hackmd 上的簡報，因為簡報使用了 graphviz 的功能，所以我沒有辦法像 hami2023 那樣直接嵌入這個網站裡面，至少 reveal.js 內建的功能沒辦法如此。而 quarto render 產生的網頁也一樣有問題，所以最後 type cafe2023 跟 hami2022 還是放到了獨立的專案之中，用 GitHub Pages 運作。這篇筆記因而誕生，首先要用

quarto create-project <name>


title: "XXX"
format: revealjs


format:
revealjs:
theme: dark


{dot}
graph G {
layout=neato
run -- intr;
intr -- runbl;
runbl -- run;
run -- kernel;
kernel -- zombie;
kernel -- sleep;
kernel -- runmem;
sleep -- swap;
swap -- runswap;
runswap -- new;
runswap -- runmem;
new -- runmem;
sleep -- runmem;
}



quarto publish gh-pages

503 math-000X.rss.xml math-000X math-000X.xml 2023 10 5 Lîm Tsú-thuàn Proof Net 雜記

Proof net 是 Girard 的 linear logic 引入的一種新語法，用圖去表現證明，在研究 cut-elimination 時更加方便。

504 tt-000I.rss.xml tt-000I tt-000I.xml 2023 10 5 Lîm Tsú-thuàn Parametricity properties

Polymorphic type in System F severely constrain the behavior of their elements. For example, if i : \forall (t.t \to t), then the definition can only be i = \lambda x.x.

Similarly, there only have two terms, \Lambda t. \lambda x : t. \lambda y : t. x and \Lambda t. \lambda x : t. \lambda y : t. y with type \forall (t.t \to t \to t).

Such thing that, properties of a program in System F can be knowing by type known as parametricity properties.

505 software-0005.rss.xml software-0005 software-0005.xml 2023 10 1 Lîm Tsú-thuàn Git send-email 的設定

I use gmail, and hence, I need to get a Google app password. After having the password, one has to setup ~/.gitconfig with content:

[sendemail]
smtpEncryption = tls
smtpServer = smtp.gmail.com
smtpServerPort = 587


Then you are able to use git send-email command:

git format-patch -n HEAD^
git send-email 0001-***********.patch


prompt will ask some questions, an important one is which mailing list is your target? After command success, your patch are sent.

506 cs-0005.rss.xml Theorem cs-0005 cs-0005.xml 2023 9 29 Lîm Tsú-thuàn Turing halting

Let P be a program that takes a string S as input, returns a yes-no answer P(S) as output, and which always halts in finite time. Then there exists a string G that is a program with no input, such that if P is given G as input, then P does not determine correctly whether G halts in finite time.

Proof. Define Q(R) to be the program taking a string R as input which does the following
1. If R is not a program that takes a string as input, it halts.
2. Otherwise, if runs P with input R(R) (which is a program with no inpupt).
3. If P(R(R)) returns no, it halts, while if P(R(R)) returns yes, it runs forever.
Now, let G be the program Q(Q). By setup, G halts if and only if P(G) returns no.
507 math-000T.rss.xml Lemma math-000T math-000T.xml 2023 9 29 Lîm Tsú-thuàn Zorn's

Let C be a partially ordered class with

1. At least one element belongs to C
2. If x \in C, then there is y \in C such that y > x
3. If (x_ \beta )_{ \beta \in B} is a totally ordered set in C, indexed by another set B, then there exists an upper bound y \in C such that y \ge x_ \beta for all \beta \in B
Then C is not a set.

• This lemma is equivalent to axiom of choice.
508 cs-0004.rss.xml Proposition cs-0004 cs-0004.xml 2023 9 27 Lîm Tsú-thuàn Busy beaver function

Let f : \N \to \N be a computable function. Then there exists a natural number n and a program G of length n (taking no input) that halts in finite time, but requires more than f(n) steps before it halts.

Proof. Let P(S) be the program that simulates S for f(n) steps, where n is the length of S, and returns yes if S is halted by the time, returns no otherwise. Then the program G generated from Turing halting theorem is such that P does not correctly determine if G halts. Since if G halts, then P(G) must be no, which implies G takes more then f(n) steps.
509 math-0004.rss.xml Definition math-0004 math-0004.xml 2023 9 26 Lîm Tsú-thuàn Slice & Coslice category

For a category C and an object x \in C, there is a slice category C/x and a coslice category x/C (dual concept).

C/x-objects are all C-morphisms where target is x, C/x-morphisms are all C-morphism g where makes the following diagram commutes: x/C-objects is dual, they are C-morphisms where source is x.

510 math-001F.rss.xml Proposition math-001F math-001F.xml 2023 2 24 Lîm Tsú-thuàn <tex>(a, id_a)</tex> is <link href="math-002F.xml" type="local" title="Initial and terminal (category theory)">terminal</link> of <tex>A/a</tex>

It's easy to prove the statement by checking the following diagram is commute. or we can also reduce the diagram to Draw a A/a diagram makes it clear, the following relationship stands for every proper b in A. 511 math-001G.rss.xml Proposition math-001G math-001G.xml 2023 2 24 Lîm Tsú-thuàn Any <tex>f : a \to a'</tex> in <tex>A</tex> gives functor <tex>f_* : A/a \to A/a'</tex>

The functor f_* takes any object g : b \to a of A/a to f \circ g of A/b.

The first point is realizing if such f existed, then we have same two b, b', for both a, a', by concating f after every b \to a morphism. This makes sure we will have if objects existed in A/a so do in A/a', remember functor no need to cover A/a'. Now, we can have the proof diagram: Convert it to a functor diagram will help. 512 math-000S.rss.xml Example math-000S math-000S.xml 2023 9 11 Lîm Tsú-thuàn <tex>\bold {Sets}/I</tex>

The \bold {Sets}/I is a category with

• objects families (X \xrightarrow { \varphi } I)
• morphisms (X \xrightarrow { \varphi } I) \xrightarrow {f} (Y \xrightarrow { \psi } I) are functions f : X \to Y making the following diagram commutes: The identities and compotision in \bold {Sets}/I are inherited from \bold {Sets}.

513 math-002B.rss.xml Collary math-002B math-002B.xml 2023 10 31 Lîm Tsú-thuàn Slice of sets is set-valued functor \bold {Sets}/A \cong \bold {Sets}^A

Combine with topos fundamental theorem, the category of presheaves is a topos.

514 math-000P.rss.xml Definition math-000P math-000P.xml 2023 9 26 Lîm Tsú-thuàn Functor category

For any two categories C, D, their functors and natural tranformations form a category [C, D].

• The objects are functors with type C \to D.
• The morphisms are natural tranformations for functors.

515 math-000N.rss.xml Lemma math-000N math-000N.xml 2023 9 26 Lîm Tsú-thuàn Size of functor categories
• If category C is small and D is locally small, then functor category [C, D] is locally small.
• If category C and D are locally small, then [C, D] need not be locally small.
516 tt-000H.rss.xml Theorem tt-000H tt-000H.xml 2023 9 24 Lîm Tsú-thuàn <tex>(A \iff (A \to B)) \to B</tex> https://mathstodon.xyz/@MartinEscardo/111115846596114122

Here is a proof in Lean4.

variable (A B : Prop)

theorem h (a : A ↔ (A → B)) : B :=
match a with
| ⟨f, g⟩ =>
f (g (λ a => f a a))
(g (λ a => f a a))

517 tt-000D.rss.xml tt-000D tt-000D.xml 2023 9 23 Lîm Tsú-thuàn Go 的 interface

Go 語言的 interface，範例如下

type Abser interface {
Abs() float64
}


type A interface {
F(C) D
}
type B interface {
F(C) D
}


518 math-000L.rss.xml math-000L math-000L.xml 2023 9 23 Lîm Tsú-thuàn Group by Category

If a small category \mathcal {C} has only one object, and each morphism is an isomorphism, then there is group detected by the category.

Category \mathcal {C} Group G
morphisms in \mathcal {C} elements of the group
composition of morphism The binary operation of the group
identity morphism of the only object identity element of the group
519 tt-000E.rss.xml tt-000E tt-000E.xml 2023 9 23 Lîm Tsú-thuàn Java 的 interface 與 bounded polymorphism (bounded quantification)

interface Comparable<T> {
int compareTo(T other);
}


<S extends Comparable> S min(S a, S b)


520 math-000K.rss.xml Definition math-000K math-000K.xml 2023 9 23 Lîm Tsú-thuàn Partial order

Usual definition is, a partial order is a preorder such that anti-symmetric, which means if A \le B and B \le A, then A = B.

A category version is a preorder such that any isomorphism is actually identical.

521 math-000J.rss.xml Definition math-000J math-000J.xml 2023 9 23 Lîm Tsú-thuàn Preorder

The usual definition of preorder is a set X with a binary relation \le, where the relation is reflexive and transitive.

The category version of preorder is a small category whenever all composition morphism of A \to B and B \to C is the unique morphism A \to C. Or we can describe it as there is at most one morphism from one object to another.

522 math-000M.rss.xml math-000M math-000M.xml 2023 9 23 Lîm Tsú-thuàn 結成浩的費馬最後定理玩笑
#lang rhombus

operator n^m:
~stronger_than: +
math.expt(n, m)

• 951413^7 + 853562^7 = 1035740599994317978862520154990926528420925
• 1005025^7 = 1035709726461858968099232282235113525390625
523 software-0002.rss.xml software-0002 software-0002.xml 2023 9 18 Lîm Tsú-thuàn Find command

For example, one can cd /usr/local and search simdjson library related files

find . -name 'simdjson*'

524 math-000H.rss.xml Definition math-000H math-000H.xml 2023 9 17 Lîm Tsú-thuàn <tex>\omega</tex>-chain

A \omega-chain (x_n)_{n \in \omega } in partial order D is a set of elements x_n \in D such that x_n \sqsubseteq x_m whenever n \le m. A partial order D is \omega-complete (and hance an \omega-cpo) if every \omega-chain has a least upper bound. Given \omega-cpo's D and E, a monotone function f : D \to E is said to be \omega-continuous if

f( \bigsqcup _{n \in \omega } x_n) = \bigsqcup _{n \in \omega } f(x_n)

for any \omega-chain (x_n)_{n \in \omega }.

\omega-chain preserves it's least upper bound with \omega-continuous function.
525 math-000I.rss.xml Theorem math-000I math-000I.xml 2023 9 17 Lîm Tsú-thuàn Fixed Points in <tex>\omega</tex>-Cpo's

Suppose D is \omega-cpo and f : D \to D is \omega-continuous. For x \in D such that x \sqsubseteq f(x), there is a least element y \in D such that

1. y = f(y), and
2. y \sqsubseteq z for any fixed point z \in D such that bigger than x (x \sqsubseteq z)
526 math-000F.rss.xml Theorem math-000F math-000F.xml 2023 9 17 Lîm Tsú-thuàn Fixed Point

If D is a pointed cpo and f : D \to D is continuous, then it has a least fixed point \text {fix}(f) \in D that satisfied

1. \text {fix}(f) = f( \text {fix}(f) ), and
2. \text {fix}(f) \sqsubseteq x for any fixed point x \in D (A fixed point means x = f(x)).
527 tt-000C.rss.xml tt-000C tt-000C.xml 2023 9 17 Lîm Tsú-thuàn Functors and Type Refinement system

Read the Functors are Type Refinement Systems, also Two Papers about Refinement Types

528 tt-000B.rss.xml tt-000B tt-000B.xml 2023 9 17 Lîm Tsú-thuàn Lean4's Vector

Instead of usual definition, the Vector in Lean Prover is based on subtype.

def Vector (α : Type u) (n : ℕ) :=
{ l : List α // l.length = n }

529 cs-0002.rss.xml cs-0002 cs-0002.xml 2023 9 17 Lîm Tsú-thuàn Rhombus: definition of function

Three ways of writing factorial

fun factorial(x):
match x
| 0: 1
| n: n * factorial(n-1)

fun
| factorial(0): 1
| factorial(n): n * factorial(n-1)

operator n!:
~stronger_than: + - * /
match n
| 0: 1
| _: n * (n - 1)!

530 cs-0003.rss.xml cs-0003 cs-0003.xml 2023 9 17 Lîm Tsú-thuàn Rhombus: repetitions

Repetitions is a syntax extension of rhombus language.

def [n, ...] = [1, 2, 3]
[factorial(n), ...]      // [1, 2, 6]
[n+10, ...]              // [11, 12, 13]

531 tt-0004.rss.xml tt-0004 tt-0004.xml 2023 9 15 Lîm Tsú-thuàn An usual <tex>\mathbb {Z}</tex> definition
def T : Nat -> Type
| 0 => Unit
| .suc _ => Bool

inductive Int : Type where
| mk : (n : Nat) -> T n -> Int


Therefore, the definition has

• Int.mk 0 () for 0
• Int.mk n true for positive integer n
• Int.mk n false for negative integer -n

For the same number indeed has definitional equality.

532 tt-0005.rss.xml tt-0005 tt-0005.xml 2023 9 15 Lîm Tsú-thuàn Pattern matching on Types: An indirected universe

By introduce a indirect level of universe \mathcal {U} ^-, such that a subtype of normal universe \mathcal {U}, and allows pattern matching. By restricting it can only be used at inductive type definitions' dependent position, it preserves parametricity, solves the problem easier compare with subscripting universe. In this setup, every defined type has type \mathcal {U} ^- first, and hence

• \mathbb {N} : \mathcal {U} ^-
• \mathbb {B} : \mathcal {U} ^-
• \mathbb {L} : \mathcal {U} \to \mathcal {U} ^-

\mathbb {L} didn't depend on \mathcal {U} ^-, so we keep using tagless encoding to explain

data Term Type
| ℕ => add (Term ℕ) (Term ℕ)
| 𝔹 => eq (Term ℕ) (Term ℕ)
| a => if (Term 𝔹) (Term a) (Term a)
| a => lit a


We have \text {Term} : \mathcal {U} ^- \to \mathcal {U} ^-, and then, if one wants List (Term Nat) it still work since \mathcal {U} ^- \le \mathcal {U}. But if one tries to define code below:

inductive Split Type^
| Nat => nat
| Bool => bool
| _ => else

def id (A : Type) (x : A) : A =>
match Split A
| nat => 0
| bool => false
| _ => x


Since the \mathcal {U} isn't the subtype of \mathcal {U} ^-, program Split A won't type check, the definition will not work as intended. This is indeed more boring than subscripting universe, but easier to check it does't break parametricity.

Till now, I haven't start to check the pattern of type, except the primitive exact value, if I'm going to push this further, a good example is:
inductive K Type^
| List a => hi a
| _ => he

This is quite intuitive since in implementation inductive types' head are also rigid values, just like constructors.
533 cs-0001.rss.xml cs-0001 cs-0001.xml 2023 9 15 Lîm Tsú-thuàn Scheduler

For each process:

shared scheduler_lock : SpinLock

procedure reschedule()
loop
if t != null
exit
scheduler_lock.release()
scheduler_lock.acquire()
transfer(t)

procedure yield()
disable_signals()
scheduler_lock.acquire()
reschedule()
scheduler_lock.release()
reenable_signals()

reschedule()

534 forester-0001.rss.xml Table forester-0001 forester-0001.xml 2023 9 15 Jon Sterling Transclusion options in Forester 2.2 https://www.jonmsterling.com/jms-0069.xml
Fluid Binding Default Meaning
\transclude/title (none) To override the tree's title during transclusion.
\transclude/taxon (none) To override the tree's taxon during transclusion.
\transclude/toc true Show the tree in the table of contents.
\transclude/expanded true Whether the tree is expanded or not.
\transclude/heading true If set to false, the tree's contents will be inlined.
\transclude/metadata false Show in a tree's heading.
\transclude/numbered true Whether the tree is displayed with a number or not, transitively on subtrees.
535 math-000D.rss.xml math-000D math-000D.xml 2023 9 14 Lîm Tsú-thuàn Cartesian Closed Category 536 math-002H.rss.xml Definition math-002H math-002H.xml 2023 9 14 Lîm Tsú-thuàn Cartesian closed category (Elements of ∞-Category Theory §A.1)

A category \mathcal {V} is cartesian closed when it

• admits finite products, or equivalently, a terminal object 1 \in \mathcal {V} and binary products and,
• for each v \in \mathcal {V}, the functor v \times - : \mathcal {V} \to \mathcal {V} admits a right adjoints (-)^v : \mathcal {V} \to \mathcal {V}.
537 math-002I.rss.xml Definition math-002I math-002I.xml 2023 11 4 Lîm Tsú-thuàn Introduction version

The introduction version about cartesian closed is focusing on having

• terminal object 1
• product A \times B for any two objects A, B
• exponential B^A for any two objects A, B

Of course, they are equivalent.

538 math-000E.rss.xml Example math-000E math-000E.xml 2023 9 14 Lîm Tsú-thuàn
1. The category of sets \bold {Sets} is cartesian closed, with B^A defined to be the set of functions from A to B. It is actually an example of topos.
2. The category of small categories \mathcal {Cat} is cartesian closed, with B^A defined to be the category of functors and natural transformations from A to B.
3. The category of Scott domains \mathcal {SDom} is cartesian closed.
539 tt-0009.rss.xml tt-0009 tt-0009.xml 2023 9 14 Lîm Tsú-thuàn Subscripting <em>Inductive types</em>

An intutive extension of inductive types is, let constructor be subscripting set of the inductive type. For example, a type with definition

inductive Nat
| zero
| suc Nat


A type Nat[suc] means only suc ... is a term, zero cannot have type Nat[suc]. It's easy to see NatNonZero = Nat[suc], this can also apply to

• List1 = List[cons]
• Int is also a good motive example
    inductive Int
| 0
| + Int[+, zero]
| - Int[-, zero]
Int[+] is positive, Int[-] is negative. The diagram in its syntactic category: To ensure this, if the following syntax of each constructor c is a list of argument types Ti ..., we say the type of constructor of type T is Ti ... -> T[c]. The corresponding part is pattern matching's type rules will refine type T with the pattern matched constructor c, below marks all binder's refined type. The type T[c, ...] is a subtype of T.

def foo : Int -> Int
| 0 => 0
| + p =>
-- p : Int[+, 0]
p
| - n =>
-- n : Int[-, 0]
n

An obvious problem is
def neg : Int -> Int
| 0 => 0
| + p => - (neg p)
| - n => + (neg p)

We can see that the type information is squeezed, the second and third case need type casting. A potential solution is case type, and hence, neg has type like: neg : \begin {cases} Int_{} \to Int_{} \\ Int_{[+]} \to Int_{[-]} \\ Int_{[-]} \to Int_{[+]} \end {cases} But then what's the type rule of it? Will need some time to explore.
540 math-000C.rss.xml Definition math-000C math-000C.xml 2023 9 13 Lîm Tsú-thuàn Monoidal Categories & <tex>\mathcal {V}</tex>-enriched Categories
From Category Theory for Programmers.

A category is a \mathcal {V}-enriched category (or \mathcal {V}-category) if its morphisms is the objects of its based monoidal category \mathcal {V}, we may also describe it as it's enriched from \mathcal {V}. This is the most general definition I known.

NOTE: In Elements of ∞-Category Theory the enrichment is more specific than this, the base is a cartesian closed category.
541 math-000Q.rss.xml Definition math-000Q math-000Q.xml 2023 9 26 Lîm Tsú-thuàn A more restricted definition of enrichment

From Seven Sketches in Compositionality
Let \mathcal {V} = (V, \le , I, \otimes ) be a symmetric monoidal preorder. A \mathcal {V} \text {-category} \mathcal {X} consists of two contituents
1. one specifies a set Ob( \mathcal {X} ), elements of the set are objects
2. for every two objects x,y, one specifies an element \mathcal {X} (x,y) \in V, called the hom-object
they satisfy two propreties
1. for every object x \in Ob( \mathcal {X} ), we have I \le \mathcal {X} (x, x)
2. for every three objects x,y,z \in Ob( \mathcal {X} ), we have \mathcal {X} (x,y) \otimes \mathcal {X} (y,z) \le \mathcal {X} (x,z)
We call \mathcal {V} the base of enrichment for \mathcal {X}, or say that \mathcal {X} is enriched in \mathcal {V}.

542 math-000R.rss.xml Example math-000R math-000R.xml 2023 9 26 Lîm Tsú-thuàn <strong>Bool</strong>

\bold {Bool}-categories are preorders. Notice that, \bold {Bool} itself is a preorder, and hence, \bold {Bool} is enriched itself.

The definition of \bold {Bool} is a preorder which has only two objects 0, 1, and the only morphism is 0 \to 1. Where the tensor product result are:

• 0 \otimes 0 = 0
• 0 \otimes 1 = 0
• 1 \otimes 0 = 0
• 1 \otimes 1 = 1

543 jp-0001.rss.xml jp-0001 jp-0001.xml 2023 9 12 Lîm Tsú-thuàn Daily Japanese
Japanese 中文
うどん 烏龍麵
うどん ていし よくはいくら ですか 烏龍麵定食要多少錢？
ラーメン　を　ひとつ　ください 請給我一碗拉麵
コーピー　を　ふたつ　ください 請給我兩杯咖啡
544 finnish-0001.rss.xml finnish-0001 finnish-0001.xml 2023 9 12 Lîm Tsú-thuàn Daily Suomea
Suomea English
Jää on kylmää. Ice is cold.
Marja on pieni ja sininen. The berry is small and blue.
Puro on jäässä. The stream is frozen.
Koko puro on jäässä. The whole stream is frozen.
Koko perhe etsii poroa. The whole family is looking for the reindeer.
Karhu seisoo kylmässä purossa. The bear is standing in the cold stream.
Harmaa velho kävelee metsässä. The gray wizard walks in the forest.
545 tt-0002.rss.xml tt-0002 tt-0002.xml 2023 9 12 Lîm Tsú-thuàn System F 中的 <tex>1</tex> 與 <tex>2</tex>

• \Lambda X. \lambda x. \lambda y. x
• \Lambda X. \lambda x. \lambda y. y

546 math-0003.rss.xml Definition math-0003 math-0003.xml 2023 9 11 Lîm Tsú-thuàn Family over Set

With a display function \varphi : X \to I, we say

• X is a family over I
• and that \varphi displays the family (X_i)
We often write it as (X \xrightarrow { \varphi } I). Such families (X \xrightarrow { \varphi } I) of sets gives two categories:

547 math-000S.rss.xml Definition math-000S math-000S.xml 2023 9 11 Lîm Tsú-thuàn Slice category <tex>\bold {Sets}/I</tex>

The \bold {Sets}/I is a category with

• objects families (X \xrightarrow { \varphi } I)
• morphisms (X \xrightarrow { \varphi } I) \xrightarrow {f} (Y \xrightarrow { \psi } I) are functions f : X \to Y making the following diagram commutes: The identities and compotision in \bold {Sets}/I are inherited from \bold {Sets}.

548 math-002B.rss.xml Collary math-002B math-002B.xml 2023 10 31 Lîm Tsú-thuàn Slice of sets is set-valued functor \bold {Sets}/A \cong \bold {Sets}^A

Combine with topos fundamental theorem, the category of presheaves is a topos.

549 math-0005.rss.xml Definition math-0005 math-0005.xml 2023 9 11 Lîm Tsú-thuàn Arrow category <tex>\bold {Sets}^{ \to }</tex>

The \bold {Sets}^{ \to } is a category with

• objects: families (X \xrightarrow { \varphi } I), for arbitrary sets I.
• morphisms: (X \xrightarrow { \varphi } I) \xrightarrow {(u, f)} (Y \xrightarrow { \psi } J) are pairs of functions u : I \to J and f : X \to Y for which the following diagram commutes: The identities and compotision in \bold {Sets}^{ \to } are component-wise inherited from \bold {Sets}.

550 software-0001.rss.xml software-0001 software-0001.xml 2023 9 10 Lîm Tsú-thuàn Mastodon 私訊相比於一般通訊軟體 e.g. LINE, Telegram

1. 可以有效分類特定話題，例如一個串是講約去哪裡吃飯、另一個串講專業內容
2. 可以用僅限提及的人，限制可見性，所以可以形成一定程度的群組概念

1. 兩方站點的站長都能看到內容
2. 客戶端不支援把一群提及名單固定成群組，這或許是一個可行的客戶端新功能

551 math-0001.rss.xml math-0001 math-0001.xml 2023 9 10 Lîm Tsú-thuàn 類與集合

552 math-0011.rss.xml Definition math-0011 math-0011.xml 2023 8 20 Lîm Tsú-thuàn 零測度 measure zero

553 cs-000G.rss.xml cs-000G cs-000G.xml 2023 5 30 Lîm Tsú-thuàn Tagless final

def naive_lit (x : Int) : Int := x
def naive_add (a b : Int) : Int := a + b


class Expr (α : Type) where
lit : Int → α
add : α → α → α

def lit [e : Expr α] : Int → α := e.lit
def add [e : Expr α] : α → α → α := e.add


instance : Expr Int where
lit x := x
add a b := a + b

instance : Expr String where
lit x := s!"{x}"
add a b := s!"{a} + {b}"

def expr [Expr α] : α := add (lit 1) (lit 2)

#eval (expr : String) -- "1 + 2"
#eval (expr : Int)    -- 3


class ExprSub (α : Type) where
sub : α → α → α
instance : ExprSub Int where
sub a b := a - b
instance : ExprSub String where
sub a b := s!"{a} - {b}"

def sub [e : ExprSub α] : α → α → α := e.sub

def expr [Expr α] [ExprSub α] : α := sub (add (lit 1) (lit 2)) (lit 3)
#eval (expr : String) -- "1 + 2 - 3"
#eval (expr : Int)    -- 0


tagless final（引入 Type → Type

class FTExpr (f : Type → Type) : Type where
lit : Int → f Int
add : f Int → f Int → f Int
compare : f Int → f Int → f Bool

@[reducible]
def Pretty (_ : Type) : Type := String
instance : FTExpr Pretty where
lit x := s!"{x}"
add a b := s!"{a} + {b}"
compare a b := s!"{a} =? {b}"

@[reducible]
def Eval (α : Type) : Type := α
instance : FTExpr Eval where
lit x := x
add a b := a + b
compare a b := a == b


def ftlit [e : FTExpr f] : Int → f Int := e.lit
def ftadd [e : FTExpr f] : f Int → f Int → f Int := e.add
def ftcompare [e : FTExpr f] : f Int → f Int → f Bool := e.compare

def ft_expr [FTExpr f] : f Bool := ftcompare (ftlit 3) (ftadd (ftlit 1) (ftlit 2))
def ft_expr2 [FTExpr f] : f Int := ftadd (ftlit 1) (ftlit 2)


#eval (ft_expr : Eval Bool)   -- true
#eval (ft_expr : Pretty Bool) -- "3 =? 1 + 2"
#eval (ft_expr2 : Eval Int)   -- 3
#eval (ft_expr2 : Pretty Int) -- "1 + 2"


1. 靜態檢查 syntax 的構造是正確的
2. 可以只寫擴充的部分的 syntax 跟對應的 interpreter 行為

okmij 中可以找到更多對 tagless final 的研究，但對我來說現在這樣應該就夠了 XD

554 math-002M.rss.xml Definition math-002M math-002M.xml 2023 3 20 Lîm Tsú-thuàn Category of (co)cones

With a fixed diagram \mathcal {D} \xrightarrow {F} \mathcal {C}, and natural transformations \Delta _c \to F (from different \Delta _c), we get a category that consituited by

• objects: all cone objects c above the fixed diagram (via \Delta _c functor).
• morphisms: \mathcal {C}-morphisms between cones.

Dual natural transformations F \xrightarrow { \beta } \Delta _c form cocones and a dual category.

555 math-002N.rss.xml Definition math-002N math-002N.xml 2023 3 20 Lîm Tsú-thuàn Limit (universal cone) and colimit

With a fixed diagram \mathcal {D} \xrightarrow {F} \mathcal {C}, a limit is a terminal of the category of cones, denoted as \text {Lim} F.

• notice that we can freely abuse language and say a \mathcal {C}-diagram is a functor target to \mathcal {C}
• Limit might not exist, so you have to ensure there has one.

The dual concept colimit is an initial of category of cocones.

556 tt-0008.rss.xml tt-0008 tt-0008.xml 2023 1 Lîm Tsú-thuàn Pattern matching on Type as a solution

If I simply allow pattern matching on "Type", it's able to restore encoding from the problem:

data Term Type
| ℕ => add (Term ℕ) (Term ℕ)
| 𝔹 => eq (Term ℕ) (Term ℕ)
| a => if (Term 𝔹) (Term a) (Term a)
| a => lit a


But then it breaks parametricity! One now can read what is a polymorphic type concretely:

data C (A : Type)
| ℕ => c1
| 𝔹 => c2
| _ => c3

id : {A : Type} -> C A -> A -> A
id c1 x = 3
id c2 x = false
id _ x = x

557 tt-0007.rss.xml tt-0007 tt-0007.xml 2022 12 Lîm Tsú-thuàn The encoding problem of <em>a simpler encoding of indexed types</em>

The benefit of the idea is clear, but it disallows definition like tagless interpreter:

data Term : Set → Set1 where
lit : ∀ {a} → a → Term a
add : Term ℕ → Term ℕ → Term ℕ
eq : Term ℕ → Term ℕ → Term 𝔹
if : ∀ {a} → Term 𝔹 → Term a → Term a → Term a

eval : ∀ {a} → Term a → a
eval (lit x) = x
eval (add x y) = eval x + eval y
eval (eq x y) = eval x == eval y
eval (if c t e) with eval c
eval (if c t e) | true = eval t
eval (if c t e) | false = eval e

NOTE: There is a workaround in paper, and hence, the problem is inconvenience instead of impossible.
558 math-000Z.rss.xml Proposition math-000Z math-000Z.xml 2022 11 23 Lîm Tsú-thuàn Identity in group is unique

If h \in G is an identity of group G, then h = 1_G.

Proof. h = h \cdot 1_G = 1_G
• a = a \cdot 1_G for all a
• a = h \cdot a for all a (h is an identity)
559 math-0010.rss.xml Proposition math-0010 math-0010.xml 2022 11 23 Lîm Tsú-thuàn Inverse of an element is unique

Let f has inverse a and b, then a = b

Proof. f \cdot a = e = f \cdot b By definition of inverse, f \cdot f^{-1} = e, hence
• f \cdot a = e
• f \cdot b = e
Then cancel f, only a = b make sense.
560 software-000B.rss.xml software-000B software-000B.xml 2022 11 17 Lîm Tsú-thuàn Racket 升級指令

export PATH=/Applications/Racket\ v8.7/bin:$PATH export PATH=$HOME/Library/Racket/8.7/bin:$PATH  migrate 指令 這可以把之前安裝的東西搬到新家 raco pkg migrate 8.6  561 software-000C.rss.xml software-000C software-000C.xml 2022 11 16 Lîm Tsú-thuàn 如何用 gpg 簽署 git commit GPG 還蠻麻煩的，所以順手紀錄一下整個流程順便複習自己的知識 562 software-000D.rss.xml software-000D software-000D.xml Lîm Tsú-thuàn 列出系統上的 keys gpg --list-secret-keys --keyid-format=long 讀出 keys 563 software-000E.rss.xml software-000E software-000E.xml Lîm Tsú-thuàn 生成新的 gpg key 要是你還沒有 key，那麼就需要 gpg --gen-key 先生成一把 gpg --default-new-key-algo rsa4096 --gen-key  它會詢問 • Real name: • Email address: • 確認生成 • 問你要不要 passphrase（設定就是使用的時候需要密碼） 注意要是你的 gpg key 還需要能夠加密的話，就需要用 gpg --full-generate-key 並選擇正確的選項。 564 software-000F.rss.xml software-000F software-000F.xml Lîm Tsú-thuàn 設定 git 要讓 git 採用 gpg 簽名，首先要設定 git config commit.gpgsign true  你會輸入 git config --global user.signingkey <keyid> 讓 git 知道要用哪一隻，假設說你的 key ID 是 3AA5C3431567BD2，那就會像是下面的指令 git config --global user.signingkey 3AA5C3431567BD2  565 software-000G.rss.xml software-000G software-000G.xml Lîm Tsú-thuàn 在 GitHub 上設定 要讓 GitHub 也能認出來，就需要用 gpg --export -a <keyid> 去拿到 PGP public key block，然後在SSH and GPG keys 設定頁面把 PGP public key block 填進去。 566 software-0004.rss.xml software-0004 software-0004.xml 2022 11 14 Lîm Tsú-thuàn 圖片工具 webp 轉換 brew install webp cwebp a.png -resize 60 60 -o a.webp  PNG 壓縮 brew install optipng optipng -o7 xxx.png  567 game-0001.rss.xml game-0001 game-0001.xml 2022 11 2 Lîm Tsú-thuàn 重複賽局 重複賽局假設參與者並不只做一次決策，而是反覆對某個博奕重複多次。 用不盡完備的說法，一次的勝利並不能長期帶來利益，例如對方可能報復。 而這也更加的符合很多現實世界的情況。 此外隨著階段進行也可能有均衡的變化。 568 math-001C.rss.xml math-001C math-001C.xml 2022 9 20 Lîm Tsú-thuàn Joint denial 記錄一下一個有趣的函數：joint denial（又稱為 Peirce's arrow 或是 NOR）。它的真值表是 P Q P \downarrow Q true true false true false false false true false false false true 這個函數好玩的地方是我們熟悉的所有邏輯謂詞都可以用它替換 • \neg P = P \downarrow P • P \rightarrow Q = ((P \downarrow P) \downarrow Q) \downarrow ((P \downarrow P) \downarrow Q) • P \land Q = (P \downarrow P) \downarrow (Q \downarrow Q) • P \lor Q = (P \downarrow Q) \downarrow (P \downarrow Q) 569 math-000Y.rss.xml Definition math-000Y math-000Y.xml 2022 4 10 Lîm Tsú-thuàn Archimedean Principle The Archimedean principle is: If a and b are real numbers with a > 0, then there exists a natural number n such that na > b. So n > \frac {b}{a}, by this we can have a particular example. Apply principle to an example Let a = \epsilon and b = 1, then n > \frac {1}{ \epsilon }, and \epsilon > \frac {1}{n}. Show that \inf \Big ( \Big \{ \frac {1}{n} : n \in \mathbb {N} \Big \} \Big ) = 0. Proof. Let A = \{ \frac {1}{n} : n \in \mathbb {N} \}. Since 1 and n are positive for each n \in \mathbb {N}, shows \frac {1}{n} > 0, so 0 is a lower bound of A. Let \epsilon > 0, by Archimedean principle there exists some n \in \mathbb {N} such that \frac {1}{n} < \epsilon. This element is in A and is less than 0 + \epsilon. Thus, 0 is infimum of A by definition: 0 + \epsilon is not a lower bound of A for all \epsilon > 0. 570 tt-000J.rss.xml tt-000J tt-000J.xml 2022 4 2 Lîm Tsú-thuàn Homotopy type theory 這篇是我對 HoTT(Homotopy Type Theory)目前的理解與整理。 571 tt-000K.rss.xml tt-000K tt-000K.xml Identity 要理解 hott 就要先知道 unique identity，即 x ≡ y 這樣的型別，在 extensional type theory（e.g. MLTT）裡面只有一個元素，即對 P Q : x ≡ y 可以證明 P ≡ Q。這就叫 UIP（Uniqueness of Identity Proofs） UIP : (X : Set) → ∀{x x' : X} → ∀(r s : x ≡ x') → r ≡ s UIP X {x} {.x} refl refl = refl  Axiom K 跟它的關係是 K \implies \text {UIP}\text {UIP} \implies K 但這個公理成立的時候我們沒辦法表示一些 topology，比如說 circle。因為 identity 在 HoTT 裡對應的解釋是一個 path，x ≡ y 就是 xy 的路徑，而 P Q : x ≡ y 自然就是 xy 的兩條路徑，如果 P ≡ Q 可證明，那 P 就跟 Q 可以替換，於是你可以先變成一條線，再收縮成一個點。circle 需要的兩條路徑就沒辦法成立，此類的拓墣都沒辦法表示，因此 agda 給了一個選項 without K 來取消這個公理，才能編寫 homotopy 系列的類型論。 一個具體的情況是 Bool 可以有兩種同構，也就是 id ∘ idnot ∘ not ，然而這兩條路徑在 extensional type theory 裡面無法區分，也就是可以證明兩者相等，在同倫類型論之中則否。 572 tt-000L.rss.xml tt-000L tt-000L.xml <tex>n</tex>-types 另一個重要的性質是 n-types，使用 n 維度之上沒有洞的特性來分類類型 1. 從 -2 的 contractible。繼續往下也是 contractible，contractible 即一個與點同倫的型別，因此「可收縮」 2. 到 -1 proposition 3. 0 set 4. 1 groupoid 5. 往上可以無限加，這就是 hlevel 命題被解釋成是一個點，也就是 true；或是一個什麼都沒有的空間，也就是 false。所以定義為 isProp : ∀{i} → Type i → Type i isProp A = (x y : A) → x ≡ y  573 tt-000M.rss.xml tt-000M tt-000M.xml Truncation 截斷 \vert \vert A \vert \vert 表示 A 有證明，但沒有具體證明的資訊 574 tt-000N.rss.xml tt-000N tt-000N.xml Univalence 允許用 equivalence 構造出 equality 575 software-0007.rss.xml software-0007 software-0007.xml 2022 1 22 Lîm Tsú-thuàn Let Racket GC manage your FFI object All you need are deallocator and allocator from ffi/unsafe/alloc. (require ffi/unsafe ffi/unsafe/define ffi/unsafe/alloc) (define-ffi-definer define-xxx (ffi-lib "<path to your libxxx>" '(#f))) (define-xxx free-yyy (_fun _YyyRef -> _void) #:c-id yyy_delete #:wrap (deallocator)) (define-xxx make-yyy (_fun -> _YyyRef) #:c-id yyy_new #:wrap (allocator free-yyy))  576 asm-0001.rss.xml asm-0001 asm-0001.xml 2022 1 19 Lîm Tsú-thuàn Arm64 print number by use svc .global printNumberEntry printNumberEntry: // asked two words on stack sub sp, sp, #16 mov x15, #10 mov x12, x0 // print prepare // fd(x0) = 1(stdout) mov x0, #1 // len(x2) = 1 mov x2, #1 // Unix write system call mov x16, #4 printNumber: // number = x12 // x14 = x12 / 10 // now x14 is rounded-down quotient of x12 udiv x14, x12, x15 // x13 = x14 * 10 - x12 msub x13, x14, x15, x12 // store rounded-down quotient to x12 for next loop mov x12, x14 // digit to string add x13, x13, #48 strb w13, [sp] // buf(x1) = sp mov x1, sp svc #0 // loop part cmp x12, #0 b.eq exit b printNumber exit: mov x13, #10 strb w13, [sp] mov x1, sp svc #0 // put used stack back add sp, sp, #16 ret  577 tt-0006.rss.xml tt-0006 tt-0006.xml 2021 12 Lîm Tsú-thuàn Paper: A simpler encoding of indexed types The idea is coming from Zhang's paper, a simpler encoding of indexed types. An example is Vec in Agda data Vec (A : Set a) : ℕ → Set a where [] : Vec A zero _∷_ : ∀ (x : A) (xs : Vec A n) → Vec A (suc n)  One can still try [] : Vec A 10, although the type check failed, it need a sophisticated unification check. With Zhang's idea, we can do: data Vec (A : Set a) : ℕ → Set a where zero => [] suc n => _∷_ A (Vec A n)  Now, [] : Vec A n where n \ne 0 is impossible to write down as usual, but now it's an easier unification! Since there has no constructor [] for type Vec A n where n \ne 0. Another good example is finite set: data Fin (n : N) | suc _ => fzero | suc n => fsuc (Fin n)  It requires overlapping pattern. One more last, we cannot define usual equality type here (please check) data Id (A : Type ℓ) (x : A) : A → Type ℓ where idp : Id A x x  Paper: Simpler indexed type essentially simplifies the problem of constructor selection just by turning the term-match-term problem to a term-match-pattern problem, which rules out numerous complication but also loses the benefit of general indexed types. 578 software-000H.rss.xml software-000H software-000H.xml 2020 8 7 Lîm Tsú-thuàn How to setup a julia project Tape julia in shell, after getting into the interactive environment of Julia, tape right square bracket to get into pkg mode:  _ _ _ _(_)_ | Documentation: https://docs.julialang.org (_) | (_) (_) | _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help. | | | | | | |/ _ | | | | |_| | | | (_| | | Version 1.5.0 (2020-08-01) _/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release |__/ | (@v1.5) pkg>  In this mode tape: generate HelloWorld (@v1.5) pkg> generate HelloWorld  In the current directory would have a new directory called HelloWorld. In directory HelloWorld/ we will see: Project.toml src/ HelloWorld.jl  To play with definitions in module HelloWorld, in pkg mode tape activate . (@v1.5) pkg> activate .  Then use ; + enter back to interactive mode: julia> import HelloWorld julia> using HelloWorld  579 tt-0012.rss.xml tt-0012 tt-0012.xml 2020 6 12 Lîm Tsú-thuàn <tex>\lambda 2</tex> (lambda 2 system) Consider identity function: \lambda x : nat.x \\ \lambda x : bool.x \\ \lambda x : (nat \to bool).x For per type, there is an identity function, but all with same definition. Therefore, we want to use the same way to build it, here we go: \lambda \alpha : \star . \lambda x : \alpha . x * denotes a type of all types, since \lambda \alpha : \star . \lambda x : \alpha . x is a term, we say this is terms depend on types. This is second order \lambda-abstraction(or type-abstraction). Rules • second order abstraction rule: \frac { \Gamma , \alpha : \star \vdash M : A }{ \Gamma \vdash \lambda \alpha : \star .M : \Pi \alpha : \star . A } • second order application rule: \frac { \Gamma \vdash M : \Pi \alpha : \star .A \; \; \; \Gamma \vdash B : \star }{ \Gamma \vdash M B : A[a := B] } 580 software-0003.rss.xml software-0003 software-0003.xml 2017 10 24 Lîm Tsú-thuàn Vim replace In vim, one can type : to enter command mode, and the command :<start line>,<end line>/<text to replace>/<replace text>/g can replace <text to replace> with <replace text>. The string can be matched with regular language, for example: [a-zA-Z]+ \".*?\"  If you want to execute multiple commands at once, you can use | character to split them. e.g. :1,$s/Care/Car/g | 1,\$s/Circlew/Circle/g

581 cs-000B.rss.xml cs-000B cs-000B.xml 2017 7 8 Lîm Tsú-thuàn Lexer 原理

run 的定義中是一個 state 與 state function 構成的迴圈。 stateFn 型別定義如下

type stateFn func(*Lexer) stateFn


void LexAll(int state) {
switch(state) {
case number:
LexNumber();
case alphabra:
LexIdentifier();
// ...
}
}


func lexWhiteSpace(l *Lexer) stateFn {
for r := l.next(); isSpace(r) || r=='\n'; l.next() {
r = l.peek()
}
l.backup() // break mount's rune is not a space
l.ignore() // because no emit, we need ignore will mount's pos runes

switch r := l.next(); {
case r == EOF:
l.emit(ItemEOF)
return nil
// ...
case r == '=':
return lexEqualOp // =, ==
case r == ':':
l.emit(ItemColon)
return lexWhiteSpace
case r == '"' || r == '' || r == '\'':
return lexString // "string literal", string literal
case '0' <= r && r <= '9':
return lexNumber // 12323, 2.344
case isAlphaNumeric(r):
return lexIdentifiers // car, car_build
default:
panic(fmt.Sprintf("Don't know how to do with:     }
}


func lexNumber(l *Lexer) stateFn {
firstDot := true
for r := l.next(); ( '0' <= r && r <= '9' ) || r == '.'; r = l.next() {
if r == '.' {
if firstDot {
firstDot = false
} else {
break
}
}
}
l.backup()

l.emit(ItemNumber)
return lexWhiteSpace
}


func (l *Lexer) run() {
for l.state = lexWhiteSpace; l.state != nil; {
l.state = l.state(l)
}
close(l.items)
}
// 得到一個狀態函數參考，然後執行狀態函數，就這麼簡單
// l.state是一個stateFn

3 582 Talks 583 talk-0006.rss.xml Reference talk-0006 talk-0006.xml 2023 10 Lîm Tsú-thuàn General recursion /hami2023Kaohsiung Medical University, Healthcare Adminstration and Medical Informatics 584 talk-0005.rss.xml Reference talk-0005 talk-0005.xml 2023 7 Lîm Tsú-thuàn Types cross languages https://dannypsnl.github.io/typecafe2023/typecafe2023.html∞-type café 2023 585 talk-0004.rss.xml Reference talk-0004 talk-0004.xml 2022 11 Lîm Tsú-thuàn Can this program stop? https://dannypsnl.github.io/hami2022/hami2022.htmlKaohsiung Medical University, Healthcare Adminstration and Medical Informatics 586 talk-0003.rss.xml Reference talk-0003 talk-0003.xml 2022 7 Lîm Tsú-thuàn Closure conversion https://dannypsnl.me/~slide/2022-07-closure-conversion.pdfcoscup 2022 587 talk-0002.rss.xml Reference talk-0002 talk-0002.xml 2021 4 Lîm Tsú-thuàn Clojure isn't lisp enough https://dannypsnl.me/~slide/2021-04-clojure-isnt-lisp-enough.pdfclojure taiwan 588 talk-0001.rss.xml Reference talk-0001 talk-0001.xml 2021 3 Lîm Tsú-thuàn Macro as type https://dannypsnl.me/~slide/2021-03-racketfest.rkthttps://youtu.be/BLHxUzj7F-Qracketfest 2021 4 589 Projects 590 minic-0001.rss.xml minic-0001 minic-0001.xml 2023 Lîm Tsú-thuàn Minic https://git.sr.ht/~dannypsnl/minic 591 functional-programming.rss.xml functional-programming functional-programming.xml 2023 fizzyeltLîm Tsú-thuàn 帶你探索 functional programming https://fizzyelt.github.io/functional-programming/

 project: github.com/FizzyElt/functional-programming ticket tracker: github.com/FizzyElt/functional-programming/discussions
592 violet-0001.rss.xml violet-0001 violet-0001.xml 2022 Lîm Tsú-thuàn Violet https://sr.ht/~dannypsnl/violet/

violet is a programming language I created for researching dependent type in use, the source code is written in lean. If you want to contribute the project, you will need the below information:

 project: sr.ht/~dannypsnl/violet ticket tracker: sr.ht/~dannypsnl/violet/trackers mailing lists: sr.ht/~dannypsnl/violet/lists
• send patch to development mailing list: ~dannypsnl/violet-devel@lists.sr.ht.
• discuss on lists.sr.ht/~dannypsnl/violet-discuss.

593 violet-0002.rss.xml Changelog violet-0002 violet-0002.xml 2023 11 6 Violet 0.1 [Unreleased]

The language currently support

• inductive types definition (incomplete)
• top-level function definition
• recursion for top level definitons
• implicit parameters
• pattern matching
• tuples
• record definition

Content is available under CC-BY-SA 4.0 unless otherwise noted 594 dannypsnl.rss.xml Person dannypsnl dannypsnl.xml Lîm Tsú-thuàn https://dannypsnl.mesecond stateCompiler Developer

I study programming language theory and system software; have interests include fiction, history, and math.

• Mail
• Sourcehut/GitHub
• Mastodon
• Resume
• pgp: 196576B231622B8F 