refactor: massively reorganize and add nix infrastructure
This commit is contained in:
parent
e596fe72d8
commit
4a5cc1b225
30 changed files with 486 additions and 0 deletions
35
2024/documents/by-course/phil-1/paper-1/package.nix
Normal file
35
2024/documents/by-course/phil-1/paper-1/package.nix
Normal file
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
pkgs,
|
||||
typstPackagesCache,
|
||||
typixLib,
|
||||
cleanTypstSource,
|
||||
...
|
||||
}:
|
||||
let
|
||||
src = cleanTypstSource ./.;
|
||||
commonArgs = {
|
||||
typstSource = "main.typ";
|
||||
|
||||
fontPaths = [
|
||||
# Add paths to fonts here
|
||||
# "${pkgs.roboto}/share/fonts/truetype"
|
||||
];
|
||||
|
||||
virtualPaths = [
|
||||
# Add paths that must be locally accessible to typst here
|
||||
# {
|
||||
# dest = "icons";
|
||||
# src = "${inputs.font-awesome}/svgs/regular";
|
||||
# }
|
||||
];
|
||||
|
||||
XDG_CACHE_HOME = typstPackagesCache;
|
||||
};
|
||||
|
||||
in
|
||||
typixLib.buildTypstProject (
|
||||
commonArgs
|
||||
// {
|
||||
inherit src;
|
||||
}
|
||||
)
|
35
2024/documents/by-name/digression-linear-algebra/package.nix
Normal file
35
2024/documents/by-name/digression-linear-algebra/package.nix
Normal file
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
pkgs,
|
||||
typstPackagesCache,
|
||||
typixLib,
|
||||
cleanTypstSource,
|
||||
...
|
||||
}:
|
||||
let
|
||||
src = cleanTypstSource ./.;
|
||||
commonArgs = {
|
||||
typstSource = "main.typ";
|
||||
|
||||
fontPaths = [
|
||||
# Add paths to fonts here
|
||||
# "${pkgs.roboto}/share/fonts/truetype"
|
||||
];
|
||||
|
||||
virtualPaths = [
|
||||
# Add paths that must be locally accessible to typst here
|
||||
# {
|
||||
# dest = "icons";
|
||||
# src = "${inputs.font-awesome}/svgs/regular";
|
||||
# }
|
||||
];
|
||||
|
||||
XDG_CACHE_HOME = typstPackagesCache;
|
||||
};
|
||||
|
||||
in
|
||||
typixLib.buildTypstProject (
|
||||
commonArgs
|
||||
// {
|
||||
inherit src;
|
||||
}
|
||||
)
|
99
2024/flake.lock
Normal file
99
2024/flake.lock
Normal file
|
@ -0,0 +1,99 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1726560853,
|
||||
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1729256560,
|
||||
"narHash": "sha256-/uilDXvCIEs3C9l73JTACm4quuHUsIHcns1c+cHUJwA=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "4c2fcb090b1f3e5b47eaa7bd33913b574a11e0a0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"typix": "typix",
|
||||
"typst-packages": "typst-packages"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"typix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1728290750,
|
||||
"narHash": "sha256-piLZT8398O69hy0e3gX8hUWqSzbCslMCt10pT8d6c8E=",
|
||||
"owner": "loqusion",
|
||||
"repo": "typix",
|
||||
"rev": "62d032735ad32a9a90225c06cb0857677fc753ee",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "loqusion",
|
||||
"repo": "typix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"typst-packages": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1729252723,
|
||||
"narHash": "sha256-xdaQYNw1GApaJnXJO4WnUTNuYeRXisxIUSuAzVXFEW4=",
|
||||
"owner": "typst",
|
||||
"repo": "packages",
|
||||
"rev": "9bcf190c85da91be6df9f5fc25a93ce5812489cc",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "typst",
|
||||
"repo": "packages",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
92
2024/flake.nix
Normal file
92
2024/flake.nix
Normal file
|
@ -0,0 +1,92 @@
|
|||
{
|
||||
description = "Compiling work in 2024 in a reproducible manner";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
|
||||
typix = {
|
||||
url = "github:loqusion/typix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
|
||||
typst-packages = {
|
||||
url = "github:typst/packages";
|
||||
flake = false;
|
||||
};
|
||||
|
||||
# Example of downloading icons from a non-flake source
|
||||
# font-awesome = {
|
||||
# url = "github:FortAwesome/Font-Awesome";
|
||||
# flake = false;
|
||||
# };
|
||||
};
|
||||
|
||||
outputs =
|
||||
inputs@{
|
||||
nixpkgs,
|
||||
typix,
|
||||
flake-utils,
|
||||
...
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in
|
||||
let
|
||||
typstPackagesSrc = "${inputs.typst-packages}/packages";
|
||||
|
||||
typstPackagesCache = pkgs.stdenv.mkDerivation {
|
||||
name = "typst-packages-cache";
|
||||
src = typstPackagesSrc;
|
||||
dontBuild = true;
|
||||
installPhase = ''
|
||||
mkdir -p "$out/typst/packages"
|
||||
cp -LR --reflink=auto --no-preserve=mode -t "$out/typst/packages" "$src"/*
|
||||
'';
|
||||
};
|
||||
typixLib = typix.lib.${system};
|
||||
in
|
||||
let
|
||||
alexandriaLib = import ./nix/lib {
|
||||
inherit pkgs typixLib typstPackagesCache;
|
||||
};
|
||||
|
||||
in
|
||||
{
|
||||
# checks = {
|
||||
# inherit build-drv build-script watch-script;
|
||||
# };
|
||||
|
||||
legacyPackages = {
|
||||
phil-1 = {
|
||||
paper-1 = alexandriaLib.callTypstProject (import ./documents/by-course/phil-1/paper-1/package.nix);
|
||||
};
|
||||
digression-linear-algebra = alexandriaLib.callTypstProject (import ./documents/by-name/digression-linear-algebra/package.nix);
|
||||
};
|
||||
# apps = rec {
|
||||
# default = watch;
|
||||
# build = flake-utils.lib.mkApp {
|
||||
# drv = build-script;
|
||||
# };
|
||||
# watch = flake-utils.lib.mkApp {
|
||||
# drv = watch-script;
|
||||
# };
|
||||
# };
|
||||
#
|
||||
# devShells.default = typixLib.devShell {
|
||||
# inherit (commonArgs) fontPaths virtualPaths;
|
||||
# packages = [
|
||||
# # WARNING: Don't run `typst-build` directly, instead use `nix run .#build`
|
||||
# # See https://github.com/loqusion/typix/issues/2
|
||||
# # build-script
|
||||
# watch-script
|
||||
# # More packages can be added here, like typstfmt
|
||||
# pkgs.typstyle
|
||||
# ];
|
||||
# };
|
||||
}
|
||||
);
|
||||
}
|
16
2024/nix/lib/callTypstProject.nix
Normal file
16
2024/nix/lib/callTypstProject.nix
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
pkgs,
|
||||
typixLib,
|
||||
typstPackagesCache,
|
||||
cleanTypstSource,
|
||||
...
|
||||
}:
|
||||
package:
|
||||
package {
|
||||
inherit
|
||||
pkgs
|
||||
typixLib
|
||||
typstPackagesCache
|
||||
cleanTypstSource
|
||||
;
|
||||
}
|
18
2024/nix/lib/cleanTypstSource.nix
Normal file
18
2024/nix/lib/cleanTypstSource.nix
Normal file
|
@ -0,0 +1,18 @@
|
|||
{ pkgs, ... }:
|
||||
src:
|
||||
let
|
||||
inherit (pkgs) lib;
|
||||
in
|
||||
lib.cleanSourceWith {
|
||||
src = lib.cleanSource src;
|
||||
filter =
|
||||
path: type:
|
||||
let
|
||||
isTypstSource = lib.hasSuffix ".typ" path || lib.hasSuffix ".bib" path;
|
||||
isImage = lib.hasSuffix ".png" path || lib.hasSuffix ".jpeg" path || lib.hasSuffix ".jpg" path;
|
||||
isSpecialFile = builtins.elem (builtins.baseNameOf path) [
|
||||
"typst.toml"
|
||||
];
|
||||
in
|
||||
type == "directory" || isTypstSource || isSpecialFile || isImage;
|
||||
}
|
19
2024/nix/lib/default.nix
Normal file
19
2024/nix/lib/default.nix
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
pkgs,
|
||||
typstPackagesCache,
|
||||
typixLib,
|
||||
}:
|
||||
let
|
||||
defaultArgs = {
|
||||
inherit pkgs typstPackagesCache typixLib;
|
||||
};
|
||||
in
|
||||
rec {
|
||||
cleanTypstSource = (import ./cleanTypstSource.nix) defaultArgs;
|
||||
callTypstProject = (import ./callTypstProject.nix) (
|
||||
defaultArgs
|
||||
// {
|
||||
inherit cleanTypstSource;
|
||||
}
|
||||
);
|
||||
}
|
165
2024/notes/math-4a/week-2/main.typ
Normal file
165
2024/notes/math-4a/week-2/main.typ
Normal file
|
@ -0,0 +1,165 @@
|
|||
#import "@preview/unequivocal-ams:0.1.1": ams-article, theorem, proof
|
||||
|
||||
#show: ams-article.with(
|
||||
title: [A Digression on Abstract Linear Algebra],
|
||||
authors: (
|
||||
(
|
||||
name: "Youwen Wu",
|
||||
organization: [University of California, Santa Barbara],
|
||||
email: "youwen@ucsb.edu",
|
||||
url: "https://youwen.dev",
|
||||
),
|
||||
),
|
||||
bibliography: bibliography("refs.bib"),
|
||||
)
|
||||
|
||||
= Introduction
|
||||
|
||||
Many introductory linear algebra classes focus on _application_. In general,
|
||||
this is a red herring and is engineer-speak for "we will teach you how to
|
||||
crunch numbers with no regard for conceptual understanding."
|
||||
|
||||
If you are a math major (or math-adjacent, such as Computer Science), this
|
||||
class is essentially useless for you. You will learn how to perform trivial
|
||||
numerical operations such as the _matrix multiplication_, _matrix-vector
|
||||
multiplication_, _row reduction_, and other trite tasks better suited for
|
||||
computers.
|
||||
|
||||
If you are taking this course, you might as well learn linear algebra properly.
|
||||
Otherwise, you will have to re-learn it later on, anyways. Completing a math
|
||||
course without gaining a theoretical appreciation for the topics at hand is an
|
||||
unequivocal waste of time. I have prepared this brief crash course designed to
|
||||
fill in the theoretical gaps left by this class.
|
||||
|
||||
= Basic Notions
|
||||
|
||||
== Vector spaces
|
||||
|
||||
Before we can understand vectors, we need to first discuss _vector spaces_. Thus
|
||||
far, you have likely encountered vectors primarily in physics classes,
|
||||
generally in the two-dimensional plane. You may conceptualize them as arrows in
|
||||
space. For vectors of size $>3$, a hand waving argument is made that they are
|
||||
essentially just arrows in higher dimensional spaces.
|
||||
|
||||
It is helpful to take a step back from this primitive geometric understanding
|
||||
of the vector. Let us build up a rigorous idea of vectors from first
|
||||
principles.
|
||||
|
||||
=== Vector axioms
|
||||
|
||||
The so-called _axioms_ of a _vector space_ (which we'll call the vector space
|
||||
$V$) are as follows:
|
||||
|
||||
#enum[
|
||||
Commutativity: $u + v = v + u, " " forall u,v in V$
|
||||
][
|
||||
Associativity: $(u + v) + w = u + (v + w), " " forall u,v,w in V$
|
||||
][
|
||||
Zero vector: $exists$ a special vector, denoted $0$, such that $v + 0 = v, " " forall v in V$
|
||||
][
|
||||
Additive inverse: $forall v in V, " " exists w in V "such that" v + w = 0$. Such an additive inverse is generally denoted $-v$
|
||||
][
|
||||
Multiplicative identity: $1 v = v, " " forall v in V$
|
||||
][
|
||||
Multiplicative associativity: $(alpha beta) v = alpha (beta v) " " forall v in V, "scalars" alpha, beta$
|
||||
][
|
||||
Distributive property for vectors: $alpha (u + v) = alpha u + alpha v " " forall u,v in V, "scalars" alpha$
|
||||
][
|
||||
Distributive property for scalars: $(alpha + beta) v = alpha v + beta v " " forall v in V, " scalars" alpha, beta$
|
||||
]
|
||||
|
||||
It is easy to show that the zero vector $0$ and the additive inverse $-v$ are
|
||||
_unique_. We leave the proof of this fact as an exercise.
|
||||
|
||||
These may seem difficult to memorize, but they are essentially the same
|
||||
familiar algebraic properties of numbers you know from high school. The
|
||||
important thing to remember is which operations are valid for what objects. For
|
||||
example, you cannot add a vector and scalar, as it does not make sense.
|
||||
|
||||
_Remark_. For those of you versed in computer science, you may recognize this
|
||||
as essentially saying that you must ensure your operations are _type-safe_.
|
||||
Adding a vector and scalar is not just false, it is an _invalid question_
|
||||
entirely because vectors and scalars and different types of mathematical
|
||||
objects. See #cite(<chen2024digression>, form: "prose") for more.
|
||||
|
||||
=== Vectors big and small
|
||||
|
||||
In order to begin your descent into what mathematicians colloquially recognize
|
||||
as _abstract vapid nonsense_, let's discuss which fields constitute a vector space. We
|
||||
have the familiar space where all scalars are real numbers, or $RR$. We
|
||||
generally discuss 2-D or 3-D vectors, corresponding to vectors of length 2 or
|
||||
3; in our case, $RR^2$ and $RR^3$.
|
||||
|
||||
However, vectors in $RR$ can really be of any length. Discard your primitive
|
||||
conception of vectors as arrows in space. Vectors are simply arbitrary length
|
||||
lists of numbers (for the computer science folk: think C++ `std::vector`).
|
||||
|
||||
_Example_. $ vec(1,2,3,4,5,6,7,8,9) $
|
||||
|
||||
Moreover, vectors need not be in $RR$ at all. Recall that a vector space need
|
||||
only satisfy the aforementioned _axioms of a vector space_.
|
||||
|
||||
_Example_. The vector space $CC$ is similar to $RR$, except it includes complex
|
||||
numbers. All complex vector spaces are real vector spaces (as you can simply
|
||||
restrict them to only use the real numbers), but not the other way around.
|
||||
|
||||
In general, we can have a vector space where the scalars are in an arbitrary
|
||||
field $FF$, as long as the axioms are satisfied.
|
||||
|
||||
_Example_. The vector space of all polynomials of degree 3, or $PP^3$. It is
|
||||
not yet clear what this vector may look like. We shall return to this example
|
||||
once we discuss _basis_.
|
||||
|
||||
== Vector addition. Multiplication
|
||||
|
||||
Vector addition, represented by $+$, and multiplication, represented by the
|
||||
$dot$ (dot) operator, can be done entrywise.
|
||||
|
||||
_Example._
|
||||
|
||||
$
|
||||
vec(1,2,3) + vec(4,5,6) = vec(1 + 4, 2 + 5, 3 + 6) = vec(5,7,9)
|
||||
$
|
||||
$
|
||||
vec(1,2,3) dot vec(4,5,6) = vec(1 dot 4, 2 dot 5, 3 dot 6) = vec(4,10,18)
|
||||
$
|
||||
|
||||
This is simple enough to understand. Again, the difficulty is simply ensuring
|
||||
that you always perform operations with the correct _types_. For example, once
|
||||
we introduce matrices, it doesn't make sense to multiply or add vectors and
|
||||
matrices in this fashion.
|
||||
|
||||
== Vector-scalar multiplication
|
||||
|
||||
Multiplying a vector by a scalar simply results in each entry of the vector
|
||||
being multiplied by the scalar.
|
||||
|
||||
_Example_.
|
||||
|
||||
$ beta vec(a, b, c) = vec(beta dot a, beta dot b, beta dot c) $
|
||||
|
||||
== Matrices
|
||||
|
||||
Before discussing any properties of matrices, let's simply reiterate what we
|
||||
learned in class about their notation. We say a matrix with rows of length $m$,
|
||||
and columns of size $n$ (in less precise terms, a matrix with length $m$ and
|
||||
height $n$) is a $m times n$ matrix.
|
||||
|
||||
Given a matrix
|
||||
|
||||
$ A = mat(1,2,3;4,5,6;7,8,9) $
|
||||
|
||||
we refer to the entry in row $j$ and column $k$ as $A_(j,k)$ .
|
||||
|
||||
=== Matrix transpose
|
||||
|
||||
A formalism that is useful later on is called the _transpose_, and we obtain it
|
||||
from a matrix $A$ by switching all the rows and columns. More precisely, each
|
||||
row becomes a column instead. We use the notation $A^T$ to represent the
|
||||
transpose of $A$.
|
||||
|
||||
$
|
||||
mat(1,2,3;4,5,6)^T = mat(1,4;2,5;3,6)
|
||||
$
|
||||
|
||||
Formally, we can say $(A_(j,k))^T = A_(k,j)$.
|
6
2024/notes/math-4a/week-2/refs.bib
Normal file
6
2024/notes/math-4a/week-2/refs.bib
Normal file
|
@ -0,0 +1,6 @@
|
|||
@misc{chen2024digression,
|
||||
author = {Evan Chen},
|
||||
title = {Digression on Type Safety},
|
||||
year = {2024},
|
||||
howpublished = {\url{https://web.evanchen.cc/upload/1802/tsafe-1802.pdf}},
|
||||
}
|
1
2024/result
Symbolic link
1
2024/result
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/fv6y2dqv26lw4gzb2pf6ms5hyikpbkm9-typst
|
Loading…
Reference in a new issue