《SICP》读书笔记--Chapter 1 Building Abstraction with Procedures

本文深入探讨了程序设计中抽象构建的重要性,从表达、命名、组合、抽象等基本元素出发,详细介绍了如何通过抽象实现复杂想法的简化。重点讨论了程序的模块化、递归与迭代、树形递归等概念,并展示了如何使用高阶过程和lambda表达式来构建通用的抽象。文章还涉及了过程的抽象化、参数化和通用方法的应用,为开发者提供了一套系统性的抽象构建方法。

Forward

Focus on: the human mind, collections of computer programs, and the computer. 

Every computer program is a model, hatched in the mind, of a real or mental process.


Chapter 1 Building Abstractions with Procedures

The acts of mind, wherein it exerts its power over simple ideas, are chiefly these three:

1. Combining several simple ideas into one compound once, and thus all complex ideas are made

2. bringing two ideas, whether simple or complex, together, and setting them by one another so as to take a view of them at once, without uniting them into one(做对比,modularity?)

3. separating them from all other ideas that accompany them in their real existence --abstraction


注:这三个方向,是作为library的提供者,framework的提供者需要思考的问题,让使用者通过什么样的方式compound, abstraction


1.1 The elements of programming

A powerful programming language is more than just a means for instructing a computer to perform task.The language also serves as a framework within which we organize our ideas about processes.Thus, when we describe a language, we should pay particular attention to themeans that the language provide for combining simple ideas to form more complex ideas:

1. primitive expression

2. means of combination

3. means of abstraction


1.1.1 Expressions

1.1.2 Naming and the Environment

(define size 2): simplest means of abstractions[ABSTRACTION]

1.1.3 Evaluating Combinations

goal: think procedurally

To evaluate a combination, do the following:

1. evaluate the subexpressions of the combination

2. apply the procedure that is the value of the leftmost subexpression (the operator) to the arguments that are the values of the other subexpressions (the operand)

1.1.4 Compound Procedures

(define (square x) (* x x)) [COMPOUND]

1.1.5 The Substitution Model for Procedure Application

Applicative vs Normal Order

1.1.6 Conditional Expressions and Predicates

1.1.7 Example: Square Roots by Newton's Method

Important difference between mathematical functions and computer procedures: Procedures must be effective.

function: describing properties of things / declarative knowledge

procedure: how to do things / imperative knowledge

1.1.8 Procedures as Black-Box Abstractions

when we define good-enough? procedure in terms of square, we are able to regard thesquare procedure as a 'black box'. We are not at the moment concerned with how the procedure computes its result, only with the fact that it computes square. 'square' is aprocedural abstraction


1.2 Procedures and the Process They Generate

1.2.1 Linear Recursion and Iteration

n! = n * (n-1)!

recursive process: a chain of deferred operations. n!length of the chain is grows linearly with n.

iterative process: whose state can be summarized by a fixed number ofstate variables, together with a fixed rule that describes how the state variables should be updated as the process moves from one state to another. n! the number ofsteps required is growing linearly with n


NOTE: NOT CONFUSE recursive process with recursive procedure

recursive procedure: procedure definition refers to itself.

recursive process: how the process involved, not the syntax of procedure is written


1.2.2 Tree Recursion

fib(n) = fib(n-1) + fib(n-2)

1.2.3 Orders of Growth

1.2.4 Exponentiation

1.2.5 Greatest Common Divisor


1.3 Formulating Abstractions with Higher-Order Procedures


1.3.1 Procedures as Arguments [ABSTRACTION]

ProceduresOne of things we should demand from a powerful programming language is the ability to buildabstractions by assigning names to common patterns and then to work in terms of the abstraction directly.


Procedure Abstraction:separate the way the procedure would be used from the details of how the procedure would be implemented in terms of more primitive procedures.


High-Order Procedures: procedures that manipulate procedures. power abstraction mechanism. limited our ability to create abstractions if we are restricted to procedures whose parameters must be numbers. [IMPORTANT]


(define (sum-integers a b)

   (if (> a b)

      0

      (+ a (sum-integers (+ a 1) b))))


(define (sum-cubes a b)

   (if (> a b)

      0

      (+ (cube a) (sum-cubes (+ a 1) b))))


1/(1*3) + 1/(5*7) + ...

(define (pi-sum a b)

   (if (> a b)

      0

      (+ (/ 1.0 (* a (+ a 2))) (pi-sum (+ a 4) b))))


General Procedure Abstraction:

(define (sum term a next b)

   (if (> a b)

      0

      (+ (term a)

         (sum term (next a) next b))))


Implement Cube Sum by General Procedure

(define (sum-cubes a b)

   (sum cube a inc b))


1.3.2 Constructing Procedures Using Lambda

lambda is used to create procedures in the same way as define, except that no name is specified for the procedure


1.3.3 Procedures as General Methods

1.3.4 Procedures as Returned Values

【电能质量扰动】基于ML和DWT的电能质量扰动分类方法研究(Matlab实现)内容概要:本文研究了一种基于机器学习(ML)和离散小波变换(DWT)的电能质量扰动分类方法,并提供了Matlab实现方案。首先利用DWT对电能质量信号进行多尺度分解,提取信号的时频域特征,有效捕捉电压暂降、暂升、中断、谐波、闪变等常见扰动的关键信息;随后结合机器学习分类器(如SVM、BP神经网络等)对提取的特征进行训练与分类,实现对不同类型扰动的自动识别与准确区分。该方法充分发挥DWT在信号去噪与特征提取方面的优势,结合ML强大的模式识别能力,提升了分类精度与鲁棒性,具有较强的实用价值。; 适合人群:电气工程、自动化、电力系统及其自动化等相关专业的研究生、科研人员及从事电能质量监测与分析的工程技术人员;具备一定的信号处理基础和Matlab编程能力者更佳。; 使用场景及目标:①应用于智能电网中的电能质量在线监测系统,实现扰动类型的自动识别;②作为高校或科研机构在信号处理、模式识别、电力系统分析等课程的教学案例或科研实验平台;③目标是提高电能质量扰动分类的准确性与效率,为后续的电能治理与设备保护提供决策依据。; 阅读建议:建议读者结合Matlab代码深入理解DWT的实现过程与特征提取步骤,重点关注小波基选择、分解层数设定及特征向量构造对分类性能的影响,并尝试对比不同机器学习模型的分类效果,以全面掌握该方法的核心技术要点。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值