diff --git a/SICP/slide12.tmu b/SICP/slide12.tmu new file mode 100644 index 0000000..936b94e --- /dev/null +++ b/SICP/slide12.tmu @@ -0,0 +1,534 @@ +> + +> + +<\body> + <\hide-preamble> + >>> + + + <\slideshow> + <\slide> + \; + + \; + + \; + + |>>|>>||<\author-affiliation> + \; + + \; + + \; + + \; + + \; + + \; + + \; + >>|> + + + <\slide> + + + <\wide-tabular> + || + <\large> + + + |<\cell> + <\large> + + + >| + > + |<\cell> + > + >| + > + |<\cell> + > + >| + 实例:符号求导 + |<\cell> + Example: Symbolic Differentiation + >| + 实例:集合的表示 + |<\cell> + Example: Representing Sets + >>> + + + \; + + 回顾:通过定义一组的选择函数和构造函数,定义数据。 + + \; + + 今天,我们定义集合。 + + \; + + + <\slide> + + + <\description> + + + <\description> + 接受集合和元素作为参数,返回一个插入了元素的新集合。 + + 接受两个集合,返回两个集合的交集set2>。 + + 接受两个集合,返回两个集合的并集set2>。 + + + + + <\description> + 判断元素x是否在集合中。 + + + + \; + + <\question> + 上述构造函数中是否有冗余或者缺失? + + + <\question> + 目前只有一个选择函数,只能判断一个元素是否在集合中,那么这样的选择函数是否还能定义集合这种数据? + + + + <\slide> + + + <\description> + + + <\description> + 无参数,直接返回空集。> + + 接受集合和元素作为参数,返回一个插入了元素的新集合。 + + <\marked> + 接受两个集合,返回两个集合的交集set2>。 + + 接受两个集合,返回两个集合的并集set2>。 + + + + + + <\description> + 判断元素x是否在集合中。 + + + + \; + + <\question> + 在定义集合时,是否可以不定义集合的交集和并集? + + + + <\slide> + + + 借助列表,实现 + + <\with|par-columns|2> + <\session|s7|default> + <\folded-io> + \\ + <|folded-io> + (define (empty-set) ‘()) + <|folded-io> + empty-set + + + <\input> + \\ + <|input> + (define (adjoin-set x set) + + \ \ (if (element-of-set? x set) + + \ \ \ \ \ \ set + + \ \ \ \ \ \ (cons x set))) + + + <\folded-io> + \\ + <|folded-io> + (define (element-of-set? x set) + + \ \ (cond ((null? set) #f) + + \ \ \ \ \ \ \ \ ((equal? x (car set)) #t) + + \ \ \ \ \ \ \ \ (else (element-of-set? x (cdr set))))) + <|folded-io> + element-of-set? + + + <\folded-io> + \\ + <|folded-io> + \; + <|folded-io> + adjoin-set + + + <\folded-io> + \\ + <|folded-io> + (empty-set) + <|folded-io> + () + + + <\folded-io> + \\ + <|folded-io> + (adjoin-set 1 (empty-set)) + <|folded-io> + (1) + + + <\folded-io> + \\ + <|folded-io> + (adjoin-set 2 (adjoin-set 1 (empty-set))) + <|folded-io> + (2 1) + + + <\folded-io> + \\ + <|folded-io> + (define 两个元素的集合 (adjoin-set 2 (adjoin-set 1 (empty-set)))) + <|folded-io> + (2 1) + + + <\folded-io> + \\ + <|folded-io> + (element-of-set? 3 两个元素的集合) + <|folded-io> + #f + + + <\folded-io> + \\ + <|folded-io> + (element-of-set? 2 两个元素的集合) + <|folded-io> + #t + + + <\input> + \\ + <|input> + \; + + + + + + <\slide> + + + 先借助列表定义二叉树,熟悉二叉树的性质,再定义集合 + + <\with|par-columns|2> + <\session|s7|default> + <\folded-io> + \\ + <|folded-io> + (define (make-tree entry left right) + + \ \ (list entry left right)) + <|folded-io> + make-tree + + + <\folded-io> + \\ + <|folded-io> + (define (entry tree) (car tree)) + <|folded-io> + entry + + + <\folded-io> + \\ + <|folded-io> + (define (left-branch tree) (cadr tree)) + <|folded-io> + left-branch + + + <\folded-io> + \\ + <|folded-io> + (define (right-branch tree) (caddr tree)) + <|folded-io> + right-branch + + + + + + <\session|s7|default> + <\folded-io> + \\ + <|folded-io> + (define l-t (make-tree 7 + + \ \ (make-tree 6 () ()) + + \ \ (make-tree 8 () ()))) + <|folded-io> + (7 (6 () ()) (8 () ())) + + + <\folded-io> + \\ + <|folded-io> + (define r-t (make-tree 20 + + \ \ (make-tree 10 () ()) + + \ \ (make-tree 21 () ()))) + <|folded-io> + (20 (10 () ()) (21 () ())) + + + + |> + + <\session|s7|default> + <\folded-io> + \\ + <|folded-io> + (make-tree 9 l-t r-t) + <|folded-io> + (7 (6 () ()) (8 () ())) + + + + + + <\slide> + + + <\session|s7|default> + <\unfolded-io> + \\ + <|unfolded-io> + (define (adjoin-set x set) + + \ \ (cond ((null? set) (make-tree x '() '())) + + \ \ \ \ \ \ \ \ ((= x (entry set)) set) + + \ \ \ \ \ \ \ \ ((\ x (entry set)) + + \ \ \ \ \ \ \ \ \ (make-tree (entry set)\ + + \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (adjoin-set x (left-branch set)) + + \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (right-branch set))) + + \ \ \ \ \ \ \ \ ((\ x (entry set)) + + \ \ \ \ \ \ \ \ \ (make-tree (entry set) + + \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (left-branch set) + + \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (adjoin-set x (right-branch set)))))) + <|unfolded-io> + adjoin-set + + + <\input> + \\ + <|input> + \; + + + + + <\slide> + + + <\session|s7|default> + <\unfolded-io> + \\ + <|unfolded-io> + (define (element-of-set? x set) + + \ \ (cond ((null? set) #f) + + \ \ \ \ \ \ \ \ ((= x (entry set)) #t) + + \ \ \ \ \ \ \ \ ((\ x (entry set)) + + \ \ \ \ \ \ \ \ \ (element-of-set? x (left-branch set))) + + \ \ \ \ \ \ \ \ ((\ x (entry set)) + + \ \ \ \ \ \ \ \ \ (element-of-set? x (right-branch set))))) + <|unfolded-io> + element-of-set? + + + <\input> + \\ + <|input> + \; + + + + + <\slide> + + + <\session|s7|default> + <\folded-io> + \\ + <|folded-io> + (empty-set) + <|folded-io> + () + + + <\folded-io> + \\ + <|folded-io> + (adjoin-set 1 (empty-set)) + <|folded-io> + (1 () ()) + + + <\folded-io> + \\ + <|folded-io> + (adjoin-set 2 (adjoin-set 1 (empty-set))) + <|folded-io> + (1 () (2 () ())) + + + <\folded-io> + \\ + <|folded-io> + (define 两个元素的集合 (adjoin-set 2 (adjoin-set 1 (empty-set)))) + <|folded-io> + (1 () (2 () ())) + + + <\folded-io> + \\ + <|folded-io> + (element-of-set? 3 两个元素的集合) + <|folded-io> + #f + + + <\folded-io> + \\ + <|folded-io> + (element-of-set? 2 两个元素的集合) + <|folded-io> + #t + + + <\input> + \\ + <|input> + \; + + + + + <\slide> + + + 墨干V1.2.7的S7 Scheme插件的隐藏功能: + + <\session|s7|default> + <\folded-io> + \\ + <|folded-io> + ‘(document (tree "7")) + <|folded-io> + + + + <\folded-io> + \\ + <|folded-io> + ‘(document (tree "7" "6" "8")) + <|folded-io> + + + + <\folded-io> + \\ + <|folded-io> + ‘(document (tree "9" (tree "7" "6" "8") (tree "20" "10" "21"))) + <|folded-io> + |> + + + <\input> + \\ + <|input> + \; + + + + <\exercise> + 利用S7 Scheme插件的隐藏功能实现二叉树(本次课程中利用列表定义的)的可视化。 + + + + <\slide> + + + <\itemize> + 回顾:如何定义数据 + + 集合:如何定义集合 + + 集合:借助列表定义集合 + + 二叉树:借助列表定义二叉树 + + 集合:借助二叉树定义集合 + + 二叉树:S7 Scheme中显示二叉树的隐藏功能 + + + + + +<\initial> + <\collection> + + + + + + + + \ No newline at end of file