1 ;; binom-demo.el - Example of scholium programming using a math example
3 ;; Copyright (C) 2013 Raymond S. Puzio
5 ;; This program is free software: you can redistribute it and/or modify
6 ;; it under the terms of the GNU Affero General Public License as published by
7 ;; the Free Software Foundation, either version 3 of the License, or
8 ;; (at your option) any later version.
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU Affero General Public License for more details.
15 ;; You should have received a copy of the GNU Affero General Public License
16 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ;; See http://arxana.net/binom.jpg for a vital map.
24 (load-file "prelim.el")
25 (load-file "bootstart.el")
26 (load-file "schprog.el")
28 ;; Access functions to pull up relevant information
29 ;; for operations to weave, tangle, and run the program.
31 (defun get-dependencies (art)
33 (list (cadr (get-txt x
))
37 (let ((z (get-txt y
)))
48 (get-txt (get-src x
)))
51 (equal 'var
(get-txt y
)))
60 (equal 'name
(get-txt y
)))
63 (defun get-chunks (art)
65 (list (cadr (get-txt x
))
69 (let ((z (get-txt y
)))
75 (defun get-code (node)
80 ;; The network shown in the accompanying picture.
83 '(24 (23 (5) (chunk (CALL MYSELF
)) (3))
84 (22 (4) (chunk (BOUNDARY CASE
)) (3))
89 (17 (3) (sub choose
) (3))
90 (16 (2) (sub pow
) (2))
91 (15 (1) (sub choose
) (3))
92 (14 (1) (sub pow
) (2))
96 (10 (0 20) choose
(0))
99 (7 (0 13) (m n p
) (0))
100 (6 (0 12) bin-prob
(0))
102 (+ (choose (- m
1) n
)
103 (choose (- m
1) (- n
1)))
113 (0 23 22 21 20 17 15))
117 (* x
(pow x
(- n
1)))))
121 (pow (- 1 p
) (- n
1))
124 (0 (0 11 10 9 8 7 6 5 4 3 2 1)
126 (0 11 10 9 8 7 6 5 4 3 2 1))))
128 ;; Run the program in situ.
137 ;; A look under the hood.
149 (quote get-dependencies
))
154 (+ (choose (- m
1) n
)
155 (choose (- m
1) (- n
1))))))
157 ;; Tangle it down to a regular program lising, then run it.
166 (defun bin-prob (m n p
)
168 (pow (- 1 p
) (- n
1))
179 (defun pow (x n
) (if (equal n
0)
181 (* x
(pow x
(- n
1)))))
195 1 (+ (choose (- m
1) n
)
196 (choose (- m
1) (- n
1)))))