collect benchmark programs together in one place, finally
svn: r3848
This commit is contained in:
parent
611ca37285
commit
d615bccb08
8
collects/tests/mzscheme/benchmarks/common/README.txt
Normal file
8
collects/tests/mzscheme/benchmarks/common/README.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
Bechmarks obtained from
|
||||
http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/scheme/code/bench/gabriel/
|
||||
http://www.ccs.neu.edu/home/will/GC/sourcecode.html
|
||||
|
||||
Files that end in ".sch" are supposed to be standard Scheme plus `time'.
|
||||
Files that end in ".ss" are MzScheme wrapper modules.
|
||||
|
||||
Unpack "dynamic-input.txt.gz" if you want to run the "dynamic" benchmark.
|
179
collects/tests/mzscheme/benchmarks/common/browse.sch
Normal file
179
collects/tests/mzscheme/benchmarks/common/browse.sch
Normal file
|
@ -0,0 +1,179 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; File: browse.sch
|
||||
; Description: The BROWSE benchmark from the Gabriel tests
|
||||
; Author: Richard Gabriel
|
||||
; Created: 8-Apr-85
|
||||
; Modified: 14-Jun-85 18:44:49 (Bob Shaw)
|
||||
; 16-Aug-87 (Will Clinger)
|
||||
; 22-Jan-88 (Will Clinger)
|
||||
; Language: Scheme (but see notes below)
|
||||
; Status: Public Domain
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
; Note: This benchmark has been run only in implementations in which
|
||||
; the empty list is the same as #f, and may not work if that is not true.
|
||||
; Note: This benchmark uses property lists. The procedures that must
|
||||
; be supplied are get and put, where (put x y z) is equivalent to Common
|
||||
; Lisp's (setf (get x y) z).
|
||||
; Note: The Common Lisp version assumes that eq works on characters,
|
||||
; which is not a portable assumption but is true in most implementations.
|
||||
; This translation makes the same assumption about eq?.
|
||||
; Note: The gensym procedure was left as in Common Lisp. Most Scheme
|
||||
; implementations have something similar internally.
|
||||
; Note: The original benchmark took the car or cdr of the empty list
|
||||
; 14,600 times. Before explicit tests were added to protect the offending
|
||||
; calls to car and cdr, MacScheme was spending a quarter of its run time
|
||||
; in the exception handler recovering from those errors.
|
||||
|
||||
; The next few definitions should be omitted if the Scheme implementation
|
||||
; already provides them.
|
||||
|
||||
(module browse mzscheme
|
||||
|
||||
(define (my-append! x y)
|
||||
(if (null? x)
|
||||
y
|
||||
(do ((a x b)
|
||||
(b (cdr x) (cdr b)))
|
||||
((null? b)
|
||||
(set-cdr! a y)
|
||||
x))))
|
||||
|
||||
(define (copy-tree x)
|
||||
(if (not (pair? x))
|
||||
x
|
||||
(cons (copy-tree (car x))
|
||||
(copy-tree (cdr x)))))
|
||||
|
||||
;;; BROWSE -- Benchmark to create and browse through
|
||||
;;; an AI-like data base of units.
|
||||
|
||||
;;; n is # of symbols
|
||||
;;; m is maximum amount of stuff on the plist
|
||||
;;; npats is the number of basic patterns on the unit
|
||||
;;; ipats is the instantiated copies of the patterns
|
||||
|
||||
(define *rand* 21)
|
||||
|
||||
(define (init n m npats ipats)
|
||||
(let ((ipats (copy-tree ipats)))
|
||||
(do ((p ipats (cdr p)))
|
||||
((null? (cdr p)) (set-cdr! p ipats)))
|
||||
(do ((n n (- n 1))
|
||||
(i m (cond ((zero? i) m)
|
||||
(else (- i 1))))
|
||||
(name (gensym) (gensym))
|
||||
(a #f))
|
||||
((= n 0) a)
|
||||
(set! a (cons name a))
|
||||
(do ((i i (- i 1)))
|
||||
((zero? i))
|
||||
(put name (gensym) #f))
|
||||
(put name
|
||||
'pattern
|
||||
(do ((i npats (- i 1))
|
||||
(ipats ipats (cdr ipats))
|
||||
(a '()))
|
||||
((zero? i) a)
|
||||
(set! a (cons (car ipats) a))))
|
||||
(do ((j (- m i) (- j 1)))
|
||||
((zero? j))
|
||||
(put name (gensym) #f)))))
|
||||
|
||||
(define (browse-random)
|
||||
(set! *rand* (remainder (* *rand* 17) 251))
|
||||
*rand*)
|
||||
|
||||
(define (randomize l)
|
||||
(do ((a '()))
|
||||
((null? l) a)
|
||||
(let ((n (remainder (browse-random) (length l))))
|
||||
(cond ((zero? n)
|
||||
(set! a (cons (car l) a))
|
||||
(set! l (cdr l))
|
||||
l)
|
||||
(else
|
||||
(do ((n n (- n 1))
|
||||
(x l (cdr x)))
|
||||
((= n 1)
|
||||
(set! a (cons (cadr x) a))
|
||||
(set-cdr! x (cddr x))
|
||||
x)))))))
|
||||
|
||||
(define (match pat dat alist)
|
||||
(cond ((null? pat)
|
||||
(null? dat))
|
||||
((null? dat) '())
|
||||
((or (eq? (car pat) '?)
|
||||
(eq? (car pat)
|
||||
(car dat)))
|
||||
(match (cdr pat) (cdr dat) alist))
|
||||
((eq? (car pat) '*)
|
||||
(or (match (cdr pat) dat alist)
|
||||
(match (cdr pat) (cdr dat) alist)
|
||||
(match pat (cdr dat) alist)))
|
||||
(else (cond ((not (pair? (car pat)))
|
||||
(cond ((eq? (string-ref (symbol->string (car pat)) 0)
|
||||
#\?)
|
||||
(let ((val (assv (car pat) alist)))
|
||||
(cond (val (match (cons (cdr val)
|
||||
(cdr pat))
|
||||
dat alist))
|
||||
(else (match (cdr pat)
|
||||
(cdr dat)
|
||||
(cons (cons (car pat)
|
||||
(car dat))
|
||||
alist))))))
|
||||
((eq? (string-ref (symbol->string (car pat)) 0)
|
||||
#\*)
|
||||
(let ((val (assv (car pat) alist)))
|
||||
(cond (val (match (append (cdr val)
|
||||
(cdr pat))
|
||||
dat alist))
|
||||
(else
|
||||
(do ((l '()
|
||||
(my-append! l
|
||||
(cons (if (null? d)
|
||||
'()
|
||||
(car d))
|
||||
'())))
|
||||
(e (cons '() dat) (cdr e))
|
||||
(d dat (if (null? d) '() (cdr d))))
|
||||
((or (null? e)
|
||||
(match (cdr pat)
|
||||
d
|
||||
(cons
|
||||
(cons (car pat) l)
|
||||
alist)))
|
||||
(if (null? e) #f #t)))))))))
|
||||
(else (and
|
||||
(pair? (car dat))
|
||||
(match (car pat)
|
||||
(car dat) alist)
|
||||
(match (cdr pat)
|
||||
(cdr dat) alist)))))))
|
||||
|
||||
(define (browse)
|
||||
(investigate
|
||||
(randomize
|
||||
(init 100 10 4 '((a a a b b b b a a a a a b b a a a)
|
||||
(a a b b b b a a
|
||||
(a a)(b b))
|
||||
(a a a b (b a) b a b a))))
|
||||
'((*a ?b *b ?b a *a a *b *a)
|
||||
(*a *b *b *a (*a) (*b))
|
||||
(? ? * (b a) * ? ?))))
|
||||
|
||||
(define (investigate units pats)
|
||||
(do ((units units (cdr units)))
|
||||
((null? units))
|
||||
(do ((pats pats (cdr pats)))
|
||||
((null? pats))
|
||||
(do ((p (get (car units) 'pattern)
|
||||
(cdr p)))
|
||||
((null? p))
|
||||
(match (car pats) (car p) '())))))
|
||||
|
||||
(time (browse))
|
||||
)
|
||||
|
619
collects/tests/mzscheme/benchmarks/common/conform.sch
Normal file
619
collects/tests/mzscheme/benchmarks/common/conform.sch
Normal file
|
@ -0,0 +1,619 @@
|
|||
;
|
||||
; conform.scm [portable/R^399RS version]
|
||||
; By Jim Miller [mods by oz]
|
||||
; [call to run-benchmark added by wdc 14 Feb 1997]
|
||||
|
||||
; (declare (usual-integrations))
|
||||
|
||||
;; SORT
|
||||
|
||||
(define (vector-copy v)
|
||||
(let* ((length (vector-length v))
|
||||
(result (make-vector length)))
|
||||
(let loop ((n 0))
|
||||
(vector-set! result n (vector-ref v n))
|
||||
(if (= n length)
|
||||
v
|
||||
(loop (+ n 1))))))
|
||||
|
||||
(define (sort obj pred)
|
||||
(define (loop l)
|
||||
(if (and (pair? l) (pair? (cdr l)))
|
||||
(split l '() '())
|
||||
l))
|
||||
|
||||
(define (split l one two)
|
||||
(if (pair? l)
|
||||
(split (cdr l) two (cons (car l) one))
|
||||
(merge (loop one) (loop two))))
|
||||
|
||||
(define (merge one two)
|
||||
(cond ((null? one) two)
|
||||
((pred (car two) (car one))
|
||||
(cons (car two)
|
||||
(merge (cdr two) one)))
|
||||
(else
|
||||
(cons (car one)
|
||||
(merge (cdr one) two)))))
|
||||
|
||||
(cond ((or (pair? obj) (null? obj))
|
||||
(loop obj))
|
||||
((vector? obj)
|
||||
(sort! (vector-copy obj) pred))
|
||||
(else
|
||||
(error "sort: argument should be a list or vector" obj))))
|
||||
|
||||
;; This merge sort is stable for partial orders (for predicates like
|
||||
;; <=, rather than like <).
|
||||
|
||||
(define (sort! v pred)
|
||||
(define (sort-internal! vec temp low high)
|
||||
(if (< low high)
|
||||
(let* ((middle (quotient (+ low high) 2))
|
||||
(next (+ middle 1)))
|
||||
(sort-internal! temp vec low middle)
|
||||
(sort-internal! temp vec next high)
|
||||
(let loop ((p low) (p1 low) (p2 next))
|
||||
(if (not (> p high))
|
||||
(cond ((> p1 middle)
|
||||
(vector-set! vec p (vector-ref temp p2))
|
||||
(loop (+ p 1) p1 (+ p2 1)))
|
||||
((or (> p2 high)
|
||||
(pred (vector-ref temp p1)
|
||||
(vector-ref temp p2)))
|
||||
(vector-set! vec p (vector-ref temp p1))
|
||||
(loop (+ p 1) (+ p1 1) p2))
|
||||
(else
|
||||
(vector-set! vec p (vector-ref temp p2))
|
||||
(loop (+ p 1) p1 (+ p2 1)))))))))
|
||||
|
||||
(if (not (vector? v))
|
||||
(error "sort!: argument not a vector" v))
|
||||
|
||||
(sort-internal! v
|
||||
(vector-copy v)
|
||||
0
|
||||
(- (vector-length v) 1))
|
||||
v)
|
||||
|
||||
;; SET OPERATIONS
|
||||
; (representation as lists with distinct elements)
|
||||
|
||||
(define (adjoin element set)
|
||||
(if (memq element set) set (cons element set)))
|
||||
|
||||
(define (eliminate element set)
|
||||
(cond ((null? set) set)
|
||||
((eq? element (car set)) (cdr set))
|
||||
(else (cons (car set) (eliminate element (cdr set))))))
|
||||
|
||||
(define (intersect list1 list2)
|
||||
(let loop ((l list1))
|
||||
(cond ((null? l) '())
|
||||
((memq (car l) list2) (cons (car l) (loop (cdr l))))
|
||||
(else (loop (cdr l))))))
|
||||
|
||||
(define (union list1 list2)
|
||||
(if (null? list1)
|
||||
list2
|
||||
(union (cdr list1)
|
||||
(adjoin (car list1) list2))))
|
||||
|
||||
;; GRAPH NODES
|
||||
|
||||
; (define-structure
|
||||
; (internal-node
|
||||
; (print-procedure (unparser/standard-method
|
||||
; 'graph-node
|
||||
; (lambda (state node)
|
||||
; (unparse-object state (internal-node-name node))))))
|
||||
; name
|
||||
; (green-edges '())
|
||||
; (red-edges '())
|
||||
; blue-edges)
|
||||
|
||||
; Above is MIT version; below is portable
|
||||
|
||||
(define make-internal-node vector)
|
||||
(define (internal-node-name node) (vector-ref node 0))
|
||||
(define (internal-node-green-edges node) (vector-ref node 1))
|
||||
(define (internal-node-red-edges node) (vector-ref node 2))
|
||||
(define (internal-node-blue-edges node) (vector-ref node 3))
|
||||
(define (set-internal-node-name! node name) (vector-set! node 0 name))
|
||||
(define (set-internal-node-green-edges! node edges) (vector-set! node 1 edges))
|
||||
(define (set-internal-node-red-edges! node edges) (vector-set! node 2 edges))
|
||||
(define (set-internal-node-blue-edges! node edges) (vector-set! node 3 edges))
|
||||
|
||||
; End of portability stuff
|
||||
|
||||
(define (make-node name . blue-edges) ; User's constructor
|
||||
(let ((name (if (symbol? name) (symbol->string name) name))
|
||||
(blue-edges (if (null? blue-edges) 'NOT-A-NODE-YET (car blue-edges))))
|
||||
(make-internal-node name '() '() blue-edges)))
|
||||
|
||||
(define (copy-node node)
|
||||
(make-internal-node (name node) '() '() (blue-edges node)))
|
||||
|
||||
; Selectors
|
||||
|
||||
(define name internal-node-name)
|
||||
(define (make-edge-getter selector)
|
||||
(lambda (node)
|
||||
(if (or (none-node? node) (any-node? node))
|
||||
(error "Can't get edges from the ANY or NONE nodes")
|
||||
(selector node))))
|
||||
(define red-edges (make-edge-getter internal-node-red-edges))
|
||||
(define green-edges (make-edge-getter internal-node-green-edges))
|
||||
(define blue-edges (make-edge-getter internal-node-blue-edges))
|
||||
|
||||
; Mutators
|
||||
|
||||
(define (make-edge-setter mutator!)
|
||||
(lambda (node value)
|
||||
(cond ((any-node? node) (error "Can't set edges from the ANY node"))
|
||||
((none-node? node) 'OK)
|
||||
(else (mutator! node value)))))
|
||||
(define set-red-edges! (make-edge-setter set-internal-node-red-edges!))
|
||||
(define set-green-edges! (make-edge-setter set-internal-node-green-edges!))
|
||||
(define set-blue-edges! (make-edge-setter set-internal-node-blue-edges!))
|
||||
|
||||
;; BLUE EDGES
|
||||
|
||||
; (define-structure
|
||||
; (blue-edge
|
||||
; (print-procedure
|
||||
; (unparser/standard-method
|
||||
; 'blue-edge
|
||||
; (lambda (state edge)
|
||||
; (unparse-object state (blue-edge-operation edge))))))
|
||||
; operation arg-node res-node)
|
||||
|
||||
; Above is MIT version; below is portable
|
||||
|
||||
(define make-blue-edge vector)
|
||||
(define (blue-edge-operation edge) (vector-ref edge 0))
|
||||
(define (blue-edge-arg-node edge) (vector-ref edge 1))
|
||||
(define (blue-edge-res-node edge) (vector-ref edge 2))
|
||||
(define (set-blue-edge-operation! edge value) (vector-set! edge 0 value))
|
||||
(define (set-blue-edge-arg-node! edge value) (vector-set! edge 1 value))
|
||||
(define (set-blue-edge-res-node! edge value) (vector-set! edge 2 value))
|
||||
|
||||
; End of portability stuff
|
||||
|
||||
; Selectors
|
||||
(define operation blue-edge-operation)
|
||||
(define arg-node blue-edge-arg-node)
|
||||
(define res-node blue-edge-res-node)
|
||||
|
||||
; Mutators
|
||||
(define set-arg-node! set-blue-edge-arg-node!)
|
||||
(define set-res-node! set-blue-edge-res-node!)
|
||||
|
||||
; Higher level operations on blue edges
|
||||
|
||||
(define (lookup-op op node)
|
||||
(let loop ((edges (blue-edges node)))
|
||||
(cond ((null? edges) '())
|
||||
((eq? op (operation (car edges))) (car edges))
|
||||
(else (loop (cdr edges))))))
|
||||
|
||||
(define (has-op? op node)
|
||||
(not (null? (lookup-op op node))))
|
||||
|
||||
; Add a (new) blue edge to a node
|
||||
|
||||
; (define (adjoin-blue-edge! blue-edge node)
|
||||
; (let ((current-one (lookup-op (operation blue-edge) node)))
|
||||
; (cond ((null? current-one)
|
||||
; (set-blue-edges! node
|
||||
; (cons blue-edge (blue-edges node))))
|
||||
; ((and (eq? (arg-node current-one) (arg-node blue-edge))
|
||||
; (eq? (res-node current-one) (res-node blue-edge)))
|
||||
; 'OK)
|
||||
; (else (error "Two non-equivalent blue edges for op"
|
||||
; blue-edge node)))))
|
||||
|
||||
;; GRAPHS
|
||||
|
||||
; (define-structure
|
||||
; (internal-graph
|
||||
; (print-procedure
|
||||
; (unparser/standard-method 'graph
|
||||
; (lambda (state edge)
|
||||
; (unparse-object state (map name (internal-graph-nodes edge)))))))
|
||||
; nodes already-met already-joined)
|
||||
|
||||
; Above is MIT version; below is portable
|
||||
|
||||
(define make-internal-graph vector)
|
||||
(define (internal-graph-nodes graph) (vector-ref graph 0))
|
||||
(define (internal-graph-already-met graph) (vector-ref graph 1))
|
||||
(define (internal-graph-already-joined graph) (vector-ref graph 2))
|
||||
(define (set-internal-graph-nodes! graph nodes) (vector-set! graph 0 nodes))
|
||||
|
||||
; End of portability stuff
|
||||
|
||||
; Constructor
|
||||
|
||||
(define (make-graph . nodes)
|
||||
(make-internal-graph nodes (make-empty-table) (make-empty-table)))
|
||||
|
||||
; Selectors
|
||||
|
||||
(define graph-nodes internal-graph-nodes)
|
||||
(define already-met internal-graph-already-met)
|
||||
(define already-joined internal-graph-already-joined)
|
||||
|
||||
; Higher level functions on graphs
|
||||
|
||||
(define (add-graph-nodes! graph nodes)
|
||||
(set-internal-graph-nodes! graph (cons nodes (graph-nodes graph))))
|
||||
|
||||
(define (copy-graph g)
|
||||
(define (copy-list l) (vector->list (list->vector l)))
|
||||
(make-internal-graph
|
||||
(copy-list (graph-nodes g))
|
||||
(already-met g)
|
||||
(already-joined g)))
|
||||
|
||||
(define (clean-graph g)
|
||||
(define (clean-node node)
|
||||
(if (not (or (any-node? node) (none-node? node)))
|
||||
(begin
|
||||
(set-green-edges! node '())
|
||||
(set-red-edges! node '()))))
|
||||
(for-each clean-node (graph-nodes g))
|
||||
g)
|
||||
|
||||
(define (canonicalize-graph graph classes)
|
||||
(define (fix node)
|
||||
(define (fix-set object selector mutator)
|
||||
(mutator object
|
||||
(map (lambda (node)
|
||||
(find-canonical-representative node classes))
|
||||
(selector object))))
|
||||
(if (not (or (none-node? node) (any-node? node)))
|
||||
(begin
|
||||
(fix-set node green-edges set-green-edges!)
|
||||
(fix-set node red-edges set-red-edges!)
|
||||
(for-each
|
||||
(lambda (blue-edge)
|
||||
(set-arg-node! blue-edge
|
||||
(find-canonical-representative (arg-node blue-edge) classes))
|
||||
(set-res-node! blue-edge
|
||||
(find-canonical-representative (res-node blue-edge) classes)))
|
||||
(blue-edges node))))
|
||||
node)
|
||||
(define (fix-table table)
|
||||
(define (canonical? node) (eq? node (find-canonical-representative node classes)))
|
||||
(define (filter-and-fix predicate-fn update-fn list)
|
||||
(let loop ((list list))
|
||||
(cond ((null? list) '())
|
||||
((predicate-fn (car list))
|
||||
(cons (update-fn (car list)) (loop (cdr list))))
|
||||
(else (loop (cdr list))))))
|
||||
(define (fix-line line)
|
||||
(filter-and-fix
|
||||
(lambda (entry) (canonical? (car entry)))
|
||||
(lambda (entry) (cons (car entry)
|
||||
(find-canonical-representative (cdr entry) classes)))
|
||||
line))
|
||||
(if (null? table)
|
||||
'()
|
||||
(cons (car table)
|
||||
(filter-and-fix
|
||||
(lambda (entry) (canonical? (car entry)))
|
||||
(lambda (entry) (cons (car entry) (fix-line (cdr entry))))
|
||||
(cdr table)))))
|
||||
(make-internal-graph
|
||||
(map (lambda (class) (fix (car class))) classes)
|
||||
(fix-table (already-met graph))
|
||||
(fix-table (already-joined graph))))
|
||||
|
||||
;; USEFUL NODES
|
||||
|
||||
(define none-node (make-node 'none #t))
|
||||
(define (none-node? node) (eq? node none-node))
|
||||
|
||||
(define any-node (make-node 'any '()))
|
||||
(define (any-node? node) (eq? node any-node))
|
||||
|
||||
;; COLORED EDGE TESTS
|
||||
|
||||
|
||||
(define (green-edge? from-node to-node)
|
||||
(cond ((any-node? from-node) #f)
|
||||
((none-node? from-node) #t)
|
||||
((memq to-node (green-edges from-node)) #t)
|
||||
(else #f)))
|
||||
|
||||
(define (red-edge? from-node to-node)
|
||||
(cond ((any-node? from-node) #f)
|
||||
((none-node? from-node) #t)
|
||||
((memq to-node (red-edges from-node)) #t)
|
||||
(else #f)))
|
||||
|
||||
;; SIGNATURE
|
||||
|
||||
; Return signature (i.e. <arg, res>) given an operation and a node
|
||||
|
||||
(define sig
|
||||
(let ((none-comma-any (cons none-node any-node)))
|
||||
(lambda (op node) ; Returns (arg, res)
|
||||
(let ((the-edge (lookup-op op node)))
|
||||
(if (not (null? the-edge))
|
||||
(cons (arg-node the-edge) (res-node the-edge))
|
||||
none-comma-any)))))
|
||||
|
||||
; Selectors from signature
|
||||
|
||||
(define (arg pair) (car pair))
|
||||
(define (res pair) (cdr pair))
|
||||
|
||||
;; CONFORMITY
|
||||
|
||||
(define (conforms? t1 t2)
|
||||
(define nodes-with-red-edges-out '())
|
||||
(define (add-red-edge! from-node to-node)
|
||||
(set-red-edges! from-node (adjoin to-node (red-edges from-node)))
|
||||
(set! nodes-with-red-edges-out
|
||||
(adjoin from-node nodes-with-red-edges-out)))
|
||||
(define (greenify-red-edges! from-node)
|
||||
(set-green-edges! from-node
|
||||
(append (red-edges from-node) (green-edges from-node)))
|
||||
(set-red-edges! from-node '()))
|
||||
(define (delete-red-edges! from-node)
|
||||
(set-red-edges! from-node '()))
|
||||
(define (does-conform t1 t2)
|
||||
(cond ((or (none-node? t1) (any-node? t2)) #t)
|
||||
((or (any-node? t1) (none-node? t2)) #f)
|
||||
((green-edge? t1 t2) #t)
|
||||
((red-edge? t1 t2) #t)
|
||||
(else
|
||||
(add-red-edge! t1 t2)
|
||||
(let loop ((blues (blue-edges t2)))
|
||||
(if (null? blues)
|
||||
#t
|
||||
(let* ((current-edge (car blues))
|
||||
(phi (operation current-edge)))
|
||||
(and (has-op? phi t1)
|
||||
(does-conform
|
||||
(res (sig phi t1))
|
||||
(res (sig phi t2)))
|
||||
(does-conform
|
||||
(arg (sig phi t2))
|
||||
(arg (sig phi t1)))
|
||||
(loop (cdr blues)))))))))
|
||||
(let ((result (does-conform t1 t2)))
|
||||
(for-each (if result greenify-red-edges! delete-red-edges!)
|
||||
nodes-with-red-edges-out)
|
||||
result))
|
||||
|
||||
(define (equivalent? a b)
|
||||
(and (conforms? a b) (conforms? b a)))
|
||||
|
||||
;; EQUIVALENCE CLASSIFICATION
|
||||
; Given a list of nodes, return a list of equivalence classes
|
||||
|
||||
(define (classify nodes)
|
||||
(let node-loop ((classes '())
|
||||
(nodes nodes))
|
||||
(if (null? nodes)
|
||||
(map (lambda (class)
|
||||
(sort class
|
||||
(lambda (node1 node2)
|
||||
(< (string-length (name node1))
|
||||
(string-length (name node2))))))
|
||||
classes)
|
||||
(let ((this-node (car nodes)))
|
||||
(define (add-node classes)
|
||||
(cond ((null? classes) (list (list this-node)))
|
||||
((equivalent? this-node (caar classes))
|
||||
(cons (cons this-node (car classes))
|
||||
(cdr classes)))
|
||||
(else (cons (car classes)
|
||||
(add-node (cdr classes))))))
|
||||
(node-loop (add-node classes)
|
||||
(cdr nodes))))))
|
||||
|
||||
; Given a node N and a classified set of nodes,
|
||||
; find the canonical member corresponding to N
|
||||
|
||||
(define (find-canonical-representative element classification)
|
||||
(let loop ((classes classification))
|
||||
(cond ((null? classes) (error "Can't classify" element))
|
||||
((memq element (car classes)) (car (car classes)))
|
||||
(else (loop (cdr classes))))))
|
||||
|
||||
; Reduce a graph by taking only one member of each equivalence
|
||||
; class and canonicalizing all outbound pointers
|
||||
|
||||
(define (reduce graph)
|
||||
(let ((classes (classify (graph-nodes graph))))
|
||||
(canonicalize-graph graph classes)))
|
||||
|
||||
;; TWO DIMENSIONAL TABLES
|
||||
|
||||
(define (make-empty-table) (list 'TABLE))
|
||||
|
||||
(define (lookup table x y)
|
||||
(let ((one (assq x (cdr table))))
|
||||
(if one
|
||||
(let ((two (assq y (cdr one))))
|
||||
(if two (cdr two) #f))
|
||||
#f)))
|
||||
|
||||
(define (insert! table x y value)
|
||||
(define (make-singleton-table x y)
|
||||
(list (cons x y)))
|
||||
(let ((one (assq x (cdr table))))
|
||||
(if one
|
||||
(set-cdr! one (cons (cons y value) (cdr one)))
|
||||
(set-cdr! table (cons (cons x (make-singleton-table y value))
|
||||
(cdr table))))))
|
||||
|
||||
;; MEET/JOIN
|
||||
; These update the graph when computing the node for node1*node2
|
||||
|
||||
(define (blue-edge-operate arg-fn res-fn graph op sig1 sig2)
|
||||
(make-blue-edge op
|
||||
(arg-fn graph (arg sig1) (arg sig2))
|
||||
(res-fn graph (res sig1) (res sig2))))
|
||||
|
||||
(define (meet graph node1 node2)
|
||||
(cond ((eq? node1 node2) node1)
|
||||
((or (any-node? node1) (any-node? node2)) any-node) ; canonicalize
|
||||
((none-node? node1) node2)
|
||||
((none-node? node2) node1)
|
||||
((lookup (already-met graph) node1 node2)) ; return it if found
|
||||
((conforms? node1 node2) node2)
|
||||
((conforms? node2 node1) node1)
|
||||
(else
|
||||
(let ((result
|
||||
(make-node (string-append "(" (name node1) " ^ " (name node2) ")"))))
|
||||
(add-graph-nodes! graph result)
|
||||
(insert! (already-met graph) node1 node2 result)
|
||||
(set-blue-edges! result
|
||||
(map
|
||||
(lambda (op)
|
||||
(blue-edge-operate join meet graph op (sig op node1) (sig op node2)))
|
||||
(intersect (map operation (blue-edges node1))
|
||||
(map operation (blue-edges node2)))))
|
||||
result))))
|
||||
|
||||
(define (join graph node1 node2)
|
||||
(cond ((eq? node1 node2) node1)
|
||||
((any-node? node1) node2)
|
||||
((any-node? node2) node1)
|
||||
((or (none-node? node1) (none-node? node2)) none-node) ; canonicalize
|
||||
((lookup (already-joined graph) node1 node2)) ; return it if found
|
||||
((conforms? node1 node2) node1)
|
||||
((conforms? node2 node1) node2)
|
||||
(else
|
||||
(let ((result
|
||||
(make-node (string-append "(" (name node1) " v " (name node2) ")"))))
|
||||
(add-graph-nodes! graph result)
|
||||
(insert! (already-joined graph) node1 node2 result)
|
||||
(set-blue-edges! result
|
||||
(map
|
||||
(lambda (op)
|
||||
(blue-edge-operate meet join graph op (sig op node1) (sig op node2)))
|
||||
(union (map operation (blue-edges node1))
|
||||
(map operation (blue-edges node2)))))
|
||||
result))))
|
||||
|
||||
;; MAKE A LATTICE FROM A GRAPH
|
||||
|
||||
(define (make-lattice g print?)
|
||||
(define (step g)
|
||||
(let* ((copy (copy-graph g))
|
||||
(nodes (graph-nodes copy)))
|
||||
(for-each (lambda (first)
|
||||
(for-each (lambda (second)
|
||||
(meet copy first second)
|
||||
(join copy first second))
|
||||
nodes))
|
||||
nodes)
|
||||
copy))
|
||||
(define (loop g count)
|
||||
(if print? (display count))
|
||||
(let ((lattice (step g)))
|
||||
(if print? (begin (display " -> ")
|
||||
(display (length (graph-nodes lattice)))))
|
||||
(let* ((new-g (reduce lattice))
|
||||
(new-count (length (graph-nodes new-g))))
|
||||
(if (= new-count count)
|
||||
(begin
|
||||
(if print? (newline))
|
||||
new-g)
|
||||
(begin
|
||||
(if print? (begin (display " -> ")
|
||||
(display new-count) (newline)))
|
||||
(loop new-g new-count))))))
|
||||
(let ((graph
|
||||
(apply make-graph
|
||||
(adjoin any-node (adjoin none-node (graph-nodes (clean-graph g)))))))
|
||||
(loop graph (length (graph-nodes graph)))))
|
||||
|
||||
;; DEBUG and TEST
|
||||
|
||||
(define a '())
|
||||
(define b '())
|
||||
(define c '())
|
||||
(define d '())
|
||||
|
||||
(define (reset)
|
||||
(set! a (make-node 'a))
|
||||
(set! b (make-node 'b))
|
||||
(set-blue-edges! a (list (make-blue-edge 'phi any-node b)))
|
||||
(set-blue-edges! b (list (make-blue-edge 'phi any-node a)
|
||||
(make-blue-edge 'theta any-node b)))
|
||||
(set! c (make-node "c"))
|
||||
(set! d (make-node "d"))
|
||||
(set-blue-edges! c (list (make-blue-edge 'theta any-node b)))
|
||||
(set-blue-edges! d (list (make-blue-edge 'phi any-node c)
|
||||
(make-blue-edge 'theta any-node d)))
|
||||
'(made a b c d))
|
||||
|
||||
(define (test)
|
||||
(reset)
|
||||
(map name
|
||||
(graph-nodes
|
||||
(make-lattice (make-graph a b c d any-node none-node) #t))))
|
||||
;;; note printflag #t
|
||||
;(define (time-test)
|
||||
; (let ((t (runtime)))
|
||||
; (let ((ans (test)))
|
||||
; (cons ans (- (runtime) t)))))
|
||||
|
||||
;
|
||||
; run and make sure result is correct
|
||||
;
|
||||
(define (go)
|
||||
(reset)
|
||||
(let ((result '("(((b v d) ^ a) v c)"
|
||||
"(c ^ d)"
|
||||
"(b v (a ^ d))"
|
||||
"((a v d) ^ b)"
|
||||
"(b v d)"
|
||||
"(b ^ (a v c))"
|
||||
"(a v (c ^ d))"
|
||||
"((b v d) ^ a)"
|
||||
"(c v (a v d))"
|
||||
"(a v c)"
|
||||
"(d v (b ^ (a v c)))"
|
||||
"(d ^ (a v c))"
|
||||
"((a ^ d) v c)"
|
||||
"((a ^ b) v d)"
|
||||
"(((a v d) ^ b) v (a ^ d))"
|
||||
"(b ^ d)"
|
||||
"(b v (a v d))"
|
||||
"(a ^ c)"
|
||||
"(b ^ (c v d))"
|
||||
"(a ^ b)"
|
||||
"(a v b)"
|
||||
"((a ^ d) ^ b)"
|
||||
"(a ^ d)"
|
||||
"(a v d)"
|
||||
"d"
|
||||
"(c v d)"
|
||||
"a"
|
||||
"b"
|
||||
"c"
|
||||
"any"
|
||||
"none")))
|
||||
|
||||
(if (equal? (test) result)
|
||||
(display " ok.")
|
||||
(display " um."))
|
||||
(newline)))
|
||||
|
||||
;[mods made by wdc]
|
||||
;(go)
|
||||
;(exit)
|
||||
|
||||
(define (conform-benchmark . rest)
|
||||
(time (go)))
|
||||
|
||||
(conform-benchmark)
|
||||
|
2
collects/tests/mzscheme/benchmarks/common/conform.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/conform.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module conform "wrap.ss")
|
34
collects/tests/mzscheme/benchmarks/common/cpstack.sch
Normal file
34
collects/tests/mzscheme/benchmarks/common/cpstack.sch
Normal file
|
@ -0,0 +1,34 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; File: cpstak.sch
|
||||
; Description: continuation-passing version of TAK
|
||||
; Author: Will Clinger
|
||||
; Created: 20-Aug-87
|
||||
; Language: Scheme
|
||||
; Status: Public Domain
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;;; CPSTAK -- A continuation-passing version of the TAK benchmark.
|
||||
;;; A good test of first class procedures and tail recursion.
|
||||
|
||||
(define (cpstak x y z)
|
||||
(define (tak x y z k)
|
||||
(if (not (< y x))
|
||||
(k z)
|
||||
(tak (- x 1)
|
||||
y
|
||||
z
|
||||
(lambda (v1)
|
||||
(tak (- y 1)
|
||||
z
|
||||
x
|
||||
(lambda (v2)
|
||||
(tak (- z 1)
|
||||
x
|
||||
y
|
||||
(lambda (v3)
|
||||
(tak v1 v2 v3 k)))))))))
|
||||
(tak x y z (lambda (a) a)))
|
||||
|
||||
;;; call: (cpstak 18 12 6)
|
||||
|
||||
(time (cpstak 18 12 2))
|
2
collects/tests/mzscheme/benchmarks/common/cpstack.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/cpstack.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module cpstack "wrap.ss")
|
55
collects/tests/mzscheme/benchmarks/common/ctak.sch
Normal file
55
collects/tests/mzscheme/benchmarks/common/ctak.sch
Normal file
|
@ -0,0 +1,55 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; File: ctak.sch
|
||||
; Description: The ctak benchmark
|
||||
; Author: Richard Gabriel
|
||||
; Created: 5-Apr-85
|
||||
; Modified: 10-Apr-85 14:53:02 (Bob Shaw)
|
||||
; 24-Jul-87 (Will Clinger)
|
||||
; Language: Scheme
|
||||
; Status: Public Domain
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
; The original version of this benchmark used a continuation mechanism that
|
||||
; is less powerful than call-with-current-continuation and also relied on
|
||||
; dynamic binding, which is not provided in standard Scheme. Since the
|
||||
; intent of the benchmark seemed to be to test non-local exits, the dynamic
|
||||
; binding has been replaced here by lexical binding.
|
||||
|
||||
; For Scheme the comment that follows should read:
|
||||
;;; CTAK -- A version of the TAK procedure that uses continuations.
|
||||
|
||||
;;; CTAK -- A version of the TAK function that uses the CATCH/THROW facility.
|
||||
|
||||
(define (ctak x y z)
|
||||
(call-with-current-continuation
|
||||
(lambda (k)
|
||||
(ctak-aux k x y z))))
|
||||
|
||||
(define (ctak-aux k x y z)
|
||||
(cond ((not (< y x)) ;xy
|
||||
(k z))
|
||||
(else (call-with-current-continuation
|
||||
(ctak-aux
|
||||
k
|
||||
(call-with-current-continuation
|
||||
(lambda (k)
|
||||
(ctak-aux k
|
||||
(- x 1)
|
||||
y
|
||||
z)))
|
||||
(call-with-current-continuation
|
||||
(lambda (k)
|
||||
(ctak-aux k
|
||||
(- y 1)
|
||||
z
|
||||
x)))
|
||||
(call-with-current-continuation
|
||||
(lambda (k)
|
||||
(ctak-aux k
|
||||
(- z 1)
|
||||
x
|
||||
y))))))))
|
||||
|
||||
;;; call: (ctak 18 12 6)
|
||||
|
||||
(time (ctak 18 12 6))
|
2
collects/tests/mzscheme/benchmarks/common/ctak.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/ctak.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module ctak "wrap.ss")
|
99
collects/tests/mzscheme/benchmarks/common/dderiv.ss
Normal file
99
collects/tests/mzscheme/benchmarks/common/dderiv.ss
Normal file
|
@ -0,0 +1,99 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; File: dderiv.sch
|
||||
; Description: DDERIV benchmark from the Gabriel tests
|
||||
; Author: Vaughan Pratt
|
||||
; Created: 8-Apr-85
|
||||
; Modified: 10-Apr-85 14:53:29 (Bob Shaw)
|
||||
; 23-Jul-87 (Will Clinger)
|
||||
; 9-Feb-88 (Will Clinger)
|
||||
; Language: Scheme (but see note below)
|
||||
; Status: Public Domain
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
; Note: This benchmark uses property lists. The procedures that must
|
||||
; be supplied are get and put, where (put x y z) is equivalent to Common
|
||||
; Lisp's (setf (get x y) z).
|
||||
|
||||
;;; DDERIV -- Symbolic derivative benchmark written by Vaughn Pratt.
|
||||
|
||||
;;; This benchmark is a variant of the simple symbolic derivative program
|
||||
;;; (DERIV). The main change is that it is `table-driven.' Instead of using a
|
||||
;;; large COND that branches on the CAR of the expression, this program finds
|
||||
;;; the code that will take the derivative on the property list of the atom in
|
||||
;;; the CAR position. So, when the expression is (+ . <rest>), the code
|
||||
;;; stored under the atom '+ with indicator DERIV will take <rest> and
|
||||
;;; return the derivative for '+. The way that MacLisp does this is with the
|
||||
;;; special form: (DEFUN (FOO BAR) ...). This is exactly like DEFUN with an
|
||||
;;; atomic name in that it expects an argument list and the compiler compiles
|
||||
;;; code, but the name of the function with that code is stored on the
|
||||
;;; property list of FOO under the indicator BAR, in this case. You may have
|
||||
;;; to do something like:
|
||||
|
||||
;;; :property keyword is not Common Lisp.
|
||||
|
||||
; Returns the wrong answer for quotients.
|
||||
; Fortunately these aren't used in the benchmark.
|
||||
|
||||
(module dderiv mzscheme
|
||||
|
||||
(define pg-alist '())
|
||||
(define (put sym d what)
|
||||
(set! pg-alist (cons (cons sym what) pg-alist)))
|
||||
(define (get sym d)
|
||||
(cdr (assq sym pg-alist)))
|
||||
|
||||
(define (dderiv-aux a)
|
||||
(list '/ (dderiv a) a))
|
||||
|
||||
(define (+dderiv a)
|
||||
(cons '+ (map dderiv a)))
|
||||
|
||||
(put '+ 'dderiv +dderiv) ; install procedure on the property list
|
||||
|
||||
(define (-dderiv a)
|
||||
(cons '- (map dderiv a)))
|
||||
|
||||
(put '- 'dderiv -dderiv) ; install procedure on the property list
|
||||
|
||||
(define (*dderiv a)
|
||||
(list '* (cons '* a)
|
||||
(cons '+ (map dderiv-aux a))))
|
||||
|
||||
(put '* 'dderiv *dderiv) ; install procedure on the property list
|
||||
|
||||
(define (/dderiv a)
|
||||
(list '-
|
||||
(list '/
|
||||
(dderiv (car a))
|
||||
(cadr a))
|
||||
(list '/
|
||||
(car a)
|
||||
(list '*
|
||||
(cadr a)
|
||||
(cadr a)
|
||||
(dderiv (cadr a))))))
|
||||
|
||||
(put '/ 'dderiv /dderiv) ; install procedure on the property list
|
||||
|
||||
(define (dderiv a)
|
||||
(cond
|
||||
((not (pair? a))
|
||||
(cond ((eq? a 'x) 1) (else 0)))
|
||||
(else (let ((dderiv (get (car a) 'dderiv)))
|
||||
(cond (dderiv (dderiv (cdr a)))
|
||||
(else 'error))))))
|
||||
|
||||
(define (run)
|
||||
(do ((i 0 (+ i 1)))
|
||||
((= i 10000))
|
||||
(dderiv '(+ (* 3 x x) (* a x x) (* b x) 5))
|
||||
(dderiv '(+ (* 3 x x) (* a x x) (* b x) 5))
|
||||
(dderiv '(+ (* 3 x x) (* a x x) (* b x) 5))
|
||||
(dderiv '(+ (* 3 x x) (* a x x) (* b x) 5))
|
||||
(dderiv '(+ (* 3 x x) (* a x x) (* b x) 5))))
|
||||
|
||||
;;; call: (run)
|
||||
|
||||
(time (run))
|
||||
)
|
||||
|
59
collects/tests/mzscheme/benchmarks/common/deriv.sch
Normal file
59
collects/tests/mzscheme/benchmarks/common/deriv.sch
Normal file
|
@ -0,0 +1,59 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; File: deriv.sch
|
||||
; Description: The DERIV benchmark from the Gabriel tests.
|
||||
; Author: Vaughan Pratt
|
||||
; Created: 8-Apr-85
|
||||
; Modified: 10-Apr-85 14:53:50 (Bob Shaw)
|
||||
; 23-Jul-87 (Will Clinger)
|
||||
; 9-Feb-88 (Will Clinger)
|
||||
; Language: Scheme
|
||||
; Status: Public Domain
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;;; DERIV -- Symbolic derivative benchmark written by Vaughn Pratt.
|
||||
;;; It uses a simple subset of Lisp and does a lot of CONSing.
|
||||
|
||||
; Returns the wrong answer for quotients.
|
||||
; Fortunately these aren't used in the benchmark.
|
||||
|
||||
(define (deriv-aux a) (list '/ (deriv a) a))
|
||||
|
||||
(define (deriv a)
|
||||
(cond
|
||||
((not (pair? a))
|
||||
(cond ((eq? a 'x) 1) (else 0)))
|
||||
((eq? (car a) '+)
|
||||
(cons '+ (map deriv (cdr a))))
|
||||
((eq? (car a) '-)
|
||||
(cons '- (map deriv
|
||||
(cdr a))))
|
||||
((eq? (car a) '*)
|
||||
(list '*
|
||||
a
|
||||
(cons '+ (map deriv-aux (cdr a)))))
|
||||
((eq? (car a) '/)
|
||||
(list '-
|
||||
(list '/
|
||||
(deriv (cadr a))
|
||||
(caddr a))
|
||||
(list '/
|
||||
(cadr a)
|
||||
(list '*
|
||||
(caddr a)
|
||||
(caddr a)
|
||||
(deriv (caddr a))))))
|
||||
(else 'error)))
|
||||
|
||||
(define (run)
|
||||
(do ((i 0 (+ i 1)))
|
||||
((= i 10000))
|
||||
(deriv '(+ (* 3 x x) (* a x x) (* b x) 5))
|
||||
(deriv '(+ (* 3 x x) (* a x x) (* b x) 5))
|
||||
(deriv '(+ (* 3 x x) (* a x x) (* b x) 5))
|
||||
(deriv '(+ (* 3 x x) (* a x x) (* b x) 5))
|
||||
(deriv '(+ (* 3 x x) (* a x x) (* b x) 5))))
|
||||
|
||||
;;; call: (run)
|
||||
|
||||
(time (run))
|
||||
|
2
collects/tests/mzscheme/benchmarks/common/deriv.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/deriv.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module deriv "wrap.ss")
|
64
collects/tests/mzscheme/benchmarks/common/destruct.sch
Normal file
64
collects/tests/mzscheme/benchmarks/common/destruct.sch
Normal file
|
@ -0,0 +1,64 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; File: destruct.sch
|
||||
; Description: DESTRUCTIVE benchmark from Gabriel tests
|
||||
; Author: Bob Shaw, HPLabs/ATC
|
||||
; Created: 8-Apr-85
|
||||
; Modified: 10-Apr-85 14:54:12 (Bob Shaw)
|
||||
; 23-Jul-87 (Will Clinger)
|
||||
; 22-Jan-88 (Will Clinger)
|
||||
; Language: Scheme
|
||||
; Status: Public Domain
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
; append! is no longer a standard Scheme procedure, so it must be defined
|
||||
; for implementations that don't already have it.
|
||||
|
||||
(define (my-append! x y)
|
||||
(if (null? x)
|
||||
y
|
||||
(do ((a x b)
|
||||
(b (cdr x) (cdr b)))
|
||||
((null? b)
|
||||
(set-cdr! a y)
|
||||
x))))
|
||||
|
||||
;;; DESTRU -- Destructive operation benchmark
|
||||
|
||||
(define (destructive n m)
|
||||
(let ((l (do ((i 10 (- i 1))
|
||||
(a '() (cons '() a)))
|
||||
((= i 0) a))))
|
||||
(do ((i n (- i 1)))
|
||||
((= i 0))
|
||||
(cond ((null? (car l))
|
||||
(do ((l l (cdr l)))
|
||||
((null? l))
|
||||
(or (car l)
|
||||
(set-car! l (cons '() '())))
|
||||
(my-append! (car l)
|
||||
(do ((j m (- j 1))
|
||||
(a '() (cons '() a)))
|
||||
((= j 0) a)))))
|
||||
(else
|
||||
(do ((l1 l (cdr l1))
|
||||
(l2 (cdr l) (cdr l2)))
|
||||
((null? l2))
|
||||
(set-cdr! (do ((j (quotient (length (car l2)) 2) (- j 1))
|
||||
(a (car l2) (cdr a)))
|
||||
((zero? j) a)
|
||||
(set-car! a i))
|
||||
(let ((n (quotient (length (car l1)) 2)))
|
||||
(cond ((= n 0) (set-car! l1 '())
|
||||
(car l1))
|
||||
(else
|
||||
(do ((j n (- j 1))
|
||||
(a (car l1) (cdr a)))
|
||||
((= j 1)
|
||||
(let ((x (cdr a)))
|
||||
(set-cdr! a '())
|
||||
x))
|
||||
(set-car! a i))))))))))))
|
||||
|
||||
;;; call: (destructive 600 50)
|
||||
|
||||
(time (destructive 600 500))
|
2
collects/tests/mzscheme/benchmarks/common/destruct.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/destruct.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module destruct "wrap.ss")
|
54
collects/tests/mzscheme/benchmarks/common/div.ss
Normal file
54
collects/tests/mzscheme/benchmarks/common/div.ss
Normal file
|
@ -0,0 +1,54 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; File: div.sch
|
||||
; Description: DIV benchmarks
|
||||
; Author: Richard Gabriel
|
||||
; Created: 8-Apr-85
|
||||
; Modified: 19-Jul-85 18:28:01 (Bob Shaw)
|
||||
; 23-Jul-87 (Will Clinger)
|
||||
; Language: Scheme
|
||||
; Status: Public Domain
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;;; DIV2 -- Benchmark which divides by 2 using lists of n ()'s.
|
||||
;;; This file contains a recursive as well as an iterative test.
|
||||
|
||||
(module div mzscheme
|
||||
(define (create-n n)
|
||||
(do ((n n (- n 1))
|
||||
(a '() (cons '() a)))
|
||||
((= n 0) a)))
|
||||
|
||||
(define *ll* (create-n 200))
|
||||
|
||||
(define (iterative-div2 l)
|
||||
(do ((l l (cddr l))
|
||||
(a '() (cons (car l) a)))
|
||||
((null? l) a)))
|
||||
|
||||
(define (recursive-div2 l)
|
||||
(cond ((null? l) '())
|
||||
(else (cons (car l) (recursive-div2 (cddr l))))))
|
||||
|
||||
(define (test-1 l)
|
||||
(do ((i 3000 (- i 1)))
|
||||
((= i 0))
|
||||
(iterative-div2 l)
|
||||
(iterative-div2 l)
|
||||
(iterative-div2 l)
|
||||
(iterative-div2 l)))
|
||||
|
||||
(define (test-2 l)
|
||||
(do ((i 3000 (- i 1)))
|
||||
((= i 0))
|
||||
(recursive-div2 l)
|
||||
(recursive-div2 l)
|
||||
(recursive-div2 l)
|
||||
(recursive-div2 l)))
|
||||
|
||||
;;; for the iterative test call: (test-1 *ll*)
|
||||
;;; for the recursive test call: (test-2 *ll*)
|
||||
|
||||
(time (test-1 *ll*))
|
||||
(time (test-2 *ll*))
|
||||
)
|
||||
|
BIN
collects/tests/mzscheme/benchmarks/common/dynamic-input.txt.gz
Normal file
BIN
collects/tests/mzscheme/benchmarks/common/dynamic-input.txt.gz
Normal file
Binary file not shown.
2340
collects/tests/mzscheme/benchmarks/common/dynamic.sch
Normal file
2340
collects/tests/mzscheme/benchmarks/common/dynamic.sch
Normal file
File diff suppressed because it is too large
Load Diff
2
collects/tests/mzscheme/benchmarks/common/dynamic.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/dynamic.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module dynamic "wrap.ss")
|
650
collects/tests/mzscheme/benchmarks/common/earley.sch
Normal file
650
collects/tests/mzscheme/benchmarks/common/earley.sch
Normal file
|
@ -0,0 +1,650 @@
|
|||
;;; EARLEY -- Earley's parser, written by Marc Feeley.
|
||||
|
||||
; $Id: earley.sch,v 1.2 1999/07/12 18:05:19 lth Exp $
|
||||
; 990708 / lth -- changed 'main' to 'earley-benchmark'.
|
||||
;
|
||||
; (make-parser grammar lexer) is used to create a parser from the grammar
|
||||
; description `grammar' and the lexer function `lexer'.
|
||||
;
|
||||
; A grammar is a list of definitions. Each definition defines a non-terminal
|
||||
; by a set of rules. Thus a definition has the form: (nt rule1 rule2...).
|
||||
; A given non-terminal can only be defined once. The first non-terminal
|
||||
; defined is the grammar's goal. Each rule is a possibly empty list of
|
||||
; non-terminals. Thus a rule has the form: (nt1 nt2...). A non-terminal
|
||||
; can be any scheme value. Note that all grammar symbols are treated as
|
||||
; non-terminals. This is fine though because the lexer will be outputing
|
||||
; non-terminals.
|
||||
;
|
||||
; The lexer defines what a token is and the mapping between tokens and
|
||||
; the grammar's non-terminals. It is a function of one argument, the input,
|
||||
; that returns the list of tokens corresponding to the input. Each token is
|
||||
; represented by a list. The first element is some `user-defined' information
|
||||
; associated with the token and the rest represents the token's class(es) (as a
|
||||
; list of non-terminals that this token corresponds to).
|
||||
;
|
||||
; The result of `make-parser' is a function that parses the single input it
|
||||
; is given into the grammar's goal. The result is a `parse' which can be
|
||||
; manipulated with the procedures: `parse->parsed?', `parse->trees'
|
||||
; and `parse->nb-trees' (see below).
|
||||
;
|
||||
; Let's assume that we want a parser for the grammar
|
||||
;
|
||||
; S -> x = E
|
||||
; E -> E + E | V
|
||||
; V -> V y |
|
||||
;
|
||||
; and that the input to the parser is a string of characters. Also, assume we
|
||||
; would like to map the characters `x', `y', `+' and `=' into the corresponding
|
||||
; non-terminals in the grammar. Such a parser could be created with
|
||||
;
|
||||
; (make-parser
|
||||
; '(
|
||||
; (s (x = e))
|
||||
; (e (e + e) (v))
|
||||
; (v (v y) ())
|
||||
; )
|
||||
; (lambda (str)
|
||||
; (map (lambda (char)
|
||||
; (list char ; user-info = the character itself
|
||||
; (case char
|
||||
; ((#\x) 'x)
|
||||
; ((#\y) 'y)
|
||||
; ((#\+) '+)
|
||||
; ((#\=) '=)
|
||||
; (else (fatal-error "lexer error")))))
|
||||
; (string->list str)))
|
||||
; )
|
||||
;
|
||||
; An alternative definition (that does not check for lexical errors) is
|
||||
;
|
||||
; (make-parser
|
||||
; '(
|
||||
; (s (#\x #\= e))
|
||||
; (e (e #\+ e) (v))
|
||||
; (v (v #\y) ())
|
||||
; )
|
||||
; (lambda (str) (map (lambda (char) (list char char)) (string->list str)))
|
||||
; )
|
||||
;
|
||||
; To help with the rest of the discussion, here are a few definitions:
|
||||
;
|
||||
; An input pointer (for an input of `n' tokens) is a value between 0 and `n'.
|
||||
; It indicates a point between two input tokens (0 = beginning, `n' = end).
|
||||
; For example, if `n' = 4, there are 5 input pointers:
|
||||
;
|
||||
; input token1 token2 token3 token4
|
||||
; input pointers 0 1 2 3 4
|
||||
;
|
||||
; A configuration indicates the extent to which a given rule is parsed (this
|
||||
; is the common `dot notation'). For simplicity, a configuration is
|
||||
; represented as an integer, with successive configurations in the same
|
||||
; rule associated with successive integers. It is assumed that the grammar
|
||||
; has been extended with rules to aid scanning. These rules are of the
|
||||
; form `nt ->', and there is one such rule for every non-terminal. Note
|
||||
; that these rules are special because they only apply when the corresponding
|
||||
; non-terminal is returned by the lexer.
|
||||
;
|
||||
; A configuration set is a configuration grouped with the set of input pointers
|
||||
; representing where the head non-terminal of the configuration was predicted.
|
||||
;
|
||||
; Here are the rules and configurations for the grammar given above:
|
||||
;
|
||||
; S -> . \
|
||||
; 0 |
|
||||
; x -> . |
|
||||
; 1 |
|
||||
; = -> . |
|
||||
; 2 |
|
||||
; E -> . |
|
||||
; 3 > special rules (for scanning)
|
||||
; + -> . |
|
||||
; 4 |
|
||||
; V -> . |
|
||||
; 5 |
|
||||
; y -> . |
|
||||
; 6 /
|
||||
; S -> . x . = . E .
|
||||
; 7 8 9 10
|
||||
; E -> . E . + . E .
|
||||
; 11 12 13 14
|
||||
; E -> . V .
|
||||
; 15 16
|
||||
; V -> . V . y .
|
||||
; 17 18 19
|
||||
; V -> .
|
||||
; 20
|
||||
;
|
||||
; Starters of the non-terminal `nt' are configurations that are leftmost
|
||||
; in a non-special rule for `nt'. Enders of the non-terminal `nt' are
|
||||
; configurations that are rightmost in any rule for `nt'. Predictors of the
|
||||
; non-terminal `nt' are configurations that are directly to the left of `nt'
|
||||
; in any rule.
|
||||
;
|
||||
; For the grammar given above,
|
||||
;
|
||||
; Starters of V = (17 20)
|
||||
; Enders of V = (5 19 20)
|
||||
; Predictors of V = (15 17)
|
||||
|
||||
(define (make-parser grammar lexer)
|
||||
|
||||
(define (non-terminals grammar) ; return vector of non-terminals in grammar
|
||||
|
||||
(define (add-nt nt nts)
|
||||
(if (member nt nts) nts (cons nt nts))) ; use equal? for equality tests
|
||||
|
||||
(let def-loop ((defs grammar) (nts '()))
|
||||
(if (pair? defs)
|
||||
(let* ((def (car defs))
|
||||
(head (car def)))
|
||||
(let rule-loop ((rules (cdr def))
|
||||
(nts (add-nt head nts)))
|
||||
(if (pair? rules)
|
||||
(let ((rule (car rules)))
|
||||
(let loop ((l rule) (nts nts))
|
||||
(if (pair? l)
|
||||
(let ((nt (car l)))
|
||||
(loop (cdr l) (add-nt nt nts)))
|
||||
(rule-loop (cdr rules) nts))))
|
||||
(def-loop (cdr defs) nts))))
|
||||
(list->vector (reverse nts))))) ; goal non-terminal must be at index 0
|
||||
|
||||
(define (ind nt nts) ; return index of non-terminal `nt' in `nts'
|
||||
(let loop ((i (- (vector-length nts) 1)))
|
||||
(if (>= i 0)
|
||||
(if (equal? (vector-ref nts i) nt) i (loop (- i 1)))
|
||||
#f)))
|
||||
|
||||
(define (nb-configurations grammar) ; return nb of configurations in grammar
|
||||
(let def-loop ((defs grammar) (nb-confs 0))
|
||||
(if (pair? defs)
|
||||
(let ((def (car defs)))
|
||||
(let rule-loop ((rules (cdr def)) (nb-confs nb-confs))
|
||||
(if (pair? rules)
|
||||
(let ((rule (car rules)))
|
||||
(let loop ((l rule) (nb-confs nb-confs))
|
||||
(if (pair? l)
|
||||
(loop (cdr l) (+ nb-confs 1))
|
||||
(rule-loop (cdr rules) (+ nb-confs 1)))))
|
||||
(def-loop (cdr defs) nb-confs))))
|
||||
nb-confs)))
|
||||
|
||||
; First, associate a numeric identifier to every non-terminal in the
|
||||
; grammar (with the goal non-terminal associated with 0).
|
||||
;
|
||||
; So, for the grammar given above we get:
|
||||
;
|
||||
; s -> 0 x -> 1 = -> 4 e ->3 + -> 4 v -> 5 y -> 6
|
||||
|
||||
(let* ((nts (non-terminals grammar)) ; id map = list of non-terms
|
||||
(nb-nts (vector-length nts)) ; the number of non-terms
|
||||
(nb-confs (+ (nb-configurations grammar) nb-nts)) ; the nb of confs
|
||||
(starters (make-vector nb-nts '())) ; starters for every non-term
|
||||
(enders (make-vector nb-nts '())) ; enders for every non-term
|
||||
(predictors (make-vector nb-nts '())) ; predictors for every non-term
|
||||
(steps (make-vector nb-confs #f)) ; what to do in a given conf
|
||||
(names (make-vector nb-confs #f))) ; name of rules
|
||||
|
||||
(define (setup-tables grammar nts starters enders predictors steps names)
|
||||
|
||||
(define (add-conf conf nt nts class)
|
||||
(let ((i (ind nt nts)))
|
||||
(vector-set! class i (cons conf (vector-ref class i)))))
|
||||
|
||||
(let ((nb-nts (vector-length nts)))
|
||||
|
||||
(let nt-loop ((i (- nb-nts 1)))
|
||||
(if (>= i 0)
|
||||
(begin
|
||||
(vector-set! steps i (- i nb-nts))
|
||||
(vector-set! names i (list (vector-ref nts i) 0))
|
||||
(vector-set! enders i (list i))
|
||||
(nt-loop (- i 1)))))
|
||||
|
||||
(let def-loop ((defs grammar) (conf (vector-length nts)))
|
||||
(if (pair? defs)
|
||||
(let* ((def (car defs))
|
||||
(head (car def)))
|
||||
(let rule-loop ((rules (cdr def)) (conf conf) (rule-num 1))
|
||||
(if (pair? rules)
|
||||
(let ((rule (car rules)))
|
||||
(vector-set! names conf (list head rule-num))
|
||||
(add-conf conf head nts starters)
|
||||
(let loop ((l rule) (conf conf))
|
||||
(if (pair? l)
|
||||
(let ((nt (car l)))
|
||||
(vector-set! steps conf (ind nt nts))
|
||||
(add-conf conf nt nts predictors)
|
||||
(loop (cdr l) (+ conf 1)))
|
||||
(begin
|
||||
(vector-set! steps conf (- (ind head nts) nb-nts))
|
||||
(add-conf conf head nts enders)
|
||||
(rule-loop (cdr rules) (+ conf 1) (+ rule-num 1))))))
|
||||
(def-loop (cdr defs) conf))))))))
|
||||
|
||||
; Now, for each non-terminal, compute the starters, enders and predictors and
|
||||
; the names and steps tables.
|
||||
|
||||
(setup-tables grammar nts starters enders predictors steps names)
|
||||
|
||||
; Build the parser description
|
||||
|
||||
(let ((parser-descr (vector lexer
|
||||
nts
|
||||
starters
|
||||
enders
|
||||
predictors
|
||||
steps
|
||||
names)))
|
||||
(lambda (input)
|
||||
|
||||
(define (ind nt nts) ; return index of non-terminal `nt' in `nts'
|
||||
(let loop ((i (- (vector-length nts) 1)))
|
||||
(if (>= i 0)
|
||||
(if (equal? (vector-ref nts i) nt) i (loop (- i 1)))
|
||||
#f)))
|
||||
|
||||
(define (comp-tok tok nts) ; transform token to parsing format
|
||||
(let loop ((l1 (cdr tok)) (l2 '()))
|
||||
(if (pair? l1)
|
||||
(let ((i (ind (car l1) nts)))
|
||||
(if i
|
||||
(loop (cdr l1) (cons i l2))
|
||||
(loop (cdr l1) l2)))
|
||||
(cons (car tok) (reverse l2)))))
|
||||
|
||||
(define (input->tokens input lexer nts)
|
||||
(list->vector (map (lambda (tok) (comp-tok tok nts)) (lexer input))))
|
||||
|
||||
(define (make-states nb-toks nb-confs)
|
||||
(let ((states (make-vector (+ nb-toks 1) #f)))
|
||||
(let loop ((i nb-toks))
|
||||
(if (>= i 0)
|
||||
(let ((v (make-vector (+ nb-confs 1) #f)))
|
||||
(vector-set! v 0 -1)
|
||||
(vector-set! states i v)
|
||||
(loop (- i 1)))
|
||||
states))))
|
||||
|
||||
(define (conf-set-get state conf)
|
||||
(vector-ref state (+ conf 1)))
|
||||
|
||||
(define (conf-set-get* state state-num conf)
|
||||
(let ((conf-set (conf-set-get state conf)))
|
||||
(if conf-set
|
||||
conf-set
|
||||
(let ((conf-set (make-vector (+ state-num 6) #f)))
|
||||
(vector-set! conf-set 1 -3) ; old elems tail (points to head)
|
||||
(vector-set! conf-set 2 -1) ; old elems head
|
||||
(vector-set! conf-set 3 -1) ; new elems tail (points to head)
|
||||
(vector-set! conf-set 4 -1) ; new elems head
|
||||
(vector-set! state (+ conf 1) conf-set)
|
||||
conf-set))))
|
||||
|
||||
(define (conf-set-merge-new! conf-set)
|
||||
(vector-set! conf-set
|
||||
(+ (vector-ref conf-set 1) 5)
|
||||
(vector-ref conf-set 4))
|
||||
(vector-set! conf-set 1 (vector-ref conf-set 3))
|
||||
(vector-set! conf-set 3 -1)
|
||||
(vector-set! conf-set 4 -1))
|
||||
|
||||
(define (conf-set-head conf-set)
|
||||
(vector-ref conf-set 2))
|
||||
|
||||
(define (conf-set-next conf-set i)
|
||||
(vector-ref conf-set (+ i 5)))
|
||||
|
||||
(define (conf-set-member? state conf i)
|
||||
(let ((conf-set (vector-ref state (+ conf 1))))
|
||||
(if conf-set
|
||||
(conf-set-next conf-set i)
|
||||
#f)))
|
||||
|
||||
(define (conf-set-adjoin state conf-set conf i)
|
||||
(let ((tail (vector-ref conf-set 3))) ; put new element at tail
|
||||
(vector-set! conf-set (+ i 5) -1)
|
||||
(vector-set! conf-set (+ tail 5) i)
|
||||
(vector-set! conf-set 3 i)
|
||||
(if (< tail 0)
|
||||
(begin
|
||||
(vector-set! conf-set 0 (vector-ref state 0))
|
||||
(vector-set! state 0 conf)))))
|
||||
|
||||
(define (conf-set-adjoin* states state-num l i)
|
||||
(let ((state (vector-ref states state-num)))
|
||||
(let loop ((l1 l))
|
||||
(if (pair? l1)
|
||||
(let* ((conf (car l1))
|
||||
(conf-set (conf-set-get* state state-num conf)))
|
||||
(if (not (conf-set-next conf-set i))
|
||||
(begin
|
||||
(conf-set-adjoin state conf-set conf i)
|
||||
(loop (cdr l1)))
|
||||
(loop (cdr l1))))))))
|
||||
|
||||
(define (conf-set-adjoin** states states* state-num conf i)
|
||||
(let ((state (vector-ref states state-num)))
|
||||
(if (conf-set-member? state conf i)
|
||||
(let* ((state* (vector-ref states* state-num))
|
||||
(conf-set* (conf-set-get* state* state-num conf)))
|
||||
(if (not (conf-set-next conf-set* i))
|
||||
(conf-set-adjoin state* conf-set* conf i))
|
||||
#t)
|
||||
#f)))
|
||||
|
||||
(define (conf-set-union state conf-set conf other-set)
|
||||
(let loop ((i (conf-set-head other-set)))
|
||||
(if (>= i 0)
|
||||
(if (not (conf-set-next conf-set i))
|
||||
(begin
|
||||
(conf-set-adjoin state conf-set conf i)
|
||||
(loop (conf-set-next other-set i)))
|
||||
(loop (conf-set-next other-set i))))))
|
||||
|
||||
(define (forw states state-num starters enders predictors steps nts)
|
||||
|
||||
(define (predict state state-num conf-set conf nt starters enders)
|
||||
|
||||
; add configurations which start the non-terminal `nt' to the
|
||||
; right of the dot
|
||||
|
||||
(let loop1 ((l (vector-ref starters nt)))
|
||||
(if (pair? l)
|
||||
(let* ((starter (car l))
|
||||
(starter-set (conf-set-get* state state-num starter)))
|
||||
(if (not (conf-set-next starter-set state-num))
|
||||
(begin
|
||||
(conf-set-adjoin state starter-set starter state-num)
|
||||
(loop1 (cdr l)))
|
||||
(loop1 (cdr l))))))
|
||||
|
||||
; check for possible completion of the non-terminal `nt' to the
|
||||
; right of the dot
|
||||
|
||||
(let loop2 ((l (vector-ref enders nt)))
|
||||
(if (pair? l)
|
||||
(let ((ender (car l)))
|
||||
(if (conf-set-member? state ender state-num)
|
||||
(let* ((next (+ conf 1))
|
||||
(next-set (conf-set-get* state state-num next)))
|
||||
(conf-set-union state next-set next conf-set)
|
||||
(loop2 (cdr l)))
|
||||
(loop2 (cdr l)))))))
|
||||
|
||||
(define (reduce states state state-num conf-set head preds)
|
||||
|
||||
; a non-terminal is now completed so check for reductions that
|
||||
; are now possible at the configurations `preds'
|
||||
|
||||
(let loop1 ((l preds))
|
||||
(if (pair? l)
|
||||
(let ((pred (car l)))
|
||||
(let loop2 ((i head))
|
||||
(if (>= i 0)
|
||||
(let ((pred-set (conf-set-get (vector-ref states i) pred)))
|
||||
(if pred-set
|
||||
(let* ((next (+ pred 1))
|
||||
(next-set (conf-set-get* state state-num next)))
|
||||
(conf-set-union state next-set next pred-set)))
|
||||
(loop2 (conf-set-next conf-set i)))
|
||||
(loop1 (cdr l))))))))
|
||||
|
||||
(let ((state (vector-ref states state-num))
|
||||
(nb-nts (vector-length nts)))
|
||||
(let loop ()
|
||||
(let ((conf (vector-ref state 0)))
|
||||
(if (>= conf 0)
|
||||
(let* ((step (vector-ref steps conf))
|
||||
(conf-set (vector-ref state (+ conf 1)))
|
||||
(head (vector-ref conf-set 4)))
|
||||
(vector-set! state 0 (vector-ref conf-set 0))
|
||||
(conf-set-merge-new! conf-set)
|
||||
(if (>= step 0)
|
||||
(predict state state-num conf-set conf step starters enders)
|
||||
(let ((preds (vector-ref predictors (+ step nb-nts))))
|
||||
(reduce states state state-num conf-set head preds)))
|
||||
(loop)))))))
|
||||
|
||||
(define (forward starters enders predictors steps nts toks)
|
||||
(let* ((nb-toks (vector-length toks))
|
||||
(nb-confs (vector-length steps))
|
||||
(states (make-states nb-toks nb-confs))
|
||||
(goal-starters (vector-ref starters 0)))
|
||||
(conf-set-adjoin* states 0 goal-starters 0) ; predict goal
|
||||
(forw states 0 starters enders predictors steps nts)
|
||||
(let loop ((i 0))
|
||||
(if (< i nb-toks)
|
||||
(let ((tok-nts (cdr (vector-ref toks i))))
|
||||
(conf-set-adjoin* states (+ i 1) tok-nts i) ; scan token
|
||||
(forw states (+ i 1) starters enders predictors steps nts)
|
||||
(loop (+ i 1)))))
|
||||
states))
|
||||
|
||||
(define (produce conf i j enders steps toks states states* nb-nts)
|
||||
(let ((prev (- conf 1)))
|
||||
(if (and (>= conf nb-nts) (>= (vector-ref steps prev) 0))
|
||||
(let loop1 ((l (vector-ref enders (vector-ref steps prev))))
|
||||
(if (pair? l)
|
||||
(let* ((ender (car l))
|
||||
(ender-set (conf-set-get (vector-ref states j)
|
||||
ender)))
|
||||
(if ender-set
|
||||
(let loop2 ((k (conf-set-head ender-set)))
|
||||
(if (>= k 0)
|
||||
(begin
|
||||
(and (>= k i)
|
||||
(conf-set-adjoin** states states* k prev i)
|
||||
(conf-set-adjoin** states states* j ender k))
|
||||
(loop2 (conf-set-next ender-set k)))
|
||||
(loop1 (cdr l))))
|
||||
(loop1 (cdr l)))))))))
|
||||
|
||||
(define (back states states* state-num enders steps nb-nts toks)
|
||||
(let ((state* (vector-ref states* state-num)))
|
||||
(let loop1 ()
|
||||
(let ((conf (vector-ref state* 0)))
|
||||
(if (>= conf 0)
|
||||
(let* ((conf-set (vector-ref state* (+ conf 1)))
|
||||
(head (vector-ref conf-set 4)))
|
||||
(vector-set! state* 0 (vector-ref conf-set 0))
|
||||
(conf-set-merge-new! conf-set)
|
||||
(let loop2 ((i head))
|
||||
(if (>= i 0)
|
||||
(begin
|
||||
(produce conf i state-num enders steps
|
||||
toks states states* nb-nts)
|
||||
(loop2 (conf-set-next conf-set i)))
|
||||
(loop1)))))))))
|
||||
|
||||
(define (backward states enders steps nts toks)
|
||||
(let* ((nb-toks (vector-length toks))
|
||||
(nb-confs (vector-length steps))
|
||||
(nb-nts (vector-length nts))
|
||||
(states* (make-states nb-toks nb-confs))
|
||||
(goal-enders (vector-ref enders 0)))
|
||||
(let loop1 ((l goal-enders))
|
||||
(if (pair? l)
|
||||
(let ((conf (car l)))
|
||||
(conf-set-adjoin** states states* nb-toks conf 0)
|
||||
(loop1 (cdr l)))))
|
||||
(let loop2 ((i nb-toks))
|
||||
(if (>= i 0)
|
||||
(begin
|
||||
(back states states* i enders steps nb-nts toks)
|
||||
(loop2 (- i 1)))))
|
||||
states*))
|
||||
|
||||
(define (parsed? nt i j nts enders states)
|
||||
(let ((nt* (ind nt nts)))
|
||||
(if nt*
|
||||
(let ((nb-nts (vector-length nts)))
|
||||
(let loop ((l (vector-ref enders nt*)))
|
||||
(if (pair? l)
|
||||
(let ((conf (car l)))
|
||||
(if (conf-set-member? (vector-ref states j) conf i)
|
||||
#t
|
||||
(loop (cdr l))))
|
||||
#f)))
|
||||
#f)))
|
||||
|
||||
(define (deriv-trees conf i j enders steps names toks states nb-nts)
|
||||
(let ((name (vector-ref names conf)))
|
||||
|
||||
(if name ; `conf' is at the start of a rule (either special or not)
|
||||
(if (< conf nb-nts)
|
||||
(list (list name (car (vector-ref toks i))))
|
||||
(list (list name)))
|
||||
|
||||
(let ((prev (- conf 1)))
|
||||
(let loop1 ((l1 (vector-ref enders (vector-ref steps prev)))
|
||||
(l2 '()))
|
||||
(if (pair? l1)
|
||||
(let* ((ender (car l1))
|
||||
(ender-set (conf-set-get (vector-ref states j)
|
||||
ender)))
|
||||
(if ender-set
|
||||
(let loop2 ((k (conf-set-head ender-set)) (l2 l2))
|
||||
(if (>= k 0)
|
||||
(if (and (>= k i)
|
||||
(conf-set-member? (vector-ref states k)
|
||||
prev i))
|
||||
(let ((prev-trees
|
||||
(deriv-trees prev i k enders steps names
|
||||
toks states nb-nts))
|
||||
(ender-trees
|
||||
(deriv-trees ender k j enders steps names
|
||||
toks states nb-nts)))
|
||||
(let loop3 ((l3 ender-trees) (l2 l2))
|
||||
(if (pair? l3)
|
||||
(let ((ender-tree (list (car l3))))
|
||||
(let loop4 ((l4 prev-trees) (l2 l2))
|
||||
(if (pair? l4)
|
||||
(loop4 (cdr l4)
|
||||
(cons (append (car l4)
|
||||
ender-tree)
|
||||
l2))
|
||||
(loop3 (cdr l3) l2))))
|
||||
(loop2 (conf-set-next ender-set k) l2))))
|
||||
(loop2 (conf-set-next ender-set k) l2))
|
||||
(loop1 (cdr l1) l2)))
|
||||
(loop1 (cdr l1) l2)))
|
||||
l2))))))
|
||||
|
||||
(define (deriv-trees* nt i j nts enders steps names toks states)
|
||||
(let ((nt* (ind nt nts)))
|
||||
(if nt*
|
||||
(let ((nb-nts (vector-length nts)))
|
||||
(let loop ((l (vector-ref enders nt*)) (trees '()))
|
||||
(if (pair? l)
|
||||
(let ((conf (car l)))
|
||||
(if (conf-set-member? (vector-ref states j) conf i)
|
||||
(loop (cdr l)
|
||||
(append (deriv-trees conf i j enders steps names
|
||||
toks states nb-nts)
|
||||
trees))
|
||||
(loop (cdr l) trees)))
|
||||
trees)))
|
||||
#f)))
|
||||
|
||||
(define (nb-deriv-trees conf i j enders steps toks states nb-nts)
|
||||
(let ((prev (- conf 1)))
|
||||
(if (or (< conf nb-nts) (< (vector-ref steps prev) 0))
|
||||
1
|
||||
(let loop1 ((l (vector-ref enders (vector-ref steps prev)))
|
||||
(n 0))
|
||||
(if (pair? l)
|
||||
(let* ((ender (car l))
|
||||
(ender-set (conf-set-get (vector-ref states j)
|
||||
ender)))
|
||||
(if ender-set
|
||||
(let loop2 ((k (conf-set-head ender-set)) (n n))
|
||||
(if (>= k 0)
|
||||
(if (and (>= k i)
|
||||
(conf-set-member? (vector-ref states k)
|
||||
prev i))
|
||||
(let ((nb-prev-trees
|
||||
(nb-deriv-trees prev i k enders steps
|
||||
toks states nb-nts))
|
||||
(nb-ender-trees
|
||||
(nb-deriv-trees ender k j enders steps
|
||||
toks states nb-nts)))
|
||||
(loop2 (conf-set-next ender-set k)
|
||||
(+ n (* nb-prev-trees nb-ender-trees))))
|
||||
(loop2 (conf-set-next ender-set k) n))
|
||||
(loop1 (cdr l) n)))
|
||||
(loop1 (cdr l) n)))
|
||||
n)))))
|
||||
|
||||
(define (nb-deriv-trees* nt i j nts enders steps toks states)
|
||||
(let ((nt* (ind nt nts)))
|
||||
(if nt*
|
||||
(let ((nb-nts (vector-length nts)))
|
||||
(let loop ((l (vector-ref enders nt*)) (nb-trees 0))
|
||||
(if (pair? l)
|
||||
(let ((conf (car l)))
|
||||
(if (conf-set-member? (vector-ref states j) conf i)
|
||||
(loop (cdr l)
|
||||
(+ (nb-deriv-trees conf i j enders steps
|
||||
toks states nb-nts)
|
||||
nb-trees))
|
||||
(loop (cdr l) nb-trees)))
|
||||
nb-trees)))
|
||||
#f)))
|
||||
|
||||
(let* ((lexer (vector-ref parser-descr 0))
|
||||
(nts (vector-ref parser-descr 1))
|
||||
(starters (vector-ref parser-descr 2))
|
||||
(enders (vector-ref parser-descr 3))
|
||||
(predictors (vector-ref parser-descr 4))
|
||||
(steps (vector-ref parser-descr 5))
|
||||
(names (vector-ref parser-descr 6))
|
||||
(toks (input->tokens input lexer nts)))
|
||||
|
||||
(vector nts
|
||||
starters
|
||||
enders
|
||||
predictors
|
||||
steps
|
||||
names
|
||||
toks
|
||||
(backward (forward starters enders predictors steps nts toks)
|
||||
enders steps nts toks)
|
||||
parsed?
|
||||
deriv-trees*
|
||||
nb-deriv-trees*))))))
|
||||
|
||||
(define (parse->parsed? parse nt i j)
|
||||
(let* ((nts (vector-ref parse 0))
|
||||
(enders (vector-ref parse 2))
|
||||
(states (vector-ref parse 7))
|
||||
(parsed? (vector-ref parse 8)))
|
||||
(parsed? nt i j nts enders states)))
|
||||
|
||||
(define (parse->trees parse nt i j)
|
||||
(let* ((nts (vector-ref parse 0))
|
||||
(enders (vector-ref parse 2))
|
||||
(steps (vector-ref parse 4))
|
||||
(names (vector-ref parse 5))
|
||||
(toks (vector-ref parse 6))
|
||||
(states (vector-ref parse 7))
|
||||
(deriv-trees* (vector-ref parse 9)))
|
||||
(deriv-trees* nt i j nts enders steps names toks states)))
|
||||
|
||||
(define (parse->nb-trees parse nt i j)
|
||||
(let* ((nts (vector-ref parse 0))
|
||||
(enders (vector-ref parse 2))
|
||||
(steps (vector-ref parse 4))
|
||||
(toks (vector-ref parse 6))
|
||||
(states (vector-ref parse 7))
|
||||
(nb-deriv-trees* (vector-ref parse 10)))
|
||||
(nb-deriv-trees* nt i j nts enders steps toks states)))
|
||||
|
||||
(define (test k)
|
||||
(let ((p (make-parser '( (s (a) (s s)) )
|
||||
(lambda (l) (map (lambda (x) (list x x)) l)))))
|
||||
(let ((x (p (vector->list (make-vector k 'a)))))
|
||||
(length (parse->trees x 's 0 k)))))
|
||||
|
||||
(time (test 12))
|
||||
|
2
collects/tests/mzscheme/benchmarks/common/earley.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/earley.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module earley "wrap.ss")
|
117
collects/tests/mzscheme/benchmarks/common/fft.sch
Normal file
117
collects/tests/mzscheme/benchmarks/common/fft.sch
Normal file
|
@ -0,0 +1,117 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; File: fft.cl
|
||||
; Description: FFT benchmark from the Gabriel tests.
|
||||
; Author: Harry Barrow
|
||||
; Created: 8-Apr-85
|
||||
; Modified: 6-May-85 09:29:22 (Bob Shaw)
|
||||
; 11-Aug-87 (Will Clinger)
|
||||
; Language: Scheme
|
||||
; Status: Public Domain
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(define pi (atan 0 -1))
|
||||
|
||||
;;; FFT -- This is an FFT benchmark written by Harry Barrow.
|
||||
;;; It tests a variety of floating point operations,
|
||||
;;; including array references.
|
||||
|
||||
(define *re* (make-vector 1025 0.0))
|
||||
|
||||
(define *im* (make-vector 1025 0.0))
|
||||
|
||||
(define (fft areal aimag)
|
||||
(let ((ar 0)
|
||||
(ai 0)
|
||||
(i 0)
|
||||
(j 0)
|
||||
(k 0)
|
||||
(m 0)
|
||||
(n 0)
|
||||
(le 0)
|
||||
(le1 0)
|
||||
(ip 0)
|
||||
(nv2 0)
|
||||
(nm1 0)
|
||||
(ur 0)
|
||||
(ui 0)
|
||||
(wr 0)
|
||||
(wi 0)
|
||||
(tr 0)
|
||||
(ti 0))
|
||||
;; initialize
|
||||
(set! ar areal)
|
||||
(set! ai aimag)
|
||||
(set! n (vector-length ar))
|
||||
(set! n (- n 1))
|
||||
(set! nv2 (quotient n 2))
|
||||
(set! nm1 (- n 1))
|
||||
(set! m 0) ;compute m = log(n)
|
||||
(set! i 1)
|
||||
(let loop ()
|
||||
(if (< i n)
|
||||
(begin (set! m (+ m 1))
|
||||
(set! i (+ i i))
|
||||
(loop))))
|
||||
(cond ((not (= n (expt 2 m)))
|
||||
(error "array size not a power of two.")))
|
||||
;; interchange elements in bit-reversed order
|
||||
(set! j 1)
|
||||
(set! i 1)
|
||||
(let l3 ()
|
||||
(cond ((< i j)
|
||||
(set! tr (vector-ref ar j))
|
||||
(set! ti (vector-ref ai j))
|
||||
(vector-set! ar j (vector-ref ar i))
|
||||
(vector-set! ai j (vector-ref ai i))
|
||||
(vector-set! ar i tr)
|
||||
(vector-set! ai i ti)))
|
||||
(set! k nv2)
|
||||
(let l6 ()
|
||||
(cond ((< k j)
|
||||
(set! j (- j k))
|
||||
(set! k (/ k 2))
|
||||
(l6))))
|
||||
(set! j (+ j k))
|
||||
(set! i (+ i 1))
|
||||
(cond ((< i n)
|
||||
(l3))))
|
||||
(do ((l 1 (+ l 1))) ;loop thru stages (syntax converted
|
||||
((> l m)) ; from old MACLISP style \bs)
|
||||
(set! le (expt 2 l))
|
||||
(set! le1 (quotient le 2))
|
||||
(set! ur 1.0)
|
||||
(set! ui 0.)
|
||||
(set! wr (cos (/ pi le1)))
|
||||
(set! wi (sin (/ pi le1)))
|
||||
;; loop thru butterflies
|
||||
(do ((j 1 (+ j 1)))
|
||||
((> j le1))
|
||||
;; do a butterfly
|
||||
(do ((i j (+ i le)))
|
||||
((> i n))
|
||||
(set! ip (+ i le1))
|
||||
(set! tr (- (* (vector-ref ar ip) ur)
|
||||
(* (vector-ref ai ip) ui)))
|
||||
(set! ti (+ (* (vector-ref ar ip) ui)
|
||||
(* (vector-ref ai ip) ur)))
|
||||
(vector-set! ar ip (- (vector-ref ar i) tr))
|
||||
(vector-set! ai ip (- (vector-ref ai i) ti))
|
||||
(vector-set! ar i (+ (vector-ref ar i) tr))
|
||||
(vector-set! ai i (+ (vector-ref ai i) ti))))
|
||||
(set! tr (- (* ur wr) (* ui wi)))
|
||||
(set! ti (+ (* ur wi) (* ui wr)))
|
||||
(set! ur tr)
|
||||
(set! ui ti))
|
||||
#t))
|
||||
|
||||
;;; the timer which does 10 calls on fft
|
||||
|
||||
(define (fft-bench)
|
||||
(do ((ntimes 0 (+ ntimes 1)))
|
||||
((= ntimes 1000))
|
||||
(fft *re* *im*)))
|
||||
|
||||
;;; call: (fft-bench)
|
||||
|
||||
(time (fft-bench))
|
||||
|
2
collects/tests/mzscheme/benchmarks/common/fft.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/fft.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module fft "wrap.ss")
|
645
collects/tests/mzscheme/benchmarks/common/graphs.sch
Normal file
645
collects/tests/mzscheme/benchmarks/common/graphs.sch
Normal file
|
@ -0,0 +1,645 @@
|
|||
; Modified 2 March 1997 by Will Clinger to add graphs-benchmark
|
||||
; and to expand the four macros below.
|
||||
; Modified 11 June 1997 by Will Clinger to eliminate assertions
|
||||
; and to replace a use of "recur" with a named let.
|
||||
;
|
||||
; Performance note: (graphs-benchmark 7) allocates
|
||||
; 34509143 pairs
|
||||
; 389625 vectors with 2551590 elements
|
||||
; 56653504 closures (not counting top level and known procedures)
|
||||
|
||||
(define (graphs-benchmark . rest)
|
||||
(let ((N (if (null? rest) 7 (car rest))))
|
||||
(time
|
||||
(fold-over-rdg N
|
||||
2
|
||||
cons
|
||||
'()))))
|
||||
|
||||
; End of new code.
|
||||
|
||||
;;; ==== std.ss ====
|
||||
|
||||
; (define-syntax assert
|
||||
; (syntax-rules ()
|
||||
; ((assert test info-rest ...)
|
||||
; #F)))
|
||||
;
|
||||
; (define-syntax deny
|
||||
; (syntax-rules ()
|
||||
; ((deny test info-rest ...)
|
||||
; #F)))
|
||||
;
|
||||
; (define-syntax when
|
||||
; (syntax-rules ()
|
||||
; ((when test e-first e-rest ...)
|
||||
; (if test
|
||||
; (begin e-first
|
||||
; e-rest ...)))))
|
||||
;
|
||||
; (define-syntax unless
|
||||
; (syntax-rules ()
|
||||
; ((unless test e-first e-rest ...)
|
||||
; (if (not test)
|
||||
; (begin e-first
|
||||
; e-rest ...)))))
|
||||
|
||||
(define assert
|
||||
(lambda (test . info)
|
||||
#f))
|
||||
|
||||
;;; ==== util.ss ====
|
||||
|
||||
|
||||
; Fold over list elements, associating to the left.
|
||||
(define fold
|
||||
(lambda (lst folder state)
|
||||
'(assert (list? lst)
|
||||
lst)
|
||||
'(assert (procedure? folder)
|
||||
folder)
|
||||
(do ((lst lst
|
||||
(cdr lst))
|
||||
(state state
|
||||
(folder (car lst)
|
||||
state)))
|
||||
((null? lst)
|
||||
state))))
|
||||
|
||||
; Given the size of a vector and a procedure which
|
||||
; sends indicies to desired vector elements, create
|
||||
; and return the vector.
|
||||
(define proc->vector
|
||||
(lambda (size f)
|
||||
'(assert (and (integer? size)
|
||||
(exact? size)
|
||||
(>= size 0))
|
||||
size)
|
||||
'(assert (procedure? f)
|
||||
f)
|
||||
(if (zero? size)
|
||||
(vector)
|
||||
(let ((x (make-vector size (f 0))))
|
||||
(let loop ((i 1))
|
||||
(if (< i size) (begin ; [wdc - was when]
|
||||
(vector-set! x i (f i))
|
||||
(loop (+ i 1)))))
|
||||
x))))
|
||||
|
||||
(define vector-fold
|
||||
(lambda (vec folder state)
|
||||
'(assert (vector? vec)
|
||||
vec)
|
||||
'(assert (procedure? folder)
|
||||
folder)
|
||||
(let ((len
|
||||
(vector-length vec)))
|
||||
(do ((i 0
|
||||
(+ i 1))
|
||||
(state state
|
||||
(folder (vector-ref vec i)
|
||||
state)))
|
||||
((= i len)
|
||||
state)))))
|
||||
|
||||
(define vector-map
|
||||
(lambda (vec proc)
|
||||
(proc->vector (vector-length vec)
|
||||
(lambda (i)
|
||||
(proc (vector-ref vec i))))))
|
||||
|
||||
; Given limit, return the list 0, 1, ..., limit-1.
|
||||
(define giota
|
||||
(lambda (limit)
|
||||
'(assert (and (integer? limit)
|
||||
(exact? limit)
|
||||
(>= limit 0))
|
||||
limit)
|
||||
(let -*-
|
||||
((limit
|
||||
limit)
|
||||
(res
|
||||
'()))
|
||||
(if (zero? limit)
|
||||
res
|
||||
(let ((limit
|
||||
(- limit 1)))
|
||||
(-*- limit
|
||||
(cons limit res)))))))
|
||||
|
||||
; Fold over the integers [0, limit).
|
||||
(define gnatural-fold
|
||||
(lambda (limit folder state)
|
||||
'(assert (and (integer? limit)
|
||||
(exact? limit)
|
||||
(>= limit 0))
|
||||
limit)
|
||||
'(assert (procedure? folder)
|
||||
folder)
|
||||
(do ((i 0
|
||||
(+ i 1))
|
||||
(state state
|
||||
(folder i state)))
|
||||
((= i limit)
|
||||
state))))
|
||||
|
||||
; Iterate over the integers [0, limit).
|
||||
(define gnatural-for-each
|
||||
(lambda (limit proc!)
|
||||
'(assert (and (integer? limit)
|
||||
(exact? limit)
|
||||
(>= limit 0))
|
||||
limit)
|
||||
'(assert (procedure? proc!)
|
||||
proc!)
|
||||
(do ((i 0
|
||||
(+ i 1)))
|
||||
((= i limit))
|
||||
(proc! i))))
|
||||
|
||||
(define natural-for-all?
|
||||
(lambda (limit ok?)
|
||||
'(assert (and (integer? limit)
|
||||
(exact? limit)
|
||||
(>= limit 0))
|
||||
limit)
|
||||
'(assert (procedure? ok?)
|
||||
ok?)
|
||||
(let -*-
|
||||
((i 0))
|
||||
(or (= i limit)
|
||||
(and (ok? i)
|
||||
(-*- (+ i 1)))))))
|
||||
|
||||
(define natural-there-exists?
|
||||
(lambda (limit ok?)
|
||||
'(assert (and (integer? limit)
|
||||
(exact? limit)
|
||||
(>= limit 0))
|
||||
limit)
|
||||
'(assert (procedure? ok?)
|
||||
ok?)
|
||||
(let -*-
|
||||
((i 0))
|
||||
(and (not (= i limit))
|
||||
(or (ok? i)
|
||||
(-*- (+ i 1)))))))
|
||||
|
||||
(define there-exists?
|
||||
(lambda (lst ok?)
|
||||
'(assert (list? lst)
|
||||
lst)
|
||||
'(assert (procedure? ok?)
|
||||
ok?)
|
||||
(let -*-
|
||||
((lst lst))
|
||||
(and (not (null? lst))
|
||||
(or (ok? (car lst))
|
||||
(-*- (cdr lst)))))))
|
||||
|
||||
|
||||
;;; ==== ptfold.ss ====
|
||||
|
||||
|
||||
; Fold over the tree of permutations of a universe.
|
||||
; Each branch (from the root) is a permutation of universe.
|
||||
; Each node at depth d corresponds to all permutations which pick the
|
||||
; elements spelled out on the branch from the root to that node as
|
||||
; the first d elements.
|
||||
; Their are two components to the state:
|
||||
; The b-state is only a function of the branch from the root.
|
||||
; The t-state is a function of all nodes seen so far.
|
||||
; At each node, b-folder is called via
|
||||
; (b-folder elem b-state t-state deeper accross)
|
||||
; where elem is the next element of the universe picked.
|
||||
; If b-folder can determine the result of the total tree fold at this stage,
|
||||
; it should simply return the result.
|
||||
; If b-folder can determine the result of folding over the sub-tree
|
||||
; rooted at the resulting node, it should call accross via
|
||||
; (accross new-t-state)
|
||||
; where new-t-state is that result.
|
||||
; Otherwise, b-folder should call deeper via
|
||||
; (deeper new-b-state new-t-state)
|
||||
; where new-b-state is the b-state for the new node and new-t-state is
|
||||
; the new folded t-state.
|
||||
; At the leaves of the tree, t-folder is called via
|
||||
; (t-folder b-state t-state accross)
|
||||
; If t-folder can determine the result of the total tree fold at this stage,
|
||||
; it should simply return that result.
|
||||
; If not, it should call accross via
|
||||
; (accross new-t-state)
|
||||
; Note, fold-over-perm-tree always calls b-folder in depth-first order.
|
||||
; I.e., when b-folder is called at depth d, the branch leading to that
|
||||
; node is the most recent calls to b-folder at all the depths less than d.
|
||||
; This is a gross efficiency hack so that b-folder can use mutation to
|
||||
; keep the current branch.
|
||||
(define fold-over-perm-tree
|
||||
(lambda (universe b-folder b-state t-folder t-state)
|
||||
'(assert (list? universe)
|
||||
universe)
|
||||
'(assert (procedure? b-folder)
|
||||
b-folder)
|
||||
'(assert (procedure? t-folder)
|
||||
t-folder)
|
||||
(let -*-
|
||||
((universe
|
||||
universe)
|
||||
(b-state
|
||||
b-state)
|
||||
(t-state
|
||||
t-state)
|
||||
(accross
|
||||
(lambda (final-t-state)
|
||||
final-t-state)))
|
||||
(if (null? universe)
|
||||
(t-folder b-state t-state accross)
|
||||
(let -**-
|
||||
((in
|
||||
universe)
|
||||
(out
|
||||
'())
|
||||
(t-state
|
||||
t-state))
|
||||
(let* ((first
|
||||
(car in))
|
||||
(rest
|
||||
(cdr in))
|
||||
(accross
|
||||
(if (null? rest)
|
||||
accross
|
||||
(lambda (new-t-state)
|
||||
(-**- rest
|
||||
(cons first out)
|
||||
new-t-state)))))
|
||||
(b-folder first
|
||||
b-state
|
||||
t-state
|
||||
(lambda (new-b-state new-t-state)
|
||||
(-*- (fold out cons rest)
|
||||
new-b-state
|
||||
new-t-state
|
||||
accross))
|
||||
accross)))))))
|
||||
|
||||
|
||||
;;; ==== minimal.ss ====
|
||||
|
||||
|
||||
; A directed graph is stored as a connection matrix (vector-of-vectors)
|
||||
; where the first index is the `from' vertex and the second is the `to'
|
||||
; vertex. Each entry is a bool indicating if the edge exists.
|
||||
; The diagonal of the matrix is never examined.
|
||||
; Make-minimal? returns a procedure which tests if a labelling
|
||||
; of the verticies is such that the matrix is minimal.
|
||||
; If it is, then the procedure returns the result of folding over
|
||||
; the elements of the automoriphism group. If not, it returns #F.
|
||||
; The folding is done by calling folder via
|
||||
; (folder perm state accross)
|
||||
; If the folder wants to continue, it should call accross via
|
||||
; (accross new-state)
|
||||
; If it just wants the entire minimal? procedure to return something,
|
||||
; it should return that.
|
||||
; The ordering used is lexicographic (with #T > #F) and entries
|
||||
; are examined in the following order:
|
||||
; 1->0, 0->1
|
||||
;
|
||||
; 2->0, 0->2
|
||||
; 2->1, 1->2
|
||||
;
|
||||
; 3->0, 0->3
|
||||
; 3->1, 1->3
|
||||
; 3->2, 2->3
|
||||
; ...
|
||||
(define make-minimal?
|
||||
(lambda (max-size)
|
||||
'(assert (and (integer? max-size)
|
||||
(exact? max-size)
|
||||
(>= max-size 0))
|
||||
max-size)
|
||||
(let ((iotas
|
||||
(proc->vector (+ max-size 1)
|
||||
giota))
|
||||
(perm
|
||||
(make-vector max-size 0)))
|
||||
(lambda (size graph folder state)
|
||||
'(assert (and (integer? size)
|
||||
(exact? size)
|
||||
(<= 0 size max-size))
|
||||
size
|
||||
max-size)
|
||||
'(assert (vector? graph)
|
||||
graph)
|
||||
'(assert (procedure? folder)
|
||||
folder)
|
||||
(fold-over-perm-tree (vector-ref iotas size)
|
||||
(lambda (perm-x x state deeper accross)
|
||||
(case (cmp-next-vertex graph perm x perm-x)
|
||||
((less)
|
||||
#F)
|
||||
((equal)
|
||||
(vector-set! perm x perm-x)
|
||||
(deeper (+ x 1)
|
||||
state))
|
||||
((more)
|
||||
(accross state))
|
||||
(else
|
||||
(assert #F))))
|
||||
0
|
||||
(lambda (leaf-depth state accross)
|
||||
'(assert (eqv? leaf-depth size)
|
||||
leaf-depth
|
||||
size)
|
||||
(folder perm state accross))
|
||||
state)))))
|
||||
|
||||
; Given a graph, a partial permutation vector, the next input and the next
|
||||
; output, return 'less, 'equal or 'more depending on the lexicographic
|
||||
; comparison between the permuted and un-permuted graph.
|
||||
(define cmp-next-vertex
|
||||
(lambda (graph perm x perm-x)
|
||||
(let ((from-x
|
||||
(vector-ref graph x))
|
||||
(from-perm-x
|
||||
(vector-ref graph perm-x)))
|
||||
(let -*-
|
||||
((y
|
||||
0))
|
||||
(if (= x y)
|
||||
'equal
|
||||
(let ((x->y?
|
||||
(vector-ref from-x y))
|
||||
(perm-y
|
||||
(vector-ref perm y)))
|
||||
(cond ((eq? x->y?
|
||||
(vector-ref from-perm-x perm-y))
|
||||
(let ((y->x?
|
||||
(vector-ref (vector-ref graph y)
|
||||
x)))
|
||||
(cond ((eq? y->x?
|
||||
(vector-ref (vector-ref graph perm-y)
|
||||
perm-x))
|
||||
(-*- (+ y 1)))
|
||||
(y->x?
|
||||
'less)
|
||||
(else
|
||||
'more))))
|
||||
(x->y?
|
||||
'less)
|
||||
(else
|
||||
'more))))))))
|
||||
|
||||
|
||||
;;; ==== rdg.ss ====
|
||||
|
||||
|
||||
; Fold over rooted directed graphs with bounded out-degree.
|
||||
; Size is the number of verticies (including the root). Max-out is the
|
||||
; maximum out-degree for any vertex. Folder is called via
|
||||
; (folder edges state)
|
||||
; where edges is a list of length size. The ith element of the list is
|
||||
; a list of the verticies j for which there is an edge from i to j.
|
||||
; The last vertex is the root.
|
||||
(define fold-over-rdg
|
||||
(lambda (size max-out folder state)
|
||||
'(assert (and (exact? size)
|
||||
(integer? size)
|
||||
(> size 0))
|
||||
size)
|
||||
'(assert (and (exact? max-out)
|
||||
(integer? max-out)
|
||||
(>= max-out 0))
|
||||
max-out)
|
||||
'(assert (procedure? folder)
|
||||
folder)
|
||||
(let* ((root
|
||||
(- size 1))
|
||||
(edge?
|
||||
(proc->vector size
|
||||
(lambda (from)
|
||||
(make-vector size #F))))
|
||||
(edges
|
||||
(make-vector size '()))
|
||||
(out-degrees
|
||||
(make-vector size 0))
|
||||
(minimal-folder
|
||||
(make-minimal? root))
|
||||
(non-root-minimal?
|
||||
(let ((cont
|
||||
(lambda (perm state accross)
|
||||
'(assert (eq? state #T)
|
||||
state)
|
||||
(accross #T))))
|
||||
(lambda (size)
|
||||
(minimal-folder size
|
||||
edge?
|
||||
cont
|
||||
#T))))
|
||||
(root-minimal?
|
||||
(let ((cont
|
||||
(lambda (perm state accross)
|
||||
'(assert (eq? state #T)
|
||||
state)
|
||||
(case (cmp-next-vertex edge? perm root root)
|
||||
((less)
|
||||
#F)
|
||||
((equal more)
|
||||
(accross #T))
|
||||
(else
|
||||
(assert #F))))))
|
||||
(lambda ()
|
||||
(minimal-folder root
|
||||
edge?
|
||||
cont
|
||||
#T)))))
|
||||
(let -*-
|
||||
((vertex
|
||||
0)
|
||||
(state
|
||||
state))
|
||||
(cond ((not (non-root-minimal? vertex))
|
||||
state)
|
||||
((= vertex root)
|
||||
'(assert
|
||||
(begin
|
||||
(gnatural-for-each root
|
||||
(lambda (v)
|
||||
'(assert (= (vector-ref out-degrees v)
|
||||
(length (vector-ref edges v)))
|
||||
v
|
||||
(vector-ref out-degrees v)
|
||||
(vector-ref edges v))))
|
||||
#T))
|
||||
(let ((reach?
|
||||
(make-reach? root edges))
|
||||
(from-root
|
||||
(vector-ref edge? root)))
|
||||
(let -*-
|
||||
((v
|
||||
0)
|
||||
(outs
|
||||
0)
|
||||
(efr
|
||||
'())
|
||||
(efrr
|
||||
'())
|
||||
(state
|
||||
state))
|
||||
(cond ((not (or (= v root)
|
||||
(= outs max-out)))
|
||||
(vector-set! from-root v #T)
|
||||
(let ((state
|
||||
(-*- (+ v 1)
|
||||
(+ outs 1)
|
||||
(cons v efr)
|
||||
(cons (vector-ref reach? v)
|
||||
efrr)
|
||||
state)))
|
||||
(vector-set! from-root v #F)
|
||||
(-*- (+ v 1)
|
||||
outs
|
||||
efr
|
||||
efrr
|
||||
state)))
|
||||
((and (natural-for-all? root
|
||||
(lambda (v)
|
||||
(there-exists? efrr
|
||||
(lambda (r)
|
||||
(vector-ref r v)))))
|
||||
(root-minimal?))
|
||||
(vector-set! edges root efr)
|
||||
(folder
|
||||
(proc->vector size
|
||||
(lambda (i)
|
||||
(vector-ref edges i)))
|
||||
state))
|
||||
(else
|
||||
state)))))
|
||||
(else
|
||||
(let ((from-vertex
|
||||
(vector-ref edge? vertex)))
|
||||
(let -**-
|
||||
((sv
|
||||
0)
|
||||
(outs
|
||||
0)
|
||||
(state
|
||||
state))
|
||||
(if (= sv vertex)
|
||||
(begin
|
||||
(vector-set! out-degrees vertex outs)
|
||||
(-*- (+ vertex 1)
|
||||
state))
|
||||
(let* ((state
|
||||
; no sv->vertex, no vertex->sv
|
||||
(-**- (+ sv 1)
|
||||
outs
|
||||
state))
|
||||
(from-sv
|
||||
(vector-ref edge? sv))
|
||||
(sv-out
|
||||
(vector-ref out-degrees sv))
|
||||
(state
|
||||
(if (= sv-out max-out)
|
||||
state
|
||||
(begin
|
||||
(vector-set! edges
|
||||
sv
|
||||
(cons vertex
|
||||
(vector-ref edges sv)))
|
||||
(vector-set! from-sv vertex #T)
|
||||
(vector-set! out-degrees sv (+ sv-out 1))
|
||||
(let* ((state
|
||||
; sv->vertex, no vertex->sv
|
||||
(-**- (+ sv 1)
|
||||
outs
|
||||
state))
|
||||
(state
|
||||
(if (= outs max-out)
|
||||
state
|
||||
(begin
|
||||
(vector-set! from-vertex sv #T)
|
||||
(vector-set! edges
|
||||
vertex
|
||||
(cons sv
|
||||
(vector-ref edges vertex)))
|
||||
(let ((state
|
||||
; sv->vertex, vertex->sv
|
||||
(-**- (+ sv 1)
|
||||
(+ outs 1)
|
||||
state)))
|
||||
(vector-set! edges
|
||||
vertex
|
||||
(cdr (vector-ref edges vertex)))
|
||||
(vector-set! from-vertex sv #F)
|
||||
state)))))
|
||||
(vector-set! out-degrees sv sv-out)
|
||||
(vector-set! from-sv vertex #F)
|
||||
(vector-set! edges
|
||||
sv
|
||||
(cdr (vector-ref edges sv)))
|
||||
state)))))
|
||||
(if (= outs max-out)
|
||||
state
|
||||
(begin
|
||||
(vector-set! edges
|
||||
vertex
|
||||
(cons sv
|
||||
(vector-ref edges vertex)))
|
||||
(vector-set! from-vertex sv #T)
|
||||
(let ((state
|
||||
; no sv->vertex, vertex->sv
|
||||
(-**- (+ sv 1)
|
||||
(+ outs 1)
|
||||
state)))
|
||||
(vector-set! from-vertex sv #F)
|
||||
(vector-set! edges
|
||||
vertex
|
||||
(cdr (vector-ref edges vertex)))
|
||||
state)))))))))))))
|
||||
|
||||
; Given a vector which maps vertex to out-going-edge list,
|
||||
; return a vector which gives reachability.
|
||||
(define make-reach?
|
||||
(lambda (size vertex->out)
|
||||
(let ((res
|
||||
(proc->vector size
|
||||
(lambda (v)
|
||||
(let ((from-v
|
||||
(make-vector size #F)))
|
||||
(vector-set! from-v v #T)
|
||||
(for-each
|
||||
(lambda (x)
|
||||
(vector-set! from-v x #T))
|
||||
(vector-ref vertex->out v))
|
||||
from-v)))))
|
||||
(gnatural-for-each size
|
||||
(lambda (m)
|
||||
(let ((from-m
|
||||
(vector-ref res m)))
|
||||
(gnatural-for-each size
|
||||
(lambda (f)
|
||||
(let ((from-f
|
||||
(vector-ref res f)))
|
||||
(if (vector-ref from-f m); [wdc - was when]
|
||||
(begin
|
||||
(gnatural-for-each size
|
||||
(lambda (t)
|
||||
(if (vector-ref from-m t)
|
||||
(begin ; [wdc - was when]
|
||||
(vector-set! from-f t #T)))))))))))))
|
||||
res)))
|
||||
|
||||
|
||||
;;; ==== test input ====
|
||||
|
||||
; Produces all directed graphs with N verticies, distinguished root,
|
||||
; and out-degree bounded by 2, upto isomorphism (there are 44).
|
||||
|
||||
;(define go
|
||||
; (let ((N 7))
|
||||
; (fold-over-rdg N
|
||||
; 2
|
||||
; cons
|
||||
; '())))
|
||||
|
||||
(graphs-benchmark 6)
|
2
collects/tests/mzscheme/benchmarks/common/graphs.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/graphs.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module graphs "wrap.ss")
|
759
collects/tests/mzscheme/benchmarks/common/nboyer.sch
Normal file
759
collects/tests/mzscheme/benchmarks/common/nboyer.sch
Normal file
|
@ -0,0 +1,759 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; File: nboyer.sch
|
||||
; Description: The Boyer benchmark
|
||||
; Author: Bob Boyer
|
||||
; Created: 5-Apr-85
|
||||
; Modified: 10-Apr-85 14:52:20 (Bob Shaw)
|
||||
; 22-Jul-87 (Will Clinger)
|
||||
; 2-Jul-88 (Will Clinger -- distinguished #f and the empty list)
|
||||
; 13-Feb-97 (Will Clinger -- fixed bugs in unifier and rules,
|
||||
; rewrote to eliminate property lists, and added
|
||||
; a scaling parameter suggested by Bob Boyer)
|
||||
; 19-Mar-99 (Will Clinger -- cleaned up comments)
|
||||
; 4-Apr-01 (Will Clinger -- changed four 1- symbols to sub1)
|
||||
; Language: Scheme
|
||||
; Status: Public Domain
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;;; NBOYER -- Logic programming benchmark, originally written by Bob Boyer.
|
||||
;;; Fairly CONS intensive.
|
||||
|
||||
; Note: The version of this benchmark that appears in Dick Gabriel's book
|
||||
; contained several bugs that are corrected here. These bugs are discussed
|
||||
; by Henry Baker, "The Boyer Benchmark Meets Linear Logic", ACM SIGPLAN Lisp
|
||||
; Pointers 6(4), October-December 1993, pages 3-10. The fixed bugs are:
|
||||
;
|
||||
; The benchmark now returns a boolean result.
|
||||
; FALSEP and TRUEP use TERM-MEMBER? rather than MEMV (which is called MEMBER
|
||||
; in Common Lisp)
|
||||
; ONE-WAY-UNIFY1 now treats numbers correctly
|
||||
; ONE-WAY-UNIFY1-LST now treats empty lists correctly
|
||||
; Rule 19 has been corrected (this rule was not touched by the original
|
||||
; benchmark, but is used by this version)
|
||||
; Rules 84 and 101 have been corrected (but these rules are never touched
|
||||
; by the benchmark)
|
||||
;
|
||||
; According to Baker, these bug fixes make the benchmark 10-25% slower.
|
||||
; Please do not compare the timings from this benchmark against those of
|
||||
; the original benchmark.
|
||||
;
|
||||
; This version of the benchmark also prints the number of rewrites as a sanity
|
||||
; check, because it is too easy for a buggy version to return the correct
|
||||
; boolean result. The correct number of rewrites is
|
||||
;
|
||||
; n rewrites peak live storage (approximate, in bytes)
|
||||
; 0 95024 520,000
|
||||
; 1 591777 2,085,000
|
||||
; 2 1813975 5,175,000
|
||||
; 3 5375678
|
||||
; 4 16445406
|
||||
; 5 51507739
|
||||
|
||||
; Nboyer is a 2-phase benchmark.
|
||||
; The first phase attaches lemmas to symbols. This phase is not timed,
|
||||
; but it accounts for very little of the runtime anyway.
|
||||
; The second phase creates the test problem, and tests to see
|
||||
; whether it is implied by the lemmas.
|
||||
|
||||
(define (nboyer-benchmark . args)
|
||||
(let ((n (if (null? args) 0 (car args))))
|
||||
(setup-boyer)
|
||||
(time (test-boyer n))))
|
||||
|
||||
(define (setup-boyer) #t) ; assigned below
|
||||
(define (test-boyer) #t) ; assigned below
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;
|
||||
; The first phase.
|
||||
;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
; In the original benchmark, it stored a list of lemmas on the
|
||||
; property lists of symbols.
|
||||
; In the new benchmark, it maintains an association list of
|
||||
; symbols and symbol-records, and stores the list of lemmas
|
||||
; within the symbol-records.
|
||||
|
||||
(let ()
|
||||
|
||||
(define (setup)
|
||||
(add-lemma-lst
|
||||
(quote ((equal (compile form)
|
||||
(reverse (codegen (optimize form)
|
||||
(nil))))
|
||||
(equal (eqp x y)
|
||||
(equal (fix x)
|
||||
(fix y)))
|
||||
(equal (greaterp x y)
|
||||
(lessp y x))
|
||||
(equal (lesseqp x y)
|
||||
(not (lessp y x)))
|
||||
(equal (greatereqp x y)
|
||||
(not (lessp x y)))
|
||||
(equal (boolean x)
|
||||
(or (equal x (t))
|
||||
(equal x (f))))
|
||||
(equal (iff x y)
|
||||
(and (implies x y)
|
||||
(implies y x)))
|
||||
(equal (even1 x)
|
||||
(if (zerop x)
|
||||
(t)
|
||||
(odd (sub1 x))))
|
||||
(equal (countps- l pred)
|
||||
(countps-loop l pred (zero)))
|
||||
(equal (fact- i)
|
||||
(fact-loop i 1))
|
||||
(equal (reverse- x)
|
||||
(reverse-loop x (nil)))
|
||||
(equal (divides x y)
|
||||
(zerop (remainder y x)))
|
||||
(equal (assume-true var alist)
|
||||
(cons (cons var (t))
|
||||
alist))
|
||||
(equal (assume-false var alist)
|
||||
(cons (cons var (f))
|
||||
alist))
|
||||
(equal (tautology-checker x)
|
||||
(tautologyp (normalize x)
|
||||
(nil)))
|
||||
(equal (falsify x)
|
||||
(falsify1 (normalize x)
|
||||
(nil)))
|
||||
(equal (prime x)
|
||||
(and (not (zerop x))
|
||||
(not (equal x (add1 (zero))))
|
||||
(prime1 x (sub1 x))))
|
||||
(equal (and p q)
|
||||
(if p (if q (t)
|
||||
(f))
|
||||
(f)))
|
||||
(equal (or p q)
|
||||
(if p (t)
|
||||
(if q (t)
|
||||
(f))))
|
||||
(equal (not p)
|
||||
(if p (f)
|
||||
(t)))
|
||||
(equal (implies p q)
|
||||
(if p (if q (t)
|
||||
(f))
|
||||
(t)))
|
||||
(equal (fix x)
|
||||
(if (numberp x)
|
||||
x
|
||||
(zero)))
|
||||
(equal (if (if a b c)
|
||||
d e)
|
||||
(if a (if b d e)
|
||||
(if c d e)))
|
||||
(equal (zerop x)
|
||||
(or (equal x (zero))
|
||||
(not (numberp x))))
|
||||
(equal (plus (plus x y)
|
||||
z)
|
||||
(plus x (plus y z)))
|
||||
(equal (equal (plus a b)
|
||||
(zero))
|
||||
(and (zerop a)
|
||||
(zerop b)))
|
||||
(equal (difference x x)
|
||||
(zero))
|
||||
(equal (equal (plus a b)
|
||||
(plus a c))
|
||||
(equal (fix b)
|
||||
(fix c)))
|
||||
(equal (equal (zero)
|
||||
(difference x y))
|
||||
(not (lessp y x)))
|
||||
(equal (equal x (difference x y))
|
||||
(and (numberp x)
|
||||
(or (equal x (zero))
|
||||
(zerop y))))
|
||||
(equal (meaning (plus-tree (append x y))
|
||||
a)
|
||||
(plus (meaning (plus-tree x)
|
||||
a)
|
||||
(meaning (plus-tree y)
|
||||
a)))
|
||||
(equal (meaning (plus-tree (plus-fringe x))
|
||||
a)
|
||||
(fix (meaning x a)))
|
||||
(equal (append (append x y)
|
||||
z)
|
||||
(append x (append y z)))
|
||||
(equal (reverse (append a b))
|
||||
(append (reverse b)
|
||||
(reverse a)))
|
||||
(equal (times x (plus y z))
|
||||
(plus (times x y)
|
||||
(times x z)))
|
||||
(equal (times (times x y)
|
||||
z)
|
||||
(times x (times y z)))
|
||||
(equal (equal (times x y)
|
||||
(zero))
|
||||
(or (zerop x)
|
||||
(zerop y)))
|
||||
(equal (exec (append x y)
|
||||
pds envrn)
|
||||
(exec y (exec x pds envrn)
|
||||
envrn))
|
||||
(equal (mc-flatten x y)
|
||||
(append (flatten x)
|
||||
y))
|
||||
(equal (member x (append a b))
|
||||
(or (member x a)
|
||||
(member x b)))
|
||||
(equal (member x (reverse y))
|
||||
(member x y))
|
||||
(equal (length (reverse x))
|
||||
(length x))
|
||||
(equal (member a (intersect b c))
|
||||
(and (member a b)
|
||||
(member a c)))
|
||||
(equal (nth (zero)
|
||||
i)
|
||||
(zero))
|
||||
(equal (exp i (plus j k))
|
||||
(times (exp i j)
|
||||
(exp i k)))
|
||||
(equal (exp i (times j k))
|
||||
(exp (exp i j)
|
||||
k))
|
||||
(equal (reverse-loop x y)
|
||||
(append (reverse x)
|
||||
y))
|
||||
(equal (reverse-loop x (nil))
|
||||
(reverse x))
|
||||
(equal (count-list z (sort-lp x y))
|
||||
(plus (count-list z x)
|
||||
(count-list z y)))
|
||||
(equal (equal (append a b)
|
||||
(append a c))
|
||||
(equal b c))
|
||||
(equal (plus (remainder x y)
|
||||
(times y (quotient x y)))
|
||||
(fix x))
|
||||
(equal (power-eval (big-plus1 l i base)
|
||||
base)
|
||||
(plus (power-eval l base)
|
||||
i))
|
||||
(equal (power-eval (big-plus x y i base)
|
||||
base)
|
||||
(plus i (plus (power-eval x base)
|
||||
(power-eval y base))))
|
||||
(equal (remainder y 1)
|
||||
(zero))
|
||||
(equal (lessp (remainder x y)
|
||||
y)
|
||||
(not (zerop y)))
|
||||
(equal (remainder x x)
|
||||
(zero))
|
||||
(equal (lessp (quotient i j)
|
||||
i)
|
||||
(and (not (zerop i))
|
||||
(or (zerop j)
|
||||
(not (equal j 1)))))
|
||||
(equal (lessp (remainder x y)
|
||||
x)
|
||||
(and (not (zerop y))
|
||||
(not (zerop x))
|
||||
(not (lessp x y))))
|
||||
(equal (power-eval (power-rep i base)
|
||||
base)
|
||||
(fix i))
|
||||
(equal (power-eval (big-plus (power-rep i base)
|
||||
(power-rep j base)
|
||||
(zero)
|
||||
base)
|
||||
base)
|
||||
(plus i j))
|
||||
(equal (gcd x y)
|
||||
(gcd y x))
|
||||
(equal (nth (append a b)
|
||||
i)
|
||||
(append (nth a i)
|
||||
(nth b (difference i (length a)))))
|
||||
(equal (difference (plus x y)
|
||||
x)
|
||||
(fix y))
|
||||
(equal (difference (plus y x)
|
||||
x)
|
||||
(fix y))
|
||||
(equal (difference (plus x y)
|
||||
(plus x z))
|
||||
(difference y z))
|
||||
(equal (times x (difference c w))
|
||||
(difference (times c x)
|
||||
(times w x)))
|
||||
(equal (remainder (times x z)
|
||||
z)
|
||||
(zero))
|
||||
(equal (difference (plus b (plus a c))
|
||||
a)
|
||||
(plus b c))
|
||||
(equal (difference (add1 (plus y z))
|
||||
z)
|
||||
(add1 y))
|
||||
(equal (lessp (plus x y)
|
||||
(plus x z))
|
||||
(lessp y z))
|
||||
(equal (lessp (times x z)
|
||||
(times y z))
|
||||
(and (not (zerop z))
|
||||
(lessp x y)))
|
||||
(equal (lessp y (plus x y))
|
||||
(not (zerop x)))
|
||||
(equal (gcd (times x z)
|
||||
(times y z))
|
||||
(times z (gcd x y)))
|
||||
(equal (value (normalize x)
|
||||
a)
|
||||
(value x a))
|
||||
(equal (equal (flatten x)
|
||||
(cons y (nil)))
|
||||
(and (nlistp x)
|
||||
(equal x y)))
|
||||
(equal (listp (gopher x))
|
||||
(listp x))
|
||||
(equal (samefringe x y)
|
||||
(equal (flatten x)
|
||||
(flatten y)))
|
||||
(equal (equal (greatest-factor x y)
|
||||
(zero))
|
||||
(and (or (zerop y)
|
||||
(equal y 1))
|
||||
(equal x (zero))))
|
||||
(equal (equal (greatest-factor x y)
|
||||
1)
|
||||
(equal x 1))
|
||||
(equal (numberp (greatest-factor x y))
|
||||
(not (and (or (zerop y)
|
||||
(equal y 1))
|
||||
(not (numberp x)))))
|
||||
(equal (times-list (append x y))
|
||||
(times (times-list x)
|
||||
(times-list y)))
|
||||
(equal (prime-list (append x y))
|
||||
(and (prime-list x)
|
||||
(prime-list y)))
|
||||
(equal (equal z (times w z))
|
||||
(and (numberp z)
|
||||
(or (equal z (zero))
|
||||
(equal w 1))))
|
||||
(equal (greatereqp x y)
|
||||
(not (lessp x y)))
|
||||
(equal (equal x (times x y))
|
||||
(or (equal x (zero))
|
||||
(and (numberp x)
|
||||
(equal y 1))))
|
||||
(equal (remainder (times y x)
|
||||
y)
|
||||
(zero))
|
||||
(equal (equal (times a b)
|
||||
1)
|
||||
(and (not (equal a (zero)))
|
||||
(not (equal b (zero)))
|
||||
(numberp a)
|
||||
(numberp b)
|
||||
(equal (sub1 a)
|
||||
(zero))
|
||||
(equal (sub1 b)
|
||||
(zero))))
|
||||
(equal (lessp (length (delete x l))
|
||||
(length l))
|
||||
(member x l))
|
||||
(equal (sort2 (delete x l))
|
||||
(delete x (sort2 l)))
|
||||
(equal (dsort x)
|
||||
(sort2 x))
|
||||
(equal (length (cons x1
|
||||
(cons x2
|
||||
(cons x3 (cons x4
|
||||
(cons x5
|
||||
(cons x6 x7)))))))
|
||||
(plus 6 (length x7)))
|
||||
(equal (difference (add1 (add1 x))
|
||||
2)
|
||||
(fix x))
|
||||
(equal (quotient (plus x (plus x y))
|
||||
2)
|
||||
(plus x (quotient y 2)))
|
||||
(equal (sigma (zero)
|
||||
i)
|
||||
(quotient (times i (add1 i))
|
||||
2))
|
||||
(equal (plus x (add1 y))
|
||||
(if (numberp y)
|
||||
(add1 (plus x y))
|
||||
(add1 x)))
|
||||
(equal (equal (difference x y)
|
||||
(difference z y))
|
||||
(if (lessp x y)
|
||||
(not (lessp y z))
|
||||
(if (lessp z y)
|
||||
(not (lessp y x))
|
||||
(equal (fix x)
|
||||
(fix z)))))
|
||||
(equal (meaning (plus-tree (delete x y))
|
||||
a)
|
||||
(if (member x y)
|
||||
(difference (meaning (plus-tree y)
|
||||
a)
|
||||
(meaning x a))
|
||||
(meaning (plus-tree y)
|
||||
a)))
|
||||
(equal (times x (add1 y))
|
||||
(if (numberp y)
|
||||
(plus x (times x y))
|
||||
(fix x)))
|
||||
(equal (nth (nil)
|
||||
i)
|
||||
(if (zerop i)
|
||||
(nil)
|
||||
(zero)))
|
||||
(equal (last (append a b))
|
||||
(if (listp b)
|
||||
(last b)
|
||||
(if (listp a)
|
||||
(cons (car (last a))
|
||||
b)
|
||||
b)))
|
||||
(equal (equal (lessp x y)
|
||||
z)
|
||||
(if (lessp x y)
|
||||
(equal (t) z)
|
||||
(equal (f) z)))
|
||||
(equal (assignment x (append a b))
|
||||
(if (assignedp x a)
|
||||
(assignment x a)
|
||||
(assignment x b)))
|
||||
(equal (car (gopher x))
|
||||
(if (listp x)
|
||||
(car (flatten x))
|
||||
(zero)))
|
||||
(equal (flatten (cdr (gopher x)))
|
||||
(if (listp x)
|
||||
(cdr (flatten x))
|
||||
(cons (zero)
|
||||
(nil))))
|
||||
(equal (quotient (times y x)
|
||||
y)
|
||||
(if (zerop y)
|
||||
(zero)
|
||||
(fix x)))
|
||||
(equal (get j (set i val mem))
|
||||
(if (eqp j i)
|
||||
val
|
||||
(get j mem)))))))
|
||||
|
||||
(define (add-lemma-lst lst)
|
||||
(cond ((null? lst)
|
||||
#t)
|
||||
(else (add-lemma (car lst))
|
||||
(add-lemma-lst (cdr lst)))))
|
||||
|
||||
(define (add-lemma term)
|
||||
(cond ((and (pair? term)
|
||||
(eq? (car term)
|
||||
(quote equal))
|
||||
(pair? (cadr term)))
|
||||
(put (car (cadr term))
|
||||
(quote lemmas)
|
||||
(cons
|
||||
(translate-term term)
|
||||
(get (car (cadr term)) (quote lemmas)))))
|
||||
(else (error "ADD-LEMMA did not like term: " term))))
|
||||
|
||||
; Translates a term by replacing its constructor symbols by symbol-records.
|
||||
|
||||
(define (translate-term term)
|
||||
(cond ((not (pair? term))
|
||||
term)
|
||||
(else (cons (symbol->symbol-record (car term))
|
||||
(translate-args (cdr term))))))
|
||||
|
||||
(define (translate-args lst)
|
||||
(cond ((null? lst)
|
||||
'())
|
||||
(else (cons (translate-term (car lst))
|
||||
(translate-args (cdr lst))))))
|
||||
|
||||
; For debugging only, so the use of MAP does not change
|
||||
; the first-order character of the benchmark.
|
||||
|
||||
(define (untranslate-term term)
|
||||
(cond ((not (pair? term))
|
||||
term)
|
||||
(else (cons (get-name (car term))
|
||||
(map untranslate-term (cdr term))))))
|
||||
|
||||
; A symbol-record is represented as a vector with two fields:
|
||||
; the symbol (for debugging) and
|
||||
; the list of lemmas associated with the symbol.
|
||||
|
||||
(define (put sym property value)
|
||||
(put-lemmas! (symbol->symbol-record sym) value))
|
||||
|
||||
(define (get sym property)
|
||||
(get-lemmas (symbol->symbol-record sym)))
|
||||
|
||||
(define (symbol->symbol-record sym)
|
||||
(let ((x (assq sym *symbol-records-alist*)))
|
||||
(if x
|
||||
(cdr x)
|
||||
(let ((r (make-symbol-record sym)))
|
||||
(set! *symbol-records-alist*
|
||||
(cons (cons sym r)
|
||||
*symbol-records-alist*))
|
||||
r))))
|
||||
|
||||
; Association list of symbols and symbol-records.
|
||||
|
||||
(define *symbol-records-alist* '())
|
||||
|
||||
; A symbol-record is represented as a vector with two fields:
|
||||
; the symbol (for debugging) and
|
||||
; the list of lemmas associated with the symbol.
|
||||
|
||||
(define (make-symbol-record sym)
|
||||
(vector sym '()))
|
||||
|
||||
(define (put-lemmas! symbol-record lemmas)
|
||||
(vector-set! symbol-record 1 lemmas))
|
||||
|
||||
(define (get-lemmas symbol-record)
|
||||
(vector-ref symbol-record 1))
|
||||
|
||||
(define (get-name symbol-record)
|
||||
(vector-ref symbol-record 0))
|
||||
|
||||
(define (symbol-record-equal? r1 r2)
|
||||
(eq? r1 r2))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;
|
||||
; The second phase.
|
||||
;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(define (test n)
|
||||
(let ((term
|
||||
(apply-subst
|
||||
(translate-alist
|
||||
(quote ((x f (plus (plus a b)
|
||||
(plus c (zero))))
|
||||
(y f (times (times a b)
|
||||
(plus c d)))
|
||||
(z f (reverse (append (append a b)
|
||||
(nil))))
|
||||
(u equal (plus a b)
|
||||
(difference x y))
|
||||
(w lessp (remainder a b)
|
||||
(member a (length b))))))
|
||||
(translate-term
|
||||
(do ((term
|
||||
(quote (implies (and (implies x y)
|
||||
(and (implies y z)
|
||||
(and (implies z u)
|
||||
(implies u w))))
|
||||
(implies x w)))
|
||||
(list 'or term '(f)))
|
||||
(n n (- n 1)))
|
||||
((zero? n) term))))))
|
||||
(tautp term)))
|
||||
|
||||
(define (translate-alist alist)
|
||||
(cond ((null? alist)
|
||||
'())
|
||||
(else (cons (cons (caar alist)
|
||||
(translate-term (cdar alist)))
|
||||
(translate-alist (cdr alist))))))
|
||||
|
||||
(define (apply-subst alist term)
|
||||
(cond ((not (pair? term))
|
||||
(let ((temp-temp (assq term alist)))
|
||||
(if temp-temp
|
||||
(cdr temp-temp)
|
||||
term)))
|
||||
(else (cons (car term)
|
||||
(apply-subst-lst alist (cdr term))))))
|
||||
|
||||
(define (apply-subst-lst alist lst)
|
||||
(cond ((null? lst)
|
||||
'())
|
||||
(else (cons (apply-subst alist (car lst))
|
||||
(apply-subst-lst alist (cdr lst))))))
|
||||
|
||||
(define (tautp x)
|
||||
(tautologyp (rewrite x)
|
||||
'() '()))
|
||||
|
||||
(define (tautologyp x true-lst false-lst)
|
||||
(cond ((truep x true-lst)
|
||||
#t)
|
||||
((falsep x false-lst)
|
||||
#f)
|
||||
((not (pair? x))
|
||||
#f)
|
||||
((eq? (car x) if-constructor)
|
||||
(cond ((truep (cadr x)
|
||||
true-lst)
|
||||
(tautologyp (caddr x)
|
||||
true-lst false-lst))
|
||||
((falsep (cadr x)
|
||||
false-lst)
|
||||
(tautologyp (cadddr x)
|
||||
true-lst false-lst))
|
||||
(else (and (tautologyp (caddr x)
|
||||
(cons (cadr x)
|
||||
true-lst)
|
||||
false-lst)
|
||||
(tautologyp (cadddr x)
|
||||
true-lst
|
||||
(cons (cadr x)
|
||||
false-lst))))))
|
||||
(else #f)))
|
||||
|
||||
(define if-constructor '*) ; becomes (symbol->symbol-record 'if)
|
||||
|
||||
(define rewrite-count 0) ; sanity check
|
||||
|
||||
(define (rewrite term)
|
||||
(set! rewrite-count (+ rewrite-count 1))
|
||||
(cond ((not (pair? term))
|
||||
term)
|
||||
(else (rewrite-with-lemmas (cons (car term)
|
||||
(rewrite-args (cdr term)))
|
||||
(get-lemmas (car term))))))
|
||||
|
||||
(define (rewrite-args lst)
|
||||
(cond ((null? lst)
|
||||
'())
|
||||
(else (cons (rewrite (car lst))
|
||||
(rewrite-args (cdr lst))))))
|
||||
|
||||
(define (rewrite-with-lemmas term lst)
|
||||
(cond ((null? lst)
|
||||
term)
|
||||
((one-way-unify term (cadr (car lst)))
|
||||
(rewrite (apply-subst unify-subst (caddr (car lst)))))
|
||||
(else (rewrite-with-lemmas term (cdr lst)))))
|
||||
|
||||
(define unify-subst '*)
|
||||
|
||||
(define (one-way-unify term1 term2)
|
||||
(begin (set! unify-subst '())
|
||||
(one-way-unify1 term1 term2)))
|
||||
|
||||
(define (one-way-unify1 term1 term2)
|
||||
(cond ((not (pair? term2))
|
||||
(let ((temp-temp (assq term2 unify-subst)))
|
||||
(cond (temp-temp
|
||||
(term-equal? term1 (cdr temp-temp)))
|
||||
((number? term2) ; This bug fix makes
|
||||
(equal? term1 term2)) ; nboyer 10-25% slower!
|
||||
(else
|
||||
(set! unify-subst (cons (cons term2 term1)
|
||||
unify-subst))
|
||||
#t))))
|
||||
((not (pair? term1))
|
||||
#f)
|
||||
((eq? (car term1)
|
||||
(car term2))
|
||||
(one-way-unify1-lst (cdr term1)
|
||||
(cdr term2)))
|
||||
(else #f)))
|
||||
|
||||
(define (one-way-unify1-lst lst1 lst2)
|
||||
(cond ((null? lst1)
|
||||
(null? lst2))
|
||||
((null? lst2)
|
||||
#f)
|
||||
((one-way-unify1 (car lst1)
|
||||
(car lst2))
|
||||
(one-way-unify1-lst (cdr lst1)
|
||||
(cdr lst2)))
|
||||
(else #f)))
|
||||
|
||||
(define (falsep x lst)
|
||||
(or (term-equal? x false-term)
|
||||
(term-member? x lst)))
|
||||
|
||||
(define (truep x lst)
|
||||
(or (term-equal? x true-term)
|
||||
(term-member? x lst)))
|
||||
|
||||
(define false-term '*) ; becomes (translate-term '(f))
|
||||
(define true-term '*) ; becomes (translate-term '(t))
|
||||
|
||||
; The next two procedures were in the original benchmark
|
||||
; but were never used.
|
||||
|
||||
(define (trans-of-implies n)
|
||||
(translate-term
|
||||
(list (quote implies)
|
||||
(trans-of-implies1 n)
|
||||
(list (quote implies)
|
||||
0 n))))
|
||||
|
||||
(define (trans-of-implies1 n)
|
||||
(cond ((equal? n 1)
|
||||
(list (quote implies)
|
||||
0 1))
|
||||
(else (list (quote and)
|
||||
(list (quote implies)
|
||||
(- n 1)
|
||||
n)
|
||||
(trans-of-implies1 (- n 1))))))
|
||||
|
||||
; Translated terms can be circular structures, which can't be
|
||||
; compared using Scheme's equal? and member procedures, so we
|
||||
; use these instead.
|
||||
|
||||
(define (term-equal? x y)
|
||||
(cond ((pair? x)
|
||||
(and (pair? y)
|
||||
(symbol-record-equal? (car x) (car y))
|
||||
(term-args-equal? (cdr x) (cdr y))))
|
||||
(else (equal? x y))))
|
||||
|
||||
(define (term-args-equal? lst1 lst2)
|
||||
(cond ((null? lst1)
|
||||
(null? lst2))
|
||||
((null? lst2)
|
||||
#f)
|
||||
((term-equal? (car lst1) (car lst2))
|
||||
(term-args-equal? (cdr lst1) (cdr lst2)))
|
||||
(else #f)))
|
||||
|
||||
(define (term-member? x lst)
|
||||
(cond ((null? lst)
|
||||
#f)
|
||||
((term-equal? x (car lst))
|
||||
#t)
|
||||
(else (term-member? x (cdr lst)))))
|
||||
|
||||
(set! setup-boyer
|
||||
(lambda ()
|
||||
(set! *symbol-records-alist* '())
|
||||
(set! if-constructor (symbol->symbol-record 'if))
|
||||
(set! false-term (translate-term '(f)))
|
||||
(set! true-term (translate-term '(t)))
|
||||
(setup)))
|
||||
|
||||
(set! test-boyer
|
||||
(lambda (n)
|
||||
(set! rewrite-count 0)
|
||||
(let ((answer (test n)))
|
||||
(write rewrite-count)
|
||||
(display " rewrites")
|
||||
(newline)
|
||||
(if answer
|
||||
rewrite-count
|
||||
#f)))))
|
||||
|
||||
(nboyer-benchmark 4)
|
||||
|
2
collects/tests/mzscheme/benchmarks/common/nboyer.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/nboyer.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module nboyer "wrap.ss")
|
48
collects/tests/mzscheme/benchmarks/common/nfa.sch
Normal file
48
collects/tests/mzscheme/benchmarks/common/nfa.sch
Normal file
|
@ -0,0 +1,48 @@
|
|||
; The recursive-nfa benchmark. (Figure 45, page 143.)
|
||||
|
||||
(define (recursive-nfa input)
|
||||
|
||||
(define (state0 input)
|
||||
(or (state1 input) (state3 input) #f))
|
||||
|
||||
(define (state1 input)
|
||||
(and (not (null? input))
|
||||
(or (and (char=? (car input) #\a)
|
||||
(state1 (cdr input)))
|
||||
(and (char=? (car input) #\c)
|
||||
(state1 input))
|
||||
(state2 input))))
|
||||
|
||||
(define (state2 input)
|
||||
(and (not (null? input))
|
||||
(char=? (car input) #\b)
|
||||
(not (null? (cdr input)))
|
||||
(char=? (cadr input) #\c)
|
||||
(not (null? (cddr input)))
|
||||
(char=? (caddr input) #\d)
|
||||
'state2))
|
||||
|
||||
(define (state3 input)
|
||||
(and (not (null? input))
|
||||
(or (and (char=? (car input) #\a)
|
||||
(state3 (cdr input)))
|
||||
(state4 input))))
|
||||
|
||||
(define (state4 input)
|
||||
(and (not (null? input))
|
||||
(char=? (car input) #\b)
|
||||
(not (null? (cdr input)))
|
||||
(char=? (cadr input) #\c)
|
||||
'state4))
|
||||
|
||||
(or (state0 (string->list input))
|
||||
'fail))
|
||||
|
||||
(time (let ([input (string-append (make-string 133 #\a) "bc")])
|
||||
(let loop ([n 10000])
|
||||
(unless (zero? n)
|
||||
(recursive-nfa input)
|
||||
(loop (sub1 n))))))
|
||||
|
||||
|
||||
|
2
collects/tests/mzscheme/benchmarks/common/nfa.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/nfa.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module nfa "wrap.ss")
|
3759
collects/tests/mzscheme/benchmarks/common/nucleic2.sch
Normal file
3759
collects/tests/mzscheme/benchmarks/common/nucleic2.sch
Normal file
File diff suppressed because it is too large
Load Diff
2
collects/tests/mzscheme/benchmarks/common/nucleic2.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/nucleic2.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module nucleic2 "wrap.ss")
|
169
collects/tests/mzscheme/benchmarks/common/puzzle.sch
Normal file
169
collects/tests/mzscheme/benchmarks/common/puzzle.sch
Normal file
|
@ -0,0 +1,169 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; File: puzzle.sch
|
||||
; Description: PUZZLE benchmark
|
||||
; Author: Richard Gabriel, after Forrest Baskett
|
||||
; Created: 12-Apr-85
|
||||
; Modified: 12-Apr-85 14:20:23 (Bob Shaw)
|
||||
; 11-Aug-87 (Will Clinger)
|
||||
; 22-Jan-88 (Will Clinger)
|
||||
; Language: Scheme
|
||||
; Status: Public Domain
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(define (iota n)
|
||||
(do ((n n (- n 1))
|
||||
(list '() (cons (- n 1) list)))
|
||||
((zero? n) list)))
|
||||
|
||||
;;; PUZZLE -- Forest Baskett's Puzzle benchmark, originally written in Pascal.
|
||||
|
||||
(define size 1048575)
|
||||
(define classmax 3)
|
||||
(define typemax 12)
|
||||
|
||||
(define *iii* 0)
|
||||
(define *kount* 0)
|
||||
(define *d* 8)
|
||||
|
||||
(define *piececount* (make-vector (+ classmax 1) 0))
|
||||
(define *class* (make-vector (+ typemax 1) 0))
|
||||
(define *piecemax* (make-vector (+ typemax 1) 0))
|
||||
(define *puzzle* (make-vector (+ size 1)))
|
||||
(define *p* (make-vector (+ typemax 1)))
|
||||
(for-each (lambda (i) (vector-set! *p* i (make-vector (+ size 1))))
|
||||
(iota (+ typemax 1)))
|
||||
|
||||
(define (fit i j)
|
||||
(let ((end (vector-ref *piecemax* i)))
|
||||
(do ((k 0 (+ k 1)))
|
||||
((or (> k end)
|
||||
(and (vector-ref (vector-ref *p* i) k)
|
||||
(vector-ref *puzzle* (+ j k))))
|
||||
(if (> k end) #t #f)))))
|
||||
|
||||
(define (place i j)
|
||||
(let ((end (vector-ref *piecemax* i)))
|
||||
(do ((k 0 (+ k 1)))
|
||||
((> k end))
|
||||
(cond ((vector-ref (vector-ref *p* i) k)
|
||||
(vector-set! *puzzle* (+ j k) #t)
|
||||
#t)))
|
||||
(vector-set! *piececount*
|
||||
(vector-ref *class* i)
|
||||
(- (vector-ref *piececount* (vector-ref *class* i)) 1))
|
||||
(do ((k j (+ k 1)))
|
||||
((or (> k size) (not (vector-ref *puzzle* k)))
|
||||
; (newline)
|
||||
; (display "*Puzzle* filled")
|
||||
(if (> k size) 0 k)))))
|
||||
|
||||
(define (puzzle-remove i j)
|
||||
(let ((end (vector-ref *piecemax* i)))
|
||||
(do ((k 0 (+ k 1)))
|
||||
((> k end))
|
||||
(cond ((vector-ref (vector-ref *p* i) k)
|
||||
(vector-set! *puzzle* (+ j k) #f)
|
||||
#f)))
|
||||
(vector-set! *piececount*
|
||||
(vector-ref *class* i)
|
||||
(+ (vector-ref *piececount* (vector-ref *class* i)) 1))))
|
||||
|
||||
|
||||
(define (trial j)
|
||||
(let ((k 0))
|
||||
(call-with-current-continuation
|
||||
(lambda (return)
|
||||
(do ((i 0 (+ i 1)))
|
||||
((> i typemax) (set! *kount* (+ *kount* 1)) '())
|
||||
(cond
|
||||
((not
|
||||
(zero?
|
||||
(vector-ref *piececount* (vector-ref *class* i))))
|
||||
(cond
|
||||
((fit i j)
|
||||
(set! k (place i j))
|
||||
(cond
|
||||
((or (trial k) (zero? k))
|
||||
;(trial-output (+ i 1) (+ k 1))
|
||||
(set! *kount* (+ *kount* 1))
|
||||
(return #t))
|
||||
(else (puzzle-remove i j))))))))))))
|
||||
|
||||
(define (trial-output x y)
|
||||
(newline)
|
||||
(display (string-append "Piece "
|
||||
(number->string x '(int))
|
||||
" at "
|
||||
(number->string y '(int))
|
||||
".")))
|
||||
|
||||
(define (definePiece iclass ii jj kk)
|
||||
(let ((index 0))
|
||||
(do ((i 0 (+ i 1)))
|
||||
((> i ii))
|
||||
(do ((j 0 (+ j 1)))
|
||||
((> j jj))
|
||||
(do ((k 0 (+ k 1)))
|
||||
((> k kk))
|
||||
(set! index (+ i (* *d* (+ j (* *d* k)))))
|
||||
(vector-set! (vector-ref *p* *iii*) index #t))))
|
||||
(vector-set! *class* *iii* iclass)
|
||||
(vector-set! *piecemax* *iii* index)
|
||||
(cond ((not (= *iii* typemax))
|
||||
(set! *iii* (+ *iii* 1))))))
|
||||
|
||||
(define (start)
|
||||
(do ((m 0 (+ m 1)))
|
||||
((> m size))
|
||||
(vector-set! *puzzle* m #t))
|
||||
(do ((i 1 (+ i 1)))
|
||||
((> i 5))
|
||||
(do ((j 1 (+ j 1)))
|
||||
((> j 5))
|
||||
(do ((k 1 (+ k 1)))
|
||||
((> k 5))
|
||||
(vector-set! *puzzle* (+ i (* *d* (+ j (* *d* k)))) #f))))
|
||||
(do ((i 0 (+ i 1)))
|
||||
((> i typemax))
|
||||
(do ((m 0 (+ m 1)))
|
||||
((> m size))
|
||||
(vector-set! (vector-ref *p* i) m #f)))
|
||||
(set! *iii* 0)
|
||||
(definePiece 0 3 1 0)
|
||||
(definePiece 0 1 0 3)
|
||||
(definePiece 0 0 3 1)
|
||||
(definePiece 0 1 3 0)
|
||||
(definePiece 0 3 0 1)
|
||||
(definePiece 0 0 1 3)
|
||||
|
||||
(definePiece 1 2 0 0)
|
||||
(definePiece 1 0 2 0)
|
||||
(definePiece 1 0 0 2)
|
||||
|
||||
(definePiece 2 1 1 0)
|
||||
(definePiece 2 1 0 1)
|
||||
(definePiece 2 0 1 1)
|
||||
|
||||
(definePiece 3 1 1 1)
|
||||
|
||||
(vector-set! *piececount* 0 13)
|
||||
(vector-set! *piececount* 1 3)
|
||||
(vector-set! *piececount* 2 1)
|
||||
(vector-set! *piececount* 3 1)
|
||||
(let ((m (+ (* *d* (+ *d* 1)) 1))
|
||||
(n 0))
|
||||
(cond ((fit 0 m) (set! n (place 0 m)))
|
||||
(else (begin (newline) (display "Error."))))
|
||||
(cond ((trial n)
|
||||
(begin (newline)
|
||||
(display "Success in ")
|
||||
(write *kount*)
|
||||
(display " trials.")
|
||||
(newline)))
|
||||
(else (begin (newline) (display "Failure."))))))
|
||||
|
||||
;;; call: (start)
|
||||
|
||||
(time (start))
|
||||
|
||||
|
2
collects/tests/mzscheme/benchmarks/common/puzzle.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/puzzle.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module puzzle "wrap.ss")
|
774
collects/tests/mzscheme/benchmarks/common/sboyer.sch
Normal file
774
collects/tests/mzscheme/benchmarks/common/sboyer.sch
Normal file
|
@ -0,0 +1,774 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; File: sboyer.sch
|
||||
; Description: The Boyer benchmark
|
||||
; Author: Bob Boyer
|
||||
; Created: 5-Apr-85
|
||||
; Modified: 10-Apr-85 14:52:20 (Bob Shaw)
|
||||
; 22-Jul-87 (Will Clinger)
|
||||
; 2-Jul-88 (Will Clinger -- distinguished #f and the empty list)
|
||||
; 13-Feb-97 (Will Clinger -- fixed bugs in unifier and rules,
|
||||
; rewrote to eliminate property lists, and added
|
||||
; a scaling parameter suggested by Bob Boyer)
|
||||
; 19-Mar-99 (Will Clinger -- cleaned up comments)
|
||||
; 4-Apr-01 (Will Clinger -- changed four 1- symbols to sub1)
|
||||
; Language: Scheme
|
||||
; Status: Public Domain
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;;; SBOYER -- Logic programming benchmark, originally written by Bob Boyer.
|
||||
;;; Much less CONS-intensive than NBOYER because it uses Henry Baker's
|
||||
;;; "sharing cons".
|
||||
|
||||
; Note: The version of this benchmark that appears in Dick Gabriel's book
|
||||
; contained several bugs that are corrected here. These bugs are discussed
|
||||
; by Henry Baker, "The Boyer Benchmark Meets Linear Logic", ACM SIGPLAN Lisp
|
||||
; Pointers 6(4), October-December 1993, pages 3-10. The fixed bugs are:
|
||||
;
|
||||
; The benchmark now returns a boolean result.
|
||||
; FALSEP and TRUEP use TERM-MEMBER? rather than MEMV (which is called MEMBER
|
||||
; in Common Lisp)
|
||||
; ONE-WAY-UNIFY1 now treats numbers correctly
|
||||
; ONE-WAY-UNIFY1-LST now treats empty lists correctly
|
||||
; Rule 19 has been corrected (this rule was not touched by the original
|
||||
; benchmark, but is used by this version)
|
||||
; Rules 84 and 101 have been corrected (but these rules are never touched
|
||||
; by the benchmark)
|
||||
;
|
||||
; According to Baker, these bug fixes make the benchmark 10-25% slower.
|
||||
; Please do not compare the timings from this benchmark against those of
|
||||
; the original benchmark.
|
||||
;
|
||||
; This version of the benchmark also prints the number of rewrites as a sanity
|
||||
; check, because it is too easy for a buggy version to return the correct
|
||||
; boolean result. The correct number of rewrites is
|
||||
;
|
||||
; n rewrites peak live storage (approximate, in bytes)
|
||||
; 0 95024
|
||||
; 1 591777
|
||||
; 2 1813975
|
||||
; 3 5375678
|
||||
; 4 16445406
|
||||
; 5 51507739
|
||||
|
||||
; Sboyer is a 2-phase benchmark.
|
||||
; The first phase attaches lemmas to symbols. This phase is not timed,
|
||||
; but it accounts for very little of the runtime anyway.
|
||||
; The second phase creates the test problem, and tests to see
|
||||
; whether it is implied by the lemmas.
|
||||
|
||||
(define (sboyer-benchmark . args)
|
||||
(let ((n (if (null? args) 0 (car args))))
|
||||
(setup-boyer)
|
||||
(time (test-boyer n))))
|
||||
|
||||
(define (setup-boyer) #t) ; assigned below
|
||||
(define (test-boyer) #t) ; assigned below
|
||||
|
||||
(define (id x) x)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;
|
||||
; The first phase.
|
||||
;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
; In the original benchmark, it stored a list of lemmas on the
|
||||
; property lists of symbols.
|
||||
; In the new benchmark, it maintains an association list of
|
||||
; symbols and symbol-records, and stores the list of lemmas
|
||||
; within the symbol-records.
|
||||
|
||||
(let ()
|
||||
|
||||
(define (setup)
|
||||
(add-lemma-lst
|
||||
(quote ((equal (compile form)
|
||||
(reverse (codegen (optimize form)
|
||||
(nil))))
|
||||
(equal (eqp x y)
|
||||
(equal (fix x)
|
||||
(fix y)))
|
||||
(equal (greaterp x y)
|
||||
(lessp y x))
|
||||
(equal (lesseqp x y)
|
||||
(not (lessp y x)))
|
||||
(equal (greatereqp x y)
|
||||
(not (lessp x y)))
|
||||
(equal (boolean x)
|
||||
(or (equal x (t))
|
||||
(equal x (f))))
|
||||
(equal (iff x y)
|
||||
(and (implies x y)
|
||||
(implies y x)))
|
||||
(equal (even1 x)
|
||||
(if (zerop x)
|
||||
(t)
|
||||
(odd (sub1 x))))
|
||||
(equal (countps- l pred)
|
||||
(countps-loop l pred (zero)))
|
||||
(equal (fact- i)
|
||||
(fact-loop i 1))
|
||||
(equal (reverse- x)
|
||||
(reverse-loop x (nil)))
|
||||
(equal (divides x y)
|
||||
(zerop (remainder y x)))
|
||||
(equal (assume-true var alist)
|
||||
(cons (cons var (t))
|
||||
alist))
|
||||
(equal (assume-false var alist)
|
||||
(cons (cons var (f))
|
||||
alist))
|
||||
(equal (tautology-checker x)
|
||||
(tautologyp (normalize x)
|
||||
(nil)))
|
||||
(equal (falsify x)
|
||||
(falsify1 (normalize x)
|
||||
(nil)))
|
||||
(equal (prime x)
|
||||
(and (not (zerop x))
|
||||
(not (equal x (add1 (zero))))
|
||||
(prime1 x (sub1 x))))
|
||||
(equal (and p q)
|
||||
(if p (if q (t)
|
||||
(f))
|
||||
(f)))
|
||||
(equal (or p q)
|
||||
(if p (t)
|
||||
(if q (t)
|
||||
(f))))
|
||||
(equal (not p)
|
||||
(if p (f)
|
||||
(t)))
|
||||
(equal (implies p q)
|
||||
(if p (if q (t)
|
||||
(f))
|
||||
(t)))
|
||||
(equal (fix x)
|
||||
(if (numberp x)
|
||||
x
|
||||
(zero)))
|
||||
(equal (if (if a b c)
|
||||
d e)
|
||||
(if a (if b d e)
|
||||
(if c d e)))
|
||||
(equal (zerop x)
|
||||
(or (equal x (zero))
|
||||
(not (numberp x))))
|
||||
(equal (plus (plus x y)
|
||||
z)
|
||||
(plus x (plus y z)))
|
||||
(equal (equal (plus a b)
|
||||
(zero))
|
||||
(and (zerop a)
|
||||
(zerop b)))
|
||||
(equal (difference x x)
|
||||
(zero))
|
||||
(equal (equal (plus a b)
|
||||
(plus a c))
|
||||
(equal (fix b)
|
||||
(fix c)))
|
||||
(equal (equal (zero)
|
||||
(difference x y))
|
||||
(not (lessp y x)))
|
||||
(equal (equal x (difference x y))
|
||||
(and (numberp x)
|
||||
(or (equal x (zero))
|
||||
(zerop y))))
|
||||
(equal (meaning (plus-tree (append x y))
|
||||
a)
|
||||
(plus (meaning (plus-tree x)
|
||||
a)
|
||||
(meaning (plus-tree y)
|
||||
a)))
|
||||
(equal (meaning (plus-tree (plus-fringe x))
|
||||
a)
|
||||
(fix (meaning x a)))
|
||||
(equal (append (append x y)
|
||||
z)
|
||||
(append x (append y z)))
|
||||
(equal (reverse (append a b))
|
||||
(append (reverse b)
|
||||
(reverse a)))
|
||||
(equal (times x (plus y z))
|
||||
(plus (times x y)
|
||||
(times x z)))
|
||||
(equal (times (times x y)
|
||||
z)
|
||||
(times x (times y z)))
|
||||
(equal (equal (times x y)
|
||||
(zero))
|
||||
(or (zerop x)
|
||||
(zerop y)))
|
||||
(equal (exec (append x y)
|
||||
pds envrn)
|
||||
(exec y (exec x pds envrn)
|
||||
envrn))
|
||||
(equal (mc-flatten x y)
|
||||
(append (flatten x)
|
||||
y))
|
||||
(equal (member x (append a b))
|
||||
(or (member x a)
|
||||
(member x b)))
|
||||
(equal (member x (reverse y))
|
||||
(member x y))
|
||||
(equal (length (reverse x))
|
||||
(length x))
|
||||
(equal (member a (intersect b c))
|
||||
(and (member a b)
|
||||
(member a c)))
|
||||
(equal (nth (zero)
|
||||
i)
|
||||
(zero))
|
||||
(equal (exp i (plus j k))
|
||||
(times (exp i j)
|
||||
(exp i k)))
|
||||
(equal (exp i (times j k))
|
||||
(exp (exp i j)
|
||||
k))
|
||||
(equal (reverse-loop x y)
|
||||
(append (reverse x)
|
||||
y))
|
||||
(equal (reverse-loop x (nil))
|
||||
(reverse x))
|
||||
(equal (count-list z (sort-lp x y))
|
||||
(plus (count-list z x)
|
||||
(count-list z y)))
|
||||
(equal (equal (append a b)
|
||||
(append a c))
|
||||
(equal b c))
|
||||
(equal (plus (remainder x y)
|
||||
(times y (quotient x y)))
|
||||
(fix x))
|
||||
(equal (power-eval (big-plus1 l i base)
|
||||
base)
|
||||
(plus (power-eval l base)
|
||||
i))
|
||||
(equal (power-eval (big-plus x y i base)
|
||||
base)
|
||||
(plus i (plus (power-eval x base)
|
||||
(power-eval y base))))
|
||||
(equal (remainder y 1)
|
||||
(zero))
|
||||
(equal (lessp (remainder x y)
|
||||
y)
|
||||
(not (zerop y)))
|
||||
(equal (remainder x x)
|
||||
(zero))
|
||||
(equal (lessp (quotient i j)
|
||||
i)
|
||||
(and (not (zerop i))
|
||||
(or (zerop j)
|
||||
(not (equal j 1)))))
|
||||
(equal (lessp (remainder x y)
|
||||
x)
|
||||
(and (not (zerop y))
|
||||
(not (zerop x))
|
||||
(not (lessp x y))))
|
||||
(equal (power-eval (power-rep i base)
|
||||
base)
|
||||
(fix i))
|
||||
(equal (power-eval (big-plus (power-rep i base)
|
||||
(power-rep j base)
|
||||
(zero)
|
||||
base)
|
||||
base)
|
||||
(plus i j))
|
||||
(equal (gcd x y)
|
||||
(gcd y x))
|
||||
(equal (nth (append a b)
|
||||
i)
|
||||
(append (nth a i)
|
||||
(nth b (difference i (length a)))))
|
||||
(equal (difference (plus x y)
|
||||
x)
|
||||
(fix y))
|
||||
(equal (difference (plus y x)
|
||||
x)
|
||||
(fix y))
|
||||
(equal (difference (plus x y)
|
||||
(plus x z))
|
||||
(difference y z))
|
||||
(equal (times x (difference c w))
|
||||
(difference (times c x)
|
||||
(times w x)))
|
||||
(equal (remainder (times x z)
|
||||
z)
|
||||
(zero))
|
||||
(equal (difference (plus b (plus a c))
|
||||
a)
|
||||
(plus b c))
|
||||
(equal (difference (add1 (plus y z))
|
||||
z)
|
||||
(add1 y))
|
||||
(equal (lessp (plus x y)
|
||||
(plus x z))
|
||||
(lessp y z))
|
||||
(equal (lessp (times x z)
|
||||
(times y z))
|
||||
(and (not (zerop z))
|
||||
(lessp x y)))
|
||||
(equal (lessp y (plus x y))
|
||||
(not (zerop x)))
|
||||
(equal (gcd (times x z)
|
||||
(times y z))
|
||||
(times z (gcd x y)))
|
||||
(equal (value (normalize x)
|
||||
a)
|
||||
(value x a))
|
||||
(equal (equal (flatten x)
|
||||
(cons y (nil)))
|
||||
(and (nlistp x)
|
||||
(equal x y)))
|
||||
(equal (listp (gopher x))
|
||||
(listp x))
|
||||
(equal (samefringe x y)
|
||||
(equal (flatten x)
|
||||
(flatten y)))
|
||||
(equal (equal (greatest-factor x y)
|
||||
(zero))
|
||||
(and (or (zerop y)
|
||||
(equal y 1))
|
||||
(equal x (zero))))
|
||||
(equal (equal (greatest-factor x y)
|
||||
1)
|
||||
(equal x 1))
|
||||
(equal (numberp (greatest-factor x y))
|
||||
(not (and (or (zerop y)
|
||||
(equal y 1))
|
||||
(not (numberp x)))))
|
||||
(equal (times-list (append x y))
|
||||
(times (times-list x)
|
||||
(times-list y)))
|
||||
(equal (prime-list (append x y))
|
||||
(and (prime-list x)
|
||||
(prime-list y)))
|
||||
(equal (equal z (times w z))
|
||||
(and (numberp z)
|
||||
(or (equal z (zero))
|
||||
(equal w 1))))
|
||||
(equal (greatereqp x y)
|
||||
(not (lessp x y)))
|
||||
(equal (equal x (times x y))
|
||||
(or (equal x (zero))
|
||||
(and (numberp x)
|
||||
(equal y 1))))
|
||||
(equal (remainder (times y x)
|
||||
y)
|
||||
(zero))
|
||||
(equal (equal (times a b)
|
||||
1)
|
||||
(and (not (equal a (zero)))
|
||||
(not (equal b (zero)))
|
||||
(numberp a)
|
||||
(numberp b)
|
||||
(equal (sub1 a)
|
||||
(zero))
|
||||
(equal (sub1 b)
|
||||
(zero))))
|
||||
(equal (lessp (length (delete x l))
|
||||
(length l))
|
||||
(member x l))
|
||||
(equal (sort2 (delete x l))
|
||||
(delete x (sort2 l)))
|
||||
(equal (dsort x)
|
||||
(sort2 x))
|
||||
(equal (length (cons x1
|
||||
(cons x2
|
||||
(cons x3 (cons x4
|
||||
(cons x5
|
||||
(cons x6 x7)))))))
|
||||
(plus 6 (length x7)))
|
||||
(equal (difference (add1 (add1 x))
|
||||
2)
|
||||
(fix x))
|
||||
(equal (quotient (plus x (plus x y))
|
||||
2)
|
||||
(plus x (quotient y 2)))
|
||||
(equal (sigma (zero)
|
||||
i)
|
||||
(quotient (times i (add1 i))
|
||||
2))
|
||||
(equal (plus x (add1 y))
|
||||
(if (numberp y)
|
||||
(add1 (plus x y))
|
||||
(add1 x)))
|
||||
(equal (equal (difference x y)
|
||||
(difference z y))
|
||||
(if (lessp x y)
|
||||
(not (lessp y z))
|
||||
(if (lessp z y)
|
||||
(not (lessp y x))
|
||||
(equal (fix x)
|
||||
(fix z)))))
|
||||
(equal (meaning (plus-tree (delete x y))
|
||||
a)
|
||||
(if (member x y)
|
||||
(difference (meaning (plus-tree y)
|
||||
a)
|
||||
(meaning x a))
|
||||
(meaning (plus-tree y)
|
||||
a)))
|
||||
(equal (times x (add1 y))
|
||||
(if (numberp y)
|
||||
(plus x (times x y))
|
||||
(fix x)))
|
||||
(equal (nth (nil)
|
||||
i)
|
||||
(if (zerop i)
|
||||
(nil)
|
||||
(zero)))
|
||||
(equal (last (append a b))
|
||||
(if (listp b)
|
||||
(last b)
|
||||
(if (listp a)
|
||||
(cons (car (last a))
|
||||
b)
|
||||
b)))
|
||||
(equal (equal (lessp x y)
|
||||
z)
|
||||
(if (lessp x y)
|
||||
(equal (t) z)
|
||||
(equal (f) z)))
|
||||
(equal (assignment x (append a b))
|
||||
(if (assignedp x a)
|
||||
(assignment x a)
|
||||
(assignment x b)))
|
||||
(equal (car (gopher x))
|
||||
(if (listp x)
|
||||
(car (flatten x))
|
||||
(zero)))
|
||||
(equal (flatten (cdr (gopher x)))
|
||||
(if (listp x)
|
||||
(cdr (flatten x))
|
||||
(cons (zero)
|
||||
(nil))))
|
||||
(equal (quotient (times y x)
|
||||
y)
|
||||
(if (zerop y)
|
||||
(zero)
|
||||
(fix x)))
|
||||
(equal (get j (set i val mem))
|
||||
(if (eqp j i)
|
||||
val
|
||||
(get j mem)))))))
|
||||
|
||||
(define (add-lemma-lst lst)
|
||||
(cond ((null? lst)
|
||||
#t)
|
||||
(else (add-lemma (car lst))
|
||||
(add-lemma-lst (cdr lst)))))
|
||||
|
||||
(define (add-lemma term)
|
||||
(cond ((and (pair? term)
|
||||
(eq? (car term)
|
||||
(quote equal))
|
||||
(pair? (cadr term)))
|
||||
(put (car (cadr term))
|
||||
(quote lemmas)
|
||||
(cons
|
||||
(translate-term term)
|
||||
(get (car (cadr term)) (quote lemmas)))))
|
||||
(else (error "ADD-LEMMA did not like term: " term))))
|
||||
|
||||
; Translates a term by replacing its constructor symbols by symbol-records.
|
||||
|
||||
(define (translate-term term)
|
||||
(cond ((not (pair? term))
|
||||
term)
|
||||
(else (cons (symbol->symbol-record (car term))
|
||||
(translate-args (cdr term))))))
|
||||
|
||||
(define (translate-args lst)
|
||||
(cond ((null? lst)
|
||||
'())
|
||||
(else (cons (translate-term (car lst))
|
||||
(translate-args (cdr lst))))))
|
||||
|
||||
; For debugging only, so the use of MAP does not change
|
||||
; the first-order character of the benchmark.
|
||||
|
||||
(define (untranslate-term term)
|
||||
(cond ((not (pair? term))
|
||||
term)
|
||||
(else (cons (get-name (car term))
|
||||
(map untranslate-term (cdr term))))))
|
||||
|
||||
; A symbol-record is represented as a vector with two fields:
|
||||
; the symbol (for debugging) and
|
||||
; the list of lemmas associated with the symbol.
|
||||
|
||||
(define (put sym property value)
|
||||
(put-lemmas! (symbol->symbol-record sym) value))
|
||||
|
||||
(define (get sym property)
|
||||
(get-lemmas (symbol->symbol-record sym)))
|
||||
|
||||
(define (symbol->symbol-record sym)
|
||||
(let ((x (assq sym *symbol-records-alist*)))
|
||||
(if x
|
||||
(cdr x)
|
||||
(let ((r (make-symbol-record sym)))
|
||||
(set! *symbol-records-alist*
|
||||
(cons (cons sym r)
|
||||
*symbol-records-alist*))
|
||||
r))))
|
||||
|
||||
; Association list of symbols and symbol-records.
|
||||
|
||||
(define *symbol-records-alist* '())
|
||||
|
||||
; A symbol-record is represented as a vector with two fields:
|
||||
; the symbol (for debugging) and
|
||||
; the list of lemmas associated with the symbol.
|
||||
|
||||
(define (make-symbol-record sym)
|
||||
(vector sym '()))
|
||||
|
||||
(define (put-lemmas! symbol-record lemmas)
|
||||
(vector-set! symbol-record 1 lemmas))
|
||||
|
||||
(define (get-lemmas symbol-record)
|
||||
(vector-ref symbol-record 1))
|
||||
|
||||
(define (get-name symbol-record)
|
||||
(vector-ref symbol-record 0))
|
||||
|
||||
(define (symbol-record-equal? r1 r2)
|
||||
(eq? r1 r2))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;
|
||||
; The second phase.
|
||||
;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(define (test n)
|
||||
(let ((term
|
||||
(apply-subst
|
||||
(translate-alist
|
||||
(quote ((x f (plus (plus a b)
|
||||
(plus c (zero))))
|
||||
(y f (times (times a b)
|
||||
(plus c d)))
|
||||
(z f (reverse (append (append a b)
|
||||
(nil))))
|
||||
(u equal (plus a b)
|
||||
(difference x y))
|
||||
(w lessp (remainder a b)
|
||||
(member a (length b))))))
|
||||
(translate-term
|
||||
(do ((term
|
||||
(quote (implies (and (implies x y)
|
||||
(and (implies y z)
|
||||
(and (implies z u)
|
||||
(implies u w))))
|
||||
(implies x w)))
|
||||
(list 'or term '(f)))
|
||||
(n n (- n 1)))
|
||||
((zero? n) term))))))
|
||||
(tautp term)))
|
||||
|
||||
(define (translate-alist alist)
|
||||
(cond ((null? alist)
|
||||
'())
|
||||
(else (cons (cons (caar alist)
|
||||
(translate-term (cdar alist)))
|
||||
(translate-alist (cdr alist))))))
|
||||
|
||||
(define (apply-subst alist term)
|
||||
(cond ((not (pair? term))
|
||||
(let ((temp-temp (assq term alist)))
|
||||
(if temp-temp
|
||||
(cdr temp-temp)
|
||||
term)))
|
||||
(else (cons (car term)
|
||||
(apply-subst-lst alist (cdr term))))))
|
||||
|
||||
(define (apply-subst-lst alist lst)
|
||||
(cond ((null? lst)
|
||||
'())
|
||||
(else (cons (apply-subst alist (car lst))
|
||||
(apply-subst-lst alist (cdr lst))))))
|
||||
|
||||
(define (tautp x)
|
||||
(tautologyp (rewrite x)
|
||||
'() '()))
|
||||
|
||||
(define (tautologyp x true-lst false-lst)
|
||||
(cond ((truep x true-lst)
|
||||
#t)
|
||||
((falsep x false-lst)
|
||||
#f)
|
||||
((not (pair? x))
|
||||
#f)
|
||||
((eq? (car x) if-constructor)
|
||||
(cond ((truep (cadr x)
|
||||
true-lst)
|
||||
(tautologyp (caddr x)
|
||||
true-lst false-lst))
|
||||
((falsep (cadr x)
|
||||
false-lst)
|
||||
(tautologyp (cadddr x)
|
||||
true-lst false-lst))
|
||||
(else (and (tautologyp (caddr x)
|
||||
(cons (cadr x)
|
||||
true-lst)
|
||||
false-lst)
|
||||
(tautologyp (cadddr x)
|
||||
true-lst
|
||||
(cons (cadr x)
|
||||
false-lst))))))
|
||||
(else #f)))
|
||||
|
||||
(define if-constructor '*) ; becomes (symbol->symbol-record 'if)
|
||||
|
||||
(define rewrite-count 0) ; sanity check
|
||||
|
||||
; The next procedure is Henry Baker's sharing CONS, which avoids
|
||||
; allocation if the result is already in hand.
|
||||
; The REWRITE and REWRITE-ARGS procedures have been modified to
|
||||
; use SCONS instead of CONS.
|
||||
|
||||
(define (scons x y original)
|
||||
(if (and (eq? x (car original))
|
||||
(eq? y (cdr original)))
|
||||
original
|
||||
(cons x y)))
|
||||
|
||||
(define (rewrite term)
|
||||
(set! rewrite-count (+ rewrite-count 1))
|
||||
(cond ((not (pair? term))
|
||||
term)
|
||||
(else (rewrite-with-lemmas (scons (car term)
|
||||
(rewrite-args (cdr term))
|
||||
term)
|
||||
(get-lemmas (car term))))))
|
||||
|
||||
(define (rewrite-args lst)
|
||||
(cond ((null? lst)
|
||||
'())
|
||||
(else (scons (rewrite (car lst))
|
||||
(rewrite-args (cdr lst))
|
||||
lst))))
|
||||
|
||||
(define (rewrite-with-lemmas term lst)
|
||||
(cond ((null? lst)
|
||||
term)
|
||||
((one-way-unify term (cadr (car lst)))
|
||||
(rewrite ( apply-subst unify-subst (caddr (car lst)))))
|
||||
(else (rewrite-with-lemmas term (cdr lst)))))
|
||||
|
||||
(define unify-subst '*)
|
||||
|
||||
(define (one-way-unify term1 term2)
|
||||
(begin (set! unify-subst '())
|
||||
(one-way-unify1 term1 term2)))
|
||||
|
||||
(define (one-way-unify1 term1 term2)
|
||||
(cond ((not (pair? term2))
|
||||
(let ((temp-temp (assq term2 unify-subst)))
|
||||
(cond (temp-temp
|
||||
(term-equal? term1 (cdr temp-temp)))
|
||||
((number? term2) ; This bug fix makes
|
||||
(equal? term1 term2)) ; nboyer 10-25% slower!
|
||||
(else
|
||||
(set! unify-subst (cons (cons term2 term1)
|
||||
unify-subst))
|
||||
#t))))
|
||||
((not (pair? term1))
|
||||
#f)
|
||||
((eq? (car term1)
|
||||
(car term2))
|
||||
(one-way-unify1-lst (cdr term1)
|
||||
(cdr term2)))
|
||||
(else #f)))
|
||||
|
||||
(define (one-way-unify1-lst lst1 lst2)
|
||||
(cond ((null? lst1)
|
||||
(null? lst2))
|
||||
((null? lst2)
|
||||
#f)
|
||||
((one-way-unify1 (car lst1)
|
||||
(car lst2))
|
||||
(one-way-unify1-lst (cdr lst1)
|
||||
(cdr lst2)))
|
||||
(else #f)))
|
||||
|
||||
(define (falsep x lst)
|
||||
(or (term-equal? x false-term)
|
||||
(term-member? x lst)))
|
||||
|
||||
(define (truep x lst)
|
||||
(or (term-equal? x true-term)
|
||||
(term-member? x lst)))
|
||||
|
||||
(define false-term '*) ; becomes (translate-term '(f))
|
||||
(define true-term '*) ; becomes (translate-term '(t))
|
||||
|
||||
; The next two procedures were in the original benchmark
|
||||
; but were never used.
|
||||
|
||||
(define (trans-of-implies n)
|
||||
(translate-term
|
||||
(list (quote implies)
|
||||
(trans-of-implies1 n)
|
||||
(list (quote implies)
|
||||
0 n))))
|
||||
|
||||
(define (trans-of-implies1 n)
|
||||
(cond ((equal? n 1)
|
||||
(list (quote implies)
|
||||
0 1))
|
||||
(else (list (quote and)
|
||||
(list (quote implies)
|
||||
(- n 1)
|
||||
n)
|
||||
(trans-of-implies1 (- n 1))))))
|
||||
|
||||
; Translated terms can be circular structures, which can't be
|
||||
; compared using Scheme's equal? and member procedures, so we
|
||||
; use these instead.
|
||||
|
||||
(define (term-equal? x y)
|
||||
(cond ((pair? x)
|
||||
(and (pair? y)
|
||||
(symbol-record-equal? (car x) (car y))
|
||||
(term-args-equal? (cdr x) (cdr y))))
|
||||
(else (equal? x y))))
|
||||
|
||||
(define (term-args-equal? lst1 lst2)
|
||||
(cond ((null? lst1)
|
||||
(null? lst2))
|
||||
((null? lst2)
|
||||
#f)
|
||||
((term-equal? (car lst1) (car lst2))
|
||||
(term-args-equal? (cdr lst1) (cdr lst2)))
|
||||
(else #f)))
|
||||
|
||||
(define (term-member? x lst)
|
||||
(cond ((null? lst)
|
||||
#f)
|
||||
((term-equal? x (car lst))
|
||||
#t)
|
||||
(else (term-member? x (cdr lst)))))
|
||||
|
||||
(set! setup-boyer
|
||||
(lambda ()
|
||||
(set! *symbol-records-alist* '())
|
||||
(set! if-constructor (symbol->symbol-record 'if))
|
||||
(set! false-term (translate-term '(f)))
|
||||
(set! true-term (translate-term '(t)))
|
||||
(setup)))
|
||||
|
||||
(set! test-boyer
|
||||
(lambda (n)
|
||||
(set! rewrite-count 0)
|
||||
(let ((answer (test n)))
|
||||
(write rewrite-count)
|
||||
(display " rewrites")
|
||||
(newline)
|
||||
(if answer
|
||||
rewrite-count
|
||||
#f)))))
|
||||
|
||||
(sboyer-benchmark 5)
|
2
collects/tests/mzscheme/benchmarks/common/sboyer.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/sboyer.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module sboyer "wrap.ss")
|
143
collects/tests/mzscheme/benchmarks/common/sort1.sch
Normal file
143
collects/tests/mzscheme/benchmarks/common/sort1.sch
Normal file
|
@ -0,0 +1,143 @@
|
|||
; This benchmark uses the code for Larceny's standard sort procedure.
|
||||
;
|
||||
; Usage:
|
||||
; (sort-benchmark sorter n)
|
||||
;
|
||||
; where
|
||||
; sorter is a sort procedure (usually sort or sort1) whose calling
|
||||
; convention is compatible with Larceny's
|
||||
; n is the number of fixnums to sort
|
||||
|
||||
(define sort1
|
||||
(let ()
|
||||
|
||||
;;; File : sort.scm
|
||||
;;; Author : Richard A. O'Keefe (based on Prolog code by D.H.D.Warren)
|
||||
;;; Updated: 11 June 1991
|
||||
;
|
||||
; $Id: sort.sch 264 1998-12-14 16:44:08Z lth $
|
||||
;
|
||||
; Code originally obtained from Scheme Repository, since hacked.
|
||||
;
|
||||
; Sort and Sort! will sort lists and vectors. The former returns a new
|
||||
; data structure; the latter sorts the data structure in-place. A
|
||||
; mergesort algorithm is used.
|
||||
|
||||
; Destructive merge of two sorted lists.
|
||||
|
||||
(define (merge!! a b less?)
|
||||
|
||||
(define (loop r a b)
|
||||
(if (less? (car b) (car a))
|
||||
(begin (set-cdr! r b)
|
||||
(if (null? (cdr b))
|
||||
(set-cdr! b a)
|
||||
(loop b a (cdr b)) ))
|
||||
;; (car a) <= (car b)
|
||||
(begin (set-cdr! r a)
|
||||
(if (null? (cdr a))
|
||||
(set-cdr! a b)
|
||||
(loop a (cdr a) b)) )) )
|
||||
|
||||
(cond ((null? a) b)
|
||||
((null? b) a)
|
||||
((less? (car b) (car a))
|
||||
(if (null? (cdr b))
|
||||
(set-cdr! b a)
|
||||
(loop b a (cdr b)))
|
||||
b)
|
||||
(else ; (car a) <= (car b)
|
||||
(if (null? (cdr a))
|
||||
(set-cdr! a b)
|
||||
(loop a (cdr a) b))
|
||||
a)))
|
||||
|
||||
; Sort procedure which copies the input list and then sorts the
|
||||
; new list imperatively. Due to Richard O'Keefe; algorithm
|
||||
; attributed to D.H.D. Warren
|
||||
|
||||
(define (sort!! seq less?)
|
||||
|
||||
(define (step n)
|
||||
(cond ((> n 2)
|
||||
(let* ((j (quotient n 2))
|
||||
(a (step j))
|
||||
(k (- n j))
|
||||
(b (step k)))
|
||||
(merge!! a b less?)))
|
||||
((= n 2)
|
||||
(let ((x (car seq))
|
||||
(y (cadr seq))
|
||||
(p seq))
|
||||
(set! seq (cddr seq))
|
||||
(if (less? y x)
|
||||
(begin
|
||||
(set-car! p y)
|
||||
(set-car! (cdr p) x)))
|
||||
(set-cdr! (cdr p) '())
|
||||
p))
|
||||
((= n 1)
|
||||
(let ((p seq))
|
||||
(set! seq (cdr seq))
|
||||
(set-cdr! p '())
|
||||
p))
|
||||
(else
|
||||
'())))
|
||||
|
||||
(step (length seq)))
|
||||
|
||||
(define (sort! seq less?)
|
||||
(cond ((null? seq)
|
||||
seq)
|
||||
((pair? seq)
|
||||
(sort!! seq less?))
|
||||
((vector? seq)
|
||||
(do ((l (sort!! (vector->list seq) less?) (cdr l))
|
||||
(i 0 (+ i 1)))
|
||||
((null? l) seq)
|
||||
(vector-set! seq i (car l))))
|
||||
(else
|
||||
(error "sort!: not a valid sequence: " seq))))
|
||||
|
||||
(define (sort seq less?)
|
||||
(cond ((null? seq)
|
||||
seq)
|
||||
((pair? seq)
|
||||
(sort!! (list-copy seq) less?))
|
||||
((vector? seq)
|
||||
(list->vector (sort!! (vector->list seq) less?)))
|
||||
(else
|
||||
(error "sort: not a valid sequence: " seq))))
|
||||
|
||||
; eof
|
||||
|
||||
; This is pretty much optimal for Larceny.
|
||||
|
||||
(define (list-copy l)
|
||||
(define (loop l prev)
|
||||
(if (null? l)
|
||||
#t
|
||||
(let ((q (cons (car l) '())))
|
||||
(set-cdr! prev q)
|
||||
(loop (cdr l) q))))
|
||||
(if (null? l)
|
||||
l
|
||||
(let ((first (cons (car l) '())))
|
||||
(loop (cdr l) first)
|
||||
first)))
|
||||
|
||||
sort))
|
||||
|
||||
|
||||
(define (rgen n m)
|
||||
(let loop ((n n) (l '()))
|
||||
(if (zero? n)
|
||||
l
|
||||
(loop (- n 1) (cons (random m) l)))))
|
||||
|
||||
(define (sort-benchmark sorter n)
|
||||
(let ((l (rgen n 1000000)))
|
||||
(time (sorter l <))))
|
||||
|
||||
(sort-benchmark sort1 1000000)
|
||||
|
2
collects/tests/mzscheme/benchmarks/common/sort1.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/sort1.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module sort1 "wrap.ss")
|
25
collects/tests/mzscheme/benchmarks/common/tak.sch
Normal file
25
collects/tests/mzscheme/benchmarks/common/tak.sch
Normal file
|
@ -0,0 +1,25 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; File: tak.sch
|
||||
; Description: TAK benchmark from the Gabriel tests
|
||||
; Author: Richard Gabriel
|
||||
; Created: 12-Apr-85
|
||||
; Modified: 12-Apr-85 09:58:18 (Bob Shaw)
|
||||
; 22-Jul-87 (Will Clinger)
|
||||
; Language: Scheme
|
||||
; Status: Public Domain
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;;; TAK -- A vanilla version of the TAKeuchi function
|
||||
|
||||
(define (tak x y z)
|
||||
(if (not (< y x))
|
||||
z
|
||||
(tak (tak (- x 1) y z)
|
||||
(tak (- y 1) z x)
|
||||
(tak (- z 1) x y))))
|
||||
|
||||
;;; call: (tak 18 12 6)
|
||||
|
||||
(time (tak 18 12 2))
|
||||
|
||||
|
2
collects/tests/mzscheme/benchmarks/common/tak.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/tak.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module tak "wrap.ss")
|
41
collects/tests/mzscheme/benchmarks/common/takl.sch
Normal file
41
collects/tests/mzscheme/benchmarks/common/takl.sch
Normal file
|
@ -0,0 +1,41 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; File: takl.sch
|
||||
; Description: TAKL benchmark from the Gabriel tests
|
||||
; Author: Richard Gabriel
|
||||
; Created: 12-Apr-85
|
||||
; Modified: 12-Apr-85 10:07:00 (Bob Shaw)
|
||||
; 22-Jul-87 (Will Clinger)
|
||||
; Language: Scheme
|
||||
; Status: Public Domain
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;;; TAKL -- The TAKeuchi function using lists as counters.
|
||||
|
||||
(define (listn n)
|
||||
(if (not (= 0 n))
|
||||
(cons n (listn (- n 1)))
|
||||
'()))
|
||||
|
||||
(define 18l (listn 18))
|
||||
(define 12l (listn 12))
|
||||
(define 6l (listn 2))
|
||||
|
||||
(define (mas x y z)
|
||||
(if (not (shorterp y x))
|
||||
z
|
||||
(mas (mas (cdr x)
|
||||
y z)
|
||||
(mas (cdr y)
|
||||
z x)
|
||||
(mas (cdr z)
|
||||
x y))))
|
||||
|
||||
(define (shorterp x y)
|
||||
(and (not (null? y))
|
||||
(or (null? x)
|
||||
(shorterp (cdr x)
|
||||
(cdr y)))))
|
||||
|
||||
;;; call: (mas 18l 12l 6l)
|
||||
|
||||
(time (mas 18l 12l 6l))
|
2
collects/tests/mzscheme/benchmarks/common/takl.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/takl.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module takl "wrap.ss")
|
521
collects/tests/mzscheme/benchmarks/common/takr.sch
Normal file
521
collects/tests/mzscheme/benchmarks/common/takr.sch
Normal file
|
@ -0,0 +1,521 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; File: takr.sch
|
||||
; Description: TAKR benchmark
|
||||
; Author: Richard Gabriel
|
||||
; Created: 12-Apr-85
|
||||
; Modified: 12-Apr-85 10:12:43 (Bob Shaw)
|
||||
; 22-Jul-87 (Will Clinger)
|
||||
; Language: Scheme
|
||||
; Status: Public Domain
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;;; TAKR -- 100 function (count `em) version of TAK that tries to defeat cache
|
||||
;;; memory effects. Results should be the same as for TAK on stack machines.
|
||||
;;; Distribution of calls is not completely flat.
|
||||
|
||||
(define (tak0 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak1 (tak37 (- x 1) y z)
|
||||
(tak11 (- y 1) z x)
|
||||
(tak17 (- z 1) x y)))))
|
||||
(define (tak1 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak2 (tak74 (- x 1) y z)
|
||||
(tak22 (- y 1) z x)
|
||||
(tak34 (- z 1) x y)))))
|
||||
(define (tak2 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak3 (tak11 (- x 1) y z)
|
||||
(tak33 (- y 1) z x)
|
||||
(tak51 (- z 1) x y)))))
|
||||
(define (tak3 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak4 (tak48 (- x 1) y z)
|
||||
(tak44 (- y 1) z x)
|
||||
(tak68 (- z 1) x y)))))
|
||||
(define (tak4 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak5 (tak85 (- x 1) y z)
|
||||
(tak55 (- y 1) z x)
|
||||
(tak85 (- z 1) x y)))))
|
||||
(define (tak5 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak6 (tak22 (- x 1) y z)
|
||||
(tak66 (- y 1) z x)
|
||||
(tak2 (- z 1) x y)))))
|
||||
(define (tak6 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak7 (tak59 (- x 1) y z)
|
||||
(tak77 (- y 1) z x)
|
||||
(tak19 (- z 1) x y)))))
|
||||
(define (tak7 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak8 (tak96 (- x 1) y z)
|
||||
(tak88 (- y 1) z x)
|
||||
(tak36 (- z 1) x y)))))
|
||||
(define (tak8 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak9 (tak33 (- x 1) y z)
|
||||
(tak99 (- y 1) z x)
|
||||
(tak53 (- z 1) x y)))))
|
||||
(define (tak9 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak10 (tak70 (- x 1) y z)
|
||||
(tak10 (- y 1) z x)
|
||||
(tak70 (- z 1) x y)))))
|
||||
(define (tak10 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak11 (tak7 (- x 1) y z)
|
||||
(tak21 (- y 1) z x)
|
||||
(tak87 (- z 1) x y)))))
|
||||
(define (tak11 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak12 (tak44 (- x 1) y z)
|
||||
(tak32 (- y 1) z x)
|
||||
(tak4 (- z 1) x y)))))
|
||||
(define (tak12 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak13 (tak81 (- x 1) y z)
|
||||
(tak43 (- y 1) z x)
|
||||
(tak21 (- z 1) x y)))))
|
||||
|
||||
(define (tak13 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak14 (tak18 (- x 1) y z)
|
||||
(tak54 (- y 1) z x)
|
||||
(tak38 (- z 1) x y)))))
|
||||
(define (tak14 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak15 (tak55 (- x 1) y z)
|
||||
(tak65 (- y 1) z x)
|
||||
(tak55 (- z 1) x y)))))
|
||||
(define (tak15 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak16 (tak92 (- x 1) y z)
|
||||
(tak76 (- y 1) z x)
|
||||
(tak72 (- z 1) x y)))))
|
||||
(define (tak16 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak17 (tak29 (- x 1) y z)
|
||||
(tak87 (- y 1) z x)
|
||||
(tak89 (- z 1) x y)))))
|
||||
(define (tak17 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak18 (tak66 (- x 1) y z)
|
||||
(tak98 (- y 1) z x)
|
||||
(tak6 (- z 1) x y)))))
|
||||
(define (tak18 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak19 (tak3 (- x 1) y z)
|
||||
(tak9 (- y 1) z x)
|
||||
(tak23 (- z 1) x y)))))
|
||||
(define (tak19 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak20 (tak40 (- x 1) y z)
|
||||
(tak20 (- y 1) z x)
|
||||
(tak40 (- z 1) x y)))))
|
||||
(define (tak20 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak21 (tak77 (- x 1) y z)
|
||||
(tak31 (- y 1) z x)
|
||||
(tak57 (- z 1) x y)))))
|
||||
(define (tak21 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak22 (tak14 (- x 1) y z)
|
||||
(tak42 (- y 1) z x)
|
||||
(tak74 (- z 1) x y)))))
|
||||
(define (tak22 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak23 (tak51 (- x 1) y z)
|
||||
(tak53 (- y 1) z x)
|
||||
(tak91 (- z 1) x y)))))
|
||||
(define (tak23 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak24 (tak88 (- x 1) y z)
|
||||
(tak64 (- y 1) z x)
|
||||
(tak8 (- z 1) x y)))))
|
||||
(define (tak24 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak25 (tak25 (- x 1) y z)
|
||||
(tak75 (- y 1) z x)
|
||||
(tak25 (- z 1) x y)))))
|
||||
(define (tak25 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak26 (tak62 (- x 1) y z)
|
||||
(tak86 (- y 1) z x)
|
||||
(tak42 (- z 1) x y)))))
|
||||
(define (tak26 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak27 (tak99 (- x 1) y z)
|
||||
(tak97 (- y 1) z x)
|
||||
(tak59 (- z 1) x y)))))
|
||||
(define (tak27 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak28 (tak36 (- x 1) y z)
|
||||
(tak8 (- y 1) z x)
|
||||
(tak76 (- z 1) x y)))))
|
||||
(define (tak28 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak29 (tak73 (- x 1) y z)
|
||||
(tak19 (- y 1) z x)
|
||||
(tak93 (- z 1) x y)))))
|
||||
(define (tak29 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak30 (tak10 (- x 1) y z)
|
||||
(tak30 (- y 1) z x)
|
||||
(tak10 (- z 1) x y)))))
|
||||
(define (tak30 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak31 (tak47 (- x 1) y z)
|
||||
(tak41 (- y 1) z x)
|
||||
(tak27 (- z 1) x y)))))
|
||||
(define (tak31 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak32 (tak84 (- x 1) y z)
|
||||
(tak52 (- y 1) z x)
|
||||
(tak44 (- z 1) x y)))))
|
||||
(define (tak32 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak33 (tak21 (- x 1) y z)
|
||||
(tak63 (- y 1) z x)
|
||||
(tak61 (- z 1) x y)))))
|
||||
(define (tak33 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak34 (tak58 (- x 1) y z)
|
||||
(tak74 (- y 1) z x)
|
||||
(tak78 (- z 1) x y)))))
|
||||
(define (tak34 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak35 (tak95 (- x 1) y z)
|
||||
(tak85 (- y 1) z x)
|
||||
(tak95 (- z 1) x y)))))
|
||||
(define (tak35 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak36 (tak32 (- x 1) y z)
|
||||
(tak96 (- y 1) z x)
|
||||
(tak12 (- z 1) x y)))))
|
||||
(define (tak36 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak37 (tak69 (- x 1) y z)
|
||||
(tak7 (- y 1) z x)
|
||||
(tak29 (- z 1) x y)))))
|
||||
(define (tak37 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak38 (tak6 (- x 1) y z)
|
||||
(tak18 (- y 1) z x)
|
||||
(tak46 (- z 1) x y)))))
|
||||
(define (tak38 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak39 (tak43 (- x 1) y z)
|
||||
(tak29 (- y 1) z x)
|
||||
(tak63 (- z 1) x y)))))
|
||||
(define (tak39 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak40 (tak80 (- x 1) y z)
|
||||
(tak40 (- y 1) z x)
|
||||
(tak80 (- z 1) x y)))))
|
||||
(define (tak40 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak41 (tak17 (- x 1) y z)
|
||||
(tak51 (- y 1) z x)
|
||||
(tak97 (- z 1) x y)))))
|
||||
(define (tak41 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak42 (tak54 (- x 1) y z)
|
||||
(tak62 (- y 1) z x)
|
||||
(tak14 (- z 1) x y)))))
|
||||
(define (tak42 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak43 (tak91 (- x 1) y z)
|
||||
(tak73 (- y 1) z x)
|
||||
(tak31 (- z 1) x y)))))
|
||||
(define (tak43 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak44 (tak28 (- x 1) y z)
|
||||
(tak84 (- y 1) z x)
|
||||
(tak48 (- z 1) x y)))))
|
||||
(define (tak44 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak45 (tak65 (- x 1) y z)
|
||||
(tak95 (- y 1) z x)
|
||||
(tak65 (- z 1) x y)))))
|
||||
(define (tak45 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak46 (tak2 (- x 1) y z)
|
||||
(tak6 (- y 1) z x)
|
||||
(tak82 (- z 1) x y)))))
|
||||
(define (tak46 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak47 (tak39 (- x 1) y z)
|
||||
(tak17 (- y 1) z x)
|
||||
(tak99 (- z 1) x y)))))
|
||||
(define (tak47 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak48 (tak76 (- x 1) y z)
|
||||
(tak28 (- y 1) z x)
|
||||
(tak16 (- z 1) x y)))))
|
||||
(define (tak48 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak49 (tak13 (- x 1) y z)
|
||||
(tak39 (- y 1) z x)
|
||||
(tak33 (- z 1) x y)))))
|
||||
(define (tak49 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak50 (tak50 (- x 1) y z)
|
||||
(tak50 (- y 1) z x)
|
||||
(tak50 (- z 1) x y)))))
|
||||
(define (tak50 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak51 (tak87 (- x 1) y z)
|
||||
(tak61 (- y 1) z x)
|
||||
(tak67 (- z 1) x y)))))
|
||||
(define (tak51 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak52 (tak24 (- x 1) y z)
|
||||
(tak72 (- y 1) z x)
|
||||
(tak84 (- z 1) x y)))))
|
||||
(define (tak52 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak53 (tak61 (- x 1) y z)
|
||||
(tak83 (- y 1) z x)
|
||||
(tak1 (- z 1) x y)))))
|
||||
(define (tak53 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak54 (tak98 (- x 1) y z)
|
||||
(tak94 (- y 1) z x)
|
||||
(tak18 (- z 1) x y)))))
|
||||
(define (tak54 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak55 (tak35 (- x 1) y z)
|
||||
(tak5 (- y 1) z x)
|
||||
(tak35 (- z 1) x y)))))
|
||||
(define (tak55 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak56 (tak72 (- x 1) y z)
|
||||
(tak16 (- y 1) z x)
|
||||
(tak52 (- z 1) x y)))))
|
||||
(define (tak56 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak57 (tak9 (- x 1) y z)
|
||||
(tak27 (- y 1) z x)
|
||||
(tak69 (- z 1) x y)))))
|
||||
(define (tak57 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak58 (tak46 (- x 1) y z)
|
||||
(tak38 (- y 1) z x)
|
||||
(tak86 (- z 1) x y)))))
|
||||
(define (tak58 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak59 (tak83 (- x 1) y z)
|
||||
(tak49 (- y 1) z x)
|
||||
(tak3 (- z 1) x y)))))
|
||||
(define (tak59 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak60 (tak20 (- x 1) y z)
|
||||
(tak60 (- y 1) z x)
|
||||
(tak20 (- z 1) x y)))))
|
||||
(define (tak60 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak61 (tak57 (- x 1) y z)
|
||||
(tak71 (- y 1) z x)
|
||||
(tak37 (- z 1) x y)))))
|
||||
(define (tak61 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak62 (tak94 (- x 1) y z)
|
||||
(tak82 (- y 1) z x)
|
||||
(tak54 (- z 1) x y)))))
|
||||
(define (tak62 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak63 (tak31 (- x 1) y z)
|
||||
(tak93 (- y 1) z x)
|
||||
(tak71 (- z 1) x y)))))
|
||||
(define (tak63 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak64 (tak68 (- x 1) y z)
|
||||
(tak4 (- y 1) z x)
|
||||
(tak88 (- z 1) x y)))))
|
||||
(define (tak64 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak65 (tak5 (- x 1) y z)
|
||||
(tak15 (- y 1) z x)
|
||||
(tak5 (- z 1) x y)))))
|
||||
(define (tak65 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak66 (tak42 (- x 1) y z)
|
||||
(tak26 (- y 1) z x)
|
||||
(tak22 (- z 1) x y)))))
|
||||
(define (tak66 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak67 (tak79 (- x 1) y z)
|
||||
(tak37 (- y 1) z x)
|
||||
(tak39 (- z 1) x y)))))
|
||||
(define (tak67 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak68 (tak16 (- x 1) y z)
|
||||
(tak48 (- y 1) z x)
|
||||
(tak56 (- z 1) x y)))))
|
||||
(define (tak68 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak69 (tak53 (- x 1) y z)
|
||||
(tak59 (- y 1) z x)
|
||||
(tak73 (- z 1) x y)))))
|
||||
(define (tak69 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak70 (tak90 (- x 1) y z)
|
||||
(tak70 (- y 1) z x)
|
||||
(tak90 (- z 1) x y)))))
|
||||
(define (tak70 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak71 (tak27 (- x 1) y z)
|
||||
(tak81 (- y 1) z x)
|
||||
(tak7 (- z 1) x y)))))
|
||||
(define (tak71 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak72 (tak64 (- x 1) y z)
|
||||
(tak92 (- y 1) z x)
|
||||
(tak24 (- z 1) x y)))))
|
||||
(define (tak72 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak73 (tak1 (- x 1) y z)
|
||||
(tak3 (- y 1) z x)
|
||||
(tak41 (- z 1) x y)))))
|
||||
(define (tak73 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak74 (tak38 (- x 1) y z)
|
||||
(tak14 (- y 1) z x)
|
||||
(tak58 (- z 1) x y)))))
|
||||
(define (tak74 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak75 (tak75 (- x 1) y z)
|
||||
(tak25 (- y 1) z x)
|
||||
(tak75 (- z 1) x y)))))
|
||||
(define (tak75 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak76 (tak12 (- x 1) y z)
|
||||
(tak36 (- y 1) z x)
|
||||
(tak92 (- z 1) x y)))))
|
||||
(define (tak76 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak77 (tak49 (- x 1) y z)
|
||||
(tak47 (- y 1) z x)
|
||||
(tak9 (- z 1) x y)))))
|
||||
(define (tak77 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak78 (tak86 (- x 1) y z)
|
||||
(tak58 (- y 1) z x)
|
||||
(tak26 (- z 1) x y)))))
|
||||
(define (tak78 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak79 (tak23 (- x 1) y z)
|
||||
(tak69 (- y 1) z x)
|
||||
(tak43 (- z 1) x y)))))
|
||||
(define (tak79 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak80 (tak60 (- x 1) y z)
|
||||
(tak80 (- y 1) z x)
|
||||
(tak60 (- z 1) x y)))))
|
||||
(define (tak80 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak81 (tak97 (- x 1) y z)
|
||||
(tak91 (- y 1) z x)
|
||||
(tak77 (- z 1) x y)))))
|
||||
(define (tak81 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak82 (tak34 (- x 1) y z)
|
||||
(tak2 (- y 1) z x)
|
||||
(tak94 (- z 1) x y)))))
|
||||
(define (tak82 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak83 (tak71 (- x 1) y z)
|
||||
(tak13 (- y 1) z x)
|
||||
(tak11 (- z 1) x y)))))
|
||||
(define (tak83 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak84 (tak8 (- x 1) y z)
|
||||
(tak24 (- y 1) z x)
|
||||
(tak28 (- z 1) x y)))))
|
||||
(define (tak84 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak85 (tak45 (- x 1) y z)
|
||||
(tak35 (- y 1) z x)
|
||||
(tak45 (- z 1) x y)))))
|
||||
(define (tak85 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak86 (tak82 (- x 1) y z)
|
||||
(tak46 (- y 1) z x)
|
||||
(tak62 (- z 1) x y)))))
|
||||
(define (tak86 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak87 (tak19 (- x 1) y z)
|
||||
(tak57 (- y 1) z x)
|
||||
(tak79 (- z 1) x y)))))
|
||||
(define (tak87 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak88 (tak56 (- x 1) y z)
|
||||
(tak68 (- y 1) z x)
|
||||
(tak96 (- z 1) x y)))))
|
||||
(define (tak88 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak89 (tak93 (- x 1) y z)
|
||||
(tak79 (- y 1) z x)
|
||||
(tak13 (- z 1) x y)))))
|
||||
(define (tak89 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak90 (tak30 (- x 1) y z)
|
||||
(tak90 (- y 1) z x)
|
||||
(tak30 (- z 1) x y)))))
|
||||
(define (tak90 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak91 (tak67 (- x 1) y z)
|
||||
(tak1 (- y 1) z x)
|
||||
(tak47 (- z 1) x y)))))
|
||||
(define (tak91 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak92 (tak4 (- x 1) y z)
|
||||
(tak12 (- y 1) z x)
|
||||
(tak64 (- z 1) x y)))))
|
||||
(define (tak92 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak93 (tak41 (- x 1) y z)
|
||||
(tak23 (- y 1) z x)
|
||||
(tak81 (- z 1) x y)))))
|
||||
(define (tak93 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak94 (tak78 (- x 1) y z)
|
||||
(tak34 (- y 1) z x)
|
||||
(tak98 (- z 1) x y)))))
|
||||
(define (tak94 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak95 (tak15 (- x 1) y z)
|
||||
(tak45 (- y 1) z x)
|
||||
(tak15 (- z 1) x y)))))
|
||||
(define (tak95 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak96 (tak52 (- x 1) y z)
|
||||
(tak56 (- y 1) z x)
|
||||
(tak32 (- z 1) x y)))))
|
||||
(define (tak96 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak97 (tak89 (- x 1) y z)
|
||||
(tak67 (- y 1) z x)
|
||||
(tak49 (- z 1) x y)))))
|
||||
(define (tak97 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak98 (tak26 (- x 1) y z)
|
||||
(tak78 (- y 1) z x)
|
||||
(tak66 (- z 1) x y)))))
|
||||
(define (tak98 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak99 (tak63 (- x 1) y z)
|
||||
(tak89 (- y 1) z x)
|
||||
(tak83 (- z 1) x y)))))
|
||||
(define (tak99 x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak0 (tak0 (- x 1) y z)
|
||||
(tak0 (- y 1) z x)
|
||||
(tak0 (- z 1) x y)))))
|
||||
|
||||
;;; call: (tak0 18 12 6)
|
||||
|
||||
(time (tak0 18 12 2))
|
||||
|
2
collects/tests/mzscheme/benchmarks/common/takr.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/takr.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module takr "wrap.ss")
|
158
collects/tests/mzscheme/benchmarks/common/traverse.sch
Normal file
158
collects/tests/mzscheme/benchmarks/common/traverse.sch
Normal file
|
@ -0,0 +1,158 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; File: traverse.sch
|
||||
; Description: TRAVERSE benchmark
|
||||
; Author: Richard Gabriel
|
||||
; Created: 12-Apr-85
|
||||
; Modified: 12-Apr-85 10:24:04 (Bob Shaw)
|
||||
; 9-Aug-87 (Will Clinger)
|
||||
; Language: Scheme (but see note)
|
||||
; Status: Public Domain
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
; Note: This benchmark may depend upon the empty list being the same
|
||||
; as #f.
|
||||
|
||||
;;; TRAVERSE -- Benchmark which creates and traverses a tree structure.
|
||||
|
||||
(define (make-node)
|
||||
(let ((node (make-vector 11 '())))
|
||||
(vector-set! node 0 'node)
|
||||
(vector-set! node 3 (snb))
|
||||
node))
|
||||
|
||||
(define (node-parents node) (vector-ref node 1))
|
||||
(define (node-sons node) (vector-ref node 2))
|
||||
(define (node-sn node) (vector-ref node 3))
|
||||
(define (node-entry1 node) (vector-ref node 4))
|
||||
(define (node-entry2 node) (vector-ref node 5))
|
||||
(define (node-entry3 node) (vector-ref node 6))
|
||||
(define (node-entry4 node) (vector-ref node 7))
|
||||
(define (node-entry5 node) (vector-ref node 8))
|
||||
(define (node-entry6 node) (vector-ref node 9))
|
||||
(define (node-mark node) (vector-ref node 10))
|
||||
|
||||
(define (node-parents-set! node v) (vector-set! node 1 v))
|
||||
(define (node-sons-set! node v) (vector-set! node 2 v))
|
||||
(define (node-sn-set! node v) (vector-set! node 3 v))
|
||||
(define (node-entry1-set! node v) (vector-set! node 4 v))
|
||||
(define (node-entry2-set! node v) (vector-set! node 5 v))
|
||||
(define (node-entry3-set! node v) (vector-set! node 6 v))
|
||||
(define (node-entry4-set! node v) (vector-set! node 7 v))
|
||||
(define (node-entry5-set! node v) (vector-set! node 8 v))
|
||||
(define (node-entry6-set! node v) (vector-set! node 9 v))
|
||||
(define (node-mark-set! node v) (vector-set! node 10 v))
|
||||
|
||||
(define *sn* 0)
|
||||
(define *rand* 21)
|
||||
(define *count* 0)
|
||||
(define *marker* #f)
|
||||
(define *root* '())
|
||||
|
||||
(define (snb)
|
||||
(set! *sn* (+ 1 *sn*))
|
||||
*sn*)
|
||||
|
||||
(define (seed)
|
||||
(set! *rand* 21)
|
||||
*rand*)
|
||||
|
||||
(define (traverse-random)
|
||||
(set! *rand* (remainder (* *rand* 17) 251))
|
||||
*rand*)
|
||||
|
||||
(define (traverse-remove n q)
|
||||
(cond ((eq? (cdr (car q)) (car q))
|
||||
(let ((x (caar q))) (set-car! q #f) x))
|
||||
((zero? n)
|
||||
(let ((x (caar q)))
|
||||
(do ((p (car q) (cdr p)))
|
||||
((eq? (cdr p) (car q))
|
||||
(set-cdr! p (cdr (car q)))
|
||||
(set-car! q p)))
|
||||
x))
|
||||
(else (do ((n n (- n 1))
|
||||
(q (car q) (cdr q))
|
||||
(p (cdr (car q)) (cdr p)))
|
||||
((zero? n) (let ((x (car q))) (set-cdr! q p) x))))))
|
||||
|
||||
(define (traverse-select n q)
|
||||
(do ((n n (- n 1))
|
||||
(q (car q) (cdr q)))
|
||||
((zero? n) (car q))))
|
||||
|
||||
(define (add a q)
|
||||
(cond ((null? q)
|
||||
`(,(let ((x `(,a)))
|
||||
(set-cdr! x x) x)))
|
||||
((null? (car q))
|
||||
(let ((x `(,a)))
|
||||
(set-cdr! x x)
|
||||
(set-car! q x)
|
||||
q))
|
||||
; the CL version had a useless set-car! in the next line (wc)
|
||||
(else (set-cdr! (car q) `(,a . ,(cdr (car q))))
|
||||
q)))
|
||||
|
||||
(define (create-structure n)
|
||||
(let ((a `(,(make-node))))
|
||||
(do ((m (- n 1) (- m 1))
|
||||
(p a))
|
||||
((zero? m)
|
||||
(set! a `(,(begin (set-cdr! p a) p)))
|
||||
(do ((unused a)
|
||||
(used (add (traverse-remove 0 a) #f))
|
||||
(x 0)
|
||||
(y 0))
|
||||
((null? (car unused))
|
||||
(find-root (traverse-select 0 used) n))
|
||||
(set! x (traverse-remove (remainder (traverse-random) n) unused))
|
||||
(set! y (traverse-select (remainder (traverse-random) n) used))
|
||||
(add x used)
|
||||
(node-sons-set! y `(,x . ,(node-sons y)))
|
||||
(node-parents-set! x `(,y . ,(node-parents x))) ))
|
||||
(set! a (cons (make-node) a)))))
|
||||
|
||||
(define (find-root node n)
|
||||
(do ((n n (- n 1)))
|
||||
((or (zero? n) (null? (node-parents node)))
|
||||
node)
|
||||
(set! node (car (node-parents node)))))
|
||||
|
||||
(define (travers node mark)
|
||||
(cond ((eq? (node-mark node) mark) #f)
|
||||
(else (node-mark-set! node mark)
|
||||
(set! *count* (+ 1 *count*))
|
||||
(node-entry1-set! node (not (node-entry1 node)))
|
||||
(node-entry2-set! node (not (node-entry2 node)))
|
||||
(node-entry3-set! node (not (node-entry3 node)))
|
||||
(node-entry4-set! node (not (node-entry4 node)))
|
||||
(node-entry5-set! node (not (node-entry5 node)))
|
||||
(node-entry6-set! node (not (node-entry6 node)))
|
||||
(do ((sons (node-sons node) (cdr sons)))
|
||||
((null? sons) #f)
|
||||
(travers (car sons) mark)))))
|
||||
|
||||
(define (traverse root)
|
||||
(let ((*count* 0))
|
||||
(travers root (begin (set! *marker* (not *marker*)) *marker*))
|
||||
*count*))
|
||||
|
||||
(define (init-traverse) ; Changed from defmacro to defun \bs
|
||||
(set! *root* (create-structure 100))
|
||||
#f)
|
||||
|
||||
(define (run-traverse) ; Changed from defmacro to defun \bs
|
||||
(do ((i 50 (- i 1)))
|
||||
((zero? i))
|
||||
(traverse *root*)
|
||||
(traverse *root*)
|
||||
(traverse *root*)
|
||||
(traverse *root*)
|
||||
(traverse *root*)))
|
||||
|
||||
;;; to initialize, call: (init-traverse)
|
||||
;;; to run traverse, call: (run-traverse)
|
||||
|
||||
(time (init-traverse))
|
||||
(time (run-traverse))
|
||||
|
84
collects/tests/mzscheme/benchmarks/common/triangle.sch
Normal file
84
collects/tests/mzscheme/benchmarks/common/triangle.sch
Normal file
|
@ -0,0 +1,84 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; File: triangle.sch
|
||||
; Description: TRIANGLE benchmark
|
||||
; Author: Richard Gabriel
|
||||
; Created: 12-Apr-85
|
||||
; Modified: 12-Apr-85 10:30:32 (Bob Shaw)
|
||||
; 11-Aug-87 (Will Clinger)
|
||||
; 22-Jan-88 (Will Clinger)
|
||||
; Language: Scheme
|
||||
; Status: Public Domain
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;;; TRIANG -- Board game benchmark.
|
||||
|
||||
(define *board* (make-vector 16 1))
|
||||
(define *sequence* (make-vector 14 0))
|
||||
(define *a* (make-vector 37))
|
||||
(for-each (lambda (i x) (vector-set! *a* i x))
|
||||
'(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
||||
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36)
|
||||
'(1 2 4 3 5 6 1 3 6 2 5 4 11 12
|
||||
13 7 8 4 4 7 11 8 12 13 6 10
|
||||
15 9 14 13 13 14 15 9 10
|
||||
6 6))
|
||||
(define *b* (make-vector 37))
|
||||
(for-each (lambda (i x) (vector-set! *b* i x))
|
||||
'(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
||||
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36)
|
||||
'(2 4 7 5 8 9 3 6 10 5 9 8
|
||||
12 13 14 8 9 5 2 4 7 5 8
|
||||
9 3 6 10 5 9 8 12 13 14
|
||||
8 9 5 5))
|
||||
(define *c* (make-vector 37))
|
||||
(for-each (lambda (i x) (vector-set! *c* i x))
|
||||
'(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
||||
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36)
|
||||
'(4 7 11 8 12 13 6 10 15 9 14 13
|
||||
13 14 15 9 10 6 1 2 4 3 5 6 1
|
||||
3 6 2 5 4 11 12 13 7 8 4 4))
|
||||
(define *answer* '())
|
||||
(define *final* '())
|
||||
(vector-set! *board* 5 0)
|
||||
|
||||
(define (last-position)
|
||||
(do ((i 1 (+ i 1)))
|
||||
((or (= i 16) (= 1 (vector-ref *board* i)))
|
||||
(if (= i 16) 0 i))))
|
||||
|
||||
(define (try i depth)
|
||||
(cond ((= depth 14)
|
||||
(let ((lp (last-position)))
|
||||
(if (not (member lp *final*))
|
||||
(set! *final* (cons lp *final*))))
|
||||
(set! *answer*
|
||||
(cons (cdr (vector->list *sequence*)) *answer*))
|
||||
#t)
|
||||
((and (= 1 (vector-ref *board* (vector-ref *a* i)))
|
||||
(= 1 (vector-ref *board* (vector-ref *b* i)))
|
||||
(= 0 (vector-ref *board* (vector-ref *c* i))))
|
||||
(vector-set! *board* (vector-ref *a* i) 0)
|
||||
(vector-set! *board* (vector-ref *b* i) 0)
|
||||
(vector-set! *board* (vector-ref *c* i) 1)
|
||||
(vector-set! *sequence* depth i)
|
||||
(do ((j 0 (+ j 1))
|
||||
(depth (+ depth 1)))
|
||||
((or (= j 36) (try j depth)) #f))
|
||||
(vector-set! *board* (vector-ref *a* i) 1)
|
||||
(vector-set! *board* (vector-ref *b* i) 1)
|
||||
(vector-set! *board* (vector-ref *c* i) 0) '())
|
||||
(else #f)))
|
||||
|
||||
(define (gogogo i)
|
||||
(let ((*answer* '())
|
||||
(*final* '()))
|
||||
(try i 1)))
|
||||
|
||||
;;; call: (gogogo 22))
|
||||
|
||||
(time (let loop ([n 10000])
|
||||
(if (zero? n)
|
||||
'done
|
||||
(begin
|
||||
(gogogo 22)
|
||||
(loop (sub1 n))))))
|
2
collects/tests/mzscheme/benchmarks/common/triangle.ss
Normal file
2
collects/tests/mzscheme/benchmarks/common/triangle.ss
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
(module triangle "wrap.ss")
|
7
collects/tests/mzscheme/benchmarks/common/wrap.ss
Normal file
7
collects/tests/mzscheme/benchmarks/common/wrap.ss
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
(module wrap mzscheme
|
||||
(provide (rename module-begin #%module-begin))
|
||||
(require (lib "include.ss"))
|
||||
(define-syntax (module-begin stx)
|
||||
(let ([name (syntax-property stx 'enclosing-module-name)])
|
||||
#`(#%plain-module-begin (include #,(format "~a.sch" name))))))
|
11
collects/tests/mzscheme/benchmarks/mz/expand-class.scm
Normal file
11
collects/tests/mzscheme/benchmarks/mz/expand-class.scm
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
(let ([dir (build-path (collection-path "mzlib")
|
||||
"private")])
|
||||
(with-input-from-file (build-path dir "class-internal.ss")
|
||||
(lambda ()
|
||||
(parameterize ([current-load-relative-directory dir])
|
||||
(let ([s (read-syntax)])
|
||||
(time (compile s)))))))
|
||||
|
||||
|
||||
|
12
collects/tests/mzscheme/benchmarks/mz/input.xml
Normal file
12
collects/tests/mzscheme/benchmarks/mz/input.xml
Normal file
File diff suppressed because one or more lines are too long
43
collects/tests/mzscheme/benchmarks/mz/parsing.scm
Normal file
43
collects/tests/mzscheme/benchmarks/mz/parsing.scm
Normal file
|
@ -0,0 +1,43 @@
|
|||
(require (lib "scheme-lexer.ss" "syntax-color"))
|
||||
|
||||
(define path "~/proj/plt/collects/framework/private/frame.ss")
|
||||
|
||||
(define content
|
||||
(with-input-from-file path
|
||||
(lambda ()
|
||||
(read-bytes (file-size path)))))
|
||||
|
||||
(define e (make-object text%))
|
||||
(send e load-file path)
|
||||
|
||||
(define (mk-p)
|
||||
;#;
|
||||
(open-input-text-editor e)
|
||||
#;
|
||||
(open-input-bytes content)
|
||||
#;
|
||||
(open-input-string (send e get-text 0 'eof)))
|
||||
|
||||
(let loop ([n 10])
|
||||
(unless (zero? n)
|
||||
(printf "lexing~n")
|
||||
(time
|
||||
(let ([p (mk-p)])
|
||||
(port-count-lines! p)
|
||||
(time
|
||||
(let loop ()
|
||||
(let-values ([(a b c d e) (scheme-lexer p)])
|
||||
(unless (eq? 'eof b)
|
||||
(loop)))))))
|
||||
(printf "reading~n")
|
||||
(time
|
||||
(let ([p (mk-p)])
|
||||
(port-count-lines! p)
|
||||
(time
|
||||
(let loop ()
|
||||
(let ([v (read p)])
|
||||
(unless (eof-object? v)
|
||||
(loop)))))))
|
||||
(printf "done~n")
|
||||
(loop (sub1 n))))
|
||||
|
6
collects/tests/mzscheme/benchmarks/mz/redsem.scm
Normal file
6
collects/tests/mzscheme/benchmarks/mz/redsem.scm
Normal file
|
@ -0,0 +1,6 @@
|
|||
(require (planet "beginner.ss" ("robby" "redex.plt") "examples"))
|
||||
(collect-garbage)
|
||||
(printf "Now\n")
|
||||
(time (begin
|
||||
(run-tests) (run-tests) (run-tests) (run-tests) (run-tests)
|
||||
))
|
8
collects/tests/mzscheme/benchmarks/mz/ssax.scm
Normal file
8
collects/tests/mzscheme/benchmarks/mz/ssax.scm
Normal file
|
@ -0,0 +1,8 @@
|
|||
(require (planet "ssax.ss" ("lizorkin" "ssax.plt" 1 3)))
|
||||
|
||||
(collect-garbage)
|
||||
(time (void (ssax:xml->sxml
|
||||
(open-input-file (build-path
|
||||
(current-load-relative-directory)
|
||||
"input.xml"))
|
||||
null)))
|
4
collects/tests/mzscheme/benchmarks/shootout/README.txt
Normal file
4
collects/tests/mzscheme/benchmarks/shootout/README.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
The program "run" should kknow how to run each benchmark with its
|
||||
standard input value. So run <benchmark.ss> like this:
|
||||
|
||||
mzscheme -qu run.ss <benchmark.ss>
|
13
collects/tests/mzscheme/benchmarks/shootout/ackermann.ss
Normal file
13
collects/tests/mzscheme/benchmarks/shootout/ackermann.ss
Normal file
|
@ -0,0 +1,13 @@
|
|||
(module ackermann mzscheme
|
||||
(define (ack m n)
|
||||
(cond ((zero? m) (+ n 1))
|
||||
((zero? n) (ack (- m 1) 1))
|
||||
(else (ack (- m 1) (ack m (- n 1))))))
|
||||
|
||||
(define (main args)
|
||||
(let ((n (if (= (vector-length args) 0)
|
||||
1
|
||||
(string->number (vector-ref args 0)))))
|
||||
(printf "Ack(3,~a): ~a~n" n (ack 3 n))))
|
||||
|
||||
(main (current-command-line-arguments)))
|
21
collects/tests/mzscheme/benchmarks/shootout/ary.ss
Normal file
21
collects/tests/mzscheme/benchmarks/shootout/ary.ss
Normal file
|
@ -0,0 +1,21 @@
|
|||
(module ary mzscheme
|
||||
(define (main args)
|
||||
(let* ((n (if (= (vector-length args) 0)
|
||||
1
|
||||
(string->number (vector-ref args 0))))
|
||||
(x (make-vector n 0))
|
||||
(y (make-vector n 0))
|
||||
(last (- n 1)))
|
||||
(do ((i 0 (+ i 1)))
|
||||
((= i n))
|
||||
(vector-set! x i (+ i 1)))
|
||||
(do ((k 0 (+ k 1)))
|
||||
((= k 1000))
|
||||
(do ((i last (- i 1)))
|
||||
((< i 0))
|
||||
(vector-set! y i (+ (vector-ref x i) (vector-ref y i)))))
|
||||
(print-list (vector-ref y 0) " " (vector-ref y last))))
|
||||
|
||||
(define (print-list . items) (for-each display items) (newline))
|
||||
|
||||
(main (current-command-line-arguments)))
|
45
collects/tests/mzscheme/benchmarks/shootout/binarytrees.ss
Normal file
45
collects/tests/mzscheme/benchmarks/shootout/binarytrees.ss
Normal file
|
@ -0,0 +1,45 @@
|
|||
;;; The Great Computer Language Shootout
|
||||
;;; http://shootout.alioth.debian.org/
|
||||
;;; Derived from the Chicken variant by Sven Hartrumpf
|
||||
|
||||
(module binarytrees mzscheme
|
||||
|
||||
(define-struct node (left val right))
|
||||
(define-struct leaf (val))
|
||||
|
||||
(define (make item d)
|
||||
(if (= d 0)
|
||||
(make-leaf item)
|
||||
(let ((item2 (* item 2))
|
||||
(d2 (- d 1)))
|
||||
(make-node (make (- item2 1) d2) item (make item2 d2)))))
|
||||
|
||||
(define (check t)
|
||||
(if (leaf? t)
|
||||
(leaf-val t)
|
||||
(+ (node-val t) (- (check (node-left t)) (check (node-right t))))))
|
||||
|
||||
(define (main argv)
|
||||
(let* ((min-depth 4)
|
||||
(max-depth (max (+ min-depth 2) (string->number (vector-ref argv 0)))))
|
||||
(let ((stretch-depth (+ max-depth 1)))
|
||||
(printf "stretch tree of depth ~a\t check: ~a\n"
|
||||
stretch-depth
|
||||
(check (make 0 stretch-depth))))
|
||||
(let ((long-lived-tree (make 0 max-depth)))
|
||||
(do ((d 4 (+ d 2))
|
||||
(c 0 0))
|
||||
((> d max-depth))
|
||||
(let ((iterations (arithmetic-shift 1 (+ (- max-depth d) min-depth))))
|
||||
(do ((i 0 (+ i 1)))
|
||||
((>= i iterations))
|
||||
(set! c (+ c (check (make i d)) (check (make (- i) d)))))
|
||||
(printf "~a\t trees of depth ~a\t check: ~a\n"
|
||||
(* 2 iterations)
|
||||
d
|
||||
c)))
|
||||
(printf "long lived tree of depth ~a\t check: ~a\n"
|
||||
max-depth
|
||||
(check long-lived-tree)))))
|
||||
|
||||
(main (current-command-line-arguments)))
|
55
collects/tests/mzscheme/benchmarks/shootout/chameneos.ss
Normal file
55
collects/tests/mzscheme/benchmarks/shootout/chameneos.ss
Normal file
|
@ -0,0 +1,55 @@
|
|||
;;; The Great Computer Language Shootout
|
||||
;;; http://shootout.alioth.debian.org/
|
||||
|
||||
(module chameneos mzscheme
|
||||
|
||||
(define (change c1 c2)
|
||||
(case c1
|
||||
[(red)
|
||||
(case c2 [(blue) 'yellow] [(yellow) 'blue] [else c1])]
|
||||
[(yellow)
|
||||
(case c2 [(blue) 'red] [(red) 'blue] [else c1])]
|
||||
[(blue)
|
||||
(case c2 [(yellow) 'red] [(red) 'yellow] [else c1])]))
|
||||
|
||||
(define (place meeting-ch n)
|
||||
(thread
|
||||
(lambda ()
|
||||
(let loop ([n n])
|
||||
(if (zero? n)
|
||||
;; Fade all:
|
||||
(let loop ()
|
||||
(let ([c (channel-get meeting-ch)])
|
||||
(channel-put (car c) #f)
|
||||
(loop)))
|
||||
;; Let two meet:
|
||||
(let ([c1 (channel-get meeting-ch)]
|
||||
[c2 (channel-get meeting-ch)])
|
||||
(channel-put (car c1) (cdr c2))
|
||||
(channel-put (car c2) (cdr c1))
|
||||
(loop (sub1 n))))))))
|
||||
|
||||
(define (creature color meeting-ch result-ch)
|
||||
(thread
|
||||
(lambda ()
|
||||
(let ([ch (make-channel)])
|
||||
(let loop ([color color][met 0])
|
||||
(channel-put meeting-ch (cons ch color))
|
||||
(let ([other-color (channel-get ch)])
|
||||
(if other-color
|
||||
;; Meet:
|
||||
(loop (change color other-color) (add1 met))
|
||||
;; Done:
|
||||
(channel-put result-ch met))))))))
|
||||
|
||||
(let ([result-ch (make-channel)]
|
||||
[meeting-ch (make-channel)])
|
||||
(place meeting-ch (string->number (vector-ref (current-command-line-arguments) 0)))
|
||||
(creature 'blue meeting-ch result-ch)
|
||||
(creature 'red meeting-ch result-ch)
|
||||
(creature 'yellow meeting-ch result-ch)
|
||||
(creature 'blue meeting-ch result-ch)
|
||||
(printf "~a\n" (+ (channel-get result-ch)
|
||||
(channel-get result-ch)
|
||||
(channel-get result-ch)
|
||||
(channel-get result-ch)))))
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
(module cheapconcurrency mzscheme
|
||||
|
||||
(define (generate receive-ch n)
|
||||
(if (zero? n)
|
||||
receive-ch
|
||||
(let ([ch (make-channel)])
|
||||
(thread (lambda ()
|
||||
(let loop ()
|
||||
(channel-put ch (add1 (channel-get receive-ch)))
|
||||
(loop))))
|
||||
(generate ch (sub1 n)))))
|
||||
|
||||
(let ([n (string->number
|
||||
(vector-ref (current-command-line-arguments) 0))])
|
||||
(let* ([start-ch (make-channel)]
|
||||
[end-ch (generate start-ch 500)])
|
||||
(let loop ([n n][total 0])
|
||||
(if (zero? n)
|
||||
(printf "~a\n" total)
|
||||
(begin
|
||||
(channel-put start-ch 0)
|
||||
(loop (sub1 n)
|
||||
(+ total (channel-get end-ch)))))))))
|
45
collects/tests/mzscheme/benchmarks/shootout/echo.ss
Normal file
45
collects/tests/mzscheme/benchmarks/shootout/echo.ss
Normal file
|
@ -0,0 +1,45 @@
|
|||
(module echo mzscheme
|
||||
(define PORT 8888)
|
||||
(define DATA "Hello there sailor\n")
|
||||
(define n 10)
|
||||
|
||||
(define (server)
|
||||
(thread client)
|
||||
(let-values ([(in out) (tcp-accept (tcp-listen PORT 5 #t))]
|
||||
[(buffer) (make-string (string-length DATA))])
|
||||
(file-stream-buffer-mode out 'none)
|
||||
(let loop ([i (read-string! buffer in)]
|
||||
[bytes 0])
|
||||
(if (not (eof-object? i))
|
||||
(begin
|
||||
(display buffer out)
|
||||
(loop (read-string! buffer in)
|
||||
(+ bytes (string-length buffer))))
|
||||
(begin
|
||||
(display "server processed ")
|
||||
(display bytes)
|
||||
(display " bytes\n"))))))
|
||||
|
||||
(define (client)
|
||||
(let-values ([(in out) (tcp-connect "127.0.0.1" PORT)]
|
||||
[(buffer) (make-string (string-length DATA))])
|
||||
(file-stream-buffer-mode out 'none)
|
||||
(let loop ([n n])
|
||||
(if (> n 0)
|
||||
(begin
|
||||
(display DATA out)
|
||||
(let ([i (read-string! buffer in)])
|
||||
(begin
|
||||
(if (equal? DATA buffer)
|
||||
(loop (- n 1))
|
||||
'error))))
|
||||
(close-output-port out)))))
|
||||
|
||||
(define (main args)
|
||||
(set! n
|
||||
(if (= (vector-length args) 0)
|
||||
1
|
||||
(string->number (vector-ref args 0))))
|
||||
(server))
|
||||
|
||||
(main (current-command-line-arguments)))
|
36
collects/tests/mzscheme/benchmarks/shootout/except.ss
Normal file
36
collects/tests/mzscheme/benchmarks/shootout/except.ss
Normal file
|
@ -0,0 +1,36 @@
|
|||
(module except mzscheme
|
||||
(define HI 0)
|
||||
(define LO 0)
|
||||
|
||||
(define (hi-excp? x) (eq? x 'Hi_Exception))
|
||||
(define (lo-excp? x) (eq? x 'Lo_Exception))
|
||||
(define (true? x) (if (boolean? x) x #t))
|
||||
|
||||
(define (some_fun n)
|
||||
(with-handlers
|
||||
([true? (lambda (exn) #f)])
|
||||
(hi_fun n)))
|
||||
|
||||
(define (hi_fun n)
|
||||
(with-handlers
|
||||
([hi-excp? (lambda (exn) (set! HI (+ HI 1))) ])
|
||||
(lo_fun n)))
|
||||
|
||||
(define (lo_fun n)
|
||||
(with-handlers
|
||||
([lo-excp? (lambda (exn) (set! LO (+ LO 1))) ])
|
||||
(blowup n)))
|
||||
|
||||
(define (blowup n)
|
||||
(if (= 0 (modulo n 2))
|
||||
(raise 'Hi_Exception)
|
||||
(raise 'Lo_Exception)))
|
||||
|
||||
(define (main args)
|
||||
(let* ((n (if (= (vector-length args) 1) (string->number (vector-ref args 0)) 1)))
|
||||
(do ((i 0 (+ i 1)))
|
||||
((= i n))
|
||||
(some_fun i)))
|
||||
(printf "Exceptions: HI=~a / LO=~a~n" HI LO))
|
||||
|
||||
(main (current-command-line-arguments)))
|
86
collects/tests/mzscheme/benchmarks/shootout/fannkuch.ss
Normal file
86
collects/tests/mzscheme/benchmarks/shootout/fannkuch.ss
Normal file
|
@ -0,0 +1,86 @@
|
|||
#!/usr/bin/mzscheme -qu
|
||||
;; fannkuch benchmark for The Computer Language Shootout
|
||||
;; Written by Dima Dorfman, 2004
|
||||
;; Slightly improved by Sven Hartrumpf, 2005-2006
|
||||
;;
|
||||
;; Ever-so-slightly tweaked for MzScheme by Brent Fulgham
|
||||
|
||||
(module fannkuch mzscheme
|
||||
(define vector-for-each (lambda (pred v)
|
||||
(do ((i 0 (add1 i))
|
||||
(v-length (vector-length v)))
|
||||
((>= i v-length))
|
||||
(pred (vector-ref v i)))))
|
||||
|
||||
(define (vector-reverse-slice! v i j)
|
||||
(do ((i i (add1 i))
|
||||
(j (sub1 j) (sub1 j))) ; exclude position j
|
||||
((<= j i))
|
||||
(vector-swap! v i j)))
|
||||
|
||||
(define (vector-swap! v i j)
|
||||
(let ((t (vector-ref v i)))
|
||||
(vector-set! v i (vector-ref v j))
|
||||
(vector-set! v j t)))
|
||||
|
||||
(define (count-flips pi)
|
||||
(do ((rho (vector-copy pi))
|
||||
(i 0 (add1 i)))
|
||||
((= (vector-ref rho 0) 0) i)
|
||||
(vector-reverse-slice! rho 0 (add1 (vector-ref rho 0)))))
|
||||
|
||||
(define (vector-copy source)
|
||||
(do ((vec (make-vector (vector-length source)))
|
||||
(i 0 (add1 i)))
|
||||
((= i (vector-length source)) vec)
|
||||
(vector-set! vec i (vector-ref source i))))
|
||||
|
||||
(define (fannkuch n)
|
||||
(let ((pi (do ((pi (make-vector n))
|
||||
(i 0 (add1 i)))
|
||||
((= i n) pi)
|
||||
(vector-set! pi i i)))
|
||||
(r n)
|
||||
(count (make-vector n)))
|
||||
(let loop ((flips 0)
|
||||
(perms 0))
|
||||
(cond ((< perms 30)
|
||||
(vector-for-each (lambda (x)
|
||||
(display (add1 x)))
|
||||
pi)
|
||||
(newline)))
|
||||
(do ()
|
||||
((= r 1))
|
||||
(vector-set! count (sub1 r) r)
|
||||
(set! r (sub1 r)))
|
||||
(let ((flips2 (max (count-flips pi) flips)))
|
||||
(let ((result
|
||||
(let loop2 ()
|
||||
(if (= r n)
|
||||
flips2
|
||||
(let ((perm0 (vector-ref pi 0)))
|
||||
(do ((i 0))
|
||||
((>= i r))
|
||||
(let ((j (add1 i)))
|
||||
(vector-set! pi i (vector-ref pi j))
|
||||
(set! i j)))
|
||||
(vector-set! pi r perm0)
|
||||
(vector-set! count r (sub1 (vector-ref count r)))
|
||||
(cond ((<= (vector-ref count r) 0)
|
||||
(set! r (add1 r))
|
||||
(loop2))
|
||||
(else
|
||||
#f)))))))
|
||||
(or result
|
||||
(loop flips2 (add1 perms)))
|
||||
)))))
|
||||
|
||||
(define (main args)
|
||||
(if (< (vector-length args) 1)
|
||||
(begin (display "An argument is required") (newline) 2)
|
||||
(let ((n (string->number (vector-ref args 0))))
|
||||
(if (not (integer? n))
|
||||
(begin (display "An integer is required") (newline) 2)
|
||||
(printf "Pfannkuchen(~S) = ~S~%" n (fannkuch n))))))
|
||||
|
||||
(main (current-command-line-arguments)))
|
119
collects/tests/mzscheme/benchmarks/shootout/fasta.ss
Normal file
119
collects/tests/mzscheme/benchmarks/shootout/fasta.ss
Normal file
|
@ -0,0 +1,119 @@
|
|||
;; The Great Computer Language Shootout
|
||||
;; http://shootout.alioth.debian.org/
|
||||
;;
|
||||
;; fasta - benchmark
|
||||
;;
|
||||
;; Derived from the Chicken variant, which was
|
||||
;; Contributed by Anthony Borla
|
||||
|
||||
(module fasta mzscheme
|
||||
|
||||
(define +alu+
|
||||
(bytes-append
|
||||
#"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"
|
||||
#"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"
|
||||
#"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"
|
||||
#"ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"
|
||||
#"GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"
|
||||
#"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"
|
||||
#"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"))
|
||||
|
||||
(define +iub+
|
||||
(list
|
||||
'(#\a . 0.27) '(#\c . 0.12) '(#\g . 0.12) '(#\t . 0.27) '(#\B . 0.02)
|
||||
'(#\D . 0.02) '(#\H . 0.02) '(#\K . 0.02) '(#\M . 0.02) '(#\N . 0.02)
|
||||
'(#\R . 0.02) '(#\S . 0.02) '(#\V . 0.02) '(#\W . 0.02) '(#\Y . 0.02)))
|
||||
|
||||
(define +homosapien+
|
||||
(list
|
||||
'(#\a . 0.3029549426680) '(#\c . 0.1979883004921)
|
||||
'(#\g . 0.1975473066391) '(#\t . 0.3015094502008)))
|
||||
|
||||
;; -------------
|
||||
|
||||
(define +line-size+ 60)
|
||||
|
||||
;; -------------------------------
|
||||
|
||||
(define (make-random seed)
|
||||
(let* ((ia 3877) (ic 29573) (im 139968) (last seed))
|
||||
(lambda (max)
|
||||
(set! last (modulo (+ ic (* last ia)) im))
|
||||
(/ (* max last) im) )))
|
||||
|
||||
;; -------------------------------
|
||||
|
||||
(define (make-cumulative-table frequency-table)
|
||||
(let ((cumulative 0.0))
|
||||
(map
|
||||
(lambda (x)
|
||||
(set! cumulative (+ cumulative (cdr x)))
|
||||
(cons (char->integer (car x)) cumulative))
|
||||
frequency-table)))
|
||||
|
||||
;; -------------
|
||||
|
||||
(define random-next (make-random 42))
|
||||
(define +segmarker+ ">")
|
||||
|
||||
;; -------------
|
||||
|
||||
(define (select-random cumulative-table)
|
||||
(let ((rvalue (random-next 1.0)))
|
||||
(select-over-threshold rvalue cumulative-table)))
|
||||
|
||||
(define (select-over-threshold rvalue table)
|
||||
(if (<= rvalue (cdar table))
|
||||
(caar table)
|
||||
(select-over-threshold rvalue (cdr table))))
|
||||
|
||||
;; -------------
|
||||
|
||||
(define (repeat-fasta id desc n_ sequence line-length)
|
||||
(let ((seqlen (bytes-length sequence))
|
||||
(out (current-output-port)))
|
||||
(display (string-append +segmarker+ id " " desc "\n") out)
|
||||
(let loop-o ((n n_) (k 0))
|
||||
(unless (<= n 0)
|
||||
(let ((m (min n line-length)))
|
||||
(let loop-i ((i 0) (k k))
|
||||
(if (>= i m)
|
||||
(begin
|
||||
(newline out)
|
||||
(loop-o (- n line-length) k))
|
||||
(let ([k (if (= k seqlen) 0 k)])
|
||||
(write-byte (bytes-ref sequence k) out)
|
||||
(loop-i (add1 i) (add1 k))))))))))
|
||||
|
||||
;; -------------
|
||||
|
||||
(define (random-fasta id desc n_ cumulative-table line-length)
|
||||
(let ((out (current-output-port)))
|
||||
(display (string-append +segmarker+ id " " desc "\n") out)
|
||||
(let loop-o ((n n_))
|
||||
(unless (<= n 0)
|
||||
(let ((m (min n line-length)))
|
||||
(let loop-i ((i 0))
|
||||
(unless (>= i m)
|
||||
(write-byte (select-random cumulative-table) out)
|
||||
(loop-i (add1 i))))
|
||||
(newline out)
|
||||
(loop-o (- n line-length)))))))
|
||||
|
||||
;; -------------------------------
|
||||
|
||||
(define (main args)
|
||||
(let ((n (string->number (vector-ref args 0))))
|
||||
|
||||
(repeat-fasta "ONE" "Homo sapiens alu" (* n 2) +alu+ +line-size+)
|
||||
|
||||
(random-fasta "TWO" "IUB ambiguity codes" (* n 3)
|
||||
(make-cumulative-table +iub+) +line-size+)
|
||||
|
||||
(random-fasta "THREE" "Homo sapiens frequency" (* n 5)
|
||||
(make-cumulative-table +homosapien+) +line-size+) ))
|
||||
|
||||
;; -------------------------------
|
||||
|
||||
(main (current-command-line-arguments)))
|
||||
|
13
collects/tests/mzscheme/benchmarks/shootout/fibo.ss
Normal file
13
collects/tests/mzscheme/benchmarks/shootout/fibo.ss
Normal file
|
@ -0,0 +1,13 @@
|
|||
(module fibo mzscheme
|
||||
(define (fib n)
|
||||
(cond ((< n 2) 1)
|
||||
(else (+ (fib (- n 2)) (fib (- n 1))))))
|
||||
|
||||
(define (main args)
|
||||
(let ((n (if (= (vector-length args) 0)
|
||||
1
|
||||
(string->number (vector-ref args 0)))))
|
||||
(display (fib n))
|
||||
(newline)))
|
||||
|
||||
(main (current-command-line-arguments)))
|
18
collects/tests/mzscheme/benchmarks/shootout/hash.ss
Normal file
18
collects/tests/mzscheme/benchmarks/shootout/hash.ss
Normal file
|
@ -0,0 +1,18 @@
|
|||
(module hash mzscheme
|
||||
(define (main argv)
|
||||
(let* ([n (string->number (vector-ref argv 0))]
|
||||
[hash (make-hash-table 'equal)]
|
||||
[accum 0]
|
||||
[false (lambda () #f)])
|
||||
(let loop ([i 1])
|
||||
(unless (> i n)
|
||||
(hash-table-put! hash (number->string i 16) i)
|
||||
(loop (add1 i))))
|
||||
(let loop ([i n])
|
||||
(unless (zero? i)
|
||||
(when (hash-table-get hash (number->string i) false)
|
||||
(set! accum (+ accum 1)))
|
||||
(loop (sub1 i))))
|
||||
(printf "~s~n" accum)))
|
||||
|
||||
(main (current-command-line-arguments)))
|
25
collects/tests/mzscheme/benchmarks/shootout/hash2.ss
Normal file
25
collects/tests/mzscheme/benchmarks/shootout/hash2.ss
Normal file
|
@ -0,0 +1,25 @@
|
|||
(module hash2 mzscheme
|
||||
(define (main argv)
|
||||
(let* ([n (string->number (vector-ref argv 0))]
|
||||
[hash1 (make-hash-table 'equal)]
|
||||
[hash2 (make-hash-table 'equal)]
|
||||
[zero (lambda () 0)])
|
||||
(let loop ([i 0])
|
||||
(unless (= i 10000)
|
||||
(hash-table-put! hash1 (string-append "foo_" (number->string i)) i)
|
||||
(loop (add1 i))))
|
||||
(let loop ([i 0])
|
||||
(unless (= i n)
|
||||
(hash-table-for-each hash1 (lambda (key value)
|
||||
(hash-table-put!
|
||||
hash2
|
||||
key
|
||||
(+ (hash-table-get hash2 key zero) value))))
|
||||
(loop (add1 i))))
|
||||
(printf "~s ~s ~s ~s~n"
|
||||
(hash-table-get hash1 "foo_1")
|
||||
(hash-table-get hash1 "foo_9999")
|
||||
(hash-table-get hash2 "foo_1")
|
||||
(hash-table-get hash2 "foo_9999"))))
|
||||
|
||||
(main (current-command-line-arguments)))
|
74
collects/tests/mzscheme/benchmarks/shootout/heapsort.ss
Normal file
74
collects/tests/mzscheme/benchmarks/shootout/heapsort.ss
Normal file
|
@ -0,0 +1,74 @@
|
|||
;;; heapsort.scm
|
||||
|
||||
;; Prints 0.9990640717878372 instead of 0.9990640718 when n=1000.
|
||||
;; Updated by Justin Smith
|
||||
;;
|
||||
;; Updated by Brent Fulgham to provide proper output formatting
|
||||
|
||||
(module heapsort mzscheme
|
||||
(require (only (lib "13.ss" "srfi") string-index string-pad-right))
|
||||
|
||||
(define IM 139968)
|
||||
(define IA 3877)
|
||||
(define IC 29573)
|
||||
|
||||
(define LAST 42)
|
||||
(define (gen_random max)
|
||||
(set! LAST (modulo (+ (* LAST IA) IC) IM))
|
||||
(/ (* max LAST) IM))
|
||||
|
||||
(define (heapsort n ra)
|
||||
(let ((ir n)
|
||||
(l (+ (quotient n 2) 1))
|
||||
(i 0)
|
||||
(j 0)
|
||||
(rra 0.0))
|
||||
(let/ec return
|
||||
(do ((bar #t))
|
||||
((= 1 0))
|
||||
(cond ((> l 1)
|
||||
(set! l (- l 1))
|
||||
(set! rra (vector-ref ra l)))
|
||||
(else
|
||||
(set! rra (vector-ref ra ir))
|
||||
(vector-set! ra ir (vector-ref ra 1))
|
||||
(set! ir (- ir 1))
|
||||
(cond ((<= ir 1)
|
||||
(vector-set! ra 1 rra)
|
||||
(return #t)))))
|
||||
(set! i l)
|
||||
(set! j (* l 2))
|
||||
(do ((foo #t))
|
||||
((> j ir))
|
||||
(cond ((and (< j ir) (< (vector-ref ra j) (vector-ref ra (+ j 1))))
|
||||
(set! j (+ j 1))))
|
||||
(cond ((< rra (vector-ref ra j))
|
||||
(vector-set! ra i (vector-ref ra j))
|
||||
(set! i j)
|
||||
(set! j (+ j i)))
|
||||
(else
|
||||
(set! j (+ ir 1)))))
|
||||
(vector-set! ra i rra)))))
|
||||
|
||||
(define (roundto digits num)
|
||||
(let* ([e (expt 10 digits)]
|
||||
[num (round (* e (inexact->exact num)))])
|
||||
(format "~a.~a"
|
||||
(quotient num e)
|
||||
(substring (string-append (number->string (remainder num e))
|
||||
(make-string digits #\0))
|
||||
0 digits))))
|
||||
|
||||
(define (main args)
|
||||
(let* ((n (or (and (= (vector-length args) 1) (string->number (vector-ref args 0)))
|
||||
1))
|
||||
(last (+ n 1))
|
||||
(ary (make-vector last 0)))
|
||||
(do ((i 1 (+ i 1)))
|
||||
((= i last))
|
||||
(vector-set! ary i (gen_random 1.0)))
|
||||
(heapsort n ary)
|
||||
(printf "~a~n"
|
||||
(roundto 10 (vector-ref ary n)))))
|
||||
|
||||
(main (current-command-line-arguments)))
|
43
collects/tests/mzscheme/benchmarks/shootout/lists.ss
Normal file
43
collects/tests/mzscheme/benchmarks/shootout/lists.ss
Normal file
|
@ -0,0 +1,43 @@
|
|||
(module lists mzscheme
|
||||
(define SIZE 10000)
|
||||
|
||||
(define (sequence start stop)
|
||||
(if (> start stop)
|
||||
'()
|
||||
(cons start (sequence (+ start 1) stop))))
|
||||
|
||||
(define (head-to-tail! headlist taillist)
|
||||
(when (null? taillist) (begin
|
||||
(set! taillist (list (car headlist)))
|
||||
(set! headlist (cdr headlist))))
|
||||
(letrec ((htt-helper (lambda (dest)
|
||||
(when (not (null? headlist))
|
||||
(let ((headlink headlist))
|
||||
(set-cdr! dest headlink)
|
||||
(set! headlist (cdr headlist))
|
||||
(htt-helper headlink))))))
|
||||
(htt-helper taillist)
|
||||
(values headlist taillist)))
|
||||
|
||||
(define (test-lists)
|
||||
(let* ([L1 (sequence 1 SIZE)]
|
||||
[L2 (append L1 '())]
|
||||
[L3 '()])
|
||||
(set!-values (L2 L3) (head-to-tail! L2 L3))
|
||||
(set!-values (L3 L2) (head-to-tail! (reverse! L3) L2))
|
||||
(set! L1 (reverse! L1))
|
||||
(cond ((not (= SIZE (car L1))) 0)
|
||||
((not (equal? L1 L2)) 0)
|
||||
(else (length L1)))))
|
||||
|
||||
(define (main args)
|
||||
(let ((result #f))
|
||||
(let loop ((counter (if (= (vector-length args) 0)
|
||||
1
|
||||
(string->number (vector-ref args 0)))))
|
||||
(when (> counter 0)
|
||||
(set! result (test-lists))
|
||||
(loop (- counter 1))))
|
||||
(printf "~s~n" result)))
|
||||
|
||||
(main (current-command-line-arguments)))
|
80
collects/tests/mzscheme/benchmarks/shootout/mandelbrot.ss
Normal file
80
collects/tests/mzscheme/benchmarks/shootout/mandelbrot.ss
Normal file
|
@ -0,0 +1,80 @@
|
|||
;; ---------------------------------------------------------------------
|
||||
;; The Great Computer Language Shootout
|
||||
;; http://shootout.alioth.debian.org/
|
||||
;;
|
||||
;; Derived from the Chicken variant, which was
|
||||
;; Contributed by Anthony Borla
|
||||
|
||||
;; Note: as of version 350, this benchmark spends much of
|
||||
;; its time GCing; it runs 2 times as fast in mzscheme3m.
|
||||
|
||||
;; The version that uses complex number is a little
|
||||
;; more elegant, but slower:
|
||||
;; (define (mandelbrot iterations x y n ci)
|
||||
;; (let ((c (+ (- (/ (* 2.0 x) n) 1.5)
|
||||
;; (* ci 0.0+1.0i))))
|
||||
;; (let loop ((i 0) (z 0.0+0.0i))
|
||||
;; (cond
|
||||
;; [(> i iterations) 1]
|
||||
;; [(> (magnitude z) 2.0) 0]
|
||||
;; [else (loop (add1 i) (+ (* z z) c))]))))
|
||||
|
||||
|
||||
(module mandelbrot mzscheme
|
||||
|
||||
;; -------------------------------
|
||||
|
||||
(define +limit-sqr+ 4.0)
|
||||
|
||||
(define +iterations+ 50)
|
||||
|
||||
;; -------------------------------
|
||||
|
||||
(define (mandelbrot iterations x y n ci)
|
||||
(let ((cr (- (/ (* 2.0 x) n) 1.5)))
|
||||
(let loop ((i 0) (zr 0.0) (zi 0.0))
|
||||
(if (> i iterations)
|
||||
1
|
||||
(let ((zrq (* zr zr))
|
||||
(ziq (* zi zi)))
|
||||
(cond
|
||||
((> (+ zrq ziq) +limit-sqr+) 0)
|
||||
(else (loop (add1 i) (+ (- zrq ziq) cr) (+ (* 2.0 zr zi) ci)))))))))
|
||||
|
||||
;; -------------------------------
|
||||
|
||||
(define (main args)
|
||||
(let ((n (string->number (vector-ref args 0)))
|
||||
(out (current-output-port)))
|
||||
|
||||
(fprintf out "P4\n~a ~a\n" n n)
|
||||
|
||||
(let loop-y ((y 0))
|
||||
|
||||
(when (< y n)
|
||||
|
||||
(let ([ci (- (/ (* 2.0 y) n) 1.0)])
|
||||
|
||||
(let loop-x ((x 0) (bitnum 0) (byteacc 0))
|
||||
|
||||
(if (< x n)
|
||||
(let ([bitnum (add1 bitnum)]
|
||||
[byteacc (+ (arithmetic-shift byteacc 1)
|
||||
(mandelbrot +iterations+ x y n ci))])
|
||||
|
||||
(cond
|
||||
((= bitnum 8)
|
||||
(write-byte byteacc out)
|
||||
(loop-x (add1 x) 0 0))
|
||||
|
||||
[else (loop-x (add1 x) bitnum byteacc)]))
|
||||
|
||||
(begin
|
||||
(when (positive? bitnum)
|
||||
(write-byte (arithmetic-shift byteacc (- 8 (bitwise-and n #x7))) out))
|
||||
|
||||
(loop-y (add1 y))))))))))
|
||||
|
||||
;; -------------------------------
|
||||
|
||||
(main (current-command-line-arguments)))
|
76
collects/tests/mzscheme/benchmarks/shootout/matrix.ss
Normal file
76
collects/tests/mzscheme/benchmarks/shootout/matrix.ss
Normal file
|
@ -0,0 +1,76 @@
|
|||
; Matrix.scm
|
||||
|
||||
(module matrix mzscheme
|
||||
(define size 30)
|
||||
|
||||
(define (1+ x) (+ x 1))
|
||||
|
||||
(define (mkmatrix rows cols)
|
||||
(let ((mx (make-vector rows 0))
|
||||
(count 1))
|
||||
(do ((i 0 (1+ i)))
|
||||
((= i rows))
|
||||
(let ((row (make-vector cols 0)))
|
||||
(do ((j 0 (1+ j)))
|
||||
((= j cols))
|
||||
(vector-set! row j count)
|
||||
(set! count (+ count 1)))
|
||||
(vector-set! mx i row)))
|
||||
mx))
|
||||
|
||||
(define (num-cols mx)
|
||||
(let ((row (vector-ref mx 0)))
|
||||
(vector-length row)))
|
||||
|
||||
(define (num-rows mx)
|
||||
(vector-length mx))
|
||||
|
||||
(define (mmult rows cols m1 m2)
|
||||
(let ((m3 (make-vector rows 0)))
|
||||
(do ((i 0 (1+ i)))
|
||||
((= i rows))
|
||||
(let ((m1i (vector-ref m1 i))
|
||||
(row (make-vector cols 0)))
|
||||
(do ((j 0 (1+ j)))
|
||||
((= j cols))
|
||||
(let ((val 0))
|
||||
(do ((k 0 (1+ k)))
|
||||
((= k cols))
|
||||
(set! val (+ val (* (vector-ref m1i k)
|
||||
(vector-ref (vector-ref m2 k) j)))))
|
||||
(vector-set! row j val)))
|
||||
(vector-set! m3 i row)))
|
||||
m3))
|
||||
|
||||
(define (matrix-print m)
|
||||
(do ((i 0 (1+ i)))
|
||||
((= i (num-rows m)))
|
||||
(let ((row (vector-ref m i)))
|
||||
(do ((j 0 (1+ j)))
|
||||
((= j (num-cols m)))
|
||||
(display (vector-ref row j))
|
||||
(if (< j (num-cols m))
|
||||
(display " ")))
|
||||
(newline))))
|
||||
|
||||
(define (print-list . items) (for-each display items) (newline))
|
||||
|
||||
(define (main args)
|
||||
(let ((n (or (and (= (vector-length args) 1) (string->number (vector-ref
|
||||
args 0)))
|
||||
1)))
|
||||
(let ((mm 0)
|
||||
(m1 (mkmatrix size size))
|
||||
(m2 (mkmatrix size size)))
|
||||
(let loop ((iter n))
|
||||
(cond ((> iter 0)
|
||||
(set! mm (mmult size size m1 m2))
|
||||
(loop (- iter 1)))))
|
||||
(let ((r0 (vector-ref mm 0))
|
||||
(r2 (vector-ref mm 2))
|
||||
(r3 (vector-ref mm 3))
|
||||
(r4 (vector-ref mm 4)))
|
||||
(print-list (vector-ref r0 0) " " (vector-ref r2 3) " "
|
||||
(vector-ref r3 2) " " (vector-ref r4 4))))))
|
||||
|
||||
(main (current-command-line-arguments)))
|
72
collects/tests/mzscheme/benchmarks/shootout/moments.ss
Normal file
72
collects/tests/mzscheme/benchmarks/shootout/moments.ss
Normal file
|
@ -0,0 +1,72 @@
|
|||
; Moments.scm
|
||||
|
||||
(module moments mzscheme
|
||||
(require (only (lib "list.ss") sort))
|
||||
|
||||
(define (roundto digits n)
|
||||
(let* ([e (expt 10 digits)]
|
||||
[num (round (abs (* e (inexact->exact n))))])
|
||||
(format "~a~a.~a"
|
||||
(if (negative? n) "-" "")
|
||||
(quotient num e)
|
||||
(substring (string-append (number->string (remainder num e))
|
||||
(make-string digits #\0))
|
||||
0 digits))))
|
||||
|
||||
(let* ((sum 0.0)
|
||||
(numlist (let loop ((line (read-line)) (numlist '()))
|
||||
(cond ((eof-object? line) numlist)
|
||||
(else
|
||||
(let ((num (string->number line)))
|
||||
(set! sum (+ num sum))
|
||||
(loop (read-line) (cons num numlist))))))))
|
||||
(let ((n (length numlist)))
|
||||
(let ((mean (/ sum n))
|
||||
(average_deviation 0.0)
|
||||
(standard_deviation 0.0)
|
||||
(variance 0.0)
|
||||
(skew 0.0)
|
||||
(kurtosis 0.0)
|
||||
(median 0.0)
|
||||
(deviation 0.0))
|
||||
(let loop ((nums numlist))
|
||||
(if (not (null? nums))
|
||||
(begin
|
||||
(set! deviation (- (car nums) mean))
|
||||
(set! average_deviation (+ average_deviation (abs deviation)))
|
||||
(set! variance (+ variance (expt deviation 2.0)))
|
||||
(set! skew (+ skew (expt deviation 3.0)))
|
||||
(set! kurtosis (+ kurtosis (expt deviation 4)))
|
||||
(loop (cdr nums)))))
|
||||
|
||||
(set! average_deviation (/ average_deviation (exact->inexact n)))
|
||||
(set! variance (/ variance (- n 1)))
|
||||
(set! standard_deviation (sqrt variance))
|
||||
|
||||
(cond ((> variance 0.0)
|
||||
(set! skew (/ skew (* n variance standard_deviation)))
|
||||
(set! kurtosis (- (/ kurtosis (* n variance variance))
|
||||
3.0))))
|
||||
|
||||
(set! numlist (sort numlist (lambda (x y) (< x y))))
|
||||
|
||||
(let ((mid (quotient n 2)))
|
||||
(if (zero? (modulo n 2))
|
||||
(set! median (/ (+ (car (list-tail numlist mid))
|
||||
(car (list-tail numlist (- mid 1))))
|
||||
2.0))
|
||||
(set! median (car (list-tail numlist mid)))))
|
||||
|
||||
|
||||
(set! standard_deviation (/ (round (* standard_deviation 1000000))
|
||||
1000000))
|
||||
|
||||
(for-each display
|
||||
`("n: " ,n "\n"
|
||||
"median: " ,(roundto 6 median) "\n"
|
||||
"mean: " ,(roundto 6 mean) "\n"
|
||||
"average_deviation: " ,(roundto 6 average_deviation ) "\n"
|
||||
"standard_deviation: " ,(roundto 6 standard_deviation) "\n"
|
||||
"variance: " ,(roundto 6 variance)"\n"
|
||||
"skew: " ,(roundto 6 skew) "\n"
|
||||
"kurtosis: " ,(roundto 6 kurtosis)"\n" ))))))
|
166
collects/tests/mzscheme/benchmarks/shootout/nbody.ss
Normal file
166
collects/tests/mzscheme/benchmarks/shootout/nbody.ss
Normal file
|
@ -0,0 +1,166 @@
|
|||
#!/usr/bin/mzscheme -qu
|
||||
;; The Great Computer Language Shootout
|
||||
;; http://shootout.alioth.debian.org/
|
||||
;;
|
||||
;; Imperative-style implementation based on the SBCL implementation by
|
||||
;; Patrick Frankenberger and Juho Snellman, but using only native Scheme
|
||||
;; idioms like 'named let' and 'do' special form.
|
||||
;;
|
||||
;; Contributed by Anthony Borla, then converted for mzscheme
|
||||
;; by Matthew Flatt and Brent Fulgham
|
||||
|
||||
#|
|
||||
Correct output N = 1000 is
|
||||
|
||||
-0.169075164
|
||||
-0.169087605
|
||||
|#
|
||||
(module nbody mzscheme
|
||||
(provide main)
|
||||
|
||||
;;; Stupid boiler-plate for formatting floating point value
|
||||
(define (roundto digits n)
|
||||
(let* ([e (expt 10 digits)]
|
||||
[num (round (abs (* e (inexact->exact n))))])
|
||||
(format "~a~a.~a"
|
||||
(if (negative? n) "-" "")
|
||||
(quotient num e)
|
||||
(substring (string-append (number->string (remainder num e))
|
||||
(make-string digits #\0))
|
||||
0 digits))))
|
||||
|
||||
;; ------------------------------
|
||||
;; define planetary masses, initial positions & velocity
|
||||
|
||||
(define +pi+ 3.141592653589793)
|
||||
(define +days-per-year+ 365.24)
|
||||
|
||||
(define +solar-mass+ (* 4 +pi+ +pi+))
|
||||
|
||||
(define-struct body (x y z vx vy vz mass))
|
||||
|
||||
(define *sun*
|
||||
(make-body 0.0 0.0 0.0 0.0 0.0 0.0 +solar-mass+))
|
||||
|
||||
(define *jupiter*
|
||||
(make-body 4.84143144246472090
|
||||
-1.16032004402742839
|
||||
-1.03622044471123109e-1
|
||||
(* 1.66007664274403694e-3 +days-per-year+)
|
||||
(* 7.69901118419740425e-3 +days-per-year+)
|
||||
(* -6.90460016972063023e-5 +days-per-year+)
|
||||
(* 9.54791938424326609e-4 +solar-mass+)))
|
||||
|
||||
(define *saturn*
|
||||
(make-body 8.34336671824457987
|
||||
4.12479856412430479
|
||||
-4.03523417114321381e-1
|
||||
(* -2.76742510726862411e-3 +days-per-year+)
|
||||
(* 4.99852801234917238e-3 +days-per-year+)
|
||||
(* 2.30417297573763929e-5 +days-per-year+)
|
||||
(* 2.85885980666130812e-4 +solar-mass+)))
|
||||
|
||||
(define *uranus*
|
||||
(make-body 1.28943695621391310e1
|
||||
-1.51111514016986312e1
|
||||
-2.23307578892655734e-1
|
||||
(* 2.96460137564761618e-03 +days-per-year+)
|
||||
(* 2.37847173959480950e-03 +days-per-year+)
|
||||
(* -2.96589568540237556e-05 +days-per-year+)
|
||||
(* 4.36624404335156298e-05 +solar-mass+)))
|
||||
|
||||
(define *neptune*
|
||||
(make-body 1.53796971148509165e+01
|
||||
-2.59193146099879641e+01
|
||||
1.79258772950371181e-01
|
||||
(* 2.68067772490389322e-03 +days-per-year+)
|
||||
(* 1.62824170038242295e-03 +days-per-year+)
|
||||
(* -9.51592254519715870e-05 +days-per-year+)
|
||||
(* 5.15138902046611451e-05 +solar-mass+)))
|
||||
|
||||
;; -------------------------------
|
||||
(define (offset-momentum system)
|
||||
(let loop-i ((i system) (px 0.0) (py 0.0) (pz 0.0))
|
||||
(if (null? i)
|
||||
(begin
|
||||
(set-body-vx! (car system) (/ (- px) +solar-mass+))
|
||||
(set-body-vy! (car system) (/ (- py) +solar-mass+))
|
||||
(set-body-vz! (car system) (/ (- pz) +solar-mass+)))
|
||||
(loop-i (cdr i)
|
||||
(+ px (* (body-vx (car i)) (body-mass (car i))))
|
||||
(+ py (* (body-vy (car i)) (body-mass (car i))))
|
||||
(+ pz (* (body-vz (car i)) (body-mass (car i))))))))
|
||||
|
||||
;; -------------------------------
|
||||
(define (energy system)
|
||||
(let loop-o ((o system) (e 0.0))
|
||||
(if (null? o)
|
||||
e
|
||||
(let ([e (+ e (* 0.5 (body-mass (car o))
|
||||
(+ (* (body-vx (car o)) (body-vx (car o)))
|
||||
(* (body-vy (car o)) (body-vy (car o)))
|
||||
(* (body-vz (car o)) (body-vz (car o))))))])
|
||||
|
||||
(let loop-i ((i (cdr o)) (e e))
|
||||
(if (null? i)
|
||||
(loop-o (cdr o) e)
|
||||
(let* ((dx (- (body-x (car o)) (body-x (car i))))
|
||||
(dy (- (body-y (car o)) (body-y (car i))))
|
||||
(dz (- (body-z (car o)) (body-z (car i))))
|
||||
(distance (sqrt (+ (* dx dx) (* dy dy) (* dz dz)))))
|
||||
(let ([e (- e (/ (* (body-mass (car o)) (body-mass (car i))) distance))])
|
||||
(loop-i (cdr i) e)))))))))
|
||||
|
||||
;; -------------------------------
|
||||
(define (advance system dt)
|
||||
(let loop-o ((o system))
|
||||
(unless (null? o)
|
||||
(let loop-i ((i (cdr o)))
|
||||
(unless (null? i)
|
||||
(let* ((o1 (car o))
|
||||
(i1 (car i))
|
||||
(dx (- (body-x o1) (body-x i1)))
|
||||
(dy (- (body-y o1) (body-y i1)))
|
||||
(dz (- (body-z o1) (body-z i1)))
|
||||
(distance (sqrt (+ (* dx dx) (* dy dy) (* dz dz))))
|
||||
(mag (/ dt (* distance distance distance)))
|
||||
(dxmag (* dx mag))
|
||||
(dymag (* dy mag))
|
||||
(dzmag (* dz mag))
|
||||
(om (body-mass o1))
|
||||
(im (body-mass i1)))
|
||||
(set-body-vx! o1 (- (body-vx o1) (* dxmag im)))
|
||||
(set-body-vy! o1 (- (body-vy o1) (* dymag im)))
|
||||
(set-body-vz! o1 (- (body-vz o1) (* dzmag im)))
|
||||
(set-body-vx! i1 (+ (body-vx i1) (* dxmag om)))
|
||||
(set-body-vy! i1 (+ (body-vy i1) (* dymag om)))
|
||||
(set-body-vz! i1 (+ (body-vz i1) (* dzmag om)))
|
||||
(loop-i (cdr i)))))
|
||||
(loop-o (cdr o))))
|
||||
|
||||
(let loop-o ((o system))
|
||||
(unless (null? o)
|
||||
(let ([o1 (car o)])
|
||||
(set-body-x! o1 (+ (body-x o1) (* dt (body-vx o1))))
|
||||
(set-body-y! o1 (+ (body-y o1) (* dt (body-vy o1))))
|
||||
(set-body-z! o1 (+ (body-z o1) (* dt (body-vz o1))))
|
||||
(loop-o (cdr o))))))
|
||||
|
||||
;; -------------------------------
|
||||
(define (main args)
|
||||
(let ((n (if (null? args)
|
||||
1
|
||||
(string->number (car args))))
|
||||
(system (list *sun* *jupiter* *saturn* *uranus* *neptune*)))
|
||||
|
||||
(offset-momentum system)
|
||||
|
||||
(printf "~a~%" (roundto 9 (energy system)))
|
||||
|
||||
(do ((i 1 (+ i 1)))
|
||||
((< n i))
|
||||
(advance system 0.01))
|
||||
|
||||
(printf "~a~%" (roundto 9 (energy system)))))
|
||||
|
||||
(main (vector->list (current-command-line-arguments))))
|
18
collects/tests/mzscheme/benchmarks/shootout/nestedloop.ss
Normal file
18
collects/tests/mzscheme/benchmarks/shootout/nestedloop.ss
Normal file
|
@ -0,0 +1,18 @@
|
|||
(module nestedloop mzscheme
|
||||
(require (lib "defmacro.ss"))
|
||||
|
||||
(define-macro (nest n expr)
|
||||
(if (> n 0)
|
||||
`(let loop ([i 1]) (unless (> i n)
|
||||
(nest ,(- n 1) ,expr)
|
||||
(loop (add1 i))))
|
||||
expr))
|
||||
|
||||
|
||||
(define (main argv)
|
||||
(let* ([n (string->number (vector-ref argv 0))]
|
||||
[x 0])
|
||||
(nest 6 (set! x (+ x 1)))
|
||||
(printf "~s~n" x)))
|
||||
|
||||
(main (current-command-line-arguments)))
|
50
collects/tests/mzscheme/benchmarks/shootout/nsieve.ss
Normal file
50
collects/tests/mzscheme/benchmarks/shootout/nsieve.ss
Normal file
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/mzscheme -qu
|
||||
;; $Id: nsieve-mzscheme.code,v 1.6 2006/06/10 23:38:29 bfulgham Exp $
|
||||
;; The Great Computer Language Shootout
|
||||
;; http://shootout.alioth.debian.org/
|
||||
;;
|
||||
;; nsieve benchmark for The Computer Language Shootout
|
||||
;; Written by Dima Dorfman, 2004
|
||||
;; Converted to MzScheme by Brent Fulgham
|
||||
|
||||
(module nseive mzscheme
|
||||
(require (only (lib "13.ss" "srfi") string-index string-pad))
|
||||
|
||||
(define (nsieve m)
|
||||
(let ((a (make-vector m #t)))
|
||||
(let loop ((i 2) (n 0))
|
||||
(if (< i m)
|
||||
(begin
|
||||
(if (vector-ref a i)
|
||||
(begin
|
||||
(let clear ((j (+ i i)))
|
||||
(if (< j m)
|
||||
(begin
|
||||
(vector-set! a j #f)
|
||||
(clear (+ j i)))))
|
||||
(loop (+ 1 i) (+ 1 n)))
|
||||
(loop (+ 1 i) n)))
|
||||
n))))
|
||||
|
||||
(define (test n)
|
||||
(let* ((m (* (expt 2 n) 10000))
|
||||
(count (nsieve m)))
|
||||
(printf "Primes up to ~a ~a~%"
|
||||
(string-pad (number->string m) 8)
|
||||
(string-pad (number->string count) 8))))
|
||||
|
||||
(define (main args)
|
||||
(if (< (vector-length args) 1)
|
||||
(begin
|
||||
(display "An argument is required") (newline) 2)
|
||||
(let ((n (string->number (vector-ref args 0))))
|
||||
(if (not n)
|
||||
(begin
|
||||
(display "An integer is required") (newline) 2)
|
||||
(begin
|
||||
(if (>= n 0) (test n))
|
||||
(if (>= n 1) (test (- n 1)))
|
||||
(if (>= n 2) (test (- n 2)))
|
||||
0)))))
|
||||
|
||||
(main (current-command-line-arguments)))
|
66
collects/tests/mzscheme/benchmarks/shootout/nsievebits.ss
Normal file
66
collects/tests/mzscheme/benchmarks/shootout/nsievebits.ss
Normal file
|
@ -0,0 +1,66 @@
|
|||
#!/usr/bin/mzscheme -qu
|
||||
;;; The Great Computer Language Shootout
|
||||
;;; http://shootout.alioth.debian.org/
|
||||
;;
|
||||
;; Adapted from CMUCL code by Dima Dorfman; bit-vector stuff by Alex Shinn;
|
||||
;; cobbled together by felix, converted to MzScheme by Brent Fulgham
|
||||
;; Note: Requires MzScheme 299+
|
||||
|
||||
(module nsievebits mzscheme
|
||||
|
||||
(define (make-bit-vector size)
|
||||
(let* ((len (quotient (+ size 7) 8))
|
||||
(res (make-bytes len #b11111111)))
|
||||
(let ((off (remainder size 8)))
|
||||
(unless (zero? off)
|
||||
(bytes-set! res (- len 1) (- (arithmetic-shift 1 off) 1))))
|
||||
res))
|
||||
|
||||
(define (bit-vector-ref vec i)
|
||||
(let ((byte (arithmetic-shift i -3))
|
||||
(off (bitwise-and i #x7)))
|
||||
(and (< byte (bytes-length vec))
|
||||
(not (zero? (bitwise-and (bytes-ref vec byte)
|
||||
(arithmetic-shift 1 off)))))))
|
||||
|
||||
(define (bit-vector-set! vec i x)
|
||||
(let ((byte (arithmetic-shift i -3))
|
||||
(off (bitwise-and i #x7)))
|
||||
(let ((val (bytes-ref vec byte))
|
||||
(mask (arithmetic-shift 1 off)))
|
||||
(bytes-set! vec
|
||||
byte
|
||||
(if x
|
||||
(bitwise-ior val mask)
|
||||
(bitwise-and val (bitwise-not mask)))))))
|
||||
|
||||
(define (nsievebits m)
|
||||
(let ((a (make-bit-vector m)))
|
||||
(define (clear i)
|
||||
(do ([j (+ i i) (+ j i)])
|
||||
((>= j m))
|
||||
(bit-vector-set! a j #f) ) )
|
||||
(let ([c 0])
|
||||
(do ([i 2 (add1 i)])
|
||||
((>= i m) c)
|
||||
(when (bit-vector-ref a i)
|
||||
(clear i)
|
||||
(set! c (add1 c)) ) ) ) ) )
|
||||
|
||||
(define (string-pad s n)
|
||||
(string-append (make-string (- n (string-length s)) #\space)
|
||||
s))
|
||||
|
||||
(define (test n)
|
||||
(let ((m (* 10000 (arithmetic-shift 1 n))))
|
||||
(printf "Primes up to ~a ~a~%"
|
||||
(string-pad (number->string m) 8)
|
||||
(string-pad (number->string (nsievebits m)) 8))))
|
||||
|
||||
(define (main args)
|
||||
(let ([n (string->number (vector-ref args 0))])
|
||||
(when (>= n 0) (test n))
|
||||
(when (>= n 1) (test (- n 1)))
|
||||
(when (>= n 2) (test (- n 2)))))
|
||||
|
||||
(main (current-command-line-arguments)))
|
70
collects/tests/mzscheme/benchmarks/shootout/partialsums.ss
Normal file
70
collects/tests/mzscheme/benchmarks/shootout/partialsums.ss
Normal file
|
@ -0,0 +1,70 @@
|
|||
;; ---------------------------------------------------------------------
|
||||
;; The Great Computer Language Shootout
|
||||
;; http://shootout.alioth.debian.org/
|
||||
;;
|
||||
;; Based on D language implementation by Dave Fladebo [imperative version]
|
||||
;;
|
||||
;; Derived from the Chicken variant, which was
|
||||
;; Contributed by Anthony Borla
|
||||
;; ---------------------------------------------------------------------
|
||||
|
||||
;; Note: as of version 350, this benchmark spends much of
|
||||
;; its time GCing; it runs 1.5 times as fast in mzscheme3m.
|
||||
|
||||
(module partialsums mzscheme
|
||||
|
||||
(define (roundto digits n)
|
||||
(let* ([e (expt 10 digits)]
|
||||
[num (round (abs (* e (inexact->exact n))))])
|
||||
(format "~a~a.~a"
|
||||
(if (negative? n) "-" "")
|
||||
(quotient num e)
|
||||
(substring (string-append (number->string (remainder num e))
|
||||
(make-string digits #\0))
|
||||
0 digits))))
|
||||
|
||||
(let ((n (exact->inexact
|
||||
(string->number
|
||||
(vector-ref (current-command-line-arguments) 0))))
|
||||
|
||||
(alt 1) (d2 0) (d3 0) (ds 0) (dc 0)
|
||||
(s0 0) (s1 0) (s2 0) (s3 0) (s4 0) (s5 0) (s6 0) (s7 0) (s8 0))
|
||||
|
||||
(let loop ([d 0.0]
|
||||
(alt 1) (d2 0) (d3 0) (ds 0) (dc 0)
|
||||
(s0 0) (s1 0) (s2 0) (s3 0) (s4 0) (s5 0) (s6 0) (s7 0) (s8 0))
|
||||
(if (= d n #;(+ n 1))
|
||||
(let ([format-result
|
||||
(lambda (str n)
|
||||
(printf str (roundto 9 n)))])
|
||||
|
||||
(format-result "~a\t(2/3)^k\n" s0)
|
||||
(format-result "~a\tk^-0.5\n" s1)
|
||||
(format-result "~a\t1/k(k+1)\n" s2)
|
||||
(format-result "~a\tFlint Hills\n" s3)
|
||||
(format-result "~a\tCookson Hills\n" s4)
|
||||
(format-result "~a\tHarmonic\n" s5)
|
||||
(format-result "~a\tRiemann Zeta\n" s6)
|
||||
(format-result "~a\tAlternating Harmonic\n" s7)
|
||||
(format-result "~a\tGregory\n" s8))
|
||||
|
||||
(let* ((d (+ d 1))
|
||||
(d2 (* d d))
|
||||
(d3 (* d2 d))
|
||||
(ds (sin d))
|
||||
(dc (cos d))
|
||||
|
||||
(s0 (+ s0 (expt (/ 2.0 3) (- d 1))))
|
||||
(s1 (+ s1 (/ 1 (sqrt d))))
|
||||
(s2 (+ s2 (/ 1 (* d (+ d 1)))))
|
||||
(s3 (+ s3 (/ 1 (* d3 (* ds ds)))))
|
||||
(s4 (+ s4 (/ 1 (* d3 (* dc dc)))))
|
||||
(s5 (+ s5 (/ 1 d)))
|
||||
(s6 (+ s6 (/ 1 d2)))
|
||||
(s7 (+ s7 (/ alt d)))
|
||||
(s8 (+ s8 (/ alt (- (* 2 d) 1))))
|
||||
(alt (- alt)))
|
||||
|
||||
(loop d
|
||||
alt d2 d3 ds dc
|
||||
s0 s1 s2 s3 s4 s5 s6 s7 s8))))))
|
46
collects/tests/mzscheme/benchmarks/shootout/pidigits.ss
Normal file
46
collects/tests/mzscheme/benchmarks/shootout/pidigits.ss
Normal file
|
@ -0,0 +1,46 @@
|
|||
;; The Computer Language Shootout
|
||||
;; http://shootout.alioth.debian.org/
|
||||
;; Based on the MLton version of the benchmark
|
||||
;; contributed by Scott Cruzen
|
||||
|
||||
;; Note: as of version 350, this benchmark spends most of
|
||||
;; its time GCing; it runs 3 times as fast in mzscheme3m.
|
||||
|
||||
(module pidigits mzscheme
|
||||
|
||||
(define (floor_ev q r s t x)
|
||||
(quotient (+ (* q x) r) (+ (* s x) t)))
|
||||
|
||||
(define (comp q r s t q2 r2 s2 t2)
|
||||
(values (+ (* q q2) (* r s2))
|
||||
(+ (* q r2) (* r t2))
|
||||
(+ (* s q2) (* t s2))
|
||||
(+ (* s r2) (* t t2))))
|
||||
|
||||
(define (next q r s t) (floor_ev q r s t 3))
|
||||
(define (safe? q r s t n) (= n (floor_ev q r s t 4)))
|
||||
(define (prod q r s t n) (comp 10 (* -10 n) 0 1 q r s t))
|
||||
(define (mk q r s t k) (comp q r s t k (* 2 (add1 (* 2 k))) 0 (add1 (* 2 k))))
|
||||
|
||||
(define (digit k q r s t n row col)
|
||||
(if (> n 0)
|
||||
(let ([y (next q r s t)])
|
||||
(if (safe? q r s t y)
|
||||
(let-values ([(q r s t) (prod q r s t y)])
|
||||
(if (= col 10)
|
||||
(let ([row (+ row 10)])
|
||||
(printf "\t:~a\n~a" row y)
|
||||
(digit k q r s t (sub1 n) row 1))
|
||||
(begin
|
||||
(printf "~a" y)
|
||||
(digit k q r s t(sub1 n) row (add1 col)))))
|
||||
(let-values ([(q r s t) (mk q r s t k)])
|
||||
(digit (add1 k) q r s t n row col))))
|
||||
(printf "~a\t:~a\n"
|
||||
(make-string (- 10 col) #\space)
|
||||
(+ row col))))
|
||||
|
||||
(define (digits n)
|
||||
(digit 1 1 0 0 1 n 0 0))
|
||||
|
||||
(digits (string->number (vector-ref (current-command-line-arguments) 0))))
|
57
collects/tests/mzscheme/benchmarks/shootout/pidigits1.ss
Normal file
57
collects/tests/mzscheme/benchmarks/shootout/pidigits1.ss
Normal file
|
@ -0,0 +1,57 @@
|
|||
#!/usr/bin/mzscheme -r
|
||||
; The Computer Language Shootout
|
||||
; http://shootout.alioth.debian.org/
|
||||
; Sven Hartrumpf 2005-04-12
|
||||
; Implements 'Spigot' algorithm origionally due to Stanly Rabinowitz.
|
||||
; This program is based on an implementation for SCM by Aubrey Jaffer and
|
||||
; Jerry D. Hedden.
|
||||
|
||||
(module pidigits1 mzscheme
|
||||
|
||||
(define (pi n d)
|
||||
(let* ((r (inexact->exact (floor (exp (* d (log 10)))))) ; 10^d
|
||||
(p (+ (quotient n d) 1))
|
||||
(m (quotient (* p d 3322) 1000))
|
||||
(a (make-vector (+ m 1) 2))
|
||||
(out (current-output-port)))
|
||||
(vector-set! a m 4)
|
||||
(let j-loop ([b 2][digits 0])
|
||||
(if (= digits n)
|
||||
;; Add whitespace for ungenerated digits
|
||||
(let ([left (modulo digits 10)])
|
||||
(unless (zero? left)
|
||||
(fprintf out "~a\t:~a\n" (make-string (- 10 left) #\space) n)))
|
||||
;; Compute more digits
|
||||
(let loop ([k m][q 0])
|
||||
(if (zero? k)
|
||||
(let* ((s (let ([s (number->string (+ b (quotient q r)))])
|
||||
(if (zero? digits)
|
||||
s
|
||||
(string-append (make-string (- d (string-length s)) #\0) s)))))
|
||||
(j-loop (remainder q r)
|
||||
(print-digits out s 0 (string-length s) digits n)))
|
||||
(let ([q (+ q (* (vector-ref a k) r))])
|
||||
(let ((t (+ (* k 2) 1)))
|
||||
(let-values ([(qt rr) (quotient/remainder q t)])
|
||||
(vector-set! a k rr)
|
||||
(loop (sub1 k) (* k qt)))))))))))
|
||||
|
||||
(define (print-digits out s start end digits n)
|
||||
(let* ([len (- end start)]
|
||||
[cnt (min len (- n digits) (- 10 (modulo digits 10)) len)])
|
||||
(if (zero? cnt)
|
||||
digits
|
||||
(begin
|
||||
(write-string s out start (+ start cnt))
|
||||
(let ([digits (+ digits cnt)])
|
||||
(when (zero? (modulo digits 10))
|
||||
(fprintf out "\t:~a\n" digits))
|
||||
(print-digits out s (+ start cnt) end digits n))))))
|
||||
|
||||
(define (main args)
|
||||
(let ((n (if (= (vector-length args) 0)
|
||||
1
|
||||
(string->number (vector-ref args 0)))))
|
||||
(pi n 10)))
|
||||
|
||||
(main (current-command-line-arguments)))
|
40
collects/tests/mzscheme/benchmarks/shootout/random.ss
Normal file
40
collects/tests/mzscheme/benchmarks/shootout/random.ss
Normal file
|
@ -0,0 +1,40 @@
|
|||
;;; http://shootout.alioth.debian.org/
|
||||
;;; Random implementation, by Jens Axel Sogaard
|
||||
;;;
|
||||
;;; Modified for proper string output by Brent Fulgham
|
||||
|
||||
(module random mzscheme
|
||||
(provide main)
|
||||
|
||||
(define IM 139968)
|
||||
(define IA 3877)
|
||||
(define IC 29573)
|
||||
|
||||
(define gen_random
|
||||
(let ((LAST 42))
|
||||
(lambda (max)
|
||||
(set! LAST (modulo (+ (* LAST IA) IC) IM))
|
||||
(/ (* max LAST) IM))))
|
||||
|
||||
(define (roundto digits num)
|
||||
(let* ([e (expt 10 digits)]
|
||||
[num (round (* e (inexact->exact num)))])
|
||||
(format "~a.~a"
|
||||
(quotient num e)
|
||||
(substring (string-append (number->string (remainder num e))
|
||||
(make-string digits #\0))
|
||||
0 digits))))
|
||||
|
||||
(define (main args)
|
||||
(let ((n (if (= (vector-length args) 0)
|
||||
1
|
||||
(string->number (vector-ref args 0)))))
|
||||
(let loop ((iter n))
|
||||
(if (> iter 1)
|
||||
(begin
|
||||
(gen_random 100.0)
|
||||
(loop (- iter 1)))))
|
||||
(printf "~a~%"
|
||||
(roundto 9 (gen_random 100.0)))))
|
||||
|
||||
(main (current-command-line-arguments)))
|
65
collects/tests/mzscheme/benchmarks/shootout/recursive.ss
Normal file
65
collects/tests/mzscheme/benchmarks/shootout/recursive.ss
Normal file
|
@ -0,0 +1,65 @@
|
|||
;; ---------------------------------------------------------------------
|
||||
;; The Great Computer Language Shootout
|
||||
;; http://shootout.alioth.debian.org/
|
||||
;;
|
||||
;; Code based on / inspired by existing, relevant Shootout submissions
|
||||
;;
|
||||
;; Derived from the Chicken variant, which was
|
||||
;; Contributed by Anthony Borla
|
||||
;; ---------------------------------------------------------------------
|
||||
|
||||
(module recursive mzscheme
|
||||
|
||||
;; -------------------------------
|
||||
|
||||
(define (ack m n)
|
||||
(cond ((zero? m) (+ n 1))
|
||||
((zero? n) (ack (- m 1) 1))
|
||||
(else (ack (- m 1) (ack m (- n 1))))))
|
||||
|
||||
;; --------------
|
||||
|
||||
(define (fib n)
|
||||
(cond ((< n 2) 1)
|
||||
(else (+ (fib (- n 2)) (fib (- n 1))))))
|
||||
|
||||
(define (fibflt n)
|
||||
(cond ((< n 2.0) 1.0)
|
||||
(else (+ (fibflt (- n 2.0)) (fibflt (- n 1.0))))))
|
||||
|
||||
;; --------------
|
||||
|
||||
(define (tak x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (tak (tak (- x 1) y z) (tak (- y 1) z x) (tak (- z 1) x y)))))
|
||||
|
||||
(define (takflt x y z)
|
||||
(cond ((not (< y x)) z)
|
||||
(else (takflt (takflt (- x 1.0) y z) (takflt (- y 1.0) z x) (takflt (- z 1.0) x y)))))
|
||||
|
||||
;; -------------------------------
|
||||
|
||||
(define (roundto digits n)
|
||||
(let* ([e (expt 10 digits)]
|
||||
[num (round (* e (inexact->exact n)))])
|
||||
(format "~a.~a"
|
||||
(quotient num e)
|
||||
(substring (string-append (number->string (remainder num e))
|
||||
(make-string digits #\0))
|
||||
0 digits))))
|
||||
|
||||
(define (main args)
|
||||
(let ((n (string->number (vector-ref args 0))))
|
||||
|
||||
(printf "Ack(3,~A): ~A~%" n (ack 3 n))
|
||||
(printf "Fib(~a): ~a~%" (roundto 1 (+ 27.0 n)) (roundto 1 (fibflt (+ 27.0 n))))
|
||||
|
||||
(set! n (- n 1))
|
||||
(printf "Tak(~A,~A,~A): ~A~%" (* n 3) (* n 2) n (tak (* n 3) (* n 2) n))
|
||||
|
||||
(printf "Fib(3): ~A~%" (fib 3))
|
||||
(printf "Tak(3.0,2.0,1.0): ~a~%" (roundto 1 (takflt 3.0 2.0 1.0)))))
|
||||
|
||||
;; -------------------------------
|
||||
|
||||
(main (current-command-line-arguments)))
|
59
collects/tests/mzscheme/benchmarks/shootout/regexmatch.ss
Normal file
59
collects/tests/mzscheme/benchmarks/shootout/regexmatch.ss
Normal file
|
@ -0,0 +1,59 @@
|
|||
;; $Id: regexmatch-mzscheme.code,v 1.9 2006/06/21 15:05:29 bfulgham Exp $
|
||||
;;; http://shootout.alioth.debian.org/
|
||||
;;;
|
||||
;;; Based on the Chicken implementation
|
||||
;;; Contributed by Brent Fulgham
|
||||
|
||||
;; Uses byte regexps instead of string regexps for a fairer comparison
|
||||
|
||||
;; NOTE: the running time of this benchmark is dominated by
|
||||
;; construction of the `num' string.
|
||||
|
||||
(module regexmatch mzscheme
|
||||
(define rx
|
||||
(string-append
|
||||
"(?:^|[^0-9\\(])" ; (1) preceeding non-digit or bol
|
||||
"(" ; (2) area code
|
||||
"\\(([0-9][0-9][0-9])\\)" ; (3) is either 3 digits in parens
|
||||
"|" ; or
|
||||
"([0-9][0-9][0-9])" ; (4) just 3 digits
|
||||
")" ; end of area code
|
||||
" " ; area code is followed by one space
|
||||
"([0-9][0-9][0-9])" ; (5) exchange is 3 digits
|
||||
"[ -]" ; separator is either space or dash
|
||||
"([0-9][0-9][0-9][0-9])" ; (6) last 4 digits
|
||||
"(?:[^0-9]|$)" ; must be followed by a non-digit
|
||||
))
|
||||
|
||||
|
||||
(define (main args)
|
||||
(let ((n (if (= (vector-length args) 0)
|
||||
"1"
|
||||
(vector-ref args 0)))
|
||||
(phonelines '())
|
||||
(rx (byte-regexp (string->bytes/utf-8 rx)))
|
||||
(count 0))
|
||||
(let loop ((line (read-bytes-line)))
|
||||
(cond ((eof-object? line) #f)
|
||||
(else
|
||||
(set! phonelines (cons line phonelines))
|
||||
(loop (read-line)))))
|
||||
(set! phonelines (reverse! phonelines))
|
||||
(do ([n (string->number n) (sub1 n)])
|
||||
((negative? n))
|
||||
(let loop ((phones phonelines)
|
||||
(count 0))
|
||||
(if (null? phones)
|
||||
count
|
||||
(let ([m (regexp-match rx (car phones))])
|
||||
(if m
|
||||
(let-values ([(a1 a2 a3 exch numb) (apply values (cdr m))])
|
||||
(let* ([area (and a1 (or a2 a3))]
|
||||
[num (bytes-append #"(" area #") " exch #"-" numb)]
|
||||
[count (add1 count)])
|
||||
(when (zero? n)
|
||||
(printf "~a: ~a~n" count num))
|
||||
(loop (cdr phones) count)))
|
||||
(loop (cdr phones) count))))))))
|
||||
|
||||
(main (current-command-line-arguments)))
|
105
collects/tests/mzscheme/benchmarks/shootout/regexpdna.ss
Normal file
105
collects/tests/mzscheme/benchmarks/shootout/regexpdna.ss
Normal file
|
@ -0,0 +1,105 @@
|
|||
;; ---------------------------------------------------------------------
|
||||
;; The Great Computer Language Shootout
|
||||
;; http://shootout.alioth.debian.org/
|
||||
;;
|
||||
;; Tested with PCRE [compiler must be built with PCRE already installed
|
||||
;; else other regex routines (with different behaviours) will be used].
|
||||
;; Regex performance appears reasonable, but file loading [of 'large'
|
||||
;; files] performance requires tweaking to effect a significant improvement.
|
||||
;;
|
||||
;; Contributed by Anthony Borla
|
||||
;; ---------------------------------------------------------------------
|
||||
|
||||
(module regexpdna mzscheme
|
||||
|
||||
(require (lib "port.ss"))
|
||||
|
||||
;; -------------------------------
|
||||
|
||||
(define VARIANTS
|
||||
'(#"agggtaaa|tttaccct" #"[cgt]gggtaaa|tttaccc[acg]" #"a[act]ggtaaa|tttacc[agt]t"
|
||||
#"ag[act]gtaaa|tttac[agt]ct" #"agg[act]taaa|ttta[agt]cct" #"aggg[acg]aaa|ttt[cgt]ccct"
|
||||
#"agggt[cgt]aa|tt[acg]accct" #"agggta[cgt]a|t[acg]taccct" #"agggtaa[cgt]|[acg]ttaccct"))
|
||||
|
||||
|
||||
(define IUBS
|
||||
'((#"B" #"(c|g|t)") (#"D" #"(a|g|t)") (#"H" #"(a|c|t)")
|
||||
(#"K" #"(g|t)") (#"M" #"(a|c)") (#"N" #"(a|c|g|t)")
|
||||
(#"R" #"(a|g)") (#"S" #"(c|g)") (#"V" #"(a|c|g)")
|
||||
(#"W" #"(a|t)") (#"Y" #"(c|t)")))
|
||||
|
||||
;; -------------------------------
|
||||
|
||||
(define (ci-byte-regexp s)
|
||||
(byte-regexp (ci-pattern s)))
|
||||
(define (ci-pattern s)
|
||||
(let ([m (regexp-match #rx#"^(.*)\\[([^]]*)\\](.*)$" s)])
|
||||
(if m
|
||||
(bytes-append (ci-pattern (cadr m))
|
||||
#"["
|
||||
(regexp-replace* #rx#"[a-zA-Z]" (caddr m) both-cases)
|
||||
#"]"
|
||||
(ci-pattern (cadddr m)))
|
||||
(regexp-replace* #rx#"[a-zA-Z]" s (lambda (s)
|
||||
(string->bytes/latin-1
|
||||
(format "[~a]" (both-cases s))))))))
|
||||
(define (both-cases s)
|
||||
(string->bytes/latin-1
|
||||
(format "~a~a"
|
||||
(string-downcase (bytes->string/latin-1 s))
|
||||
(string-upcase (bytes->string/latin-1 s)))))
|
||||
|
||||
;; -------------------------------
|
||||
|
||||
(define (match-count str rx offset cnt)
|
||||
(let ([m (regexp-match-positions rx str offset)])
|
||||
(if m
|
||||
(match-count str rx (cdar m) (add1 cnt))
|
||||
cnt)))
|
||||
|
||||
;; --------------
|
||||
|
||||
(define (replace-all rx str new)
|
||||
(let ([out (open-output-bytes)])
|
||||
(let loop ([pos 0])
|
||||
(let ([m (regexp-match-positions rx str pos)])
|
||||
(if m
|
||||
(begin
|
||||
(write-bytes str out pos (caar m))
|
||||
(write-bytes new out)
|
||||
(loop (cdar m)))
|
||||
(write-bytes str out pos))))
|
||||
(get-output-bytes out)))
|
||||
|
||||
;; -------------------------------
|
||||
|
||||
(define (input->bytes)
|
||||
(let ([b (open-output-bytes)])
|
||||
(copy-port (current-input-port) b)
|
||||
(get-output-bytes b)))
|
||||
|
||||
;; -------------------------------
|
||||
|
||||
;; Load sequence and record its length
|
||||
(let* ([orig (input->bytes)]
|
||||
[filtered (replace-all #rx#"(>.*?\n)|\n" orig #"")])
|
||||
|
||||
;; Perform regexp counts
|
||||
(for-each
|
||||
(lambda (i)
|
||||
(printf "~a ~a\n" i (match-count filtered (ci-byte-regexp i) 0 0)))
|
||||
VARIANTS)
|
||||
|
||||
;; Perform regexp replacements, and record sequence length
|
||||
(let ([replaced
|
||||
(let loop ([sequence filtered]
|
||||
[IUBS IUBS])
|
||||
(if (null? IUBS)
|
||||
sequence
|
||||
(loop (replace-all (byte-regexp (caar IUBS)) sequence (cadar IUBS))
|
||||
(cdr IUBS))))])
|
||||
;; Print statistics
|
||||
(printf "~%~A~%~A~%~A~%"
|
||||
(bytes-length orig)
|
||||
(bytes-length filtered)
|
||||
(bytes-length replaced)))))
|
|
@ -0,0 +1,60 @@
|
|||
|
||||
(module reversecomplement mzscheme
|
||||
|
||||
(define translation (make-vector 128))
|
||||
|
||||
(for-each (lambda (from-to)
|
||||
(let ([char (lambda (sym)
|
||||
(string-ref (symbol->string sym) 0))])
|
||||
(let ([from (char (car from-to))]
|
||||
[to (char->integer (char-upcase (char (cadr from-to))))])
|
||||
(vector-set! translation (char->integer from) to)
|
||||
(vector-set! translation (char->integer (char-upcase from)) to))))
|
||||
'([a t]
|
||||
[c g]
|
||||
[g c]
|
||||
[t a]
|
||||
[u a]
|
||||
[m k]
|
||||
[r y]
|
||||
[w w]
|
||||
[s s]
|
||||
[y R]
|
||||
[k M]
|
||||
[v b]
|
||||
[h d]
|
||||
[d h]
|
||||
[b v]
|
||||
[n n]))
|
||||
|
||||
(define (output lines)
|
||||
(let* ([str (apply bytes-append lines)]
|
||||
[o (current-output-port)]
|
||||
[len (bytes-length str)])
|
||||
(let loop ([offset 0])
|
||||
(when (< offset len)
|
||||
(write-bytes str o offset (min len (+ offset 60)))
|
||||
(newline o)
|
||||
(loop (+ offset 60))))))
|
||||
|
||||
(let ([in (current-input-port)])
|
||||
(let loop ([accum null])
|
||||
(let ([l (read-bytes-line in)])
|
||||
(if (eof-object? l)
|
||||
(output accum)
|
||||
(cond
|
||||
[(regexp-match #rx#"^>" l)
|
||||
(output accum)
|
||||
(printf "~a\n" l)
|
||||
(loop null)]
|
||||
[else
|
||||
(let* ([len (bytes-length l)]
|
||||
[dest (make-bytes len)])
|
||||
(let loop ([i 0][j (- len 1)])
|
||||
(unless (= i len)
|
||||
(bytes-set! dest
|
||||
j
|
||||
(vector-ref translation (bytes-ref l i)))
|
||||
(loop (add1 i) (sub1 j))))
|
||||
(loop (cons dest accum)))]))))))
|
||||
|
13
collects/tests/mzscheme/benchmarks/shootout/reversefile.ss
Normal file
13
collects/tests/mzscheme/benchmarks/shootout/reversefile.ss
Normal file
|
@ -0,0 +1,13 @@
|
|||
;;; -*- mode: scheme -*-
|
||||
;;; $Id: reversefile-mzscheme.code,v 1.10 2006/06/21 15:05:29 bfulgham Exp $
|
||||
;;; http://shootout.alioth.debian.org/
|
||||
;;; Provided by Bengt Kleberg
|
||||
|
||||
(module reversefile mzscheme
|
||||
(let ([inport (current-input-port)])
|
||||
(let rev ([lines null])
|
||||
(let ([line (read-bytes-line inport)])
|
||||
(if (eof-object? line)
|
||||
(for-each (lambda (l) (printf "~a\n" l))
|
||||
lines)
|
||||
(rev (cons line lines)))))))
|
54
collects/tests/mzscheme/benchmarks/shootout/run.ss
Normal file
54
collects/tests/mzscheme/benchmarks/shootout/run.ss
Normal file
|
@ -0,0 +1,54 @@
|
|||
(module run mzscheme
|
||||
(define input-map
|
||||
'(
|
||||
("ackermann.ss" . "11")
|
||||
("ary.ss" . "9000")
|
||||
("binarytrees.ss" . "16")
|
||||
("chameneos.ss")
|
||||
("cheapconcurrency.ss")
|
||||
("echo.ss" . "150000")
|
||||
("except.ss" . "2500000")
|
||||
("fannkuch.ss")
|
||||
("fasta.ss")
|
||||
("fibo.ss" . "32")
|
||||
("hash.ss" . "100000")
|
||||
("hash2.ss" . "200")
|
||||
("heapsort.ss" . "100000")
|
||||
("lists.ss" . "18")
|
||||
("mandelbrot.ss")
|
||||
("matrix.ss" . "600")
|
||||
("moments.ss" . "200")
|
||||
("nbody.ss")
|
||||
("nestedloop.ss" . "18")
|
||||
("nsieve.ss")
|
||||
("nsievebits.ss")
|
||||
("partialsums.ss")
|
||||
("pidigits.ss")
|
||||
("pidigits1.ss")
|
||||
("random.ss" . "900000")
|
||||
("recursive.ss")
|
||||
("regexmatch.ss")
|
||||
("regexpdna.ss")
|
||||
("reversecomplement.ss")
|
||||
("reversefile.ss")
|
||||
("sieve.ss" . "1200")
|
||||
("spellcheck.ss")
|
||||
("strcat.ss" . "40000")
|
||||
("sumcol.ss")
|
||||
("wc.ss")
|
||||
("wordfreq.ss")
|
||||
))
|
||||
|
||||
(let ([len (vector-length (current-command-line-arguments))])
|
||||
(unless (= 1 len)
|
||||
(error 'run "provide ~athe name of a benchmark on the command line"
|
||||
(if (zero? len) "" "ONLY "))))
|
||||
|
||||
(let ([prog (vector-ref (current-command-line-arguments) 0)])
|
||||
(let ([m (assoc prog input-map)])
|
||||
(unless m
|
||||
(error 'run "cannot find input for ~a" prog))
|
||||
(when (null? (cdr m))
|
||||
(error 'run "don't know input for ~a" prog))
|
||||
(parameterize ([current-command-line-arguments (vector (cdr m))])
|
||||
(time (dynamic-require prog #f))))))
|
25
collects/tests/mzscheme/benchmarks/shootout/sieve.ss
Normal file
25
collects/tests/mzscheme/benchmarks/shootout/sieve.ss
Normal file
|
@ -0,0 +1,25 @@
|
|||
(module sieve mzscheme
|
||||
|
||||
(define (main args)
|
||||
(let ((n (if (= (vector-length args) 0)
|
||||
1
|
||||
(string->number (vector-ref args 0))))
|
||||
(count 0)
|
||||
(flags (make-vector 8192)))
|
||||
(let loop ((iter n))
|
||||
(if (> iter 0)
|
||||
(begin
|
||||
(do ((i 0 (+ i 1))) ((>= i 8192)) (vector-set! flags i #t))
|
||||
(set! count 0)
|
||||
(do ((i 2 (+ 1 i)))
|
||||
((>= i 8192))
|
||||
(if (vector-ref flags i)
|
||||
(begin
|
||||
(do ((k (+ i i) (+ k i)))
|
||||
((>= k 8192))
|
||||
(vector-set! flags k #f))
|
||||
(set! count (+ 1 count)))))
|
||||
(loop (- iter 1)))))
|
||||
(display "Count: ") (display count) (newline)))
|
||||
|
||||
(main (current-command-line-arguments)))
|
23
collects/tests/mzscheme/benchmarks/shootout/spellcheck.ss
Normal file
23
collects/tests/mzscheme/benchmarks/shootout/spellcheck.ss
Normal file
|
@ -0,0 +1,23 @@
|
|||
;;; The Great Computer Language Shootout
|
||||
;;; http://shootout.alioth.debian.org/
|
||||
;;;
|
||||
;;; spellcheck benchmark
|
||||
|
||||
(module spellcheck mzscheme
|
||||
(define dict (make-hash-table 'equal))
|
||||
|
||||
(with-input-from-file "Usr.Dict.Words"
|
||||
(lambda ()
|
||||
(let loop ()
|
||||
(let ([r (read-bytes-line)])
|
||||
(unless (eof-object? r)
|
||||
(hash-table-put! dict r #t)
|
||||
(loop))))))
|
||||
|
||||
(let ([in (current-input-port)])
|
||||
(let loop ()
|
||||
(let ([w (read-bytes-line in)])
|
||||
(unless (eof-object? w)
|
||||
(unless (hash-table-get dict w (lambda () #f))
|
||||
(printf "~a\n" w))
|
||||
(loop))))))
|
35
collects/tests/mzscheme/benchmarks/shootout/strcat.ss
Normal file
35
collects/tests/mzscheme/benchmarks/shootout/strcat.ss
Normal file
|
@ -0,0 +1,35 @@
|
|||
; strcat.scm
|
||||
|
||||
;;; SPECIFICATION
|
||||
|
||||
;For this test, each program should be implemented in the same way,
|
||||
;according to the following specification.
|
||||
;
|
||||
; pseudocode for strcat test
|
||||
;
|
||||
; s is initialized to the null string
|
||||
; repeat N times:
|
||||
; append "hello\n" to s
|
||||
; count the number of individual characters in s
|
||||
; print the count
|
||||
|
||||
; There should be N distinct string append statements done in a loop.
|
||||
; After each append the resultant string should be 6 characters
|
||||
; longer (the length of "hello\n").
|
||||
; s should be a string, string buffer, or character array.
|
||||
; The program should not construct a list of strings and join it.
|
||||
|
||||
(module strcat mzscheme
|
||||
(define p (open-output-bytes))
|
||||
|
||||
(define hello #"hello\n")
|
||||
|
||||
(let loop ([n (string->number
|
||||
(vector-ref (current-command-line-arguments) 0))])
|
||||
(unless (zero? n)
|
||||
(display hello p)
|
||||
;; At this point, (get-output-bytes p) would
|
||||
;; return the byte string accumulated so far.
|
||||
(loop (sub1 n))))
|
||||
|
||||
(printf "~a\n" (file-position p)))
|
10
collects/tests/mzscheme/benchmarks/shootout/sumcol.ss
Normal file
10
collects/tests/mzscheme/benchmarks/shootout/sumcol.ss
Normal file
|
@ -0,0 +1,10 @@
|
|||
;;; http://shootout.alioth.debian.org/
|
||||
;;;
|
||||
;;; Contributed by Eli Barzilay
|
||||
|
||||
(module sumcol mzscheme
|
||||
(let loop ([acc 0])
|
||||
(let ([n (read)])
|
||||
(if (eof-object? n)
|
||||
(printf "~a\n" acc)
|
||||
(loop (+ acc n))))))
|
18
collects/tests/mzscheme/benchmarks/shootout/wc.ss
Normal file
18
collects/tests/mzscheme/benchmarks/shootout/wc.ss
Normal file
|
@ -0,0 +1,18 @@
|
|||
;
|
||||
; Faster, more idiomatic Scheme by Neil Van Dyke
|
||||
;
|
||||
|
||||
(module wc mzscheme
|
||||
(define (main iport)
|
||||
(apply printf "~s ~s ~s\n"
|
||||
(let wc ((i #f) (lines 0) (words 0) (chars 0))
|
||||
(let ((x (read-char iport)))
|
||||
(if (eof-object? x)
|
||||
(list lines words chars)
|
||||
(case x
|
||||
((#\newline) (wc #f (add1 lines) words (add1 chars)))
|
||||
((#\space #\tab) (wc #f lines words (add1 chars)))
|
||||
(else
|
||||
(wc #t lines (if i words (add1 words)) (add1 chars)))))))))
|
||||
|
||||
(main (current-input-port)))
|
32
collects/tests/mzscheme/benchmarks/shootout/wordfreq.ss
Normal file
32
collects/tests/mzscheme/benchmarks/shootout/wordfreq.ss
Normal file
|
@ -0,0 +1,32 @@
|
|||
; $Id: wordfreq-mzscheme.code,v 1.10 2006/06/21 15:05:34 bfulgham Exp $
|
||||
; http://shootout.alioth.debian.org/
|
||||
; wordfreq.mzscheme by Grzegorz Chrupaa
|
||||
; Updated and corrected by Brent Fulgham
|
||||
; Re-written by Matthew Flatt with some inspriation from the Python example
|
||||
|
||||
(module wordfreq mzscheme
|
||||
(require (lib "list.ss"))
|
||||
|
||||
(define t (make-hash-table 'equal))
|
||||
|
||||
(define (register-word! s)
|
||||
(let ([s (string-downcase (bytes->string/utf-8 s))])
|
||||
(hash-table-put! t s (add1 (hash-table-get t s (lambda () 0))))))
|
||||
|
||||
(let ([in (current-input-port)])
|
||||
(let loop ()
|
||||
(let ([m (regexp-match #rx#"[a-zA-Z]+" in)])
|
||||
(when m
|
||||
(register-word! (car m))
|
||||
(loop)))))
|
||||
|
||||
(for-each display
|
||||
(sort (hash-table-map
|
||||
t
|
||||
(lambda (word count)
|
||||
(let ((count (number->string count)))
|
||||
(format"~a~a ~a~%"
|
||||
(make-string (- 7 (string-length count)) #\space)
|
||||
count
|
||||
word))))
|
||||
string>?)))
|
Loading…
Reference in New Issue
Block a user