;; ;; field.lisp ;; Release: Field-6.0.9 (3/14/14) ;; ;; Contact: Cesar Munoz (cesar.a.munoz@nasa.gov) ;; NASA Langley Research Center ;; http://shemesh.larc.nasa.gov/people/cam/Field ;; ;; Copyright (c) 2011-2012 United States Government as represented by ;; the National Aeronautics and Space Administration. No copyright ;; is claimed in the United States under Title 17, U.S.Code. All Other ;; Rights Reserved. ;; ;; Field is a simplification procedure for the field of reals. ;; This strategy was originally implemented with the collaboration of ;; Micaela Mayero (Micaela.Mayero@inria.fr). ;; ;; Strategies in Field:
(defparameter *field-strategies* "
% field, grind-reals, real-props,
% neg-formula, add-formulas, sub-formulas,
% cancel-by, cancel-formula,
% both-sides-f, sq-simp")
;; Message for an invalid arithmetic relational formula.
(defun msg-norelation (fnum)
(msg-noformula fnum "arithmetic relational formula"))
;; Message for an invalid formula number.
(defun msg-noformula (fnum &optional (msg "formula"))
(let ((fnums (extra-get-fnums fnum)))
(format nil"No ~a~p found in ~{~a~^ or ~}."
msg (length fnums) fnums)))
(defun in-polynom (polynom e)
(when polynom
(let* ((a (caar polynom))
(na (str2int a))
(ne (str2int (car e)))
(b (cdar polynom))
(r (cdr polynom)))
(cond ((and ne (= ne 0)) e)
((and na (= na 0)) e)
((and na ne)
(let ((g (gcd na ne)))
(if (= g 1) (in-polynom r e)
(cons (expr2str g) 1))))
((or na ne)(in-polynom r e))
((string= a (car e))
(cons a (min b (cdr e))))
(t (in-polynom r e))))))
(defun makecases-monoms (monoms)
(loop for monom in monoms
as cmonom = (let* ((cm (cancel-monom nil monom 1))
(nt (normal-term cm)))
nt)
when (string/= (format nil"~a" monom) cmonom)
collect (format nil"~a = ~a" monom cmonom)))
(defstrat name-distrib (&optional (fnums *) (prefix "ND") label hide? (tcc-step (extra-tcc-step)))
(let ((dist (get-distrib-formulas nil (extra-get-fnums fnums))))
(when dist
(let ((names (freshnames prefix (length dist)))
(nameseq (merge-lists names dist))
(lbl (or label 'none)))
(name-label* nameseq :label label :fnums fnums :hide? hide? :tcc-step tcc-step)))) "[Field] Introduces new names, which are based on PREFIX, to block the automatic
application of distributive laws in formulas FNUMS. Labels as LABEL(s) the formulas
where new names are defined. These formulas are hidden if HIDE? is t. TCCs generated
during the execution of the command are discharged with the proof command TCC-STEP.")
(defstep neg-formula (&optional (fnum (+ -)) (hide? t) label (tcc-step (extra-tcc-step)) (auto-step (assert)))
(let ((fnexpr (first-formula fnum :test #'field-formula))
(fn (car fnexpr))
(formula (cadr fnexpr))
(rel (is-relation formula)))
(if rel
(with-fresh-labels
((!ngf fn :tccs)
(!ngl)
(!ngo))
(protect
!ngf
(then@
(if label
(relabel (!ngo label) !ngf :push? nil)
(relabel !ngo !ngf))
(wrap-manip !ngo (mult-by !ngo "-1" :sign -) :tcc-step tcc-step)
(real-props !ngo :simple? t)
(finalize auto-step))
!ngl hide?))
(printf "No arithmetic relational formula in ~a" fnum))) "[Field] Negates both sides of the relational formula FNUM. If HIDE? is t,
the original formula is hidden. The new formula is labeled as the original
one, unless an explicit LABEL is provided. TCCs generated during the execution
of the command are discharged with the proof command TCC-STEP. At the end, the
strategy tries to discharge the current branch using the proof command AUTO-STEP." "Negating relational formula ~a")
(defstep field (&optional (fnum (+ -)) theories cancel? (tcc-step (extra-tcc-step)))
(let ((fnexpr (first-formula fnum :test #'field-formula))
(fn (car fnexpr))
(formula (cadr fnexpr))
(rel (is-relation formula)))
(if rel
(with-fresh-labels
((!fd fn)
(!fdt)
(!ndf)
(!x))
(tccs-formula !fd :label !fdt)
(branch (name-distrib (!fd !fdt) :prefix "NDF" :label !ndf :tcc-step tcc-step)
((field__$ !fd !ndf !x theories cancel? tcc-step)
(delete !fd)))
(delete !fdt))
(printf "No arithmetic relational formula in ~a" fnum))) "[Field] Removes divisions and apply simplification heuristics to the relational
formula on real numbers FNUM. It autorewrites with THEORIES when possible. If CANCEL?
is t, then it tries to cancel common terms once the expression is free of divisions.
TCCs generated during the execution of the command are discharged with the proof command TCC-STEP." "Removing divisions and simplifying formula ~a with field")
(defstep sq-simp (&optional (fnum *) (auto-step (assert)))
(then (rewrite* ("sq_0""sq_1""sq_abs""sq_abs_neg""sq_neg""sq_times""sq_plus""sq_minus" "sq_div""sqrt_0""sqrt_1""sqrt_def""sqrt_square" "sqrt_sq""sq_sqrt""sqrt_times""sqrt_div""sqrt_sq_abs") fnum)
(finalize auto-step)) "[Field] Simplifies FNUM with lemmas from sq and sqrt. At the end, the strategy tries to
discharge the current branch using the proof command AUTO-STEP." "Simplifying sq and sqrt in ~a")
(defstep both-sides-f (fnum f &optional (hide? t) label (tcc-step (extra-tcc-step)) (auto-step (assert)))
(let ((fnexpr (first-formula fnum :test #'field-formula))
(fn (car fnexpr))
(formula (cadr fnexpr))
(rel (is-relation formula))
(str (format nil"~a(%1)" f))
(lbs (or label (extra-get-labels-from-fnum fn))))
(if rel
(with-fresh-labels
((!bsf fn :tccs)
(!bsp)
(!bsl))
(branch (discriminate (wrap-manip !bsf (transform-both !bsf str) :tcc-step (skip) :labels? nil) !bsl)
((else (finalize auto-step) (delabel !bsf hide?))
(finalize auto-step)
(then (delabel !bsf hide?) (finalize tcc-step))))
(relabel lbs !bsl :push? nil))
(printf "No arithmetic relational formula in ~a" fnum))) "[Field] Applies function F to both sides of the relational expression in FNUM. If
HIDE? is t, the original formula is hidden. The new formulas are labeled as the original
one, unless an explicit LABEL is provided. TCCs generated during the execution of the
command are discharged with the proof command TCC-STEP. At the end, the strategy tries to
discharge the current branch using the proof command AUTO-STEP." "Applying ~1@*~a to both sides of formula ~@*~a")
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.