重构目录层次

0-课程笔记
1-平时作业
2-实验报告
3-期末大作业
This commit is contained in:
2024-09-02 18:29:19 +08:00
parent b2fb901612
commit 5906ac1efc
108 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\usepackage{amssymb, amsfonts, amstext, amsopn, amsthm}
\usepackage[outputdir=./latex-output]{minted}
\usepackage{subfiles}
\usepackage{mylatex}
\usepackage{fancyhdr}
\usepackage{zhnumber} % change chapter number to chinese
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{enumitem}
\usepackage{multicol}
\usepackage{hyperref}
\usepackage{subfig}
\usepackage{tasks}
\usepackage{appendix}
\usepackage{gbt7714}
\usepackage{totpages} % 不加这个会导致总页数出错
\fancyfoot[C]{\thepage\quad\ref{TotPages}}
\renewcommand\thesection{\thechapter.\arabic{section}}
\renewcommand \thesubsection {\arabic{subsection}}
\renewcommand{\labelenumii}{(\arabic{enumii})}
\title{《离散数学》作业}
\author{岳锦鹏}
\newcommand{\mysignature}{10213903403 岳锦鹏}
\date{2023年9月19日 —— 2023年12月31日}
\setlist[1]{listparindent=\parindent}
\setlist[2]{listparindent=\parindent}
\def\myitem#1#2{
\item \text{#1}
\begin{enumerate}
#2
\end{enumerate}
}
% \newcommand{\mycircle}[1]{\large{\textcircled{\normalsize#1}}\normalsize}
\setminted{linenos=true, breaklines=true, baselinestretch=0.85}
\bibliographystyle{gbt7714-numerical}

View File

@@ -0,0 +1,24 @@
\documentclass[a4paper]{ctexbook}
\input{mypreamble}
\begin{document}
\maketitle
\tableofcontents
\setcounter{page}{0} % 这样会导致目录的最后一页页码为0TODO: 待修复
\subfile{第一周作业}
\subfile{第二周作业}
\chapter{数论基础}
\subfile{第三周作业}
\subfile{第四周作业}
\subfile{第五周作业}
\subfile{第七周作业}
\subfile{第八周作业}
\subfile{第十周作业}
\subfile{第十二周作业}
\subfile{第十三周作业}
\subfile{第十四周作业}
\subfile{第十五周作业}
\subfile{第十六周作业}
\appendix
\chapter{附录}
\subfile{课程项目}
\end{document}

View File

@@ -0,0 +1,204 @@
\documentclass[全部作业]{subfiles}
% \documentclass[a4paper]{ctexart}
\usepackage[margin=1in]{geometry} % 设置边距符合Word设定
% \usepackage{ctex}
\usepackage{lipsum}
\usepackage{amssymb, amsfonts, amstext, amsmath, amsopn, amsthm}
% \usepackage{fontspec}
\usepackage{minted}
% \usepackage{shellesc}
% \usepackage{regexpatch}
% \usepackage{xpatch}
% \usepackage{l3regex}
\usepackage{expl3}
\usepackage{environ}
\usepackage{mylatex}
% \setmainfont{Microsoft YaHei}
% \setCJKmainfont{SimSun}
\date{2023年9月14日}
\begin{document}
\chapter{集合论基础}
\section{集合的概念和术语}
\renewcommand{\labelenumii}{(\arabic{enumii})}
\begin{enumerate}
\item
给出集合{-3,-2,-1,0,1,2,3}的谓词表示法。
$\{ x|x \in \mathbb{Z}, -3\le x\le 3 \}$
\item
判断2和{2}是否下列集合的元素。
\begin{enumerate}
\item
$\{ x| {x\text{是大于1的整数}} \}$
2是 {2}不是。
\item
$\{ x|x {\text{是某整数的平方}} \}$
2不是{2}不是。
\item
$\{ 2,\{ 2 \} \}$
2是{2}是。
\item
$\{ \{ 2 \},\{ \{ 2 \} \} \}$
2不是{2}是。
\item
$\{ \{ 2 \},\{ 2,\{ 2 \} \} \}$
2不是{2}是。
\item
$\{ \{ \{ 2 \} \} \}$
2不是{2}不是。
\end{enumerate}
\item
下列哪些命题成立?哪些不成立?为什么?
\begin{enumerate}
\item
$\emptyset \in \{ \emptyset,\{ \emptyset \} \}$
成立。
\item
$\emptyset\subseteq \{ \emptyset,\{ \emptyset \} \} $
成立。
\item
$\{ \emptyset \}\subseteq \{ \emptyset,\{ \emptyset \} \}$
成立。
\item
$\{ \{ \emptyset \} \}\subseteq \{ \emptyset,\{ \emptyset \} \}$
成立。
\end{enumerate}
\end{enumerate}
\section{集合的运算}
\renewcommand{\labelenumii}{(\arabic{enumii})}
\begin{enumerate}
\item
设A是ECNU二年级学生的集合B是ECNU必须学习离散数学的学生的集合。请用A和B表示ECNU不必学习离散数学的二年级的学生的集合。\\
$A\setminus B$
\item
设A是集合下列命题是否必定成立?
\begin{enumerate}
\item
$A\in P(A)$\\
是。
\item
$A \subseteq P(A)$\\
否。
\item
$\{ A \}\in P(A)$\\
否。
\item
$\{ A \} \subseteq P(A)$\\
是。
\end{enumerate}
\item
设A和B是任意集合证明 $P(A)\cap P(B)=P(A\cap B)$\\
\begin{proof}
\ExplSyntaxOn
\begin{zhongwen}
$$
\begin{aligned}
证明:&\\
&X \in P(A) \cap P(B)\\
\Leftrightarrow &X \in P(A) 且 X \in P(B)\\
\Leftrightarrow &X \subseteq A, X \subseteq B\\
\Leftrightarrow &X \subseteq A \cap B\\
\Leftrightarrow &X \in P(A \cap B)\\
\therefore &P(A)\cap P(B) = P(A\cap B)\\
\end{aligned}
$$
\end{zhongwen}
\ExplSyntaxOff
\end{proof}
\item
设A是任意集合$A^3=(A×A)×A=A×(A×A)$是否成立?为什么?\\
\ExplSyntaxOn
\begin{zhongwen}
$不一定假设A=\{ 1 \}则A^3=\{ (1,1,1) \}, (A\times A)\times A=\{ ((1,1),1) \}, A\times (A\times A)=\{ (1,(1,1)) \}$
\end{zhongwen}
\ExplSyntaxOff
\item
设A、B、C和D是集合证明若A、B、C和D均非空集且A×B=C×D那么A=C且B=D。\\
% {\ctex@fontset{middle}}
\begin{proof}
\ExplSyntaxOn
\begin{zhongwen}
$$
\begin{aligned}
&假设 A \neq C 或 B \neq D\\
&\exists x, x \in A, x \notin C 或x \in C, x \notin A\\
&\exists y, y \in B, y \notin D 或y \in D, y \notin B\\
&不妨设\exists x, x \in A, x \notin C\\
&\because B 非空\\
&\therefore 设b \in B\\
&(x,b) \in A\times B\\
&\because x \notin C\\
&\therefore (x,b) \notin C\times D\\
&\therefore A\times B \neq C \times D\\
&与已知矛盾\\
&\therefore 若A、B、C和D均非空集且A×B=C×D\\
&那么A=C且B=D。\\
\end{aligned}
$$
% \endbf
\end{zhongwen}
\ExplSyntaxOff
\end{proof}
\item *编写一个程序输入任意一个自然数n输出P({1,2,…,n})的所有元素。 \\
JavaScriptNodejs环境
\begin{minted}{javascript}
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let n;
function get_pow_set(end_num) {
end_num = parseInt(end_num);
let pow_set = [[]];
for (let i = 1; i <= end_num; i++) {
pow_set = pow_set.concat(pow_set.map((ele) => {
return ele.concat([i]);
}));
}
return pow_set;
}
rl.question("", (answer) => {
n = parseInt(answer);
console.log(get_pow_set(n));
rl.close();
});
\end{minted}
\end{enumerate}
\end{document}

View File

@@ -0,0 +1,79 @@
\documentclass[全部作业]{subfiles}
\pagestyle{fancyplain}
\fancyhead{}
\fancyhead[C]{\mysignature}
\setcounter{chapter}{4}
\setcounter{section}{1}
\begin{document}
\section{谓词公式的等值演算和前束范式}
\begin{enumerate}
\item 指出谓词公式$\forall x\forall y(P(x,y)\lor Q(y,z))\land \exists xR(x,y)$的指导变元、量词的辖域、约束变元和自由变元。
\begin{figure}[h]
\centering
\includexopp[0.8]{7.1.1}
\end{figure}
\item 求谓词公式$\forall x \forall y (P(x,y) \leftrightarrow Q(x,y)) \to \exists x \forall y R(x,y)$的前束范式。
\begin{proof}[解]
\begin{zhongwen}
$$
\begin{aligned}
&\forall x \forall y(P(x,y) \leftrightarrow Q(x,y)) \to \exists x \forall y R(x, y) \\
=&\forall x \forall y(P(x,y)\leftrightarrow Q(x,y)) \to \exists z \forall uR(z, u) & (换名) \\
=&\lnot (\forall x\forall y(P(x,y)\leftrightarrow Q(x,y)))\lor \exists z\forall uR(z,u) & (消去\to \\
=&\exists x\exists y(\lnot (P(x,y)\leftrightarrow Q(x,y)))\lor \exists z\forall u R(z,u) & (内移\lnot \\
=&\exists x\exists y\exists z\forall u(\lnot (P(x,y)\leftrightarrow Q(x,y))\lor R(z,u)) & (量词前移) \\
=&\exists x\exists y\exists z\forall u((P(x,y)\leftrightarrow Q(x,y))\to R(z,u)) & (恢复\to (非必要)) \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\end{enumerate}
\section{一阶逻辑的推理理论}
\begin{enumerate}
\item 构造$\forall x(P(x)\lor Q(x)), \forall x(Q(x) \to \lnot R(x)), \forall xR(x) \Rightarrow \forall xP(x)$的形式证明。
\begin{proof}
\begin{zhongwen}
$$设y为任意的个体变量$$
\begin{enumerate}[label=\mycircle{\arabic{enumii}},leftmargin=\linewidth/4,rightmargin=\linewidth/4]
\item $\forall x(P(x)\lor Q(x))$\hfill 前提引入
\item $P(y)\lor Q(y)$\hfill \mycircle{1} US规则
\item $\forall x(Q(x)\to \lnot R(x))$\hfill 前提引入
\item $Q(y)\to \lnot R(y)$\hfill \mycircle{3} US规则
\item $\forall xR(x)$ \hfill 前提引入
\item $R(y)$\hfill \mycircle{5} US规则
\item $\lnot Q(y)$\hfill \mycircle{4} \mycircle{6} 拒取式
\item $P(y)$ \hfill \mycircle{2} \mycircle{7} 析取三段论
\item $\forall xP(x)$\hfill \mycircle{8} UG规则
\end{enumerate}
\end{zhongwen}
\end{proof}
\item 证明下面的推理:\\
“每个科研工作者都是努力工作的。每个努力工作而又聪明的人都取得事业的成功。某个人是科研工作者并且聪明。所以,某人事业取得成功。”
\begin{zhongwen}
$$
\begin{aligned}
&设P(x): x是科研工作者Q(x): x努力工作R(x): x聪明S(x): x取得事业的成功 \\
&e: 某个人,则需要证明: \\
&\forall x(P(x)\to Q(x)), \forall x (Q(x)\land R(x)\to S(x)), P(e)\land R(e) \Rightarrow S(e) \\
\end{aligned}
$$
\end{zhongwen}
\begin{proof}
\begin{zhongwen}
\begin{enumerate}[label=\mycircle{\arabic{enumii}},leftmargin=\linewidth/4,rightmargin=\linewidth/4]
\item $P(e)\land R(e)$\hfill 前提引入
\item $P(e)$\hfill \mycircle{1} 化简
\item $R(e)$\hfill \mycircle{1} 化简
\item $\forall x(P(x)\to Q(x))$\hfill 前提引入
\item $P(e)\to Q(e)$\hfill \mycircle{4} US规则
\item $Q(e)$\hfill \mycircle{2} \mycircle{5} 假言推理
\item $Q(e)\land R(e)$\hfill \mycircle{3} \mycircle{6} 合取引入
\item $\forall x(Q(x)\land R(x)\to S(x))$\hfill 前提引入
\item $Q(e)\land R(e)\to S(e)$\hfill \mycircle{8} US规则
\item $S(e)$\hfill \mycircle{7} \mycircle{9} 假言推理
\end{enumerate}
\end{zhongwen}
\end{proof}
\end{enumerate}
\end{document}

View File

@@ -0,0 +1,206 @@
\documentclass[全部作业]{subfiles}
\usepackage{titlesec}
\pagestyle{fancyplain}
\fancyhead{}
\fancyhead[C]{\mysignature}
\setcounter{chapter}{2}
\begin{document}
% \titleformat{\chapter}{}
\chapter{命题逻辑}
\section{命题}
\begin{enumerate}
\myitem{下列语句哪些是命题?}{
\item 2是正数吗
\begin{zhongwen}
$$
\begin{aligned}
不是。
\end{aligned}
$$
\end{zhongwen}
\item $x^{2}+x+1=0$
\begin{zhongwen}
$$
\begin{aligned}
是。
\end{aligned}
$$
\end{zhongwen}
\item 我要上学。
\begin{zhongwen}
$$
\begin{aligned}
是。
\end{aligned}
$$
\end{zhongwen}
\item 明年2月1日下雨。
\begin{zhongwen}
$$
\begin{aligned}
是。
\end{aligned}
$$
\end{zhongwen}
\item 如果股票涨了,那么我就赚钱。
\begin{zhongwen}
$$
\begin{aligned}
是。
\end{aligned}
$$
\end{zhongwen}
}
\item 将当当网的图书高级搜索符号化http://search.dangdang.com/AdvanceSearch/AdvanceSearch.aspx?c=0
\begin{zhongwen}
$$
\begin{aligned}
&介质=\{\}\land 书名=\{\}\land 作者译者=\{\}\land 关键词=\{\}\land 出版社=\{\}\land ISBN=\{\}\land 包装=\{\} \\
&\land 分类=\{\}\land \{最低价格\} \le 价格 \le \{最高价格\}\land \{最低折扣\}\le 折扣\le \{最高折扣\} \\
&\land \{最早出版时间\}\le 出版时间\le \{最晚出版时间\}\land 库存状态=\{\} \\
\end{aligned}
$$
\end{zhongwen}
\item 请将语句“除非你已满16周岁否则只要你身高不足1.2米就不能乘公园的滑行铁道”符号化。
\begin{zhongwen}
$$
\begin{aligned}
&令p你已满16周岁q你身高足1.2r你能乘公园的滑行铁道。 \\
&命题符号化为:\lnot p \to (\lnot q \to \lnot r) \\
\end{aligned}
$$
\end{zhongwen}
\item p、q、r为如下命题 \par
\qquad p你得流感了 \par
\qquad q你错过了最后的考试 \par
\qquad r这门课你通过了 \\
请用自然语言表达命题$(p \to \lnot r)\lor (q \to \lnot r)$
\begin{zhongwen}
$$
\begin{aligned}
如果你得流感了,那么这门课你没通过,或者如果你错过了最后的考试,那么这门课你没通过。
\end{aligned}
$$
\end{zhongwen}
\myitem{判断下列命题的真值:}{
\item \begin{zhongwen}
$1+1=3,则2+2=4$
\end{zhongwen}
\begin{zhongwen}
$$
\begin{aligned}
最外层的蕴含式的前件为假,所以此命题的真值为1
\end{aligned}
$$
\end{zhongwen}
\item \begin{zhongwen}
$若鸟会飞,则1+1=3$
\end{zhongwen}
\begin{zhongwen}
$$
\begin{aligned}
&在考虑例外的情况下(\exists 不会飞的鸟类): \\
&\qquad 最外层的蕴含式的前件为假,所以此命题的真值为1\\
&在不考虑例外的情况下: \\
&\qquad 最外层的蕴含式的前件为真,但后件为假,所以此命题的真值为0\\
\end{aligned}
$$
\end{zhongwen}
}
\item 构造一个只含命题变量p、q和r的命题公式A满足p、q和r的任意一个赋值是A的成真赋值当且仅当p、q和r中恰有两个为真
\begin{zhongwen}
$$
\begin{aligned}
A=(p\land q\land \lnot r)\lor (p\land \lnot q\land r)\lor (\lnot p\land q\land r)
\end{aligned}
$$
\end{zhongwen}
\end{enumerate}
\section{等值演算}
\begin{enumerate}
\myitem{将下列两个命题符号化,并分别用真值表和等值演算的方法证明所得到的那两个命题公式是等值的。}{
\item 你不会休息所以就不会工作,你没有丰富的知识所以你就不会工作。
\item 你会工作所以一定会休息并具有丰富的知识。
}
\begin{zhongwen}
$$
\begin{aligned}
&p你会休息q你会工作r你有丰富的知识 \\
&(1)符号化为(\lnot p \to \lnot q)\land (\lnot r \to \lnot q) \\
&(2)符号化为q \to p \land r \\
\end{aligned}
$$
\end{zhongwen}
\begin{proof}
\begin{zhongwen}
$$
以下是真值表:
$$
\begin{longtable}{ccccc}
\hline
$p$ & $q$ & $r$ & $(\lnot p \to \lnot q)\land (\lnot r \to \lnot q)$ & $q \to p \land r$ \\
\hline
0 & 0 & 0 & 1 & 1 \\
0 & 0 & 1 & 1 & 1 \\
0 & 1 & 0 & 0 & 0 \\
0 & 1 & 1 & 0 & 0 \\
1 & 0 & 0 & 1 & 1 \\
1 & 0 & 1 & 1 & 1 \\
1 & 1 & 0 & 0 & 0 \\
1 & 1 & 1 & 1 & 1 \\
\hline
\end{longtable}
$$
\begin{aligned}
以下是等值演算: \\
(\lnot p \to \lnot q)\land (\lnot r \to \lnot q) & = (p\lor \lnot q)\land (r\lor \lnot q) \\
& = (p\land r)\lor \lnot q \\
& = \lnot q\lor (p\land r) \\
& = q \to p\land r \\
\end{aligned}
$$
$$
所以(\lnot p \to \lnot q)\land (\lnot r \to \lnot q)与q \to p \land r等值。
$$
\end{zhongwen}
\end{proof}
\item 用等值演算的方法证明命题恒等式$p \to (q \to p)=\lnot p \to (p \to \lnot q)$
\begin{proof}
\begin{zhongwen}
$$
\begin{aligned}
\lnot p \to (p \to \lnot q) & = p \lor (p \to \lnot q) \\
& = p \lor (\lnot p \lor \lnot q) \\
& = \lnot p \lor \lnot q \lor p \\
& = p \to (\lnot q \lor p) \\
& = p \to (q \to p) \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\myitem{一教师要从3名学生A、B和C中选派1$\sim $2人参加市级科技竞赛需满足以下条件}{
\item 若A去则C同去
\item 若B去则C不能去
\item 若C不去则A或B可以去。
}
问该如何选派?\\
\begin{zhongwen}
$$
\begin{aligned}
&令aA去bB去cC去 \\
则需满足:& \quad (a \to c)\land (b \to \lnot c) \land (\lnot c \to a \lor b)\land \lnot (a\land b\land c) \\
&=(\lnot a \lor c)\land (\lnot b \lor \lnot c)\land (c \lor (a \lor b))\land (\lnot a\lor \lnot b\lor \lnot c) \\
&=(\lnot a \lor c)\land (\lnot b \lor \lnot c)\land (a \lor b\lor c)\land (\lnot a\lor \lnot b\lor \lnot c) \\
&=(\lnot a\lor \lnot b\lor c)\land (\lnot a\lor b\lor c)\land (\lnot a\lor \lnot b\lor \lnot c)\land (a\lor \lnot b\lor \lnot c)\land (a\lor b\lor c) \\
&=\bigwedge M(0,3,4,6,7) \\
&=\bigvee m(1,2,5) \\
&=(\lnot a\land \lnot b\land c)\lor (\lnot a\land b\land \lnot c)\lor (a\land \lnot b\land c) \\
\end{aligned}
$$
\begin{flalign*}
即选派C或选派B或选派AC。&&\\
\end{flalign*}
\end{zhongwen}
\end{enumerate}
\end{document}

View File

@@ -0,0 +1,201 @@
\documentclass[全部作业]{subfiles}
\usepackage{mylatex}
\pagestyle{fancy}
\fancyhead{}
\fancyhead[C]{\mysignature}
\setcounter{chapter}{1}
\setcounter{section}{2}
\begin{document}
\section{集合运算的性质}
\begin{enumerate}
\item[9.] \ExplSyntaxOn
\begin{zhongwen}
$设A、B、C是集合证明下列结论$
\end{zhongwen}
\ExplSyntaxOff
\begin{enumerate}
\item[(3)] \ExplSyntaxOn
\begin{zhongwen}
$若A\cap B=\varnothing则A-B=A$
\end{zhongwen}
\ExplSyntaxOff
\begin{proof}
\ExplSyntaxOn
\begin{zhongwen}
$$
\begin{aligned}
&\because A\cap B=\varnothing\\
&\therefore \forall x \in A \implies x\notin B\\
&\therefore \forall x \in A\implies x\in \bar{B}\\
&\therefore A \subseteq \bar{B}\\
&\therefore A\cap \bar{B}=A\\
&\therefore A-B=A\\
\end{aligned}
$$
\end{zhongwen}
\ExplSyntaxOff
\end{proof}
\end{enumerate}
\item[11.] \ExplSyntaxOn
\begin{zhongwen}
$指出下列集合等式成立的充分必要条件其中A、B和C是集合$
\end{zhongwen}
\ExplSyntaxOff
\begin{enumerate}
\item[(5)] $(A-B)\cap (A-C)=\varnothing$
$$
\begin{aligned}
&(A-B)\cap (A-C)=A\cap \bar{B}\cap A \cap \bar{C}=A\cap \bar{B}\cap \bar{C}=A-B-C=\varnothing\\
&\iff A-B-C=\varnothing\\
\end{aligned}
$$
\end{enumerate}
\item[13.] \ExplSyntaxOn
\begin{zhongwen}
$设A和B是集合集合运算对称差\oplus 定义如下A\oplus B=(A-B)\cup (B-A).\\证明下列恒等式其中A、B和C是任意集合$
\end{zhongwen}
\ExplSyntaxOff
\begin{enumerate}
\item[(5)] $A\oplus B=(A\cup B)-(A\cap B)$
\begin{proof}
\ExplSyntaxOn
\begin{zhongwen}
$$
\begin{aligned}
(A\cup B)-(A\cap B) & = (A\cup B)\cap \overline{A\cap B} \\
& = (A\cup B)\cap (\bar{A}\cup \bar{B}) \\
& = ((A\cup B)\cap \bar{A})\cup ((A\cup B)\cap \bar{B}) \\
& = (B\cap \bar{A})\cup (A\cap \bar{B}) \\
& = (A-B)\cup (B-A) \\
& = A\oplus B \\
\end{aligned}
$$
\end{zhongwen}
\ExplSyntaxOff
\end{proof}
\end{enumerate}
\item[21.] \textit{设A、B、C和D是任意集合.请证明:}
\begin{enumerate}
\item $(A\times C)\cap (B\times D)=(A\cap B)\times (C\cap D)$
\begin{proof}
\ExplSyntaxOn
\begin{zhongwen}
$$
\begin{aligned}
\forall (x,y), \quad&(x,y)\in (A\times C)\cap (B\times D)\\
\iff &(x,y)\in (A\times C)(x,y)\in (B\times D)\\
\iff &x\in A,y\in C且x\in B,y\in D\\
\iff &x\in A\cap B且y\in C\cap D\\
\iff &(x,y)\in (A\cap B)\times (C\cap D)\\
\therefore \quad&(A\times C)\cap (B\times D)=(A\cap B)\times (C\cap D)\\
\end{aligned}
$$
\end{zhongwen}
\ExplSyntaxOff
\end{proof}
\end{enumerate}
\item[22.] \textit{$\{ A_\beta|\beta\in B \}$是以B为下标集的集合族.证明下列恒等式.}
\begin{enumerate}
\item $\overline{\displaystyle \bigcup_{\beta\in B} A_\beta}=\displaystyle \bigcap_{\beta\in B} \overline{A_\beta}$
\begin{proof}
% \ExplSyntaxOn
\begin{zhongwen}
$$
\begin{aligned}
\forall x, \quad&x\in \overline{\bigcup_{\beta\in B}A_\beta}\\
\iff& x\notin \bigcup_{\beta\in B} A_\beta\\
\iff&\lnot (\exists \beta\in B, x\in A_\beta)\\
\iff&\forall \beta\in B, x\notin A_\beta\\
\iff&\forall \beta\in B, x\in \overline{A_\beta}\\
\iff&x\in \bigcap_{\beta\in B} \overline{A_\beta}\\
\therefore \quad&\overline{\bigcup_{\beta\in B} A_\beta}=\bigcap_{\beta\in B} \overline{A_\beta}\\
\end{aligned}
$$
\end{zhongwen}
% \ExplSyntaxOff
\end{proof}
\end{enumerate}
\item[24.] \textit{设集合族$\{A_n|n\in \mathbb{N}\}$,令$B_0=A_0$$B_n=A_n-\displaystyle \bigcup_{k=0}^{n-1} A_k(n>0) $.证明:}
\begin{enumerate}
\item[(2)] $\displaystyle\bigcup_{ n\in \mathbb{N}} A_n =\displaystyle \bigcup_{n\in \mathbb{N}} B_n$
\begin{proof}
\begin{zhongwen}
$$
\begin{aligned}
&\because B_n=A_n-\displaystyle \bigcup_{k=0}^{n-1}A_k(n>0)\\
&\therefore \forall n>0, B_n\in A_n\\
&\forall x\in \bigcup_{n\in \mathbb{N}} B_n \iff\exists n_0\in \mathbb{N},x\in B_{n_0}\implies x\in A_{n_0}\\
&\therefore \displaystyle \bigcup_{n\in \mathbb{N}}A_n\supseteq \bigcup_{n\in \mathbb{N}} B_n \\
&\forall x\in \displaystyle \bigcup_{n\in \mathbb{N}} A_n, 则 \exists n\in \mathbb{N},x\in A_{n} \\
&设C_x=\{ n|x\in A_n \} \\
&设n_1=\min{C_x} \\
&则x\in A_{n_1}\forall n_2<n_1,x\notin A_{n_2} \\
&\therefore x\notin \displaystyle \bigcup_{k=0}^{n_1-1}A_k \\
&\therefore x\in A_{n_1}-\bigcup_{k=0}^{n_1-1}A_k \\
&\therefore x\in B_{n_1} \\
&\therefore x\in \displaystyle \bigcup_{n\in \mathbb{N}} B_n \\
&\therefore \bigcup_{n\in \mathbb{N}}A_n \subseteq \bigcup_{n\in \mathbb{N}} B_n \\
&\therefore \bigcup_{n\in \mathbb{N}} A_n =\bigcup_{n\in \mathbb{N}} B_n \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\end{enumerate}
\end{enumerate}
\section{有限集合的计数}
\begin{enumerate}
\item[26.] \textit{以1开头或者以00结束的不同的字节8位的二进制串有多少个}
\begin{zhongwen}
$$
\begin{aligned}
&设A为以1开头的不同的字节B为以00结束的不同的字节。 \\
&\left\vert1开头或者以00结束的不同的字节 \right\vert =\left\vert A\cup B \right\vert =\left\vert A \right\vert +\left\vert B \right\vert -\left\vert A\cap B \right\vert =2^{7}+2^{6}-2^{5} = 160 \\
\end{aligned}
$$
\end{zhongwen}
\item[27.] \begin{zhongwen}
$1\sim 200的正整数中,$
\end{zhongwen}
\begin{enumerate}
\item[(3)] \begin{zhongwen}
$含因子35,但不同时含因子35的正整数共有多少个?$
\end{zhongwen}
\begin{zhongwen}
$$
\begin{aligned}
&设A为1\sim 200中含因子3的正整数B为1\sim 200中含因子5的正整数 \\
&\left\vert1\sim 200的正整数中 含因子35,但不同时含因子35的正整数 \right\vert \\
&= \left\vert A\oplus B \right\vert =\left\vert A \right\vert +\left\vert B \right\vert -2\left\vert A\cap B \right\vert =66+40-2*13 = 80 \\
\end{aligned}
$$
\end{zhongwen}
*用JavaScript再验证一下
\begin{minted}{javascript}
> a =[]
[]
> for (let i = 1; i<=200; i++){
... a.push(i);
... }
> a.reduce((out, cur) => {
... if ((cur%3==0 || cur%5==0) && cur%15!=0) out.push(cur);
... return out;
... }, Array()).length
80
\end{minted}
\item[(5)] \begin{zhongwen}
$15互素的正整数(即与15之间的最大公因子为1的那些正整数)共有多少个?$
\end{zhongwen}
\begin{zhongwen}
$$
\begin{aligned}
&A与B的定义和上题相同 \\
&\left\vert1\sim 200的正整数中与15互素的正整数 \right\vert \\
&=\left\vert 1\sim 200的正整数 \right\vert -\left\vert A\cup B \right\vert \\
&=200-(\left\vert A \right\vert +\left\vert B \right\vert -\left\vert A\cap B \right\vert )=200-(66+40-13) = 107 \\
\end{aligned}
$$
\end{zhongwen}
\end{enumerate}
\end{enumerate}
\end{document}

View File

@@ -0,0 +1,125 @@
\documentclass[全部作业]{subfiles}
\pagestyle{fancyplain}
\fancyhead{}
\fancyhead[C]{\mysignature}
\setcounter{chapter}{3}
\setcounter{section}{2}
\begin{document}
\chapter{一阶逻辑}
\section{谓词、量词和谓词公式}
\begin{enumerate}
\item 用谓词公式表达语句“所有的运动员都钦佩某些教练”,个体域为全总个体域。
\begin{proof}[解]
\begin{zhongwen}
$$
\begin{aligned}
&由于个体域为全总个体域, \\
&设P(x)表示x为运动员Q(x)表示x为教练R(x,y)表示x钦佩y \\
&注意到“某些”表示复数,则语句“所有的运动员都钦佩某些教练”可表示为: \\
&\forall x(P(x) \to \exists y\exists z((y \neq z)\land Q(y)\land Q(z) \land R(x,y)\land R(x,z))) \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\item 用谓词公式表达语句“本班的学生都已学过微积分”个体域分别取ECNU的学生集合和本班的学生集合。
\begin{proof}[解]
\begin{zhongwen}
$$
\begin{aligned}
&当个体域取ECNU的学生集合时 \\
&设P(x)表示x为本班的学生Q(x)表示x已学过微积分 \\
&则语句“本班的学生都已学过微积分”可表示为: \\
&\forall x(P(x) \to Q(x)) \\
&当个体域取本班的学生集合时, \\
&设Q(x)表示x已学过微积分 \\
&则语句“本班的学生都已学过微积分”可表示为: \\
&\forall x Q(x) \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\item 用谓词公式表达语句“班上无人恰给另外两个同班同学发过电子邮件”,个体域取本班学生的集合。
\begin{proof}[解]
\begin{zhongwen}
$$
\begin{aligned}
&由于个体域为本班学生的集合, \\
&设P(x, y)表示x给y发过电子邮件 \\
&则语句“班上无人恰给另外两个同班同学发过电子邮件”可表示为: \\
&\lnot \exists x(\exists y\exists z((y\neq z)\land P(x,y)\land P(x,z)\land \forall w((w \neq y)\land (w\neq z) \to \lnot P(x,w)))) \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\item$\forall x(C(x)\lor \exists y(C(y)\land F(x,y)))$翻译成汉语其中C(x)表示x有电脑F(x,y) 表示x和y是同班同学个体域是学校全体学生的集合。
\begin{proof}[解]
\begin{zhongwen}
$$
\begin{aligned}
&对于学校中的任何一个学生,他有电脑,或者存在一个他的同班同学有电脑。 \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\item 给定解释I如下\\
个体域$D: \{ -2,3,6 \}$\\
个体常元$a: 6$\\
谓词$P: 2 > 1, Q(x): x\leqslant 3, R(x): x>5$\\
求出谓词公式$\forall x(P \to Q(x))\lor R(a)$在解释I下的真值。
\begin{proof}[解]
\begin{zhongwen}
$$
\begin{aligned}
&\forall x(P \to Q(x))\lor R(a)在解释I下的真值为 \\
&((P \to Q(-2))\land (P \to Q(3))\land (P \to Q(6)))\lor R(6) \\
&=(((2>1) \to (-2\leqslant 3))\land ((2>1) \to (3\leqslant 3))\land ((2>1) \to (6\leqslant 3)))\lor (6>5) \\
&=((1 \to 1)\land (1 \to 1)\land (1 \to 0))\lor 1\\
&=(1\land 1\land 0)\lor 1 \\
&=0\lor 1 \\
&=1 \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\item[书上3.] 请将下列谓词公式翻译为汉语,并指出每个命题的真值,这里个体域为实数集。
\begin{enumerate}
\item $\forall x(x^{2}=x)$
\begin{zhongwen}
$$
对于任何一个实数x都有x^{2}=x
$$
$$
真值为0
$$
\end{zhongwen}
\item $\exists x(2x=x)$
\begin{zhongwen}
$$
存在一个实数x满足2x=x
$$
$$
真值为1
$$
\end{zhongwen}
\item $\exists x(x^{2}+3x-2=x)$
\begin{zhongwen}
$$
存在一个实数x使得x^{2}+3x-2=x
$$
$$
真值为1
$$
\end{zhongwen}
\item $\forall x(x-3<x)$
\begin{zhongwen}
$$
对于任意一个实数x都有x-3<x
$$
$$
真值为1
$$
\end{zhongwen}
\end{enumerate}
\end{enumerate}
\end{document}

View File

@@ -0,0 +1,211 @@
% \PassOptionsToClass{twocolumn}{ctexbook} % 这个得在设置文档类之前使用才有效
% \PassOptionsToPackage{twocolumn}{ctexbook} % 这样没用
\documentclass[全部作业]{subfiles}
% \usepackage{multicol} % 已经放到mypreamble里了
% 以下这样和\setlength{\columnseprule}{1pt}应该是一样的
\columnseprule=1pt
\columnsep=30pt
\pagestyle{fancyplain}
\fancyhead{}
\fancyhead[C]{\mysignature}
\setcounter{chapter}{4}
\begin{document}
\chapter{关系}
\section{关系的概念}
\begin{enumerate}
\item 集合$X=\{a,b,c\}$上的一个关系R的关系矩阵如下请写出这个关系。矩阵的第1、2、3行以及第1、2、3列分别对应X中的元素a、b、c
$$
\begin{bmatrix} 1 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 0 & 1 \\\end{bmatrix}
$$
\begin{proof}[解]
\begin{zhongwen}
$$
\begin{aligned}
R = \{ (a,a),(a,c),(b,b), (c,a), (c,c) \}
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\item 一集合上的一个关系的关系图如下图所示,请写出这个关系。
\begin{center}
\includegraphics[width=0.3\linewidth]{imgs/2023-11-11-10-13-03.png}
\end{center}
\begin{proof}[解]
\begin{zhongwen}
$$
\begin{aligned}
R=\{ (a,a),(a,b),(b,a),(b,b),\\(c,a),(c,c),(c,d),(d,d) \}
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\item 设X和Y都是有限集$|X|=m$$|Y|=n$。问X到Y的不同的关系有多少个
\begin{proof}[解]
\begin{zhongwen}
$$
\begin{aligned}
X到Y的不同的关系有2^{m\times n}个。
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\end{enumerate}
\section{关系的运算}
\begin{enumerate}
\item 设R是X到Y的二元关系S是Y到Z的二元关系证明$(R \circ S)^{-1}=S^{-1}\circ R^{-1}$
\begin{proof}
\begin{zhongwen}
$$
\begin{aligned}
\forall (z, x),\qquad &(z, x)\in (R\circ S)^{-1} \\
\iff& (x, z)\in R\circ S \\
\iff&\exists y\in Y, \ \ \text{s.t.} \ (x,y)\in R \land (y,z)\in S \\
\iff& \exists y\in Y,\ \ \text{s.t.} \ (y,x)\in R^{-1}\land (z,y)\in S^{-1} \\
\iff&(z,x)\in S^{-1}\circ R^{-1} \\
\end{aligned}
$$
$$
\therefore (R\circ S)^{-1}=S^{-1}\circ R^{-1}
$$
\end{zhongwen}
\end{proof}
\item 设R、S、T都是X上的关系。证明$R\circ (S\cap T)\subseteq (R\circ S)\cap (R\circ T)$, $(R\cap S)\circ T \subseteq (R\circ T)\cap (S\circ T)$
\begin{proof}
\begin{zhongwen}
$$
\begin{aligned}
&\forall (x,w)\in R\circ (S\cap T) \\
&\exists y\in X,\ \ \text{s.t.} \ (x,y)\in R\land (y,w)\in S\cap T \\
&\therefore (x,y)\in R, (y,w)\in S,(y,w)\in T \\
&\therefore (x,w)\in R\circ S, (x,w)\in R\circ T \\
&\therefore (x,w)\in (R\circ S)\cap (R\circ T) \\
&\therefore R\circ (S\cap T)\subseteq (R\circ T)\cap (S\circ T) \\
\end{aligned}
$$
$$
\begin{aligned}
&\forall (x,w)\in (R\cap S)\circ T \\
&\exists z\in X,\ \ \text{s.t.} \ (x,z)\in R\cap S\land (z,w)\in T \\
&\therefore (x,z)\in R,(x,z)\in S,(z,w)\in T \\
&\therefore (x,w)\in R\circ T,(x,w)\in S\circ T \\
&\therefore (x,w)\in (R\circ T)\cap (S\circ T) \\
&\therefore (R\cap S)\circ T \subseteq (R\circ T)\cap (S\circ T) \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\end{enumerate}
\section{关系的特殊性质及其闭包}
\begin{enumerate}
\item 下列关系是否是自反、反自反、对称、反对称和传递的?
\begin{enumerate}
\item 集合$X=\{1,2,…,9,10\}$$X$上的关系$R=\{(x,y) | x+y=10\}$
\item 任意集合$X$上的恒等关系$I_{X}$
\item 任意集合$X$上的空关系$\varnothing $
\begin{table}[H]
\centering
\tabcolsep=0.5em
\begin{tabular}{c|ccccc}
\toprule
关系 & 自反 & 反自反 & 对称 & 反对称 & 传递\\
\midrule
(1) $R$ &&&&&\\
(2) $I_{X}$ &&&&&\\
(3) $\varnothing $ &&&&&\\
\bottomrule
\end{tabular}
\end{table}
\end{enumerate}
\item$X$是所有人组成的集合,定义$X$上的关系$R_1$$R_2$$aR_1b$当且仅当$a$$b$高,$aR_2b$当且仅当$a$$b$有共同的祖父母。问关系$R_1$$R2$是否是自反、反自反、对称、反对称、传递的?
\begin{table}[H]
\centering
\begin{tabular}{c|ccccc}
\toprule
关系 & 自反 & 反自反 & 对称 & 反对称 & 传递\\
\midrule
$R_1$ &&&&&\\
$R_2$ &&&&&\\
\bottomrule
\end{tabular}
\end{table}
\item* 下面的论证试图证明如果集合S上的关系R是对称和传递的那么R必定也是自反的。请指出其中的错误。\\
“由对称性从xRy可推出yRx再由传递性可从xRy和yRx推出xRx。于是对任意x$\in $SxRx成立所以R是自反的”
\begin{proof}[解]
\begin{zhongwen}
$$
\begin{aligned}
&对于\forall x\in S,并不一定\exists y\in S,\ \ \text{s.t.} \ xRy \\
&\lnot\exists y(y\in S\land xRy)时上述论证无效。 \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\item 证明:若$R$$X$上自反和传递的关系,则$R^2$=$R$
\begin{proof}
\begin{zhongwen}
$$
\begin{aligned}
&\forall (x,z)\in R^{2}\\
&\Rightarrow\exists y\in X,\ \ \text{s.t.} \ (x,y)\in R\land (y,z)\in R \\
&\because R是传递的 \\
&\therefore (x,z)\in R \\
&\therefore R^{2} \subseteq R \\
&\forall (x,z)\in R \\
&\because R是自反的 \\
&\therefore (z,z)\in R \\
&\therefore (x,z) \in R^{2} \\
&\therefore R \subseteq R^{2} \\
&综上所述R^{2}=R \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\item$X$是有限集,$|X|=n$。问$X$上有多少个不同的:
\begin{enumerate}
\item* 对称关系?
\begin{zhongwen}
$$
即n维对称矩阵的个数
$$
$$
2^{\frac{n(n+1)}{2}}
$$
\end{zhongwen}
\item* 反对称关系?
\begin{zhongwen}
$$
\begin{aligned}
&n维矩阵的每组对称位置只有000110\\
&三种情况,对角线每个位置可以为01\\
\end{aligned}
$$
$$
3^{\frac{n(n-1)}{2}}\times 2^{n}
$$
\end{zhongwen}
\item 既非自反又非反自反的关系?
\begin{zhongwen}
$$
即对角线既不是全1,也不是全0的n维矩阵个数
$$
$$
(2^{n}-2)\times 2^{n^{2}-n}
$$
\end{zhongwen}
\end{enumerate}
\item$R_1$$R_2$$X$上的关系。证明$t(R_1\cup R_2)\supseteq t(R_1)\cup t(R_2)$
\begin{proof}
\begin{zhongwen}
$$
\begin{aligned}
&\because t(R)=\bigcup_{i=1} ^{\infty}R^{i} \\
&\therefore 原式可转化为\bigcup_{i=1} ^{\infty}(R_1\cup R_2)^{i}\supseteq \bigcup_{j=1} ^{\infty}R_1^{j}\cup \bigcup_{k=1} ^{\infty}R_2^{k} \\
&之后实在不会做了。 \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\end{enumerate}
\end{document}

View File

@@ -0,0 +1,119 @@
\documentclass[全部作业]{subfiles}
\pagestyle{fancyplain}
\fancyhead{}
\fancyhead[C]{\mysignature}
\setcounter{chapter}{6}
\setcounter{section}{1}
\begin{document}
\section{集合的基数}
\label{cardinality}
\begin{enumerate}
\item 集合$\{ x\ |\ x\in \mathbb{Z},\text{}x\text{不能被3整除} \}$是否是可数集?若是,则给出自然数集$\mathbb{N}$与它之间的一个一一对应。
\begin{proof}[解]
\begin{zhongwen}
将给定的集合记为$A$,它是可数集。
给出一一对应的函数如下:
$$
f\colon \mathbb{N} \to A, x \mapsto \begin{cases}
\displaystyle (-1)^{\left\lfloor \frac{x}{2} \right\rfloor}\times 3 \left\lfloor \frac{x+2}{4} \right\rfloor + 1 , & x为偶数,x\geqslant 0 \vspace{1em} \\
\displaystyle (-1)^{\left\lfloor \frac{x}{2} \right\rfloor}\times 3 \left\lfloor \frac{x+2}{4} \right\rfloor + 2 , & x为奇数,x\geqslant 0 \\
\end{cases}
$$
\end{zhongwen}
\end{proof}
\item 设集合族$\{ A_n\ |\ n\in \mathbb{N} \}$$\{ B_n\ |\ n\in \mathbb{N} \}$中的集合都是两两不相交的($i\neq j$$A_i\cap A_j=\varnothing $$B_i\cap B_j=\varnothing $),且对任意$n\in \mathbb{N}$$A_n\sim B_n$。请证明$\displaystyle \bigcup_{n\in \mathbb{N}} A_n \sim \bigcup_{n\in \mathbb{N}} B_n$
\begin{proof}
\begin{zhongwen}
对于$\forall n\in \mathbb{N}$$A_n\sim B_n$,所以存在一一对应的$f_n: A_n \to B_n$
那么可以定义$f$如下:
$$
f\colon \bigcup_{n\in \mathbb{N}} A_n \to \bigcup_{n\in \mathbb{N}} B_n, x \mapsto \begin{cases}
f_1(x) , & x\in A_1 \\
f_2(x) , & x\in A_2 \\
\cdots , & \cdots \\
f_n(x) , & x\in A_n \\
\end{cases}
$$
因为$\{ A_n\ |\ n\in \mathbb{N} \}$两两不相交,所以$f$是一个函数,下面证明$f$是一一对应的。
对于任意的$\displaystyle y \in \bigcup_{n\in \mathbb{N}} B_n$,由于$\{ B_n\ |\ n\in \mathbb{N} \}$两两不相交,则必定存在唯一的$ i \in \mathbb{N}$使得$y \in B_i$,而$f_i:A_i \to B_i$是一一对应的,所以必定存在唯一的$\displaystyle x\in A_i \subseteq \bigcup_{n\in \mathbb{N}} A_n$使得$f(x)=y$,因此$f$是一一对应的。
由于构造出了$\displaystyle \bigcup_{n\in \mathbb{N}} A_n$$\displaystyle \bigcup_{n\in \mathbb{N}} B_i$之间的一一对应的函数,所以$\displaystyle \bigcup_{n\in \mathbb{N}} A_n \sim \bigcup_{n\in \mathbb{N}} B_n$
\end{zhongwen}
\end{proof}
\item$F$$X$$Y$的所有函数所组成的集合,$F=\{ f\ |\ f:X \to Y \}$$\left\vert X \right\vert =n$。证明$F\sim Y^{n}$ \label{functioncardinality}
\begin{proof}
\begin{zhongwen}
对于$\forall f \in F$$f$都唯一对应于一个$\left\vert X \right\vert $$\left\vert Y \right\vert $列的关系矩阵并且每行有且仅有一个1。
那么每一行这个1的位置有$\left\vert Y \right\vert $种情况,一共有$\left\vert X \right\vert $行,所以一共有$\left\vert Y \right\vert ^{\left\vert X \right\vert }=\left\vert Y \right\vert ^{n}$种情况。
所以$\left\vert F \right\vert =\left\vert Y \right\vert ^{n}$
$Y^{n}$表示集合的笛卡尔积,所以有$\left\vert Y \right\vert ^{n}=\left\vert Y^{n} \right\vert $
所以$\left\vert F \right\vert =\left\vert Y \right\vert ^{n}=\left\vert Y^{n} \right\vert $,所以$F\sim Y^{n}$
\end{zhongwen}
\end{proof}
\item *证明无限可数集的所有有限子集组成一个可数集。
\begin{proof}
\begin{zhongwen}
$A$为无限可数集,则$A$可以和$\mathbb{N}$一一对应,所以可以将$A$记为$\{ a_i\ |\ i\in \mathbb{N} \}$
对于$\forall M \in \mathbb{N}$,取$B_{M}=\{ a_i\ |\ i\in \mathbb{N},i\leqslant M \}$,则$A$的所有有限子集可以记作
$$
\bigcup_{M\in \mathbb{N}} P(B_{M})
$$
而对于$\forall M\in \mathbb{N}$$a_{M+1} \not \in B_{M}$$a_{M+1}\in B_{M+1}$,所以$\{ a_{M+1} \}\not \in P(B_{M})$$\{ a_{M+1} \}\in P(B_{M+1})$,所以
$$
\bigcup_{1\leqslant m\leqslant M} P(B_{m}) \subsetneqq \bigcup_{1\leqslant m\leqslant M+1} P(B_{m})
$$
所以对于有限集合$\displaystyle \bigcup_{1\leqslant m\leqslant M} P(B_{m})$$\displaystyle \bigcup_{1\leqslant m\leqslant M+1} P(B_{m})$,有
$$
\left\vert \bigcup_{1\leqslant m\leqslant M} P(B_{m}) \right\vert +1\leqslant \left\vert \bigcup_{1\leqslant m\leqslant M+1} P(B_{m}) \right\vert
$$
根据极限的定义可知
$$
\left\vert\bigcup_{M\in \mathbb{N}} P(B_{M})\right\vert=\left\vert\lim_{M \to \infty} \bigcup_{1\leqslant m\leqslant M} P(B_{m}) \right\vert \geqslant \lim_{M \to \infty}\left\vert \bigcup_{1\leqslant m\leqslant M} P(B_{m}) \right\vert =+\infty
$$
所以A的所有有限子集$\displaystyle \bigcup_{n\in \mathbb{N}} P(B_{M})$是无限集,并且能找到$\mathbb{N}$$\displaystyle \bigcup_{n\in \mathbb{N}} P(B_{M})$的映射,所以$\displaystyle \left\vert \bigcup_{n\in \mathbb{N}} P(B_{M}) \right\vert \leqslant $可数集的基数,并且$\displaystyle \left\vert \bigcup_{n\in \mathbb{N}} P(B_{M}) \right\vert \geqslant $可数集的基数。
所以A的所有有限子集$\displaystyle \bigcup_{n\in \mathbb{N}} P(B_{M})$是可数集。
即 无限可数集的所有有限子集组成一个可数集。
\end{zhongwen}
\end{proof}
\end{enumerate}
\section{不可解问题}
\begin{enumerate}
\item *设集合$F=\{ f\ |\ \mathbb{N} \to M \}$,其中$M$为正偶数集。证明:$F$中存在这样的函数$f$,计算$f$的C程序不存在。
\begin{proof}
\begin{zhongwen}
由于C程序的集合是可数的因此只需证明$F$为不可数集合。
根据 \ref{cardinality} 节的第 \ref{functioncardinality} 题可知,$
\left\vert F \right\vert = \left\vert M \right\vert ^{\left\vert \mathbb{N} \right\vert }$,所以$F\sim \{ f\ |\ f:\mathbb{N} \to \mathbb{N} \}$,即$F$与问题集等势,所以$F$不可数。
\end{zhongwen}
\end{proof}
\end{enumerate}
\end{document}

View File

@@ -0,0 +1,101 @@
\documentclass[全部作业]{subfiles}
\pagestyle{fancyplain}
\fancyhead{}
\fancyhead[C]{\mysignature}
\setcounter{chapter}{5}
\begin{document}
\chapter{函数}
\section{函数的概念和性质}
\begin{enumerate}
\item $f:X \to Y$。对任意$M \subseteq X$,定义$f(M)=\{ f(x)\ |\ x\in M \}$。对于任意$A,B \subseteq X$
\begin{enumerate}
\item 证明$f(A\cup B)=f(A)\cup f(B)$
\begin{proof}
\begin{zhongwen}
$\forall Z \in f(A\cup B)$,则$\exists x \in A\cup B$,使得$Z=f(x)$,因此$x\in A$或者$x\in B$
$x\in A$,则$Z\in f(A)$;若$x\in B$,则$Z\in f(B)$
于是$Z\in f(A)\cup f(B)$
所以$f(A\cup B) \subseteq f(A)\cup f(B)$\label{1}
$\forall Z\in f(A)\cup f(B)$,则$Z\in f(A)$$Z\in f(B)$
$Z\in f(A)$,则$\exists x \in A$,使得$Z=f(x)$,因此$x\in A\cup B$,所以$Z\in f(A\cup B)$
所以$f(A)\cup f(B) \subseteq f(A\cup B)$
所以$f(A\cup B)=f(A)\cup f(B)$
\end{zhongwen}
\end{proof}
\item 举例说明$f(A\cap B)\neq f(A)\cap f(B)$
\begin{zhongwen}
$f,A,B$定义如下:
$$
f\colon \mathbb{R} \to \mathbb{R}, x \mapsto x^{2}
$$
$$A=(-\infty, 0]\quad B=[0,+\infty)$$
$f(A\cap B)=f(\{ 0 \})=\{ 0 \}$$f(A)\cap f(B)=[0,+\infty)$
$f(A\cap B)\neq f(A)\cap f(B)$
\end{zhongwen}
\end{enumerate}
\item $f:X \to Y$,下列命题是否成立?
\begin{enumerate}
\item $f$是一对一的当且仅当对任意$a,b \in X$,当$f(a)=f(b)$时,必有$a=b$
\begin{zhongwen}
成立,即一对一的定义的逆否命题。
\end{zhongwen}
\item $f$是一对一的当且仅当对任意$a,b \in X$,当$f(a)\neq f(b)$时,必有$a\neq b$
\begin{zhongwen}
不成立,取$X=\{ 1,2 \}$$f(x)=\{ \{ 1,1 \},\{ 2,1 \} \}$。则$f$$X$$Y$的函数,且满足$\forall a,b \in X$$f(a)\neq f(b) \Rightarrow a\neq b$,但$f$不是一对一的。
\end{zhongwen}
\end{enumerate}
\item 下图展示了五个关系的关系图。问:这些关系中,哪些是函数?哪些是一对一的函数?哪些是到上的函数?哪些是一一对应?\\
\includegraphics[width=1\linewidth]{imgs/2023-12-04-06-31-00.png}
\begin{zhongwen}
设从左到右分别为图1、2、3、4、5。
图1、2、3、4是函数
图1、3是一对一的函数
图2、3是到上的函数
图3是一一对应的函数。
\end{zhongwen}
\item $f:X \to Y$, $g:Y \to Z$。命题“$f \circ g$是一对一的当且仅当$f$$g$都是一对一的”是否成立?
\begin{zhongwen}
成立。
$f$$g$都是一对一的,则$f \circ g$是一对一的为定理6.1.2,现给出证明如下:
\begin{proof}
$f$是一对一的可知$\forall a,b \in X$$a\neq b$,有$f(a)\neq f(b)$,而$g$也是一对一的,所以$g(f(a))\neq g(f(b))$,即$f\circ g(a)\neq f\circ g(b)$,所以$f\circ g$是一对一的。
\end{proof}
下证若$f\circ g$是一对一的,则$f$$g$都是一对一的。
\begin{proof}
反证,若$f$$g$都不是一对一的,则$\exists a,b \in X$,使得$f(a)=f(b)$,因此$g(f(a))=g(f(b))$,即$f\circ g(a)=f\circ g(b)$,所以$f\circ g$也不是一对一的。
\end{proof}
\end{zhongwen}
\end{enumerate}
\end{document}

View File

@@ -0,0 +1,192 @@
\documentclass[全部作业]{subfiles}
\pagestyle{fancyplain}
\fancyhead{}
\fancyhead[C]{\mysignature}
\setcounter{chapter}{7}
\setcounter{section}{2}
\begin{document}
\section{图的连通性}
\begin{enumerate}
\item 设简单无向图$G=(V,E)$,若$\delta (G)\geqslant k (k\geqslant 1)$。请证明:$G$有长度为$k$的基本通路。
\begin{proof}
\begin{zhongwen}
使用数学归纳法,
由于$\delta (G)\geqslant k\geqslant 1$,所以$G$中存在边,从而$G$不是零图因此必定有长度为1的基本通路。
假设$G$中存在长度为$m-1$的基本通路$\alpha $ $(m\leqslant k)$,则$\alpha $中的顶点总数为$m$(基本通路的顶点互不相同)。那么对于$\alpha $两端的其中一个端点$v$$\alpha $去除$v$后的顶点总数为$m-1$。由于$d(v)\geqslant \delta (G)\geqslant k\geqslant m>m-1$,即$v$的度数大于$\alpha $中去除$v$后的顶点总数,所以与$v$相连的边中必定存在一条边$e$连接了不在$\alpha $中的顶点$v'$,于是将边$e$和顶点$v'$加入到$\alpha $中,就构成了长度为$m$的基本通路。
所以$\forall m \in \mathbb{N}, 1\leqslant m\leqslant k$$G$有长度为$m$的基本通路。自然地,$G$有长度为$k$的基本通路。
\end{zhongwen}
\end{proof}
\item 证明:若无向图$G$没有长度为奇数的基本回路,则$G$没有任何长度为奇数的回路。
\begin{proof}
\begin{zhongwen}
证明原命题的逆否命题“若$G$中存在一条长度为奇数的回路,则$G$中必定存在长度为奇数的基本回路。”
$G$中存在一条长度为奇数的回路$\alpha $,则可以设$\alpha =v_0e_1v_1e_2\cdots e_k v_k$$\alpha $的长度$k$为奇数。若$\alpha $是基本回路,则$G$中存在长度为奇数的基本回路。
$\alpha $不是基本回路,则其中存在相同的顶点,不妨设$v_i=v_j$, $0\leqslant i<j\leqslant k$,于是$\alpha $的子序列$v_i e_{i+1} v_{i+1} e_{i+2}\cdots e_j v_j$构成一个回路,记为$\alpha '$,并且从$\alpha $中删除$\alpha '$后(保留顶点$v_i$)仍然是一个回路,记为$\alpha ''$,并且$\alpha '$$\alpha ''$的长度之和为原始回路$\alpha $的长度$k$。因为$k$为正奇数,所以将其拆分成两个正整数之和后其中必定有一个正整数为奇数,即$\alpha '$$\alpha ''$中必定有一个长度为奇数。取这个长度为奇数的回路,记为$\alpha_1$,则可以对$\alpha_1$重复上述拆分回路的过程,得到长度为奇数的回路$\alpha_2, \cdots \cdots$。注意到$\alpha $的有限性,上述拆分回路的过程不可能无限进行,最后一次拆分过程结束后,所得到的回路就是长度为奇数的基本回路。
总之,$G$中必定存在长度为奇数的基本回路。
\end{zhongwen}
\end{proof}
\item 证明:在任何无向图中,任何奇数度的顶点都有通路到某个其他的奇数度顶点。
\begin{proof}
\begin{zhongwen}
对于任何一个无向图$G$,在其中任取一个奇数度的顶点$v$,使用反证法。
假设对于所有以$v$为一端的通路,通路的另一端的顶点都是偶数度的,那么将$v$与这些顶点以及与它们相连的边全部取出,即构成$G$的一个连通分量$G'$。在$G'$中,只有$v$是奇数度的,其它所有顶点都是偶数度的,那么$G'$的度数之和为奇数,不满足握手定理,因此这种情况不可能发生。
所以$v$必定有通路到某个其他的奇数度顶点。
\end{zhongwen}
\end{proof}
\item 分别求出下列三个无向图的各个连通分量。
\begin{center}
\includegraphics[width=0.8\linewidth]{imgs/2023-12-24-08-27-46.png}
\end{center}
\begin{proof}[解]
\begin{center}
\includexopp[0.7]{7.3.4}
\end{center}
\end{proof}
\end{enumerate}
\section{最短通路和Dijkstra算法}
\section{图着色}
\begin{enumerate}
\item 无向图的色数为1意味着什么
\begin{zhongwen}
图中不存在边。
\end{zhongwen}
\item 一大学有5个专业委员会物理、化学、数学、生物、计算机6位院士B、C、D、G、S、W。专业委员会由院士组成物理委员会有院士C、S和W化学委员会有院士C、D和W数学委员会有院士B、C、G和S生物委员会有院士B和G计算机委员会有院士D和G。每个专业委员会每周开一小时例会所有成员都不能缺席。如果某院士同时是两个专业委员会的成员那么这两个专业委员会的例会就不能安排在同一个时间。现要为这些例会安排时间希望它们的时间尽可能集中。问最少需要几个开会时间请给出一种安排。
\begin{proof}[解]
\begin{zhongwen}
首先将专业委员会和院士的关系整理成如下表格:
\begin{center}
\begin{tabular}{cc} % tabular里用\centering会导致一直在编译停不下来
\toprule
专业委员会 & 院士\\
\midrule
物理&C、S、W\\
化学&C、D、W\\
数学&B、C、G、S\\
生物&B、G\\
计算机&D、G\\
\bottomrule
\end{tabular}
\end{center}
之后根据“如果某院士同时是两个专业委员会的成员,那么这两个专业委员会的例会就不能安排在同一个时间”构造图,将专业委员会作为顶点,如果这两个专业委员会有相同的院士,那么就在这两个顶点之间连一条边,问题即可转化为图着色问题。于是构造出下方左图:
\begin{center}
\includesvgpdf[0.45]{7.5.2.drawio}
\hfill
\includesvgpdf[0.45]{7.5.2-colour.drawio}
\end{center}
设此图为$G$,由于存在$C_3$的结构,因此$\chi (G)\geqslant 3$又因为此图不是完全图也不是奇圈所以根据Brooks定理$\chi (G)\leqslant \Delta (G)=4$
那么尝试找到色数为3的着色方案即上方右图。
因此最少需要3个开会时间即物理和计算机同一时间开会化学和生物同一时间开会数学单独时间开会。
\end{zhongwen}
\end{proof}
\end{enumerate}
\pagebreak[1]
\section{图的同构}
\begin{enumerate}
\item 有3个顶点的不同构的简单无向图有多少个
\begin{zhongwen}
3个。分别为一条边、两条边、三条边的情况
\end{zhongwen}
\item 证明若无向图G不是连通图则其补图必为连通图。
\begin{proof}
\begin{zhongwen}
$G$的补图为$G'$,下证$G'$是连通图。
$G'$中任取两个顶点,若这两个顶点在$G$中不相邻,那么根据补图的定义,它们在$G'$中必定相邻,从而是连通的。
若这两个顶点(设为$v_1,v_2$)在$G$中相邻,即它们在$G$中是连通的,而$G$不是连通图,所以必定存在另一个顶点$v_3$,使得$v_1$$v_3$不连通,$v_2$$v_3$不连通,从而$v_1$$v_3$不相邻,$v_2$$v_3$不相邻。那么根据补图的定义,在$G'$$v_1$$v_3$相邻,$v_2$$v_3$相邻,所以$v_1$$v_2$$G'$中连通。
所以在$G'$中任取两个顶点,它们都是连通的,因此$G'$是连通图。
\end{zhongwen}
\end{proof}
\end{enumerate}
\chapter{具有特殊性质的图}
\section{欧拉图}
\begin{enumerate}
\item 一房子的平面图如图。问能否从前门进去,最后从后门出去,走过所有的门且每扇门只经过一次?
\begin{center}
\includegraphics[width=0.3\linewidth]{imgs/2023-12-24-10-01-59.png}
\end{center}
\begin{proof}[解]
\begin{zhongwen}
将每个房间作为一个顶点,如果两个房间之间有门,则在这两个房间之间连一条边,同时将前门外的空间也作为一个顶点,后门外的空间也作为一个顶点,则可以构造出图如下:
\begin{center}
\includexopp[0.8]{8.1.1}
\end{center}
对于该图只有前门外的顶点和后门外的顶点度数为1是奇数其它顶点的度数都是偶数因此存在从前门外顶点到后门外顶点的欧拉通路因为门与图中的边对应所以能从前门进去最后从后门出去走过所有的门且每扇门只经过一次。
\end{zhongwen}
\end{proof}
\item 对于有16个扇区和4个探测器的磁鼓给出一种合理的0-1赋值。
\begin{zhongwen}
% 虽然可以借助欧拉图来做,但是比较复杂,这里使用一个比较简便的方法。
\begin{proof}[解]
% 首先4个探测器探测出的0-1序列最多有$2^{4}=16$种情况也即4位二进制串的数量。要区分16个扇区则必定这16种情况要和16个扇区一一对应也即每个4位二进制串都对应了一个扇区。因此必定有一个扇区与1111对应也有一个扇区与0000对应好吧这样还是很麻烦还是用欧拉图来做吧。
以所有的3位二进制串为顶点对于两个二进制串如果前一个二进制串的后2位等于后一个二进制串的前2位则从前一个二进制串到后一个二进制串连一条有向边。可以构造出图如下
\begin{center}
\includesvgpdf[0.5]{8.1.2.drawio}
\end{center}
值得注意的是上图也可以看成是数字逻辑电路中3位移位寄存器的状态转换图。
% 在上图中寻找到一条欧拉回路:$000\to 001\to 010\to 101\to 011\to 111\to 110\to 100\to 000$这个好像是经过了所有顶点但没有经过所有的边那个把图中的所有顶点换成边所有边换成顶点的操作叫什么好像这样操作之后就是欧拉通路而且是3位的欧拉通路但是这个本来能解决4位的问题转换后只能解决3位了感觉好像和米利模型、摩尔模型也有关系因为米利模型比摩尔模型可以用更少的状态。
在上图中寻找到一条欧拉回路:$110\to 100\to 000\to 000\to 001\to 011\to 111\to 111\to 110\to 101\to 010\to 100\to 001\to 010\to 101\to 011\to 110 $
依次选取这条欧拉回路所经过的每个节点终点除外的最后一位则可得到一个满足要求的0-1赋值为$0000111101001011$
\end{proof}
\end{zhongwen}
\end{enumerate}
\end{document}

View File

@@ -0,0 +1,67 @@
\documentclass[全部作业]{subfiles}
\pagestyle{fancyplain}
\fancyhead{}
\fancyhead[C]{\mysignature}
\setcounter{chapter}{8}
\setcounter{section}{1}
\begin{document}
\section{哈密顿图}
\begin{enumerate}
\item 说明下图不是哈密顿图。
\begin{center}
\includegraphics[width=0.3\linewidth]{imgs/2023-12-30-09-42-18.png}
\end{center}
\begin{zhongwen}
由于在此图中找不到哈密顿回路,所以此图不是哈密顿图。
\end{zhongwen}
\item *证明任意竞赛图都有有向哈密顿通路。
\begin{zhongwen}
不会。
\end{zhongwen}
\item 为了测试计算机网络上的所有连接和设备,可以在网络上发一个诊断消息。为了测试所有的连接,应当使用什么种类的通路?为了测试所有的设备呢?
\begin{zhongwen}
为了测试所有的连接,应当使用欧拉通路;为了测试所有的设备,应当使用哈密顿通路。
\end{zhongwen}
\end{enumerate}
\section{平面图}
\begin{enumerate}
\item 设简单连通图$G$$n$个顶点、$e$条边。若$G$是平面图,请证明:$e\leqslant 3n-6$\label{question:1}
\begin{proof}
\begin{zhongwen}
因为$G$是简单图所以其面的次数都不小于3根据欧拉公式的推论
$$
e\leqslant \frac{3}{3-2}\times (n-2)=3n-6
$$
\end{zhongwen}
\end{proof}
\item 若简单连通图$G$$n$个顶点、$e$条边,则$G$的厚度至少为$\left\lceil e/(3n-6) \right\rceil $。(简单图$G$的厚度是指$G$的平面子图的最小个数,这些子图的并是$G$。)
\begin{proof}
\begin{zhongwen}
$G$的厚度为$m$,则可以将$G$看做$m$个平面子图的并,将这些平面子图设为$G_1,G_2, \ldots G_m$,则$ G=\bigcup_{i=1}^{m} G_i$。对$\forall i=1,2, \ldots , m$,设$G_i$的顶点数为$n_i$,边数为$e_i$。则根据第 \ref{question:1} 题,有$0<e_i\leqslant 3 n_i - 6$,所以
$$
\forall i=1,2, \ldots ,m, \quad e_i\leqslant 3 n_i-6\leqslant 3n-6
$$
对不等式进行求和可得
$$
e \leqslant \sum_{i=1}^{m}e_i \leqslant \sum_{i=1}^{m}(3n-6)=m(3n-6)
$$
所以有
$$
m\geqslant \frac{e}{3n-6}
$$
注意到$G$的厚度$m$为整数,所以$G$的厚度至少为$\left\lceil e/(3n-6) \right\rceil $
\end{zhongwen}
\end{proof}
\end{enumerate}
\end{document}

View File

@@ -0,0 +1,205 @@
\documentclass[全部作业]{subfiles}
\pagestyle{fancyplain}
\fancyhead{}
\fancyhead[C]{\mysignature}
\setcounter{chapter}{5}
\setcounter{section}{3}
\begin{document}
\section{等价关系和划分}
\begin{enumerate}
\item 设X是所有人组成的集合如下定义的关系哪些是X上的等价关系
\begin{enumerate}[rightmargin=\linewidth/3]
\item $\{ \left. (a,b) \right|\text{a是b的兄弟} \}$\hfill 不是
\item $\{ \left. (a,b) \right|\text{a与b的年龄相差不超过3} \}$\hfill 不是
\item $\{ \left. (a,b) \right|\text{a和b有相同的祖父} \}$\hfill
\item $\{ \left. (a,b) \right|\text{a与b相识} \}$\hfill 不是
\item $\{ \left. (a,b) \right|\text{a与b会说同一种语言} \}$\hfill
\end{enumerate}
\item$R_1$$R_2$$X$上的等价关系,则$X^{2}-R_1$$R_1-R_2$$R_1^{2}$$t(R_1\cup R_2)$是否也都是$X$上的等价关系?为什么?
\begin{proof}[解]
\begin{zhongwen}
$$
\begin{aligned}
&\because \forall x \in X, (x,x)\in R_1 \quad \therefore (x,x)\not \in X^{2}-R_1 \quad\therefore X^{2}-R_1不是X上的等价关系\\
\\
&\because X^{2}是X上的等价关系 \quad \therefore 若取R_1=X^{2}则R_1-R_2不是X上的等价关系 \\
&若取R_2=\varnothing 则R_1-R_2是X上的等价关系 \\
&\therefore R_1-R_2不一定是X上的等价关系 \\
\\
&R_1^{2}=R_1是X上的等价关系 \\
\\
&\forall x\in X(x,x)\in R_1 \subseteq R_1\cup R_2\subseteq t(R_1\cup R_2) \quad\therefore t(R_1\cup R_2)是自反关系\\
&由上一节的例题可知,对称关系的并也是对称关系,对称关系的传递闭包也是对称关系\\
&\therefore t(R_1\cup R_2)是对称关系 \\
&t(R_1\cup R_2)是传递闭包,所以是传递关系 \\
&因此t(R_1\cup R_2)是X上的等价关系 \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\item$X=\{ \left. (x,y) \right|\text{x和y是不为零的实数} \}$$E$$X$上的关系:$(x_1,y_1)E(x_2,y_2)$当且仅当$\displaystyle \frac{y_1}{x_1}=\frac{y_2}{x_2}$$x_1\cdot x_2>0$
证明$E$$X$上的等价关系,并给出$[(x,y)]_{E}$的几何解释。
\begin{proof}
\begin{zhongwen}
$$
\begin{aligned}
&\forall (x,y)\in X则x \neq 0,y\neq 0\quad\therefore x\cdot x=x^{2}>0,\frac{y}{x}=\frac{y}{x} \quad \therefore (x,y)E(x,y)即E是自反关系 \\
&\forall ((x_1,y_1),(x_2,y_2))\in E即x_1\cdot x_2>0,\frac{y_1}{x_1}=\frac{y_2}{x_2}则x_2\cdot x_1>0,\frac{y_2}{x_2}=\frac{y_1}{x_1} \\
&\therefore ((x_2,y_2),(x_1,y_1))\in E即 E是对称关系 \\
&\forall ((x_1,y_1),(x_2,y_2)),((x_2,y_2),(x_3,y_3))\in E即x_1\cdot x_2>0,x_2\cdot x_3>0,\frac{y_1}{x_1}=\frac{y_2}{x_2},\frac{y_2}{x_2}=\frac{y_3}{x_3}\\
&\therefore x_1\cdot x_3>0,\frac{y_1}{x_1}=\frac{y_3}{x_3}\quad \therefore ((x_1,y_1),(x_3,y_3))\in E即E是传递关系 \\
&\therefore E是X上的等价关系 \\
&[(x,y)]_{E}表示从原点出发并经过(x,y)的某一条射线去除原点 \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\item 下面哪些$\mathbb{Z}$的子集簇构成$\mathbb{Z}$的划分?为什么?
\begin{enumerate}
\item \{偶数集,奇数集\}
\begin{zhongwen}
$$
\begin{aligned}
&构成,令\pi =\{ 偶数集,奇数集 \},则偶数集\neq \varnothing ,奇数集\neq \varnothing \\
&偶数集\cap 奇数集=\varnothing,\quad 偶数集\cup 奇数集=\mathbb{Z} \\
&\therefore \{ 偶数集,奇数集 \}构成\mathbb{Z}的划分 \\
\end{aligned}
$$
\end{zhongwen}
\item \{正整数集,负整数集\}
\begin{zhongwen}
$$
\begin{aligned}
不构成,\because 0\in \mathbb{Z},但0\not \in 正整数集\cup 负整数集,即正整数集\cup 负整数集\neq \mathbb{Z}
\end{aligned}
$$
\end{zhongwen}
\item \{能被3整除的整数的集合,被3除余数为1的整数的集合,被3除余数为2的整数的集合\}
\begin{zhongwen}
$$
\begin{aligned}
构成,因为任何一个整数除以3的余数只能是012.
\end{aligned}
$$
\end{zhongwen}
\item \{小于-100的整数的集合,绝对值不超过100的整数的集合,大于100的整数的集合\}
\begin{zhongwen}
$$
\begin{aligned}
构成,任何一个整数必然在且只在这三个集合中的某一个集合中。
\end{aligned}
$$
\end{zhongwen}
\item \{不能被3整除的整数的集合,偶数集合,被6除余数为3的整数的集合\}
\begin{zhongwen}
$$
\begin{aligned}
&不构成,\because 2\in 不能被3整除的整数的集合\cap 偶数集合, \\
&即 不能被3整除的整数的集合\cap 偶数集合\neq \varnothing \\
\end{aligned}
$$
\end{zhongwen}
\end{enumerate}
\end{enumerate}
\section{偏序关系}
\begin{enumerate}
\item 下列集合关于整除关系$|$构成偏序集。请分别画出它们的哈斯图,判断它们是否是全序集,给出它们的极大元、极小元、最大元、最小元。
\begin{multicols}{2}
\begin{enumerate}
\item $\{ 2,4,8,16 \}$
% \centering
% \includegraphics[1\linewidth]{imgs/5.5.1.drawio.png}
\hspace{5em}\includesvgpdf[0.1]{5.5.1.drawio}
极大元16极小元2\\
最大元16最小元2。
\item $\{ 2,3,4,5,9,10,80 \}$
\includesvgpdf[0.8]{5.5.2.drawio}
极大元80、9极小元2、5、3\\
最大元:无,最小元:无。
\end{enumerate}
\end{multicols}
\pagebreak[2]
\item 证明:
\begin{enumerate}
\item 偏序集的最小元也必定是其极小元;
\begin{proof}
\begin{zhongwen}
$$
\begin{aligned}
&对于任意的偏序集(X,\leqslant )若a\in X是它的最小元取个体域为X\\
&\forall x(a\leqslant x) \\
&\because 偏序关系具有反对称性, \\
&\therefore \forall x((x=a)\lor \lnot (x\leqslant a)) \\
&\therefore \forall x(\lnot (x\neq a\land x\leqslant a)) \\
&\therefore \lnot \exists x(x<a) \\
&\therefore a是(X,\leqslant )的极小元 \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\item 任意全序集至多只有一个极小元,即全序集的极小元是唯一的。
\begin{proof}
\begin{zhongwen}
$$
\begin{aligned}
&对于任意的全序集(X,\leqslant )假设a,b \in X都是它的极小元取个体域为X \\
&\lnot \exists x(x<a)\land \lnot \exists y(y<b) \\
&\therefore \forall x(\lnot (x<a))\land \forall y(\lnot (y<b)) \\
&\therefore \lnot (b<a)\land \lnot (a<b) \\
&\because (X,\leqslant )是全序集 \\
&\therefore a\leqslant b\land b\leqslant a \\
&\therefore a=b \\
&因此,全序集的极小元是唯一的。 \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\end{enumerate}
\item$R$$X$上自反、传递的关系,$S=R\cap R^{-1}$
\begin{enumerate}
\item 证明$S$$X$上的等价关系。
\begin{proof}
\begin{zhongwen}
$$
\begin{aligned}
&\forall x\in X,(x,x)\in R\quad \therefore (x,x)\in R^{-1}\quad \therefore (x,x)\in R\cap R^{-1}=S即S是自反关系 \\
&\forall (x,y)\in S(x,y)\in R\land (x,y)\in R^{-1}\quad \therefore (y,x)\in R^{-1}\land (y,x)\in R\\
&\therefore (y,x)\in R\cap R^{-1}=S即S是对称关系\\
&\forall (x,y),(y,z)\in S(x,y)\in R\land (x,y)\in R^{-1}\land (y,z)\in R\land (y,z)\in R^{-1} \\
&\therefore (x,y)\in R\land (y,z)\in R,\quad (y,x)\in R\land (z,y)\in R \\
&\therefore (x,z)\in R,(z,x)\in R \\
&\therefore (x,z)\in R,(x,z)\in R^{-1},即(x,z)\in R\cap R^{-1}=S即S是传递关系 \\
&因此S是X上的等价关系。 \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\item$X/S$上定义关系$T: ([x]_{S},[y]_{S})\in T$当且仅当$(x,y)\in R$。证明$T$$X/S$上的偏序关系。
\begin{proof}
\begin{zhongwen}
$$
\begin{aligned}
&\forall [x]_{S}\in X/S,则x\in X\quad \because R是X上的自反关系\quad \therefore (x,x)\in R\\
&\therefore ([x]_{S},[x]_{S})\in T即T是自反关系 \\
&\forall ([x]_{S},[y]_{S})\in T(x,y)\in R[x]_{S}\neq [y]_{S},则(x,y)\not \in S \\
&\therefore (x,y)\not \in R\lor (x,y)\not \in R^{-1} \\
&\because (x,y)\in R\quad \therefore (x,y)\not \in R^{-1} \quad \therefore (y,x)\not \in R\\
&\therefore ([y]_{S},[x]_{S})\not \in T即T是反对称关系 \\
&\forall ([x]_{S},[y]_{S}),([y]_{S},[z]_{S})\in T(x,y)\in R,(y,z)\in R\\
&\because R是X上的传递关系\quad \therefore (x,z)\in R \\
&\therefore ([x]_{S},[z]_{S})\in T即T是传递关系 \\
&因此T是X/S上的偏序关系。 \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\end{enumerate}
\end{enumerate}
\end{document}

View File

@@ -0,0 +1,93 @@
\documentclass[全部作业]{subfiles}
\pagestyle{fancyplain}
\fancyhead{}
\fancyhead[C]{\mysignature}
\setcounter{chapter}{6}
\begin{document}
\chapter{图论基础}
\section{图及其表示}
\begin{enumerate}
\item 6个学生Alice、Bob、Carol、Dean、Santos和tom其中Alice和Carol不和Dean和Carol不和Santos、Tom和Alice两两不和。请给出表示这种情形的图模型。
\begin{zhongwen}
用顶点表示学生,如果两个学生之间不和则连一条无向边,则可以表示成左图;如果两个学生相和则连一条无向边,则可以表示成右图。
\begin{figure}[H]
\centering
\subfloat[不和图]{
\includesvgpdf[0.4]{7.1.1.drawio}
}
\hfill
\subfloat[相和图]{
\includesvgpdf[0.4]{7.1.2.drawio}
}
\end{figure}
\end{zhongwen}
\item 至少含一个顶点的$C_3$的子图有多少个?
\begin{zhongwen}
\begin{proof}[解]
含一个顶点的,点的情况有$\mathrm{C}_{3}^{1}=3$种,无法形成边,所以有$3\times 1=3$种情况;
含两个顶点的,点的情况有$\mathrm{C}_{3}^{2}=3$可以没有边或者有1条边所以有$3\times 2=6$种情况;
含3个顶点的点的情况有$\mathrm{C}_{3}^{3}=1$种,边的情况为$2^{3}$种,所以有$1\times 2^{3}=8$种情况。
所以至少含一个顶点的$C_3$的子图有$3+6+8=17$个。
\end{proof}
\end{zhongwen}
\item 证明在顶点个数不小于2的简单无向图中必有度数相同的顶点。
\begin{zhongwen}
\begin{proof}
使用归纳法首先对于顶点数为2的简单无向图这两个顶点之间要么有一条边要么没有边而这两种情况它们的度都是相同的。
假设对于顶点数为$k(k\geqslant 2)$的简单无向图,必有度数相同的顶点。那么对于顶点数为$k+1$的简单无向图如果存在一个顶点的度为0那么去除这个顶点后其他顶点构成$k$个顶点的简单无向图,因此它们之中必有度数相同的顶点。
如果不存在一个顶点的度数为0即所有顶点的度数都至少为1之后就不会了。
\end{proof}
\end{zhongwen}
\item 对哪些n值来说下列图是偶图
\begin{tasks}[](2)
\task $K_n$
\hfill $n = 2$ \hfill
\task $C_n$
\hfill $n\geqslant 3$且为偶数 \hfill
\task $W_n$
\hfill $n\in \varnothing $ \hfill
\task $Q_n$
\hfill $n$为任意正整数 \hfill
\end{tasks}
\end{enumerate}
\section{握手定理}
\begin{enumerate}
\item 简单无向图$G$$n$个顶点,$n+1$条边,证明$G$中至少有一个顶点的度大于或等于3。
\begin{zhongwen}
\begin{proof}
反证法,设$G=(V,E)$,假设$G$中所有顶点的度都小于3$\forall v\in V$, $d(v)<3$$d(v)\leqslant 2$,又已知$\left\vert V \right\vert =n$, $\left\vert E \right\vert =n+1$,那么根据握手定理,则有
$$
2(n+1)=2\left\vert E \right\vert =\sum_{v\in V}d(v)\leqslant 2n
$$
而这是不可能的,因此$G$中至少有一个顶点的度大于或等于3。
\end{proof}
\end{zhongwen}
\item *一天晚上张先生夫妇参加了一个聚会,参加聚会的人中还有另外三对夫妇,他们相互握了手。假设没有人自己与自己握手,没有夫妻之间的握手,且同两个人握手不超过一次。当其他人告诉张先生,他或她握了多少次手时,答案都不相同。问张先生和太太分别握了几次手?
\begin{zhongwen}
想了半天也想不出来怎么做。
\end{zhongwen}
\end{enumerate}
\end{document}

View File

@@ -0,0 +1,80 @@
\documentclass[全部作业]{subfiles}
\pagestyle{fancyplain}
\fancyhead{}
\fancyhead[C]{\mysignature}
\setcounter{chapter}{3}
\setcounter{section}{2}
\begin{document}
\section{范式和联结词的功能完备集}
\begin{enumerate}
\item 通过等值演算求$p \to (p\land (q \to p))$的主析取范式和主合取范式。
\begin{proof}[解]
\begin{zhongwen}
$$
\begin{aligned}
p \to (p \land (q \to p))&=\lnot p\lor (p\land (\lnot q\lor p))=\lnot p\lor ((p\lor 0)\land (p\lor \lnot q)) \\
&=\lnot p \lor (p\lor (0 \land \lnot q)) = \lnot p \lor p = 1 \\
&=(p\land q)\lor (p\land \lnot q)\lor (\lnot p\land q)\lor (\lnot p\land \lnot q) \qquad (主析取范式)\\
\end{aligned}
$$
$$
因为原式为永真式,所以无主合取范式。
$$
\end{zhongwen}
\end{proof}
\item 证明$\{ \lnot ,\to \}$是功能完备集。
\begin{proof}
\begin{zhongwen}
$$
\begin{aligned}
&\lnot p=\lnot p \\
&p\lor q=\lnot p \to q \\
&\because \{ \lnot ,\lor \}是功能完备集 \\
&\therefore \{ \lnot ,\to \}是功能完备集 \\
\end{aligned}
$$
\end{zhongwen}
\end{proof}
\end{enumerate}
\section{命题逻辑的推理理论}
\begin{enumerate}
\item 证明$p \to (q \to s),q,p\lor \lnot r \Rightarrow r \to s$
\begin{proof}
\begin{zhongwen}
\begin{enumerate}[label=\mycircle{\arabic{enumii}},leftmargin=\linewidth/4,rightmargin=\linewidth/4]
\item $r$\hfill 附加前提引入
\item $p\lor \lnot r$ \hfill 前提引入
\item $p$\hfill \mycircle{1}\mycircle{2}析取三段论
\item $p \to (q \to s)$\hfill 前提引入
\item $q \to s$\hfill \mycircle{3}\mycircle{4}假言推理
\item $q$ \hfill 前提引入
\item $s$ \hfill \mycircle{5}\mycircle{6}假言推理
\end{enumerate}
\end{zhongwen}
\end{proof}
\item 构造下列推理的形式证明:
“今天下午没有出太阳并且今天比昨天冷。只有今天下午出太阳,我们才去游泳。若我们不去游泳,则我们乘独木舟游览。若我们乘独木舟游览,则我们在黄昏时回家。 所以,我们在黄昏时回家。”
\begin{proof}
\begin{zhongwen}
$$
\begin{aligned}
&p:今天下午出太阳q:今天比昨天冷r:我们去游泳, \\
&s:我们乘独木舟游览t:我们在黄昏时回家 \\
&则需要证明:\lnot p \land q,r \to p,\lnot r \to s, s \to t \Rightarrow t \\
\end{aligned}
$$
\begin{enumerate}[label=\mycircle{\arabic{enumii}},leftmargin=\linewidth/4,rightmargin=\linewidth/4]
\item $\lnot p\land q$\hfill 前提引入
\item $\lnot p$\hfill \mycircle{1}化简
\item $r \to p$\hfill 前提引入
\item $\lnot r$\hfill \mycircle{2}\mycircle{3}拒取式
\item $\lnot r \to s$\hfill 前提引入
\item $s$\hfill \mycircle{4}\mycircle{5}假言推理
\item $s \to t$\hfill 前提引入
\item $t$\hfill \mycircle{6}\mycircle{7}假言推理
\end{enumerate}
\end{zhongwen}
\end{proof}
\end{enumerate}
\end{document}

View File

@@ -0,0 +1,316 @@
\documentclass[全部作业]{subfiles}
\usepackage{titlesec} % 只在这个文件里的序言里用到了\titlelabel
\usepackage{titletoc}
\pagestyle{fancyplain}
\fancyhead{}
\fancyhead[C]{\mysignature}
% \titlelabel{\thechapter}
% \renewcommand{\section}{\section*}
\titlelabel{} % 去除序号,但是在主文件中不去除
% \titleformat{\section}{}{}{0pt}{} % 去除section的序号但是不去除别的
\begin{document}
% appendices环境设置的服务好像还是用了“第一章”
% 因此使用\appendix命令但是放到主文件里
\section{课程项目——函数式程序设计及其发展历史和研究现状综述}
\ifSubfilesClassLoaded{
\ctexset{section/numbering = false,
subsection/numbering = false,
subsection/format += \centering,
subsubsection/numbering = false,
secnumdepth = 0,
tocdepth = 3,
}
% \titlecontents*{lsubsection}[0pt]
% {\small\itshape}{}{}
% {}[ \textbullet\ ][.]
% \titlecontents{subsection}[0pt]{}{}{}{}[]
% \contentspush{12}
% \setcounter{tocdepth}{3}
\subsection{目录}
\startcontents
% \tableofcontents
\printcontents{l}{2}[3]{}
}{}
\subsection{摘要}
本文没有过多晦涩难懂的理论知识例如函数式程序设计中的Monad、范畴等概念也没有冗长的介绍发展历史而是更多从实际使用的角度讲述函数式程序设计在实际业务场景中如何使用。
\subsection{发展历史}
首先让我们看一下函数式程序设计的定义。以下内容在维基百科The Free Dictionary网站中找到这里认为“函数式程序设计”和“函数式编程”同义。
在计算机科学中,函数式编程是一种编程范式,其中程序是通过应用和组合函数来构造的。它是一种声明性编程范例,其中函数定义是将值映射到其他值的表达式树,而不是一系列命令式语句 更新 程序的运行状态 。\cite{wikidefination}
那么函数式程序设计的历史可以追溯到$\lambda $演算\cite{zhihuJS1},并且发展出了很多函数式编程语言,这里就不详细展开了。
\subsection{研究现状}
要真正搞懂函数式程序设计,我们先要明白什么是状态。以及状态和逻辑如何分离。
我们知道程序是由输入、处理、输出组成。那么有一个直接的问题是我每次使用这个程序并且给定相同的输入是否都能得到同样的输出呢如果只是从算法题OJ, Online Judge的角度看那确实是这样。
我们遇到的算法题总是给你一些输入,让你输出某个结果,就像课程项目中的一部分题:“输入……,输出……”,这种题目的直观感受就是给定一个输入,那么必定会产生某个输出(甚至有时候只有唯一的正确输出)。
但是脱离算法题的框架呢比如我要实现读取好几个文件的内容之后把他们拼接起来放到一个新的文件里。这样的情况是不是就没有输入了那文件不同得到的输出结果也不同了。这就是一种典型的文件IO输入输出操作。
再举个例子之前的数据结构课上的作业要实现模拟队列动态变化这个的输出又是什么呢可以看到这个的输出其实是有时间维度的在每个时间都应该输出不同的内容。因此这很难用无状态的方式来输出。那这个例子再扩展出去就是图形用户界面GUI这就是典型的输出不仅和状态有关还和当前时刻的输入有关也就类似数字逻辑及实验中的米利模型的有限状态机
因此,根据个人的理解,状态就是除了代码之外的,会影响程序的行为的东西。那么与之相对的,代码体现的就是程序的逻辑。因此,数据库、文件、外部服务,都可以看作是状态。
搞清楚了状态,我们接下来考虑为什么要分离状态和逻辑?主要的原因是为了便于备份和迁移。让我们先看一个例子:
假设有需求要请求一个网址并且把响应保存到本地。那么自然的写法可能是这样用Python举例
\begin{minted}{python}
import requests
url = input("请输入网址")
filename = input("请输入文件名")
res = requests.get(url)
with open(filename, "wb") as f:
f.write(res.content)
\end{minted}
但考虑如果要多次使用这个功能,那么每次使用,都会将响应保存到运行的工作目录下,而如果每次都在代码文件所在的目录下运行,那么时间长了,就会在这个目录里产生很多下载的文件,看起来非常杂乱。
假设在之后的某一天,我们想把这个功能的源代码加入版本控制中,并且放到开源平台,但又不想把下载的响应文件一起公开,那么还需要添加到忽略列表等操作。
又过了一段时间,需要备份这些下载的响应内容,那么只能把整个目录连带代码文件一起备份,但是代码已经使用版本控制进行管理了,再进行备份只能备份当前版本,这就非常冗余。
但是,如果将状态和逻辑进行了分离,也就是把响应全部放到同一个位置,和代码逻辑分离开,这样在备份和迁移的时候都非常方便,而这就需要用到函数式程序设计了。
接下来我们结合几个实际的应用场景来具体讲解函数式程序设计如何使用。
\subsubsection{Serverless}
目前Serverless架构也算是一个比较活跃的话题它主要是将静态的页面文件和动态的请求分离开静态页面由云服务器的存储实现并且还能方便实现CDN内容分发网络加速而动态的请求也可以由云厂商提供的事件驱动的函数计算服务来实现当收到请求后进行函数计算并返回结果给前端这里就把整个应用拆分成了各个函数因此需要用到函数式程序设计。
\subsubsection{数据预处理}
在深度学习的任务中,经常需要对数据进行预处理,而这些预处理可能分成很多步骤,并且有时候还需要把中间结果保存下载作为状态,以便下次使用时继续执行。比如自然语言处理的预处理可能就有分词、转词表、词嵌入。当数据量非常大的时候,如果中间某一步由于意外原因中断了,这时如果没有保存中间结果,那只能重新运行,这是非常浪费时间的。但是要保存中间结果就不可避免地要涉及到状态的存储。这时如果使用面向对象的方式,会是什么样的?
\begin{minted}{python}
class PreProcessing:
def tokenize(self, text):
...
with open(self.token_path, "w") as f:
f.write(result)
return result
def token_to_id(self, tokens):
...
with open(self.id_path, "w") as f:
for id_ in ids:
print(id_, file=f)
return ids
def id_to_embedding(self, ids):
...
paddle.save(embeddings, self.embedding_path)
return embeddings
\end{minted}
这样会产生一个问题,每一个流程如何向下一个流程传递数据?直接通过函数的返回值传递?还是通过文件读取和写入来传递?直接通过函数的返回值传递的话,那怎么实现接续上次的运行结果?那还需要再单独写读取的方法?这样就会导致调用时非常麻烦。那如果全部使用文件的读取和写入,也就是把上述代码改成
\begin{minted}{python}
class PreProcessing:
def tokenize(self):
...
with open(self.token_path, "w") as f:
f.write(result)
return result
def token_to_id(self):
tokens = open(self.token_path).read()
...
with open(self.id_path, "w") as f:
for id_ in ids:
print(id_, file=f)
return ids
def id_to_embedding(self, ids):
with open(self.id_path, "r") as f:
ids = [int(i) for i in f.readlines()]
...
paddle.save(embeddings, self.embedding_path)
return embeddings
\end{minted}
那这样的话,在第一次运行的时候,还需要判断文件是否存在,这也会导致复杂度提升。
并且最关键的问题是,从外部调用这些方法的时候,只看方法名称,不看文档,无法知道这个方法是有状态的还是无状态的,也就是说不知道这个方法是会把运行结果保存在文件中还是不保存,也不知道这个方法是否会从文件中读取内容。这样就非常不利于状态的统一管理。
而且还有一个问题是面向对象很难将原先功能改成多进程并行处理,因为整个对象中保存了很多状态,而有些状态是在并行处理中用不到的,有些状态可能是需要用到并且需要共享的,这些状态如果没有很好地区分,就很难进行并行处理。
于是可以尝试使用函数式的方式改写上述功能:
\begin{minted}{python}
from pathlib import Path
import asyncio
def tokenize(text):
...
return result
def token_to_id(token): # 注意这里的参数是单数也就是单个token
...
return result
def id_to_embedding(ids): # 这里由于Embedding是矩阵形式因此参数是复数
...
return result
def compose(*monads):
asyncio.run(asyncio.gather(*monads))
async def monad(function, in_func=None, out_func=None): # 这样命名可能不太对因为确实不太清楚这样是否符合真正的Monad的定义
args = None
if in_func:
args = await in_func()
result = function(args)
if out_func:
asyncio.create_task(lambda :await out_func(result))
return result
def list_map(*args, **kwargs):
return list(map(*args, **kwargs))
main = lambda token_path, id_path, embedding_path : compose(
monad(tokenize,
in_func=None,
out_func=lambda x:Path(token_path).write_text(x)
),
monad(token_to_id,
in_func=lambda :Path(token_path).read_text(),
out_func=lambda file: lambda ids:list_map(
lambda id_ : print(id_, file=file),
ids)(open(id_path, "w")) # 这样写是为了完全使用函数式的写法实际使用时如果这样写可读性非常差而且Python有更多有用的语法比如withyield列表解析式等不太适合强行使用函数式
),
monad(id_to_embedding,
in_func=lambda :list_map(int, Path(id_path).read_text().splitlines()),
out_func=lambda embeddings:paddle.save(embeddings, embedding_path),
),
)
main(...)()
\end{minted}
由于时间所限一些细节可能不是非常准确但总体思路大致就是这样使用了函数式程序设计后能非常清晰地看出数据的流动过程以及什么时候使用了IO并且能非常方便地改为并发执行。
不过也能看到,函数式程序设计也可能会导致代码可读性下降,虽然也可能是写得不太规范的原因。
\subsubsection{装饰器}
装饰器实际上对应了函数式程序设计中高阶函数的概念,调用时传入一个函数,之后可以对这个函数进行修改,并且再返回。
例如在Python中可以写一个测量函数调用需要的时间的装饰器
\begin{minted}{python}
import time
def measure_time(function):
def inner(*args, **kwargs):
start_time = time.time()
result = function(*args, **kwargs)
print(time.time() - start_time)
return result
return inner
\end{minted}
之后如果要测量一个函数的使用时间,就可以这样
\begin{minted}[firstnumber=last]{python}
@measure_time
def test():
time.sleep(1)
test()
\end{minted}
那么在JavaScript中也可以有类似的实现正式的JavaScript装饰器语法还在提案阶段目前无法直接使用
\begin{minted}{javascript}
const measure_time = func => (...args) => {
const start_time = new Date();
const result = func(...args);
console.log(new Date() - start_time);
return result;
}
function func1(args) {
do_some_thing(args);
}
const func = measure_time(func1);
func();
\end{minted}
这里使用了JavaScript的箭头函数的语法特性这种语法特性能非常方便地实现函数式程序设计的多种特性如函数部分参数调用柯里(curry)化等,详细内容可见参考文献\cite{zhihuJS1, zhihuJS2}
同样在C++中也可以实现装饰器的概念。
\begin{minted}{cpp}
#include <functional>
#include <ctime>
template <typename RET, typename ... ARGS>
std::function<RET(ARGS... args)> measure_time(std::function<RET(ARGS... args)> func) {
return [=](ARGS... args) -> RET {
time_t start_time = time(nullptr);
RET result = func(args...);
std::cout << time(nullptr) - start_time << std::endl;
return result;
}
}
std::function<void(void)> do_something;
const func = measure_time(do_something);
func();
\end{minted}
上述代码参考\cite{zhihuc++1}同样也没经过测试但大致思路体现了函数式程序设计的思想包括lambda匿名函数等特性。
虽然不知道各种编程语言的装饰器是否是受到了函数式程序设计的启发,但可以看到它们都能实现装饰器的功能,这也是函数式程序设计在现代发展的体现。
\subsubsection{\LaTeX 排版}
另一个非常需要函数式程序设计的思维的地方就是\LaTeX 排版了,在使用\LaTeX 的过程中,我曾经有这样一个需求:要在一个列表环境中使用多个\mintinline{latex}|\item|,但是它们有不同序号格式,比如有的格式是\mintinline{latex}|P\arabic{enumi}.|有的格式是\mintinline{latex}|R\arabic{enumi}.|,但是又希望序号能连续。因此在以前,只能使用\mintinline{latex}|\item[]|单独为每一项指定带格式的序号。但是在了解了函数式程序设计后,同时结合\LaTeX3的语法写出了如下的\LaTeX 代码:
\begin{minted}{latex}
\def\getenum{%
\ifnum\EnumitemId=1%
enumi%
\else
\ifnum\EnumitemId=2%
enumii%
\else
\ifnum\EnumitemId=3%
enumiii%
\else%
enumiv%
\fi
\fi
\fi%
}
\ExplSyntaxOn
\cs_set:Nn \rawquestionandanswer:Nnnn {%
\ifstrequal{#2}{-}{}{\format_item:Nn #1{#2}} #3%
#4%
}
\cs_set:Nn \format_item:Nn {
\IfBlankTF{#2}{
\stepcounter{\getenum}
\item[#1{\csname the\getenum\endcsname}]
% 完美结合了LaTeX2e和LaTeX3
}{
\item[#1{#2}]
}
}
\cs_set:Nn \Rformat:n {R#1.}
\cs_set:Nn \Pformat:n {P#1.}
\newcommand{\Rquestionandanswer}[3][]{%
\rawquestionandanswer:Nnnn \Rformat:n {#1}{#2}{#3}
}
\newcommand{\Pquestionandanswer}[3][]{%
\rawquestionandanswer:Nnnn \Pformat:n {#1}{#2}{#3}
}
\ExplSyntaxOff
\end{minted}
这里的\mintinline{latex}|\Rquestionandanswer|和\mintinline{latex}|\Pquestionandanswer|其实是使用了函数式程序设计中的部分参数调用的思想,对于原始的\mintinline{latex}|\rawquestionandanswer|,分别传入不同的格式,即\mintinline{latex}|\Rformat|和\mintinline{latex}|\Pformat|,形成了不同的函数,使用时直接调用\mintinline{latex}|\Rquestionandanswer|和\mintinline{latex}|\Pquestionandanswer|,传入剩余的参数,完成整个调用过程,这时之前定义的格式就会产生作用,形成不同的效果。
\subsection{总结}
从上面这些例子中,我们可以看到虽然函数式程序设计听起来比较陌生,但其实它的思想在很多编程语言中早已有所体现。还要注意的是,在一些情况其实也不是很适合使用函数式程序设计,比如具有大量可变状态的图形用户界面。了解函数式程序设计,也许在目前来看,并不能给我们带来什么实质性的帮助,但也许受到了函数式的思想潜移默化的影响,在未来的某一天,实现某个功能的时候,突然就有了灵感,想到一个绝妙的设计方案。函数式程序设计归根结底还是一种编程范式,了解各种编程范式,一定不能生搬硬套,要学会灵活使用,最终达成高内聚低耦合的目的。
\phantomsection\addcontentsline{toc}{subsection}{参考文献} %将参考文献放进目录
\bibliography{ref}
\ifSubfilesClassLoaded{
\stopcontents
}{}
\end{document}