plafer
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Multiset checks with multiplicities and LogUp This note picks up where the previous one on [multiset checks](/b5JjgH5HQye1Rwoxq-zzig) left off. The main motivation for this note is to support a variation on multiset checks where we can encode how many times we expect an element to show up in the set (*i.e.* the *multiplicity*) without having that element showing up that many times. Specifically, the multiset check with multiplicities equation is $$ \prod_{i=1}^{n-1} \prod_{j=1}^k (\alpha - a_{ij})^{m_{a_{ij}}} = \prod_{i=1}^{n-1} \prod_{j=1}^k (\alpha - b_{ij})^{m_{b_{ij}}} $$ For example, if $m_{a_{23}} = 2$, then the term $(\alpha - a_{23})$ in the equation is repeated twice: $(\alpha - a_{23})\cdot(\alpha - a_{23})$. Hence, the value $a_{23}$ would appear once in the $\{a_{ij}\}$ multiset, but would need to appear twice in the $\{b_{ij}\}$ multiset (or equivalently, only once, but with an associated multiplicity of $2$). Note also that setting a multiplicity value to $m_{a_{ij}} = 0$ has the effect of "turning off" the associated $(\alpha - a_{ij})$ term. This is especially useful for range checks, which the [Miden VM docs](https://0xpolygonmiden.github.io/miden-vm/design/range.html) have a good introduction about. ## The problem with multiplicities Adding multiplicities creates challenges when implementing the new equation in STARKs, as it makes the running product column discussed in the previous note no longer viable. Specifically, the transition constraint for the running product column $p$ would need to be: $$ p[i+1] = p[i] \times \prod_{j=1}^k \frac{(\alpha - a_{ij})^{m_{a_{ij}}}}{(\alpha - b_{ij})^{m_{b_{ij}}}}. $$ The right-hand side equation is *not* a polynomial, since both $m_{a_{ij}}$ appears in the exponent position, and is itself a polynomial (and similarly for $m_{b_{ij}}$). LogUp was designed to solve that problem. ## LogUp The core idea of LogUp is relatively simple. It involves applying the logarithm to both sides of the multiset check with multiplicities equation, followed by a derivative. > Note that the logarithm and the derivative are concepts defined over the real numbers. The [paper](https://eprint.iacr.org/2022/1530.pdf) goes into the formalism of how to formally think about these operations over finite fields, which we will take for granted in this note. Start with the multiset check with multiplicities equation, $$ \prod_{i=1}^{n-1} \prod_{j=1}^k (\alpha - a_{ij})^{m_{a_{ij}}} = \prod_{i=1}^{n-1} \prod_{j=1}^k (\alpha - b_{ij})^{m_{b_{ij}}}, $$ apply the logarithm to both sides (and a few logarithm rules), $$ \begin{align} \log \prod_{i=1}^{n-1} \prod_{j=1}^k (\alpha - a_{ij})^{m_{a_{ij}}} &= \log \prod_{i=1}^{n-1} \prod_{j=1}^k (\alpha - b_{ij})^{m_{b_{ij}}} \\ \sum_{i=1}^{n-1} \sum_{j=1}^k \log ((\alpha - a_{ij})^{m_{a_{ij}}}) &= \sum_{i=1}^{n-1} \sum_{j=1}^k \log ((\alpha - b_{ij})^{m_{b_{ij}}}) \\ \sum_{i=1}^{n-1} \sum_{j=1}^k m_{a_{ij}} \log (\alpha - a_{ij}) &= \sum_{i=1}^{n-1} \sum_{j=1}^k m_{b_{ij}} \log (\alpha - b_{ij}), \\ \end{align} $$ and then apply the derivative to both sides (where $x$ will stand for the "current" and "next" row, the inputs to $a_{ij}$ and $b_{ij}$) $$ \begin{align} \frac{d}{dx} \sum_{i=1}^{n-1} \sum_{j=1}^k m_{a_{ij}} \log (\alpha - a_{ij}) &= \frac{d}{dx} \sum_{i=1}^{n-1} \sum_{j=1}^k m_{b_{ij}} \log (\alpha - b_{ij}) \\ \sum_{i=1}^{n-1} \sum_{j=1}^k m_{a_{ij}} \frac{d}{dx} \log (\alpha - a_{ij}) &= \sum_{i=1}^{n-1} \sum_{j=1}^k m_{b_{ij}} \frac{d}{dx} \log (\alpha - b_{ij}) \\ \sum_{i=1}^{n-1} \sum_{j=1}^k \frac{m_{a_{ij}}}{(\alpha - a_{ij})} &= \sum_{i=1}^{n-1} \sum_{j=1}^k \frac{m_{b_{ij}}}{(\alpha - b_{ij})}. \end{align} $$ And that's it! The final form of the LogUp equation is $$ \sum_{i=1}^{n-1} \sum_{j=1}^k \frac{m_{a_{ij}}}{(\alpha - a_{ij})} = \sum_{i=1}^{n-1} \sum_{j=1}^k \frac{m_{b_{ij}}}{(\alpha - b_{ij})} $$ ## Implementing LogUp in STARKs LogUp in STARKs is going to look very similar to standard multiset checks: we will implement a *running sum* auxiliary column instead of a *running product*. Let's see how that would work. But first, we need to rearrange the LogUp equation slightly by subtracting the right-hand side on both sides: $$ \begin{align} \sum_{i=1}^{n-1} \sum_{j=1}^k \frac{m_{a_{ij}}}{(\alpha - a_{ij})} - \sum_{i=1}^{n-1} \sum_{j=1}^k \frac{m_{b_{ij}}}{(\alpha - b_{ij})} &= 0 \\ \sum_{i=1}^{n-1} (\sum_{j=1}^k \frac{m_{a_{ij}}}{(\alpha - a_{ij})} - \frac{m_{b_{ij}}}{(\alpha - b_{ij})}) &= 0 \end{align} $$ Our running sum column $s$ is going to be built similarly to the running product column for multiset checks. The first row will always contain $0$, and each new row will start with the previous row's value, add $\sum_{j=1}^k \frac{m_{a_{ij}}}{(\alpha - a_{ij})}$, and subtract $\sum_{j=1}^k \frac{m_{b_{ij}}}{(\alpha - b_{ij})}$: | Row | $s$ | | ---- | ------------- | | 1 | 0 | | 2 | $\sum_{j=1}^k \frac{m_{a_{0j}}}{\alpha - a_{0j}} - \frac{m_{b_{0j}}}{\alpha - b_{0j}}$ | | 3 | $\sum_{i=1}^2 \sum_{j=1}^k \frac{m_{a_{ij}}}{(\alpha - a_{ij})} - \frac{m_{b_{ij}}}{(\alpha - b_{ij})}$ | | 4 | $\sum_{i=1}^3 \sum_{j=1}^k \frac{m_{a_{ij}}}{(\alpha - a_{ij})} - \frac{m_{b_{ij}}}{(\alpha - b_{ij})}$ | | $\dots$ | $\dots$ | | $n-1$ | $\sum_{i=1}^{n-2} \sum_{j=1}^k \frac{m_{a_{ij}}}{(\alpha - a_{ij})} - \frac{m_{b_{ij}}}{(\alpha - b_{ij})}$ | | $n$ | $\sum_{i=1}^{n-1} \sum_{j=1}^k \frac{m_{a_{ij}}}{(\alpha - a_{ij})} - \frac{m_{b_{ij}}}{(\alpha - b_{ij})}$ | ### Boundary constraints In the boundary constraints, we make sure that the first and last row of $s$ contain $0$: $$ s[1] = s[n] = 0 $$ ### Transition constraint Then, the transition constraint needs to ensure that every row $i$ (except the last) is built by taking the value in the previous row, add in $\sum_{j=1}^k \frac{m_{a_{ij}}}{(\alpha - a_{ij})}$, and subtract out $\sum_{j=1}^k \frac{m_{b_{ij}}}{(\alpha - b_{ij})}$: $$ s[i+1] = s[i] + (\sum_{j=1}^k \frac{m_{a_{ij}}}{(\alpha - a_{ij})}) - (\sum_{j=1}^k \frac{m_{b_{ij}}}{(\alpha - b_{ij})}). $$ However, the current form is not a valid polynomial expression. We need to rearrange the equation so that we remove the division operations for equivalent multiplications: $$ \begin{align} & s[i+1] (\prod_{j=1}^k \alpha - a_{ij})(\prod_{j=1}^k \alpha - b_{ij}) = \\ & s[i] (\prod_{j=1}^k \alpha - a_{ij})(\prod_{j=1}^k \alpha - b_{ij}) \\ &+ \sum_{j=1}^k m_{a_{ij}} \prod_{e \neq j}(\alpha - a_{ie}) \prod_{e =1}^k (\alpha - b_{ie}) \\ &- \sum_{j=1}^k m_{b_{ij}} \prod_{e \neq j}(\alpha - b_{ie}) \prod_{e =1}^k (\alpha - a_{ie}) \end{align} $$ This equation is a little difficult to parse, but it is simply the result of multiplying out all the denominators on both sides. For example, if $k=1$, then the equation would look like: $$ \begin{align} &s[i+1](\alpha - a_{i0})(\alpha - b_{i0}) = \\ &s[i](\alpha - a_{i0})(\alpha - b_{i0}) + m_{a_{i0}}(\alpha - b_{i0}) - m_{b_{i0}}(\alpha - a_{i0}) \end{align} $$ Ultimately, the running sum column implementing LogUp achieved what the running product column could not: a polynomial transition constraint. ### Transition constraint degree LogUp is a good choice for use cases that can't do without representing multiplicities. However, as we'll see, we pay with a higher transition constraint degree. Specifically, the transition constraint degree is the maximum of $$ \begin{align} &1 + \sum_{j=1}^k (\deg a_{ij} + \deg b_{ij}), \\ &\forall j,\quad \deg m_{a_{ij}} + \sum_{e \neq j}\deg a_{ie} + \sum_{e =1}^k \deg b_{ie}, \quad \mathrm{and} \\ &\forall j,\quad \deg m_{b_{ij}} + \sum_{e \neq j}\deg b_{ie} + \sum_{e =1}^k \deg a_{ie}. \\ \end{align} $$ The biggest difference with the running product column transition constraint degree (other than the fact that we now have multiplicities) is that now the degree of the $a_{ij}$'s and the $b_{ij}$'s *add together*. Hence, the rule of thumb is that between a standard multiset check and LogUp, prefer to use a standard multiset check *when possible* to lower the transition constraint degree.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully