aboutsummaryrefslogtreecommitdiff
path: root/scheme/logo.scm
blob: 18fc9ed20f65f81bf0165bfab276ddea6427df8e (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49

; Equivalent to test/logo.adb


(define (value bin)
  (cond
    ((null? bin) 0)
    ((zero? (car bin)) (* 2 (value (cdr bin))))
    (#t (+ 1 (* 2 (value (cdr bin)))))))


(define (test pow base)
  (begin
    (display (string-append "log_" (number->string base) " (" (number->string pow) ") = "))
    (let* ((n (build-num pow))
           (b (build-num base))
           (s (run 1 (d) (fresh (q r) (== d `(,q ,r)) (logo n b q r))))
           (q (car (car s)))
           (r (car (cdr (car s)))))
      (begin
        (display (value q))
        (display " r ")
        (display (value r))
        (newline)))))


(define (run-logo args)
  (begin
    (display "Logarithm")
    (newline)
    (test 1 1)
    (test 68 2)
    (test 68 3)
    (test 68 4)
    (test 68 5)
    (test 68 6)
    (test 68 7)
    (test 68 8)
    (newline)
    (display "Expected Failure")
    (newline)
    (display (run 1 (d) (fresh (q r) (== d `(,q ,r)) (logo 68 1 q r))))
    (newline)
    (display (run 1 (d) (fresh (q r) (== d `(,q ,r)) (logo 68 0 q r))))
    (newline)
    (display (run 1 (d) (fresh (q r) (== d `(,q ,r)) (logo 0 0 q r))))
    (newline)))