• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
      • Gl
      • Witness-cp
      • Ccg
      • Install-not-normalized
      • Rewrite$
      • Fgl
        • Fgl-rewrite-rules
          • Binder-functions
          • Fgl-syntactic-checker-binders
          • Binder
          • Fancy-ev
          • Annotate
            • Bind-fn-annotation
            • Interp-st-nth-fn-annotation
            • Bind-nth-fn-annotation
          • Binder-rules
          • Def-fgl-program
          • Bind-var
          • Add-fgl-brewrites
          • Def-fgl-rewrite
          • Narrow-equiv
          • Trigger-constraints
          • Def-fgl-branch-merge
          • Add-fgl-rewrites
          • Fgl-interp-obj
          • Syntax-bind
          • Fgl-hide
          • Collect-cmr-rewrites-for-formula-name
          • Fgl-time
          • Fgl-prog2
          • Assume
          • Add-fgl-binder-meta
          • Add-fgl-primitive
          • Add-fgl-meta
          • Add-fgl-branch-merges
          • Cmr::rewritelist->lhses
          • Remove-fgl-brewrites
          • Remove-fgl-branch-merges
          • Lhses->branch-function-syms
          • Enable-execution
          • Abort-rewrite
          • Syntax-interp
          • Remove-fgl-rewrites
          • Lhses->leading-function-syms
          • Remove-fgl-primitive
          • Remove-fgl-binder-meta
          • If!
          • Disable-execution
          • Remove-fgl-meta
          • Fgl-time-fn
          • Disable-definition
          • Def-fgl-brewrite
        • Fgl-function-mode
        • Fgl-object
        • Fgl-solving
        • Fgl-handling-if-then-elses
        • Fgl-getting-bits-from-objects
        • Fgl-primitive-and-meta-rules
        • Fgl-counterexamples
        • Fgl-interpreter-overview
        • Fgl-correctness-of-binding-free-variables
        • Fgl-debugging
        • Fgl-testbenches
        • Def-fgl-boolean-constraint
        • Fgl-stack
        • Fgl-rewrite-tracing
        • Def-fgl-param-thm
        • Def-fgl-thm
        • Fgl-fast-alist-support
        • Fgl-array-support
        • Advanced-equivalence-checking-with-fgl
        • Fgl-fty-support
        • Fgl-internals
      • Removable-runes
      • Efficiency
      • Rewrite-bounds
      • Bash
      • Def-dag-measure
      • Bdd
      • Remove-hyps
      • Contextual-rewriting
      • Simp
      • Rewrite$-hyps
      • Bash-term-to-dnf
      • Use-trivial-ancestors-check
      • Minimal-runes
      • Clause-processor-tools
      • Fn-is-body
      • Without-subsumption
      • Rewrite-equiv-hint
      • Def-bounds
      • Rewrite$-context
      • Try-gl-concls
      • Hint-utils
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Math
    • Testing-utilities
  • Fgl-rewrite-rules

Annotate

Wrapper to mark a function call with some data for use by the FGL rewriter

Signature
(annotate arg x) → *

Annotate is just a two-argument function that returns its second argument. It is intended to be used to temporarily associate the data in its first argument with the subterm in its second argument, such that rewrite rules can treat that subterm differently based on whether it has an annotation and what it contains.

Example: print some info about a call before going on to rewrite it as normal:

(fgl::def-fgl-rewrite print-first-argument-of-my-fn
  (implies (and (fgl::bind-fn-annotation annot 'my-fn)
                (not annot))
           (equal (my-fn a b)
                  (fgl::fgl-prog2
                   (fgl::syntax-interp (cw "my-fn first arg: ~x0~%" a))
                   (fgl::annotate :already-printed (my-fn a b))))))

Normally, a rule that included the unchanged LHS in the RHS would loop. However, the RHS of the rule wraps an annotation around the LHS call, and the hypotheses of this rule check that there is no annotation wrapped around the call, so when trying this rule on the LHS occurrence in the RHS, it will fail instead of looping.

The associated utility bind-fn-annotation binds to a variable the annotation data from the annotation wrapped around the most recent (innermost) call of the given function, or NIL if there was no annotation.

Another utility, bind-nth-fn-annotation, similarly binds the annotation from the nth-innermost call of the function. The following example implements a simple way of tracing the rewriting of a function -- we check that the current call of the function is not yet annotated, so that the rule doesn't loop; then we look for a prior call of the function and get its annotation to find the nesting depth to use for the tracing:

(defun next-printed-annotation-index (old-annot)
  (case-match old-annot
    ((':printed n) (if (natp n) (+ 1 n) 0))
    (& 0)))

(fgl::def-fgl-rewrite trace-my-fn
  (implies (and (fgl::bind-fn-annotation annot 'my-fn)
                (not annot)
                (fgl::bind-nth-fn-annotation old-annot 1 'my-fn)
                (equal index (next-printed-annotation-index old-annot)))
           (equal (my-fn a b)
                  (fgl::fgl-prog2
                   (fgl::syntax-interp (cw "~t0~x0> my-fn ~x1~%" index a))
                   (let ((res (fgl::annotate `(:printed ,index) (my-fn a b))))
                     (fgl::fgl-prog2
                      (fgl::syntax-interp (cw "~t0<~x0 my-fn ~x1~%" index a))
                      res))))))

Definitions and Theorems

Function: annotate

(defun annotate (arg x)
  (declare (ignore arg))
  (declare (xargs :guard t))
  (let ((__function__ 'annotate))
    (declare (ignorable __function__))
    x))

Subtopics

Bind-fn-annotation
Get the annotation associated with the innermost call of the given function being rewritten
Interp-st-nth-fn-annotation
Finds the annotation, if any, of the nth-innermost nesting of fn on the stack.
Bind-nth-fn-annotation
Get the annotation associated with the nth-innermost call of the given function being rewritten