Skip to content

Commit

Permalink
update: 240305
Browse files Browse the repository at this point in the history
  • Loading branch information
V1CeVersaa committed Mar 5, 2024
1 parent 87f4781 commit 0a8272f
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 3 deletions.
58 changes: 58 additions & 0 deletions docs/Computer Science/Algorithm/Discrete Mathematics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Discrete Mathematics

!!! Abstract
这是我在2023-2024学年春夏学期修读《离散数学理论基础》的课程笔记,由于我实在不想将它安排在数学一类,加之以`markdown`编写,所以就放在了这里。

参考书籍:

- 《Discrete Mathematics and Its Applications》 By Kenneth H. Rosen
- 《Concrete Mathmatics》 By Ronald L. Graham

## Part 01 Propositional Logic

### 1.1 Propositions

A **proposition** is a declarative sentence that is either true or false, but not both. We use letters to denote **propositional variables**, or sentential variables, i.e. variables that represent propositions. The **truth value** of a proposition is true, denoted by **T**, if it is a true proposition, and similiarly, the truth value of a proposition is false, denoted by **F**, if it is a false proposition.Propositions that cannot be expressed in terms of simpler propositions are called **atomic propositions**.

We can form new propostions from existing ones using **logical connectives**. Here are six useful logical connectives: Negation/NOT ($\neg$), Conjunction/AND ($\land$), Disjunction/OR ($\lor$), Exclusive Or/XOR ($\oplus$), Conditional/IF-THEN ($\to$), and Biconditional/IFF AND ONLY IF ($\leftrightarrow$).

**More on IMPLICATION**:

- In $p\to q$, $p$ is the **hypothesis/antecedent前件/premise前提**, and $q$ is the **conclusion/consequent后件**.
- In $p\to q$ there does not need to be any connection between the antecedent or the consequent. The “meaning” of $p\to q$ **depends only on the truth values** of $p$ and $q$.

From $p\to q$, we can form the **converse** $q\to p$, the **inverse** $\neg p\to \neg q$, and the **contrapositive** $\neg q\to \neg p$. The **converse** and the **inverse** are not logically equivalent to the original conditional, but the **contrapositive** is.

Construction of a **truth table**:

- Rows: Need a row for every possible combination of values for the atomic propositions.
- Columns.1: Need a column for the compound proposition (usually at far right)
- Columns.2: Need a column for the truth value of each expression that occurs in the compound proposition as it is built up. (This includes the atomic propositions.)

**Precedence of Logical Operators**: From highest to lowest, the precedence of logical operators is $\neg$, $\land$, $\lor$, $\to$, and $\leftrightarrow$.

### 1.3 Logical Equivalence

Compound propositions that have the same truth values for all possible cases are called **logically equivalent**. The compound propositions $p$ and $q$ are called **logically equivalent** if $p\leftrightarrow q$ is a tautology. We denote this by $p\equiv q$.

**De Morgan's Laws** states that for any propositions $p$ and $q$, we have

$$\neg(p\land q)\equiv \neg p\lor \neg q$$

$$\neg(p\lor q)\equiv \neg p\land \neg q.$$

**Conditional-disjunction equivalence** states that for any propositions $p$ and $q$, we have

$$p\to q\equiv \neg p\lor q.$$

**Distribution laws** states that for any propositions $p$, $q$, and $r$, we have

$$p\lor (q\land r)\equiv (p\lor q)\land (p\lor r).$$

$$p\land (q\lor r)\equiv (p\land q)\lor (p\land r).$$

**Absorption laws** states that for any propositions $p$ and $q$, we have

$$p\lor (p\land q)\equiv p.$$

$$p\land (p\lor q)\equiv p.$$
73 changes: 72 additions & 1 deletion docs/Computer Science/System/CSAPP.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,75 @@ $$S=\frac{1}{1-\alpha}.$$

并发(concurrency)和并行(parallelism)是两个不同的概念。并发是一个通用的概念,指一个同时具有多个活动的系统。并行是指使用并发来使一个系统运行得更快。并行可以在计算机系统的多个抽象层次上运用,我们按照系统层次结构中从高到底的顺序重点强调三个层次:

- 线程级并发:使用
- 线程级并发:使用

## Chapter 02 Representing and Manipulating Information

### 2.1 Information Storage

#### 2.1.6 Introduction to Boolean Algebra

十九世纪中期,布尔通过将逻辑值`TRUE``FALSE`编码为二进制值`1``0`,能够设计为一种代数,以研究逻辑推理的基本原则,这种代数叫做**布尔代数/Boolean algebra**

布尔代数有四种基本运算`~``&``|``^`,分别对应于逻辑运算**NOT****AND****OR****EXCLUSIVE-OR**,我们可以列出简单的真值表如下:

