• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Error-checking
        • Apt
        • Abnf
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Prime-field-constraint-systems
        • Soft
        • Bv
        • Imp-language
        • Event-macros
        • Bitcoin
        • Ethereum
        • Yul
        • Zcash
        • ACL2-programming-language
        • Prime-fields
        • Java
        • C
        • Syntheto
        • Number-theory
        • Cryptography
          • R1cs
            • R1cs-verification-with-axe
            • R1cs-constraintp
            • Dot-product
              • R1csp
              • R1cs-constraint-holdsp
              • Sparse-vectorp
              • R1cs-holdsp
              • R1cs-constraints-holdp
              • R1cs-constraint-listp
              • Pseudo-varp
              • Pseudo-var-listp
            • Interfaces
            • Sha-2
            • Keccak
            • Kdf
            • Mimc
            • Padding
            • Hmac
            • Elliptic-curves
            • Attachments
            • Elliptic-curve-digital-signature-algorithm
          • Lists-light
          • File-io-light
          • Json
          • Built-ins
          • Solidity
          • Axe
          • Std-extensions
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Execloader
        • Axe
      • Testing-utilities
      • Math
    • R1cs

    Dot-product

    Dot product of R1CS coefficients and values.

    ;; Compute the dot product of the vector of coefficients and the vector of
    ;; values, where each value is either obtained by looking up a variable in the
    ;; valuation or is the special constant 1.  Since the representation is sparse,
    ;; we map over all the pairs in the vector and take the sum of the
    ;; corresponding products.
    (defund dot-product (vec valuation prime)
      (declare (xargs :guard (and (sparse-vectorp vec)
                                  (primep prime)
                                  (r1cs-valuationp valuation prime)
                                  (good-sparse-vectorp vec (strip-cars valuation)))
                      :verify-guards nil ;done below
                      ))
      (if (endp vec)
          0
        (let* ((item (first vec))
               (coeff (first item))
               (pseudo-var (second item))
               (var-value (if (equal 1 pseudo-var)
                              1
                            (lookup-eq pseudo-var valuation))))
          (add (mul (mod coeff prime) ;reduce the coefficient mod the prime in case it is, e.g., -1
                    var-value prime)
               (dot-product (rest vec) valuation prime)
               prime))))