• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
      • Vwsim
      • Isar
      • Wp-gen
      • Dimacs-reader
      • Pfcs
      • Legacy-defrstobj
      • C
      • Proof-checker-array
      • Soft
      • Farray
      • Rp-rewriter
      • Instant-runoff-voting
      • Imp-language
      • Sidekick
      • Ethereum
      • Leftist-trees
      • Java
      • Riscv
      • Taspi
      • Bitcoin
      • Zcash
      • Des
      • X86isa
      • Sha-2
      • Yul
      • Proof-checker-itp13
      • Regex
      • ACL2-programming-language
      • Json
      • Jfkr
      • Equational
      • Cryptography
        • R1cs
          • Axe-r1cs
          • R1cs-constraintp
          • Dot-product
            • R1csp
            • R1cs-constraint-holdsp
            • R1cs-holdsp
            • Sparse-vectorp
            • R1cs-constraints-holdp
            • R1cs-constraint-listp
            • Pseudo-varp
            • Pseudo-var-listp
          • Interfaces
          • Sha-2
          • Keccak
          • Kdf
          • Mimc
          • Padding
          • Hmac
          • Elliptic-curves
          • Attachments
          • Primes
          • Elliptic-curve-digital-signature-algorithm
        • Axe
        • Poseidon
        • Where-do-i-place-my-book
        • Aleo
        • Bigmems
        • Builtins
        • Execloader
        • Solidity
        • Paco
        • Concurrent-programs
        • Bls12-377-curves
      • Debugging
      • Community
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • 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))))