other
(in-package "ACL2")
install-df-basic-primitivesfunction
(defun install-df-basic-primitives (state) (declare (xargs :mode :program)) (if (global-val 'boot-strap-pass-2 (w state)) state (set-w 'extension (install-df-basic-primitives-1 *df-basic-primitives* (w state)) state)))
other
(pprogn (install-df-basic-primitives state) (deflabel df-basic-primitives-installed))
to-df?-fnfunction
(defun to-df?-fn (x) (declare (xargs :guard t)) (let ((x (cond ((and (consp x) (consp (cdr x)) (null (cddr x)) (eq (car x) 'quote) (acl2-numberp (cadr x))) (cadr x)) (t x)))) (cond ((acl2-numberp x) (cond ((dfp x) `(to-df ,X)) (t x))) ((and (symbolp x) (legal-constantp1 x) (not (member-eq x '(t nil)))) `(let ((c ,X)) (assert$ (dfp c) (to-df c)))) (t x))))
to-df?-argsfunction
(defun to-df?-args (lst) (declare (xargs :guard (true-listp lst))) (cond ((endp lst) nil) (t (cons (to-df?-fn (car lst)) (to-df?-args (cdr lst))))))
defun-df-eventsfunction
(defun defun-df-events (fn-name macro-name formals rest) (declare (xargs :guard (and (symbolp macro-name) (symbolp fn-name)))) (let ((dfp-thm-name (packn-pos (list 'dfp- fn-name) fn-name)) (rationalp-thm-name (packn-pos (list 'rationalp- fn-name) fn-name))) `((defun ,FN-NAME ,FORMALS ,@(AND FORMALS `((DECLARE (TYPE DOUBLE-FLOAT ,@FORMALS)))) ,@REST) (defthm ,DFP-THM-NAME (dfp (,FN-NAME ,@FORMALS))) (defthm ,RATIONALP-THM-NAME (rationalp (,FN-NAME ,@FORMALS)) :rule-classes :type-prescription) ,@(AND MACRO-NAME `((DEFMACRO ,MACRO-NAME ,FORMALS (CONS ',FN-NAME (TO-DF?-ARGS (LIST ,@FORMALS)))) ,(IF (EQ MACRO-NAME 'DF-LOG) `(TABLE UNTRANS-TABLE ',FN-NAME '(,MACRO-NAME)) `(ADD-MACRO-FN ,MACRO-NAME ,FN-NAME)) (VALUE-TRIPLE ',MACRO-NAME))))))
defun-dfmacro
(defmacro defun-df (fn formals &rest rest) (let* ((fn-fn (packn-pos (list fn '-fn) fn)) (events (defun-df-events fn-fn fn formals rest)) (defun-ev (car events)) (rest-evs (cdr events))) `(with-output :stack :push :off :all :on error (progn (with-output :stack :pop ,DEFUN-EV) ,@REST-EVS))))
other
(add-macro-fn df< df<-fn)
other
(add-macro-fn df= df=-fn)
df/=-fnfunction
(defun df/=-fn (x y) (declare (type double-float x y)) (/= (from-df x) (from-df y)))
other
(add-macro-fn df/= df/=-fn)
df-minus-1function
(defun df-minus-1 nil (declare (xargs :guard t)) (to-df -1))
df-function-sigsfunction
(defun df-function-sigs (flg) (declare (xargs :guard t)) `((df-expt-fn (x y) (or (df< 0 x) (and (df= 0 x) (df< 0 y)))) (df-exp-fn (x)) (df-sqrt-fn (x) (df<= 0 x)) (binary-df-log (x y) (and (df< 0 x) (df<= 0 y))) (unary-df-log (x) (df< 0 x)) (df-abs-fn (x)) (df-sin-fn (x)) (df-cos-fn (x)) (df-tan-fn (x) (not (df= (,(IF FLG 'CONSTRAINED-DF-COS-FN 'DF-COS-FN) x) 0))) (df-asin-fn (x) (df<= (df-abs-fn x) 1)) (df-acos-fn (x) (df<= (df-abs-fn x) 1)) (df-atan-fn (x)) (df-sinh-fn (x)) (df-cosh-fn (x)) (df-tanh-fn (x) (not (df= (,(IF FLG 'CONSTRAINED-DF-COSH-FN 'DF-COSH-FN) x) 0))) (df-asinh-fn (x)) (df-acosh-fn (x) (df<= 1 x)) (df-atanh-fn (x) (df< (df-abs x) 1)) (df-pi nil)))
*df-function-sigs-exec*constant
(defconst *df-function-sigs-exec* (df-function-sigs nil))
df-macro-namefunction
(defun df-macro-name (fn) (declare (type symbol fn)) (let ((name (symbol-name fn))) (and (string-suffixp "-FN" name) (intern-in-package-of-symbol (subseq name 0 (- (length name) 3)) fn))))
*df-primitives*constant
(defconst *df-primitives* (cons 'dfp (append-strip-cars *df-basic-primitives* (strip-cars *df-function-sigs-exec*))))
df-events-1function
(defun df-events-1 (sig flg) (declare (xargs :guard (and (<= 2 (len sig)) (symbolp (car sig)) (symbol-listp (cadr sig))))) (let* ((name (car sig)) (formals (cadr sig)) (guard (if (consp (cddr sig)) (caddr sig) t)) (constrained-name (packn (list 'constrained- name))) (name (if flg constrained-name name)) (macro-name (and (null flg) (df-macro-name name))) (rest `((declare (xargs :guard ,GUARD)) (to-df (non-exec (,CONSTRAINED-NAME ,@FORMALS))))) (events (defun-df-events name macro-name formals rest))) (if flg (cons `(local (defun ,NAME ,FORMALS 0)) (cdr events)) events)))
df-eventsfunction
(defun df-events (sigs flg) (declare (xargs :guard (and (symbol-alistp sigs) (all->=-len sigs 2) (symbol-list-listp (strip-cadrs sigs))))) (cond ((endp sigs) nil) (t (append (df-events-1 (car sigs) flg) (df-events (cdr sigs) flg)))))
prefix-sigs-with-constrainedfunction
(defun prefix-sigs-with-constrained (sigs) (declare (xargs :guard (and (alistp sigs) (symbol-alistp sigs) (true-list-listp sigs)))) (cond ((endp sigs) nil) (t (cons (let* ((sig (car sigs)) (fn (car sig)) (formals (cadr sig))) (list (packn (list 'constrained- fn)) formals t)) (prefix-sigs-with-constrained (cdr sigs))))))
df-constrained-functions-intromacro
(defmacro df-constrained-functions-intro nil (let ((sigs (df-function-sigs t))) `(encapsulate nil (logic) (partial-encapsulate ,(PREFIX-SIGS-WITH-CONSTRAINED SIGS) nil (set-ignore-ok t) (set-irrelevant-formals-ok t) ,@(DF-EVENTS SIGS T)))))
df-non-constrained-functions-eventsfunction
(defun df-non-constrained-functions-events nil (declare (xargs :guard t)) (df-events *df-function-sigs-exec* nil))
df-non-constrained-functions-intromacro
(defmacro df-non-constrained-functions-intro nil (cons 'progn (df-non-constrained-functions-events)))
other
(df-constrained-functions-intro)
df-rationalizefunction
(defun df-rationalize (x) (declare (xargs :mode :logic) (type double-float x)) (constrained-df-rationalize (from-df x)))
rationalp-df-rationalizetheorem
(defthm rationalp-df-rationalize (rationalp (df-rationalize x)) :rule-classes :type-prescription)
to-df-of-df-rationalizetheorem
(defthm to-df-of-df-rationalize (implies (dfp x) (equal (to-df (df-rationalize x)) x)))
in-theory
(in-theory (disable (:definition df-rationalize)))
rizefunction
(defun rize (x) (declare (type rational x)) (df-rationalize (to-df x)))
to-dfp-of-rizetheorem
(defthm to-dfp-of-rize (implies (dfp x) (equal (to-dfp (rize x)) x)))
stringp-df-stringtheorem
(defthm stringp-df-string (stringp (df-string x)) :rule-classes :type-prescription)
df+macro
(defmacro df+ (&rest rst) (let ((rst (to-df?-args rst))) (if rst (if (cdr rst) (xxxjoin 'binary-df+ rst) (cons 'binary-df+ (cons '(df0) (cons (car rst) nil)))) '(df0))))
df-macro
(defmacro df- (x &optional (y 'nil yp)) (cond (yp `(binary-df+ ,(TO-DF?-FN X) (unary-df- ,(TO-DF?-FN Y)))) (t `(unary-df- ,(TO-DF?-FN X)))))
df*macro
(defmacro df* (&rest rst) (let ((rst (to-df?-args rst))) (cond ((null rst) '(df1)) ((null (cdr rst)) (list 'binary-df* '(df1) (car rst))) (t (xxxjoin 'binary-df* rst)))))
df/macro
(defmacro df/ (x &optional (y 'nil yp)) (cond (yp `(binary-df/ ,(TO-DF?-FN X) ,(TO-DF?-FN Y))) (t `(unary-df/ ,(TO-DF?-FN X)))))
df-logmacro
(defmacro df-log (x &optional (y 'nil yp)) (if yp `(binary-df-log ,(TO-DF?-FN X) ,(TO-DF?-FN Y)) `(unary-df-log ,(TO-DF?-FN X))))
other
(add-macro-fn df+ binary-df+ t)
other
(add-macro-fn df* binary-df* t)
other
(table untrans-table 'unary-df- '(df-))
other
(table untrans-table 'unary-df/ '(df/))
other
(table untrans-table 'binary-df/ '(df/))
other
(table untrans-table 'unary-df-log '(df-log))
other
(table untrans-table 'binary-df-log '(df-log))
in-theory
(in-theory (set-difference-theories (current-theory :here) (strip-cars *df-function-sigs-exec*)))