libsnark:Lagrange interpolation at Roots of unity

本文详细解析了libsnark库中基于《Behavior of the Lagrange Interpolants in the Roots of unity》论文的Lagrange插值算法实现。重点介绍了_radix2_evaluate_all_lagrange_polynomials函数,该函数用于计算相对根集S={omega^{0}

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

libsnark\depends\libfqfft\libfqfft\evaluation_domain\domains\basic_radix2_domain_aux.tcc中的_basic_radix2_evaluate_all_lagrange_polynomials(…)函数的计算依据为《Behavior of the Lagrange Interpolants in the Roots of unity》论文中如下图的公式:
Behavior of the Lagrange Interpolants in the Roots of Unity论文公式

根据论文公式,令w=e(1m)=ej∗2∗πm=cos(2∗πm)+j∗sin(2∗πm)w=e(\frac{1}{m})=e^{j*\frac{2*\pi}{m}} =cos(\frac{2*\pi}{m}) + j * sin(\frac{2*\pi}{m})w=e(m1)=ejm2π=cos(m2π)+jsin(m2π)
⇓\Downarrow
Lm−1(f,z)=zm−1m∗∑k=0n−1wk∗f(wk)z−wkL_{m-1}(f,z) =\frac{z^m-1}{m}*\sum_{k=0}^{n-1}\frac{w^k*f(w^k)}{z-w^k} Lm1(f,z)=mzm1k=0n1zwkwkf(wk)
z=tz=tz=t,可以推导出:
u[k]=tm−1m∗wk∗1t−wku[k]=\frac{t^m-1}{m} * w^k * \frac{1}{t-w^k}u[k]=mtm1wktwk1
S[k]=f(wk)S[k]=f(w^k)S[k]=f(wk)
使得 Lm−1(f,t)=u⋅SL_{m-1}(f,t) =u·SLm1(f,t)=uS(点乘)

/**
 * Compute the m Lagrange coefficients, relative to the set S={omega^{0},...,omega^{m-1}}, at the field element t.
 */
template<typename FieldT>
std::vector<FieldT> _basic_radix2_evaluate_all_lagrange_polynomials(const size_t m, const FieldT &t)
{
    if (m == 1)
    {
        return std::vector<FieldT>(1, FieldT::one());
    }

    if (m != (1u << libff::log2(m))) throw DomainSizeException("expected m == (1u << log2(m))");

    const FieldT omega = libff::get_root_of_unity<FieldT>(m);

    std::vector<FieldT> u(m, FieldT::zero());

    /*
     If t equals one of the roots of unity in S={omega^{0},...,omega^{m-1}}
     then output 1 at the right place, and 0 elsewhere
     */

    if ((t^m) == (FieldT::one()))
    {
        FieldT omega_i = FieldT::one();
        for (size_t i = 0; i < m; ++i)
        {
            if (omega_i == t) // i.e., t equals omega^i
            {
                u[i] = FieldT::one();
                return u;
            }

            omega_i *= omega;
        }
    }

    /*
     Otherwise, if t does not equal any of the roots of unity in S,
     then compute each L_{i,S}(t) as Z_{S}(t) * v_i / (t-\omega^i)
     where:
     - Z_{S}(t) = \prod_{j} (t-\omega^j) = (t^m-1), and
     - v_{i} = 1 / \prod_{j \neq i} (\omega^i-\omega^j).
     Below we use the fact that v_{0} = 1/m and v_{i+1} = \omega * v_{i}. 
     // 计算依据见《Behavior of the Lagrange Interpolants in the Roots of unity.pdf》中的Ln-1(f, z)的系数
     // S=[f(1),f(w),f(w^2),....,f(w^m-1)]
     */

    const FieldT Z = (t^m)-FieldT::one();
    FieldT l = Z * FieldT(m).inverse();
    FieldT r = FieldT::one();
    for (size_t i = 0; i < m; ++i)
    {
        u[i] = l * (t - r).inverse();
        l *= omega;
        r *= omega;
    }

    return u;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值