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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
; Lispfloat - Interface to the Common Lisp Floating Point Operations
; Copyright (C) 2016 Centaur Technology
;
; Contact:
; Centaur Technology Formal Verification Group
; 7600-C N. Capital of Texas Highway, Suite 300, Austin, TX 78731, USA.
; http://www.centtech.com/
;
; License: (An MIT/X11-style license)
;
; Permission is hereby granted, free of charge, to any person obtaining a
; copy of this software and associated documentation files (the "Software"),
; to deal in the Software without restriction, including without limitation
; the rights to use, copy, modify, merge, publish, distribute, sublicense,
; and/or sell copies of the Software, and to permit persons to whom the
; Software is furnished to do so, subject to the following conditions:
;
; The above copyright notice and this permission notice shall be included in
; all copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
; DEALINGS IN THE SOFTWARE.
;
; Original author: Jared Davis <jared@centtech.com>
(in-package "LISPFLOAT")
(include-book "std/basic/defs" :dir :system)
(include-book "std/strings/cat" :dir :system)
(include-book "std/util/defmvtypes" :dir :system)
(include-book "centaur/fty/basetypes" :dir :system)
(include-book "centaur/fty/fixequiv" :dir :system)
(defmacro def-float-op (name args short)
`(progn
(local (defun ,name ,args
;; Keeping this out of the defsection seems to help to avoid
;; sucking the whole encapsulate into the docs for each function.
(declare (ignorable . ,args))
(mv nil 0)))
(defsection-progn ,name
:parents (lispfloat)
:short ,short
:long ,(str::cat
"<p>@(call " (xdoc::full-escape-symbol name) ") is a @(see
lispfloat) wrapper function.</p>
<p>In the logic this function does not have a definition, but
its @(see acl2::constraint)s say it returns @('(mv errmsg ans)'),
where:</p>
<ul>
<li>@('errmsg') is either a string that indicates an error
has occurred (e.g., a rounding error when converting rationals
to floats, an overflow, etc.)</li>
<li>@('ans') is a rational.</li>
</ul>")
"<h5>Basic Type Theorems</h5>"
(defmvtypes ,name (maybe-stringp rationalp))
"<h5>Rational-Equiv Congruence Rules</h5>"
(deffixequiv ,name
:args ,(pairlis$ args (acl2::replicate (len args) '(rationalp)))))))
(encapsulate
(((er-float+ * *) => (mv * *) :formals (a b) :guard (and (rationalp a) (rationalp b)))
((er-float- * *) => (mv * *) :formals (a b) :guard (and (rationalp a) (rationalp b)))
((er-float* * *) => (mv * *) :formals (a b) :guard (and (rationalp a) (rationalp b)))
((er-float/ * *) => (mv * *) :formals (a b) :guard (and (rationalp a) (rationalp b)))
((er-float-expt * *) => (mv * *) :formals (a b) :guard (and (rationalp a) (rationalp b)))
((er-float-sqrt *) => (mv * *) :formals (a) :guard (rationalp a))
((er-float-e^x *) => (mv * *) :formals (a) :guard (rationalp a))
((er-float-sin *) => (mv * *) :formals (a) :guard (rationalp a))
((er-float-cos *) => (mv * *) :formals (a) :guard (rationalp a))
((er-float-tan *) => (mv * *) :formals (a) :guard (rationalp a))
;; Not yet implemented:
;; log -- may return complex when given negatives
;; asin -- may return complex
;; acos -- may return complex
;; atan -- may return complex
)
(def-float-op er-float+ (a b) "(Single-precision) floating point addition.")
(def-float-op er-float- (a b) "(Single-precision) floating point subtraction.")
(def-float-op er-float* (a b) "(Single-precision) floating point multiplication.")
(def-float-op er-float/ (a b) "(Single-precision) floating point division.")
(def-float-op er-float-expt (a b) "(Single-precision) floating point exponentiation.")
(def-float-op er-float-sqrt (a) "(Single-precision) floating point square root.")
(def-float-op er-float-e^x (a) "(Single-precision) floating point e^x.")
(def-float-op er-float-sin (a) "(Single-precision) floating point sine.")
(def-float-op er-float-cos (a) "(Single-precision) floating point cosine.")
(def-float-op er-float-tan (a) "(Single-precision) floating point tangent.")
)
(encapsulate
(((er-double+ * *) => (mv * *) :formals (a b) :guard (and (rationalp a) (rationalp b)))
((er-double- * *) => (mv * *) :formals (a b) :guard (and (rationalp a) (rationalp b)))
((er-double* * *) => (mv * *) :formals (a b) :guard (and (rationalp a) (rationalp b)))
((er-double/ * *) => (mv * *) :formals (a b) :guard (and (rationalp a) (rationalp b)))
((er-double-expt * *) => (mv * *) :formals (a b) :guard (and (rationalp a) (rationalp b)))
((er-double-sqrt *) => (mv * *) :formals (a) :guard (rationalp a))
((er-double-e^x *) => (mv * *) :formals (a) :guard (rationalp a))
((er-double-sin *) => (mv * *) :formals (a) :guard (rationalp a))
((er-double-cos *) => (mv * *) :formals (a) :guard (rationalp a))
((er-double-tan *) => (mv * *) :formals (a) :guard (rationalp a))
)
(def-float-op er-double+ (a b) "(Double-precision) floating point addition.")
(def-float-op er-double- (a b) "(Double-precision) floating point subtraction.")
(def-float-op er-double* (a b) "(Double-precision) floating point multiplication.")
(def-float-op er-double/ (a b) "(Double-precision) floating point division.")
(def-float-op er-double-expt (a b) "(Double-precision) floating point exponentiation.")
(def-float-op er-double-sqrt (a) "(Double-precision) floating point square root.")
(def-float-op er-double-e^x (a) "(Double-precision) floating point e^x.")
(def-float-op er-double-sin (a) "(Double-precision) floating point sine.")
(def-float-op er-double-cos (a) "(Double-precision) floating point cosine.")
(def-float-op er-double-tan (a) "(Double-precision) floating point tangent.")
)
|