This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define norm 2.328306549295728e-10) | |
(define m1 4294967087.0) | |
(define m2 4294944443.0) | |
(define a12 1403580.0) | |
(define a13n 810728.0) | |
(define a21 527612.0) | |
(define a23n 1370589.0) | |
(define SEED 12345) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
32-bits Random number generator U(0,1): MRG32k3a | |
Author: Pierre L'Ecuyer, | |
Source: Good Parameter Sets for Combined Multiple Recursive Random | |
Number Generators, | |
Shorter version in Operations Research, | |
47, 1 (1999), 159--164. | |
--------------------------------------------------------- | |
*/ | |
#include "MRG32k3a.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> (estimate-pi 10000) | |
2.449489742783178 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (estimate-pi trials) | |
(sqrt (/ 6 (monte-carlo trials cesaro-test)))) | |
(define (cesaro-test) | |
(= (gcd (rand) (rand)) 1)) | |
(define (monte-carlo trials experiment) | |
(define (iter trials-remaining trials-passed) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; Wikipediaの作例によるrand-update | |
(define (rand-update x) | |
(let ((a 3) (b 5) (m 13)) | |
(modulo (+ (* a x) b) m))) | |
;;; 乱数の初期値も Wikipedia に倣って8とする | |
(define random-init 8) | |
;;; SICP の rand | |
(define rand |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require srfi/1) | |
(define (make-table) | |
(let loop ((local-table `(*table*))) | |
(letrec ((lookup | |
(lambda (key-1 key-2) | |
(let ((subtable (assoc key-1 (cdr local-table)))) | |
(when subtable | |
(let ((record (assoc key-2 (cdr subtable)))) | |
(when record |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
もうひとつの Scheme 入門 | |
17. 遅延評価 | |
https://www.shido.info/lisp/scheme_lazy.html | |
に付いての補講 | |
4.1. 無限リストを表現するための基本関数とマクロ | |
遅延評価は普通の一般的なプログラミング言語と違った評価機構を持ちます。 | |
言い換えると、プログラミング言語の「機構」をまるっきり置き換えるような前提で、一々「基本関数とマクロ」を定義してプログラムを書く | |
のはあまり現実的ではないです。平たく言うと「メンドくさい」(笑)。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (addressing-mode registers memory) | |
(let ((k (registers 'PC-ref))) | |
(let ((opcode (memory-ref memory k))) | |
(letrec ((self | |
(lambda (message) | |
(case message | |
;; Immediate | |
((#b00000 #b00010 #b01001) | |
(values opcode | |
(memory-ref memory (+ k 1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require srfi/1 srfi/60) | |
;;;;;; 1 システム COMET IIの仕様 | |
;;;;; 1.1 ハードウェアの仕様 | |
;;;; 1. 1語は16ビットで,そのビット構成は,次のとおりである。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-syntax defineq | |
(syntax-rules () | |
((_ (var e) ...) | |
(begin (define var e) ...)))) |