Compare commits

...

13 Commits
v0.2.0 ... main

Author SHA1 Message Date
a91d55151b
fix: typo 2025-06-16 13:39:34 +03:00
66bb36d746
fix: small-o example 3
o(n^3) -> o(3^n)
2025-06-15 22:05:52 +03:00
be4811206c
fix: and table 2025-06-15 20:35:17 +03:00
4741efe3dc
fix: graph caption 2025-06-15 20:32:39 +03:00
624b3f0ce5
minor adjustments 2025-06-15 11:06:08 +03:00
68398c0f93
Merge pull request #2 from jorenchik/main 2025-06-15 11:00:41 +03:00
jorenchik
6fac4ccafa some of suggestions from Deniss 2025-06-15 10:48:27 +03:00
jorenchik
b33790252d addition in NP defn 2025-06-15 09:57:15 +03:00
jorenchik
914c91fab4 fix in ind-set <=p clique 2025-06-15 09:56:47 +03:00
jorenchik
7590c1eab0 log in derivation tab.; derivation rules; exponentiation rules 2025-06-15 09:56:36 +03:00
cd0a512d39
fixup! refactor: redraw images using fletcher 2025-06-15 02:43:09 +03:00
e67ff9fdaf
docs: add readme 2025-06-15 02:39:40 +03:00
16c21da5cd
refactor: redraw images using fletcher 2025-06-15 02:38:11 +03:00
7 changed files with 364 additions and 70 deletions

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2025 Kristofers Solo
Copyright (c) 2025 Kristofers Solo, jorenchik
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

118
README.md Normal file
View File

