A categorical programming language
Revisión | bb980a9488cc1866b3be9f784be7722bcb8f4795 (tree) |
---|---|
Tiempo | 2021-09-30 07:25:05 |
Autor | Corbin <cds@corb...> |
Commiter | Corbin |
Fix up float functions, raytrace a cubic function.
@@ -4,8 +4,8 @@ module CodeCache = Map.Make (String) | ||
4 | 4 | |
5 | 5 | let primitives = |
6 | 6 | "id comp ignore fst snd pair left right case curry uncurry \ |
7 | - zero succ pr nil cons fold t f not conj disj pick \ | |
8 | - f-zero f-one f-negate f-add f-mul f-sqrt" | |
7 | + zero succ pr nil cons fold t f not conj disj either pick \ | |
8 | + f-zero f-one f-negate f-recip f-lt f-add f-mul f-sqrt" | |
9 | 9 | |
10 | 10 | let filter = |
11 | 11 | List.fold_left |
@@ -0,0 +1 @@ | ||
1 | +(comp (pair f-one f/9) f-add) |
@@ -0,0 +1 @@ | ||
1 | +(comp f/10 f/cube) |
@@ -0,0 +1 @@ | ||
1 | +(comp (pair f-one f-one) f-add) |
@@ -0,0 +1 @@ | ||
1 | +(comp (pair f-one f/2) f-add) |
@@ -0,0 +1 @@ | ||
1 | +(comp f/3 f/sqr) |
@@ -0,0 +1,2 @@ | ||
1 | +(comp (comp (f/error @0) f/sqr) | |
2 | + (comp (pair id (comp ignore (comp f/1000 f-recip))) f-lt)) |
@@ -0,0 +1 @@ | ||
1 | +(comp (comp (pair id fun/dup) (pair fst (comp snd f-mul))) f-mul) |
@@ -0,0 +1 @@ | ||
1 | +(comp (pair (comp fst @0) (comp snd f-negate)) f-add) |
@@ -0,0 +1 @@ | ||
1 | +(comp (comp fun/dup (pair fst (comp snd nat/sqr))) nat/mul) |
@@ -14,6 +14,7 @@ | ||
14 | 14 | ; Literal s and t. |
15 | 15 | ((== expr 'conj) (== s (list 'pair '2 '2)) (== t '2)) |
16 | 16 | ((== expr 'disj) (== s (list 'pair '2 '2)) (== t '2)) |
17 | + ((== expr 'either) (== s '2) (== t (list 'sum '1 '1))) | |
17 | 18 | ((== expr 'f-lt) (== s (list 'pair 'F 'F)) (== t '2)) |
18 | 19 | ((== expr 'f-add) (== s (list 'pair 'F 'F)) (== t 'F)) |
19 | 20 | ((== expr 'f-mul) (== s (list 'pair 'F 'F)) (== t 'F)) |
@@ -27,6 +28,7 @@ | ||
27 | 28 | ((== expr 'f-zero) (== s '1) (== t 'F)) |
28 | 29 | ((== expr 'f-one) (== s '1) (== t 'F)) |
29 | 30 | ((== expr 'f-negate) (== s 'F) (== t 'F)) |
31 | + ((== expr 'f-recip) (== s 'F) (== t 'F)) | |
30 | 32 | ; Literal s, recursive t. |
31 | 33 | ((fresh (x f) (== expr (list 'pr x f)) |
32 | 34 | (== s 'N) (cammyo x '1 t) (cammyo f t t))) |
@@ -26,6 +26,7 @@ | ||
26 | 26 | (define f (lambda (x) #f)) |
27 | 27 | (define conj (lambda (xy) (and (car xy) (cdr xy)))) |
28 | 28 | (define disj (lambda (xy) (or (car xy) (cdr xy)))) |
29 | +(define either (lambda (b) (if b (left '()) (right '())))) | |
29 | 30 | (define pick (lambda (bxy) |
30 | 31 | (let ((xy (cdr bxy))) |
31 | 32 | (if (car bxy) (car xy) (cdr xy))))) |
@@ -43,6 +44,7 @@ | ||
43 | 44 | (define f-zero (lambda (x) (flonum 0.0))) |
44 | 45 | (define f-one (lambda (x) (flonum 1.0))) |
45 | 46 | (define (f-negate x) (fl- x)) |
47 | +(define (f-recip x) (fl/ x)) | |
46 | 48 | (define (f-lt xy) (fl<? (car xy) (cdr xy))) |
47 | 49 | (define (f-add xy) (fl+ (car xy) (cdr xy))) |
48 | 50 | (define (f-mul xy) (fl* (car xy) (cdr xy))) |
@@ -78,6 +80,7 @@ | ||
78 | 80 | (parser (argv))) |
79 | 81 | |
80 | 82 | (define ty-parse (match-lambda |
83 | + ['1 arg-unit] | |
81 | 84 | ['N arg-nat] |
82 | 85 | ['F arg-fp] |
83 | 86 | [('list x) (arg-list (ty-parse x))] |