![alt text](images/image.png)

接下来,我们将上述四个布尔运算推广到**位向量/Bit vectors**的运算,所谓位向量就是固定长度$w$,由`0``1`组成的串。所谓的推广也非常简单,就是将上述四个布尔运算应用到位向量的每一位上,得到的结果也是一个位向量。换句话说,就是我们在C语言中学的按位运算。

### 2.2 Integer Representations

#### 2.2.1 Unsigned Encodings

无符号数的编码就是经典的二进制编码,假设一个无符号整数数据有$w$位,我们可以将位向量写作$\vec{x}$,也就是$[x_{w-1},x_{w-2},\cdots,x_0]$来表示向量的每一位。我们用一个函数$B2U_w$(是Binary to Unsigned的缩写)来表示二进制向无符号整数的转换:

$$B2U_w(\vec{x})\colonequals\sum_{i=0}^{w-1}x_i2^i.$$

我们很容易可以得知:

- 用$w$位能表示的无符号整数的范围为$[0,2^w-1]$;
- 函数$B2U_w$是一个双射。$B2U_w$将每一个长度为$w$的位向量映射为唯一的无符号整数,相对地,每一个在区间$[0,2^w-1]$内的整数都可以唯一表示为一个长度为$w$的位向量。

#### 2.2.2 Two's-Complement Encodings

最常见的有符号整数编码是**补码/Two's-complement**编码。在补码编码中,一个$w$位的有符号整数$\vec{x}$的值可以表示为:

$$B2T_w(\vec{x})\colonequals -x_{w-1}2^{w-1}+\sum_{i=0}^{w-2}x_i2^i.$$

最高有效位也称为符号位,其权重为$-2^{w-1}$,其余位的权重和无符号整数编码一样。同样,我们可以得知:

- 用$w$位能表示的有符号整数的范围为$[-2^{w-1},2^{w-1}-1]$;
- 函数$B2T_w$是一个双射。

类似的,我们可以定义四进制与十六进制的编码。

补码编码有十分有趣的特性:

- 补码的范围是**不对称**的,负数的范围比整数的范围大1,也就是说编码的最小值$TMin$没有与之对应的整数。
- 最大的无符号数值刚刚好比最大值的两倍多一点点$UMax_w=2TMax_w+1$。补码的负数的位模式在无符号表示中都变成了比原补码整数大的正数。

> 在C库中的`limits.h`中定义了一些常用的整数的最大值与最小值,用来限制编译器运行的不同整型数据的取值范围,例如`INT_MAX``INT_MIN``UINT_MAX`等。
>
> 在C库中的`stdint.h`中定义了一些固定大小的整数类型,例如`int8_t``uint8_t``int16_t``uint16_t`等,这些类型很好地提升了程序的可移植性。
有符号数还有下面两种其他的表示方法:

- **反码/Ones'-complement**:除了最高位有效的权是$-(2^{w-1}-1)$,其余和补码是一样的:

$$B2O_w(\vec{x}) \colonequals -x_{w-1}(2^{w-1}-1)+\sum_{i=0}^{w-2}x_i2^i.$$

- **原码/Sign-magnitude**:最高位是符号位,用来确定剩下的位应该取正权还是取负权,其余位表示数值的绝对值:

$$B2S_w(\vec{x}) \colonequals (-1)^{x_w-1}\cdot\left(\sum_{i=0}^{w-2}x_i2^i\right).$$

这两种编码方式都有统一的缺点:对于数字`0`,有两种完全不同的表示方法,并且这两种编码不能很好地支持算数运算,因而,我们现在开始使用更加方便的补码编码。

### 2.3 Integer Arithmetic

#### 2.3.1 Unsigned Addition



### 2.4 Floating Point

## Chapter 03 Machine-Level Representation of Programs
Binary file added docs/Computer Science/System/images/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ theme:
name: material
language: 'zh'
# icon:
# logo: material/notebook-outline
logo: material/notebook-outline
# favicon: material/notebook-outline
# custom_dir: overrides
features:
- header.autohide
# - header.autohide
- content.code.annotate
- content.action.edit
- toc.follow
Expand Down Expand Up @@ -130,6 +130,7 @@ nav:
- CSS: Computer Science/Programming Language/CSS.md
- Algorithm:
- Computer Science/Algorithm/index.md
- Discrete Mathematics: Computer Science/Algorithm/Discrete Mathematics.md
- Fundamental Data Structure: Computer Science/Algorithm/Foundamental Data Structure.md
- Advanced Data Structure and Alogrithm Analysis: Computer Science/Algorithm/ads.md
- Algorithms: Computer Science/Algorithm/Algorithms.md
Expand Down

0 comments on commit 0a8272f

Please sign in to comment.