@ -0,0 +1,118 @@
# Typst Project Template with Automated Releases
This repository serves as a template for creating documents with [Typst](https://typst.app/), a modern, markup-based typesetting system. It includes a pre-configured GitHub Actions workflow that automatically compiles your document and creates a GitHub Release whenever you push a new version tag.
## Features
- **Automated PDF Compilation**: Automatically compiles `main.typ` into `main.pdf` on every run.
- **Dependency Caching**: Uses `typst-community/setup-typst` to cache dependencies listed in `requirements.typ`, speeding up subsequent builds.
- **Automatic Releases**: Creates a new GitHub Release with the compiled PDF attached whenever a tag matching the `v*.*.*` pattern is pushed.
- **Manual Workflow Trigger**: Allows for manual builds directly from the GitHub Actions tab, perfect for testing changes without creating a release.
## File Structure
```bash
.
├── .github/
│ └── workflows/
│ └── release.yml # The GitHub Actions workflow definition.
├── main.typ # Your main Typst document entry point.
├── requirements.typ # List your Typst package dependencies here.
├── bibliography.yml # A sample bibliography file (if needed).
└── README.md # This file.
```
- **`main.typ`**: This is the heart of your document. All your content should start here.
- **`requirements.typ`**: If your project uses external Typst packages, you should specify them here. The workflow will automatically fetch and cache them. For example:
```typst
#import "@preview/fletcher:0.5.8"
#import "@preview/physica:0.9.5"
```
- **`.github/workflows/release.yml`**: This file defines the Continuous Integration/Continuous Deployment (CI/CD) pipeline. See the "Workflow Breakdown" section below for a detailed explanation.
## How to Use This Template
There are two primary ways to use the automation provided in this template.
### Method 1: Creating a Release/Tag (Recommended)
This is the standard way to publish a new version of your document. The workflow will automatically create a GitHub Release and attach your compiled PDF.
1. **Commit Your Changes**: Make sure all your latest changes to the `.typ` files are committed to your main branch.
```bash
git add .
git commit -m "Finalize version 1.0.0"
```
2. **Tag the Version**: Create a new Git tag that follows the semantic versioning format (e.g., `v1.0.0`, `v1.2.3`).
```bash
git tag v1.0.0
```
3. **Push the Tag**: Push your commits and the new tag to GitHub.
```bash git push origin main
git push origin v1.0.0
```
Once the tag is pushed, the "Release" workflow will automatically start. It will compile `main.typ` and create a new release on your repository's "Releases" page, named `v1.0.0 — <current_date>`, with `main.pdf` attached as an asset.
### Method 2: Manual Build for Testing
If you want to compile the PDF to see the result without creating a public release, you can trigger the workflow manually.
1. Navigate to the **Actions** tab in your GitHub repository.
2. In the left sidebar, click on the **Release** workflow.
3. You will see a message: "This workflow has a `workflow_dispatch` event trigger." Click the **Run workflow** dropdown button.
4. You will be prompted to enter a `version` string. This is for informational purposes in the run log; you can enter any value (e.g., `test-build`).
5. Click the green **Run workflow** button.
The workflow will run, but the final "Release" step will be skipped. You can download the compiled `main.pdf` from the "Artifacts" section on the summary page for that workflow run.
## Workflow Breakdown (`release.yml`)
The automation is powered by the `.github/workflows/release.yml` file. Here is a step-by-step explanation of what it does.
### Triggers
The workflow is triggered by two events:
1. **`push: tags:`**: Runs automatically when a tag matching the pattern `v[0-9]+.[0-9]+.[0-9]+*` is pushed.
2. **`workflow_dispatch:`**: Allows the manual execution described above.
### Permissions
- `contents: write`: This is essential. It grants the workflow permission to create GitHub Releases and upload files (artifacts) to them.
### Job: `build`
The workflow consists of a single job named `build` that runs on an `ubuntu-latest` virtual machine.
- **`actions/checkout@v4`**: This step checks out your repository's code so the workflow can access your `.typ` files.
- **`typst-community/setup-typst@v4`**: This community action installs the specified version of Typst (`0.13`). The `cache-dependency-path` key is configured to look at `requirements.typ`, enabling caching of Typst packages to make future runs faster.
- **`Compile Typst files`**: A simple shell command that runs the Typst compiler, taking `main.typ` as input and producing `main.pdf`.
```bash
typst compile main.typ main.pdf
```
- **`Upload PDF file`**: This step uses `actions/upload-artifact@v4` to save the generated `main.pdf` as a workflow artifact. This is useful for every run, as it allows you to download the PDF even if a release isn't created.
- **`Get current date`**: Creates a timestamp that is used in the release name for uniqueness.
- **`softprops/action-gh-release@v1`**: This is the final step that creates the release.
- `if: github.ref_type == 'tag'`: This crucial condition ensures this step **only runs if the workflow was triggered by a tag**. It is skipped during manual `workflow_dispatch` runs.
- `name: "${{ github.ref_name }} — ${{ env.DATE }}"`: Sets the release title to the tag name (e.g., `v1.0.0`) plus the date.
- `files: main.pdf`: Attaches the compiled `main.pdf` to the release.
## Customization
- **Typst Version**: To use a different version of Typst, simply change the `typst-version` in the `release.yml` file.
- **Main File**: If your main Typst file is not named `main.typ`, you will need to update the `Compile Typst files` and `Release` steps in `release.yml`.
- **Release Assets**: You can add more files to the release (e.g., a ZIP of the source code) by modifying the `files:` list in the `Release` step.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

312
main.typ
View File

@ -1,5 +1,5 @@
#import "@preview/finite:0.5.0": automaton
#import "@preview/fletcher:0.5.7" as fletcher: diagram, edge, node
#import "@preview/fletcher:0.5.8" as fletcher: diagram, edge, node
#import "@preview/gentle-clues:1.2.0": *
#import "@preview/tablex:0.0.9": tablex
#import "layout.typ": indent-par, project
@ -15,6 +15,7 @@
#let TM = $"TM"$
#let qrej = $q_"rej"$
#let qacc = $q_"acc"$
#let qnew = $q_"new"$
#let halt = $"HALTING"$
#let halt2 = $"HALTING"_2$
#let NP = $"NP"$
@ -38,14 +39,14 @@ un iet virzienā $d space (<- "vai" ->)$.
=== Divas (vai vairākas fiksētas) lentes
$(q, a_1, a_2) -> (q', b_1, b_2, d_1, d_2)$ -- $a_1$, $b_1$, $d_1$ pirmai
lentei un $a_2$, $b_2$, $d_2$ otrai lentei.
Svarīga atšķirība ir ka vairlāklenšu #TM papildus $<-$ un $->$ virzieniem ir
Svarīga atšķirība ir ka vairāklenšu #TM papildus $<-$ un $->$ virzieniem ir
$arrow.b$ (stāvēšana uz vietas). #footnote[Derīgs ar uzdevumiem, kur palīdz
kopēšana/salīdzināšana.]
=== Stāvēšana uz vietas
Nosimulēt stāvēšanu uz vietas jeb $d=0$ var šādi:
- $(q, a) -> (q_"new", a', ->)$
- $(q_"new", a slash b slash c slash * ) -> (q_"new", a slash b slash c slash *, <-)$
- $(q, a) -> (qnew, a', ->)$
- $(qnew, a slash b slash c slash * ) -> (qnew, a slash b slash c slash *, <-)$
=== Modelis, ko pamatā izmanto šajā kursā!
@ -245,9 +246,9 @@ jāparāda, ka varam konstruēt Tjūringa mašīnu, kas atrisina #halt2, izmanto
#halt kā atrisinātu problēmu (jeb kā apakšprogrammu).
Pieņemsim, ka mums ir Tjūringa mašīna $H$, kas atrisina #halt problēmu.
Konstruēsim jaunu Tjūringa mašīnu $H 2$, kas atrisina #halt2 problēmu:
Konstruēsim jaunu Tjūringa mašīnu $H_2$, kas atrisina #halt2 problēmu:
Tjūringa mašīna $H 2$ darbojas sekojoši:
Tjūringa mašīna $H_2$ darbojas sekojoši:
- Doti ievades dati $M$, $x$ un $y$.
- Palaiž $H$ ar ievaddatiem $(M, x)$.
- Ja $H$ akceptē $(M, x)$, apstājas un akceptē.
@ -257,10 +258,10 @@ Tjūringa mašīna $H 2$ darbojas sekojoši:
// Jorens:Nav "vai nu", bet "vai". Citādi paliek abi pozitīvi, kas nav
// apskatīti.
Konstruējot $H 2$ šādā veidā, mēs simulējam $H$ darbību uz abām ievadēm $x$ un
Konstruējot $H_2$ šādā veidā, mēs simulējam $H$ darbību uz abām ievadēm $x$ un
$y$:
- Ja $H$ akceptē $(M, x)$ vai $(M, y)$, $H 2$ akceptēs un apstāsies.
- Ja $H$ noraida gan $(M, x)$, gan $(M, y)$, $H 2$ noraidīs un apstāsies.
- Ja $H$ akceptē $(M, x)$ vai $(M, y)$, $H_2$ akceptēs un apstāsies.
- Ja $H$ noraida gan $(M, x)$, gan $(M, y)$, $H_2$ noraidīs un apstāsies.
// Jorens: Tas jau ir nedaudz liekvārdīgi, izņēmu dažas lietas.
@ -268,7 +269,7 @@ _Tālākais teksts nav obligāts risinājumā._
Redukcijas analīze:
- Ja $halt2(M, x, y) = 1$, tas nozīmē, ka Tjūringa mašīna $M$ apstājas vismaz
uz vienas no ievadēm $x$ vai $y$. Šajā gadījumā $H 2$ arī apstāsies un
uz vienas no ievadēm $x$ vai $y$. Šajā gadījumā $H_2$ arī apstāsies un
akceptēs, jo tā veiksmīgi simulē $H$ uz abām ievadēm un akceptē, ja $H$
akceptē kādu no tām. Tādējādi #halt2 tiek reducēta uz #halt.
- Ja $halt2(M, x, y) = 0$, tas nozīmē, ka Tjūringa mašīna $M$ neapstājas ne uz
@ -301,8 +302,8 @@ atrisinātu šo problēmu.
- $F$ var definēt caur $M$ atbildēm uz dažādām ieejas virknēm $x$.
Piemēram:
- $"ONE"(M) = 1$, ja $exists x: M(x) = 1$
- $"INFINITE"(M) = 1$, ja $exists^infinity x: M(x) = 1$
- $one(M) = 1$, ja $exists x: M(x) = 1$
- $infinite(M) = 1$, ja $exists^oo x: M(x) = 1$
Citiem vārdiem, ja $forall x: M_1(x) = M_2(x)$, tad $F(M_1) = F(M_2)$.
@ -313,7 +314,7 @@ Citiem vārdiem, ja $forall x: M_1(x) = M_2(x)$, tad $F(M_1) = F(M_2)$.
nevienai ieejas virknei $x$.
Papildus Tjūringa mašīnas funkcionālam aprakstam, mums ir papildus informācija
par mašīnu, par tās struktūru etc.
par mašīnu, par tās struktūru utt.
== Raisa teorēma
@ -487,14 +488,6 @@ ka $L in NP$ un ka $SAT <_p L$ (vai jebkura cita zināma NP-pilna problēma).
- Ja $A(x) = 1$, tad $T(x) = 1$.
- Ja $A(x) = 0$, tad $T(x) = 0$ vai $T(x)$ neapstājas.
Tas, ka problēma ir daļēji atrisināma, nozīmē, ka nav konkrēta un *vispārīga*
algoritma, kas vienmēr varētu sniegt pareizu "nē" atbildi gadījumiem ārpus
problēmas.
Var būt iespējams konstruēt Tjūringa mašīnu, kas apstājas un sniedz
"nē" atbildi noteiktiem gadījumiem ārpus problēmas, bet tas nav garantēts
visiem gadījumiem (_un īsti nav apskatīts šajā kursā_).
#teo[$A$ -- daļēji atrisināma tad un tikai tad, ja $A$ -- algoritmiski sanumurējama.]
Cits nosaukums daļējai atrisināmībai ir atpazīstamība (angl.
@ -504,8 +497,8 @@ recognizability/recognizable).
Problēma $A$, kurai neviena no $A$, $overline(A)$ nav daļēji atrisināma?
- $"EQUIV"(M_1, M_2) = 1$, ja $forall x: M_1(x) = M_2(x)$.
- $overline("EQUIV")(M_1, M_2) = 1$, ja $exists x: M_1(x) != M_2(x)$.
- $equiv(M_1, M_2) = 1$, ja $forall x: M_1(x) = M_2(x)$.
- $overline(equiv)(M_1, M_2) = 1$, ja $exists x: M_1(x) != M_2(x)$.
= Nekustīgo punktu teorija
@ -559,11 +552,11 @@ QED.
Notācija, kas tiek izmantota, lai raksturotu *funkciju* sarežģītību
asimptotiski.
=== Lielais-O (formālā definīcija)
=== Lielais-$O$ (formālā definīcija)
$f(n) in O(g(n))$, ja:
$exists C > 0, exists n_0 > 0:$ $(forall n >= n_0: f(n) <= c * g(n))$
$exists C > 0, exists n_0 > 0:$ $(forall n >= n_0: f(n) <= c dot g(n))$
Tas nozīmē, ka funkcija $f(n)$ asimptotiski nepārsniedz konstanti $c$ reizinātu
$g(n)$.
@ -650,7 +643,7 @@ Tātad vienādojums ir
patiess.
=== Piemērs (mazais-$o$)
$ 2^n n^2 =^? o(n^3) $
$ 2^n n^2 =^? o(3^n) $
Pēc tās pašas aprakstītās īpašības, kā @small-o-example-3, sanāktu
$ lim_(n->oo) (2^n n^2)/3^n $
@ -708,7 +701,7 @@ Lai atrastu koda izpildes laiku:
no $n$ (skat. @time_analysis_expressions).
+ Novērtē šīs funkcijas klasi izmantojot lielā-O notāciju.
===== Piemērs ($|a| =^? |b|$)
===== Piemērs ($abs(a) =^? abs(b)$)
Vai ieejas virknē ir vienāds skaits $a$ un $b$?
+ Virzās no kreisās puses uz labo, aizstājot vienu $a$ un vienu $b$ ar $x$;
@ -731,7 +724,7 @@ Kopējais soļu skaits:
$
"SPACE"(f(N)) = \
= {L | L "var atrisināt ar Tjūringa" \
= {L mid(|) L "var atrisināt ar Tjūringa" \
"mašīnu, kurai" S(N) <= C f(N)}. \
$
@ -739,7 +732,7 @@ $
$
"NSPACE"(f(N)) = \
= {L | L "ir determinēta" M, "visiem" x, L(x)=M(x), \
= {L mid(|) L "ir determinēta" M, "visiem" x, L(x)=M(x), \
"un" M "izmanto " <= c f(N) "šūnas uz darba lentes"}. \
$
@ -756,6 +749,9 @@ $
U_c "TIME" (N^c) = P
$
Labs mentālais modelis, lai pierādītu, ka algoritms pieder $"LOGSPACE"$ -- ja
var iztikt ar $O(1)$ mainīgo daudzumu, kur katrs mainīgais ir no $0$ līdz $N$
vai noteikts fiksētu vērtību skaits.
=== Laika-Telpas sakarības
@ -763,7 +759,7 @@ $
Ja $f(n) >= log N$, tad
$
"TIME"(f(N)) subset.eq "SPACE"(f(N)) subset.eq \
subset.eq U_c "TIME" (c^(f(N)))
subset.eq union.big_c "TIME" (c^(f(N)))
$
]
@ -771,7 +767,7 @@ Laiks $O(f(N)) ->$ atmiņa $O(f(N))$.
=== Asimptotiskas augšanas hierarhija
Sekojošas funkcijas pieaugums pie $x -> infinity$:
Sekojošas funkcijas pieaugums pie $x -> oo$:
$log(x) << x << x dot log(x) << x^k << a^x << x! << x^x$
@ -786,7 +782,36 @@ _$x^epsilon$ ir izņemts laukā, lai nejauktu galvu_
_Source; Mathematics for Computer Science, 2018, Eric Lehman, Google Inc._
= Klase P (TODO)
= Klase P
== Definīcija
Klase $P$ ir problēmu kopa, ko var atrisināt ar deterministisku Tjūringa mašīnu
polinomiālā laikā.
- $P=union.big_k "TIME"(n^k)$
Citiem vārdiem: problēma pieder $P$, ja eksistē deterministiska Tjūringa
mašīna, kas to atrisina O($n^k$) soļos, kādai konstantei $k$.
Klase $P$ tiek uzskatīta par praktiski atrisināmo problēmu klasi. Visi
saprātīgie deterministiskie skaitļošanas modeļi ir polinomiāli ekvivalenti
(vienu var simulēt ar otru polinomiālā laikā).
== Piemērs ($"PATH"$)
- Dots grafs $G$ un divas virsotnes $u$, $v$.
- Jautājums: vai eksistē ceļš no $u$ uz $v$?
- Rupjais-spēks: pārbaudīt visus ceļus -- eksponenciāls laiks.
- Efektīvs algoritms: meklēšana plašumā (breadth-first search); laika
sarežģītība: $O(abs(V) + abs(E))$.
== Piemērs ($"RELPRIME"$)
- Doti skaitļi $x$, $y$ (binārā kodējumā).
- Jautājums: vai skaitļi ir savstarpēji pirmskaitļi?
- Efektīvs algoritms: Eiklīda algoritms (izmantojot $mod$); laika sarežģītība:
$O(log n)$ (jo katrā iterācijā skaitļi būtiski samazinās).
= Klase NP
@ -795,17 +820,19 @@ _Source; Mathematics for Computer Science, 2018, Eric Lehman, Google Inc._
#NP (nederminēti-polinomiālas) problēmas
ir problēmas (2 ekvivalentas definīcijas):
+ $L in NP$, ja eksistē pārbaudes algoritms - $O(n^c)$ laika Tjūringa mašīna $M$:
+ $L in NP$, ja eksistē pārbaudes algoritms -- $O(n^c)$ laika Tjūringa mašīna $M$:
+ Ja $L(x) = 1$, tad eksistē y: $M(x, y) = 1$.
+ Ja $L(x) = 0$, tad visiem y: $M(x, y) = 0$.
+ _Informācija $y$ var saturēt brīvi definētu informāciju._
+ _Pārbaudes algoritmā tas ir risinājums, ko tas pārbauda._
+ #NP = problēmas $L$, ko var atrisināt ar nedeterminētu mašīnu $O(n^c)$ laikā.
Ekvivalence ir pierādīta ar abpusēju pārveidojumu no pārbaudītāja uz nedet.
#TM un atpakaļ.
== NP-pilnas probēmas un to redukcijas
== NP-pilnas problēmas un to redukcijas
=== Polinomiāla redukcija $(<=_("poly"))$
=== Polinomiāla redukcija $(<=#sub("poly"))$
- $A <= B$ A var atrisināt, noreducējot to uz B.
- $A <=_("poly") B$, ja ir $O(n^c)$ laika algoritms (Tjūringa mašīna) $P$:
@ -816,7 +843,7 @@ Ekvivalence ir pierādīta ar abpusēju pārveidojumu no pārbaudītāja uz nede
- A NP-pilna, ja:
- $A in "NP"$;
- Ja $B in NP$, tad $B <=_("poly") A$.
- Ja $B in NP$, tad $B <=#sub("poly") A$.
=== 3-SAT problēma
@ -825,10 +852,33 @@ būtu 1 (patiess).
=== CIRCUIT-SAT problēma
Dota funkcija $F(x_1, ..., x_n)$, kas sastāv no vārtiem (AND, OR, NOT).
Dota funkcija $F(x_1, ..., x_n)$, kas sastāv no vārtiem (`AND`, `OR`, `NOT`).
#figure(
image("assets/img/circuit_sat.png", width: 50%),
diagram(
cell-size: 1mm,
node-stroke: 0.5pt,
node-shape: circle,
spacing: 1em,
node((0, 0), `OR`, name: <or-1>, radius: 1em),
node((-1, 1), `AND`, name: <and-1>, radius: 1em),
node((1, 1), `AND`, name: <and-2>, radius: 1em),
node((-2, 2), $x_1$, stroke: none, name: <x1>, radius: 1em),
node((0, 2), `OR`, name: <or-2>, radius: 1em),
node((1, 2), `NOT`, name: <not>, radius: 1em),
node((-1, 3), $x_2$, stroke: none, name: <x2>, radius: 1em),
node((1, 3), $x_3$, stroke: none, name: <x3>, radius: 1em),
edge((0, -1), <or-1>),
edge(<or-1>, <and-1>),
edge(<or-1>, <and-2>),
edge(<and-1>, <x1>),
edge(<and-1>, <or-2>),
edge(<and-2>, <not>),
edge(<or-2>, <x2>),
edge(<or-2>, <x3>),
edge(<not>, <x3>),
),
caption: "CIRCUIT-SAT visual",
)
@ -836,14 +886,14 @@ Vai var atrast mainīgo vērtības tā lai gala izvade būtu 1 (patiess).
=== CLIQUE problēma
$exists C subset.eq V: (|C| = k) and (forall (u, v in C): (u, v) in E)$
$exists C subset.eq V: (abs(C) = k) and (forall (u, v in C): (u, v) in E)$
Vārdiski. Vai eksistē virsotņu kopa $S$ lielumā $k$, kurā katra virsotne ir
savienota ar katru otro no kopas $S$.
=== IND-SET problēma
$exists S subset.eq V: (|S| = k) and (forall (u, v in S): (u, v) in.not E)$
$exists S subset.eq V: (abs(S) = k) and (forall (u, v in S): (u, v) in.not E)$
Vārdiski. Vai grafā $G=(V, E)$ eksistē virsotņu kopa $S$ lielumā $k$, kurā
katra no virsotnēm nav savienota ar nevienu citu virsotni no šīs
@ -853,17 +903,17 @@ kopas.
Vai dotā lineāru nevienādību sistēma ar bināriem mainīgajiem ir atrisināma.
=== CIRCUIT-SAT ≤ₚ 3-SAT
=== CIRCUIT-SAT $<=#sub("p")$ 3-SAT
- Katram starprezultātam (kas nav pirmajā ievadē, i.e., $x_1$, $x_2$, $dots$,
$x_n$) ievieš jaunus mainīgos $y_i$.
- Katriem vārtiem formulē atbilstošas izteiksmes.
Piemērs AND vārtiem. Nosaucam ievades kā x, y un izvadi kā z: $z = x and y$
Piemērs `AND` vārtiem. Nosaucam ievades kā x, y un izvadi kā z: $z = x and y$
#table(
columns: 4,
[*$x$*], [*$y$*], [*$z$*], [*$z = x and z$?*],
[*$x$*], [*$y$*], [*$z$*], [*$z = x and y$?*],
$0$, $0$, $0$, [jā],
$0$, $0$, $1$, [nē],
$0$, $1$, $0$, [jā],
@ -898,39 +948,101 @@ $
Analoģiski iekavām ar vienu elementu. Rezultātā ir 3-CNF formula, ko var
izmantot ar 3-SAT algoritmu.
=== 3-SAT ≤ₚ IND-SET
=== 3-SAT $<=#sub("p")$ IND-SET
Katrai iekavai no formulas veido $3$ virsotnes (grafa komponenti), kas apzīmē
mainīgo (ar NOT, ja ir negācija). Katra virsotne (literālis) no komponentes ir
mainīgo (ar `NOT`, ja ir negācija). Katra virsotne (literālis) no komponentes ir
savā starpā savienota ar pārējām. Starp pretrunīgiem literāliem starp
komponentēm pievieno šķautni.
Piemērs formulai $(x or y or not z) and (not x or y or z)$:
#let dot-node(pos, name) = node(pos, name: name, fill: black, radius: 2pt)
#figure(
image("assets/img/3_sat_indset.png", width: 50%),
caption: "3-SAT -> INDSET visual",
diagram(
cell-size: 1mm,
node-stroke: 0pt,
spacing: 1em,
node-shape: circle,
// phantom location nodes
dot-node((0, 0), <y1>),
dot-node((1, -1), <x>),
dot-node((1, 1), <not-z>),
dot-node((4, -1), <not-x>),
dot-node((4, 1), <y2>),
dot-node((5, 0), <z>),
// label nodes
node((rel: (-0.7em, 0em), to: <y1>), $y$),
node((rel: (0em, 0.7em), to: <x>), $x$),
node((rel: (0em, 0.7em), to: <not-x>), $not x$),
node((rel: (0.7em, 0em), to: <z>), $z$),
node((rel: (0em, -0.7em), to: <not-z>), $not z$),
node((rel: (0em, -0.7em), to: <y2>), $y$),
edge(<x>, <y1>),
edge(<x>, <not-x>),
edge(<x>, <not-z>),
edge(<y1>, <not-z>),
edge(<z>, <not-z>),
edge(<z>, <not-x>),
edge(<z>, <y2>),
edge(<y2>, <not-x>),
),
caption: [3-SAT $->$ INDSET visual],
)
Tagad varam pielietot $"IND-SET"\(G, m\)$ ar izveidoto grafu un $m$ kā iekavu
Tagad varam pielietot $"IND-SET"(G, m)$ ar izveidoto grafu un $m$ kā iekavu
skaitu originālajā formulā.
=== IND-SET ≤ₚ CLIQUE
=== IND-SET $<=#sub("p")$ CLIQUE
- Veido grafa papildinājumu (komplementu) $G' = (V, E')$:
$E' := {(u, v) in V times V | (u, v) in.not E}$
$ E' := {(u, v) in V times V mid(|) (u, v) in.not E} $
Vārdiski. Jauns grafs $G$, kurā ir visas virsotnes no $V$, bet
visas šķautnes, kas ir $G$ nav $G'$ un pretēji -- visas šķautnes
kā nav $G$ ir $G'$.
#figure(
image("assets/img/graph_complement.png", width: 50%),
diagram(
cell-size: 1mm,
node-stroke: 0pt,
spacing: 1em,
node-shape: circle,
// phantom location nodes
dot-node((0, 0), <b1>),
dot-node((-2, 1), <a1>),
dot-node((0, 2), <c1>),
dot-node((0, 4), <b2>),
dot-node((-2, 5), <a2>),
dot-node((0, 6), <c2>),
// label nodes
node((rel: (0.7em, 0.7em), to: <b1>), $B$),
node((rel: (-0.7em, 0em), to: <a1>), $A$),
node((rel: (0.7em, 0.7em), to: <c1>), $C$),
node((1, 1), text(green, $G$)),
node((rel: (0.7em, 0.7em), to: <b2>), $B$),
node((rel: (-0.7em, 0em), to: <a2>), $A$),
node((rel: (0.7em, 0.7em), to: <c2>), $C$),
node((1.6, 5), text(green, $G "papildinājums"$)),
edge(<a1>, <b1>),
edge(<c1>, <b1>, "--", stroke: yellow),
edge(<c1>, <a1>),
edge(<a2>, <b2>, "--", stroke: yellow),
edge(<c2>, <b2>),
edge(<c2>, <a2>, "--", stroke: yellow),
),
caption: "Papildgrafa piemērs",
)
Ir spēkā sakarība $"INDSET"(G, k) = "CLIQUE"(G, k)$.
Ir spēkā sakarība $"INDSET"(G, k) = "CLIQUE"(G', k)$.
= Extras
@ -961,35 +1073,99 @@ Ir spēkā sakarība $"INDSET"(G, k) = "CLIQUE"(G, k)$.
log_8(3x-4)=log_8(5x+2) \
"so," 3x-4=5x+2
$,
[Pow. to log],
$
a^(log_a (x)) = x
$,
$
2^(log_2 (x)) = x
$,
))
]
== Atvasinājumu tabula
#context [
#set text(size: 11pt)
#show math.equation: set text(weight: 400, size: 11pt)
#table(
columns: 3,
inset: (top: .8em, bottom: .9em),
// vert. padding
[*Funkcija*], [*Atvasinājums*], [*Piezīmes*],
[*Funkcija*],
[*Atvasinājums #footnote[Ja $x = g(x)$ (kompleksa funkcija), tad pie atvasinājuma piereizina $g(x)'$.]*],
[*Piezīmes*],
[$x^n$], [$n x^(n-1)$], [],
[$e^x$], [$e^x$], [],
[$a^x$], [$a^x ln(a)$], [$a > 0$],
[$ln(x)$], [$1 / x$], [],
[$1 / x$], [$-1 / x^2$], [],
[$1 / x^n$], [$-n / x^(n+1)$], [],
[$sqrt(x)$], [$1 / (2 sqrt(x))$], [],
[$1 / sqrt(x)$], [$-1 / (2 x^(3/2))$], [],
$ x^n $, $ n x^(n-1) $, "",
$ e^x $, $ e^x $, "",
$ a^x $, $ a^x ln(a) $, $ a > 0 $,
$ ln(x) $, $ 1 / x $, "",
$ log_a (x) $, $ 1 / (x ln(a)) $, "",
$ 1 / x $, $ -1 / x^2 $, "",
$ 1 / x^n $, $ -n / x^(n+1) $, "",
$ sqrt(x) $, $ 1 / (2 sqrt(x)) $, "",
$ 1 / sqrt(x) $, $ -1 / (2 x^(3/2)) $, "",
)
\* Ja $x = g(x)$ (kompleksa funkcija), tad pie atvasinājuma
piereizina $g(x)'$.
]
== Atvasinājumu īpašības
#context [
#set text(size: 11pt)
#show math.equation: set text(weight: 400, size: 11pt)
#table(
columns: 3,
[*Rule Name*], [*Function*], [*Derivative*],
[Summa], [$ f(x) + g(x) $], [$ f'(x) + g'(x) $],
[Starpība], [$ f(x) - g(x) $], [$ f'(x) - g'(x) $],
[Reizinājums], [$ f(x) dot g(x) $],
[
$
f'(x) dot g(x) + \
f(x) dot g'(x)
$
],
/*
[Quotient Rule], [$ (f'(x) dot g(x) - f(x) * g'(x)) / (g(x))^2 $], [$ (f'(x) * g(x) - f(x) * g'(x)) / (g(x))^2 $],
[Chain Rule], [$ f(g(x)) $], [$ f'(g(x)) dot g'(x) $],
[Eulers Number Exponent Rule], [$ e^x $], [$ e^x $],
[Constant Exponent Rule], [$ a^x $], [$ a^x dot ln(a) $],
[Natural Log Rule], [$ ln(x) $], [$ 1 / x $],
[Logarithm Rule], [$ log_a(x) $], [$ 1 / (x dot ln(a)) $],
[Sine Rule], [$ sin(x) $], [$ cos(x) $],
[Cosine Rule], [$ cos(x) $], [$ -sin(x) $],
[Tangent Rule], [$ tan(x) $], [$ sec^2(x) $],
[Cosecant Rule], [$ csc(x) $], [$ -csc(x) dot cot(x) $],
[Secant Rule], [$ sec(x) $], [$ sec(x) dot tan(x) $],
[Cotangent Rule], [$ cot(x) $], [$ -csc^2(x) $],
*/
)
]
== Kāpinājumu īpašības
#context [
#set text(size: 11pt)
#show math.equation: set text(weight: 400, size: 11pt)
#table(
columns: 2,
[*Rule Name*], [*Formula*],
[Reizinājums], [$ a^m dot a^n = a^(m+n) $],
[Dalījums], [$ a^m / a^n = a^(m-n) $],
[Pakāpes pakāpe], [$ (a^m)^n = a^(m dot n) $],
[Reizinājuma pakāpe], [$ (a dot b)^m = a^m dot b^m $],
[Dalījuma pakāpe], [$ (a/b)^m = a^m / b^m $],
[0-pakāpe], [$ a^0 = 1 $],
[Negatīva pakāpe], [$ a^(-m) = 1 / a^m $],
[Saikne ar sakni], [$ a^(m/n) = root(n, a^m) $],
)
]
== Noderīgas izteiksmes laika analīzē<time_analysis_expressions>
$
@ -997,8 +1173,8 @@ $
sum_(i=1)^(n) i^2 = (n(n+1)(2n+1))/(6)\
sum_(i=1)^(n) i^3 = ( (n(n+1))/(2))^2 \
// Geometric series (ratio r \neq 1)
r > 1: sum_(i=0)^(n) a*r^i = a * (r^(n+1)-1)/(r-1) quad \
r < 1: sum_(i=0)^(infinity) a*r^i = (a)/(1-r) \
r > 1: sum_(i=0)^(n) a dot r^i = a dot (r^(n+1)-1)/(r-1) quad \
r < 1: sum_(i=0)^(oo) a dot r^i = (a)/(1-r) \
// Logarithmic sum
sum_(i=1)^(n) log i = log(n!) approx n log n - n + O(log n) \
// Exponential sum (appears in brute-force algorithms)

View File

@ -1,5 +1,5 @@
#import "@preview/finite:0.5.0"
#import "@preview/fletcher:0.5.7"
#import "@preview/fletcher:0.5.8"
#import "@preview/gentle-clues:1.2.0"
#import "@preview/headcount:0.1.0"
#import "@preview/tablex:0.0.9"