【SICP练习】133 练习3.64

练习3-64

原文

Exercise 3.64. Write a procedure stream-limit that takes as arguments a stream and a number (the tolerance). It should examine the stream until it finds two successive elements that differ in absolute value by less than the tolerance, and return the second of the two elements. Using this, we could compute square roots up to a given tolerance by

(define (sqrt x tolerance)  (stream-limit (sqrt-stream x) tolerance))

代码

(define (stream-limit stream tolerance)
        (if (< (abs (- (stream-ref stream 1) (stream-ref stream 0))) tolerance)
                (stream-ref stream 1)
                (stream-limit (stream-cdr stream) tolerance)))
时间: 2024-08-06 17:50:13

【SICP练习】133 练习3.64的相关文章

手机号段确定手机号码服务商类别

1: using System; 2: using System.Collections.Generic; 3: using System.Linq; 4: using System.Text; 5:   6: namespace AnkeEdu.Tools 7: { 8:   9: /// <summary> 10: /// 电话号码帮助类 11: /// author:Andrew.He 12: /// 给定一个电话号码,返回电话号码号段所属网络 13: /// </summary&

Java入门:绘制简单图形

在上一节,我们学习了如何使用swing和awt工具创建一个空的窗口,本节学习如何绘制简单图形. 基本绘图介绍 Java中绘制基本图形,可以使用Java类库中的Graphics类,此类位于java.awt包中.在我们自己的java程序文件中,要使用Graphics类就需要使用import java.awt.Graphics语句将Graphics类导入进来. Graphics类提供基本的几何图形绘制方法,主要有:画线段.画矩形.画圆.画带颜色的图形.画椭圆.画圆弧.画多边形等.本项目仅用到画直线的功

ceph离线安装与日常简单维护

1           环境介绍 主机名 系统 版本 角色 IP ceph1 RHEL7.3_64bit jewel admin/mon1 10.10.64.130 ceph2 RHEL7.3_64bit jewel mon2 10.10.64.131 ceph3 RHEL7.3_64bit jewel mon3 10.10.64.132 ceph4 RHEL7.3_64bit jewel osd1 10.10.64.133 ceph5 RHEL7.3_64bit jewel osd2 10.1

SICP 1-33 1-34 1-35

ex1-32 要求利用过程返回值给出一个用于计算 f(f (x))这样的函数过程 ex1-33要求计算一个函数的平滑函数g(x)=(f(x-dx)+f(x)+f(x+dx))/3 并利用ex1-32给出的过程进行多次的平滑运算以下,给出代码 (define (smooth f) (lambda (x) (/ (+ (f (- x .001)) (f x) (f (+ x .001))) 3))) (define (repeated f x) (lambda (times) (if (= time

转:最近5年133个Java面试问题列表

最近5年133个Java面试问题列表 Java 面试随着时间的改变而改变.在过去的日子里,当你知道 String 和 StringBuilder 的区别就能让你直接进入第二轮面试,但是现在问题变得越来越高级,面试官问的问题也更深入. 在我初入职场的时候,类似于 Vector 与 Array 的区别.HashMap 与 Hashtable 的区别是最流行的问题,只需要记住它们,就能在面试中获得更好的机会,但这种情形已经不复存在.如今,你将会被问到许多 Java 程序员都没有看过的领域,如 NIO,

Centos6.7 64位 kvm虚拟化安装配置

参考资料: http://www.apelearn.com/bbs/thread-8299-1-1.html http://taokey.blog.51cto.com/4633273/1540873 http://www.server-world.info/en/note?os=CentOS_6&p=kvm&f=1http://koumm.blog.51cto.com/703525/1288795http://www.361way.com/category/v ... d-automati

centos6.5 64位 openvpn安装配置

1 查看系统版本 2 cat /etc/redhat-release 3 CentOS release 6.5 (Final) 4 5 查看内核和cpu架构 6 uname -rm 7 2.6.32-431.el6.x86_64 x86_64 8 9 查看ip 10 ifconfig 11 eth0 Link encap:Ethernet HWaddr 08:00:27:5E:DF:74 12 inet addr:xxx.xxx.xxx.xxx Bcast:xxx.xxx.xxx.255 Mas

CUDA 6.0 安装及配置( WIN7 64位 / 英伟达G卡 / VS2010 )

前言 本文讲解如何在VS 2010开发平台中搭建CUDA开发环境 当前配置: 系统:WIN7 64位 开发平台:VS 2010 显卡:英伟达G卡 CUDA版本:6.0 若配置不一样,请勿参阅本文. 第一步 点击这里下载 cuda最新版,目前最高版本是6.0.下载完毕后得到 cuda_6.0.37_winvista_win7_win8.1_general_64.exe 文件. 第二步 运行安装程序,弹出安装过程中转文件路径设定框: 这个路径随便填无所谓,安装完后就会自动删除的,我就直接设置为默认的

SICP 1.23-1.26体会

1.23 代码改动很简单, 关键是时间. 电脑上算了一下, 100000000以下全是0, 开始还以为代码写错了. 最后没办法, 用1e10 1e11来计算, 发现比 1e11 1e12快1.2-1.5之间.比2小.想了半天也给不出很合理的解析. 开始以为是对3 5 7 取余数 比 4 6 8 要慢, 测试了一下,发现也不是这么一回事.网上有人怀疑是函数调用花了一定时间做if 判断, 老实说这东西性能影响也不应有这么大. 现在唯一想到的,就是编译器做了一些优化,导致性能不完全取决于调用次数. 这