"[]", "[[]]", "[][]", Good (Well-balanced) (成对)
"]", "[[]", "[]]", Bad(Not well-balanced)(不成对)
那我们如何定义 wbb(well balanced bracket) 呢?
An inductive definition of wbb:
- Rule 1:
$^"[]^" \in wbb$ (Base Case) - Rule 2: If
$s\in wbb$ then$"[s]" \in wbb$ (Inductive Case 1) - Rule 3: If
$s, t \in wbb$ then$st \in wbb$ (Inductive Case 2)
by selection:
by inductive definition:
$17 \in \mathcal{I}$ $20 \in \mathcal{I}$ - If
$x, y \in \mathcal{I}$ then$x - y \in \mathcal{I}$
简单来说,by selection是规范了一个集合,而定义,是指定一个集合内的构造。而by inductive definition则是定义基础条件,以及迭代条件,通过基础条件迭代实现向后证明。
wbb 我们假定一个 wbb 的字符串,将其截成两半,我们可以发现,前侧的字符串
对于其证明,我们可以:
Proof.
Base case:
Inductive Case 1: $$ s \in wbb $$
Assume statement holds for
Want: that it holds also
Case | Result |
---|---|
See Sub Proof #1 | |
- |
Sub Proof #1:
- $#_(\overline{s}) \geq #_$ by assume
- Then $#[(s')=#[([\overline{s})=#(\overline{s}) + 1\geq #_+1= #](\overline{s}) + 1 =#_ + 1>#_](s')$
Inductive Case 2:
$$
s, t \in wbb
$$
Assume the statement holds for
Want: Statement holds for
Case | Result |
---|---|
$#_(\overline{s}\geq #_$ by assumption | |
$#(\overline{t}\geq #_$ by assumption $#(\overline{s}\geq #_$ by assumption |
$#[{(s\overline{t})}=#[{(s)}+#{(\overline{t})} \geq #_ + #](\overline{s}) = #_](s\overline{t})$
define a function:
Bae case:
Inductive Case 1: If
Inductive Case 2: If
Code Generation:
if (condition)
block1
else
block2
+----------+
| S_cond |
+----------+
B_IF_FALSE GOTO label 25
+----------+
| S_block1 |
+----------+
BRANCH GOTO label 26
25: +----------+
| S_block1 |
+----------+
26: +----------+
| |
+----------+
对于表达式优先级
- Maybe need a better grammar (BODMAS法则)
- May adopt a convention ("left most evaluation")