LagrangeInterpolation sets out = yVec[0] if k = 1

pull/2/head
MITSUNARI Shigeo 6 years ago
parent d6229da5aa
commit 08148dcf60
  1. 1
      include/mcl/bn.h
  2. 13
      include/mcl/lagrange.hpp
  3. 1
      readme.md
  4. 2
      test/bench.hpp

@ -379,6 +379,7 @@ MCLBN_DLL_API void mclBn_precomputedMillerLoop2mixed(mclBnGT *f, const mclBnG1 *
Lagrange interpolation Lagrange interpolation
recover out = y(0) by { (xVec[i], yVec[i]) } recover out = y(0) by { (xVec[i], yVec[i]) }
return 0 if success else -1 return 0 if success else -1
@note *out = yVec[0] if k = 1
@note k >= 2, xVec[i] != 0, xVec[i] != xVec[j] for i != j @note k >= 2, xVec[i] != 0, xVec[i] != xVec[j] for i != j
*/ */
MCLBN_DLL_API int mclBn_FrLagrangeInterpolation(mclBnFr *out, const mclBnFr *xVec, const mclBnFr *yVec, mclSize k); MCLBN_DLL_API int mclBn_FrLagrangeInterpolation(mclBnFr *out, const mclBnFr *xVec, const mclBnFr *yVec, mclSize k);

@ -15,14 +15,19 @@ namespace mcl {
template<class G, class F> template<class G, class F>
void LagrangeInterpolation(bool *pb, G& out, const F *S, const G *vec, size_t k) void LagrangeInterpolation(bool *pb, G& out, const F *S, const G *vec, size_t k)
{ {
if (k == 0) {
*pb = false;
return;
}
if (k == 1) {
out = vec[0];
*pb = true;
return;
}
/* /*
delta_{i,S}(0) = prod_{j != i} S[j] / (S[j] - S[i]) = a / b delta_{i,S}(0) = prod_{j != i} S[j] / (S[j] - S[i]) = a / b
where a = prod S[j], b = S[i] * prod_{j != i} (S[j] - S[i]) where a = prod S[j], b = S[i] * prod_{j != i} (S[j] - S[i])
*/ */
if (k < 2) {
*pb = false;
return;
}
F a = S[0]; F a = S[0];
for (size_t i = 1; i < k; i++) { for (size_t i = 1; i < k; i++) {
a *= S[i]; a *= S[i];

@ -443,6 +443,7 @@ Y. Sakemi, Y. Nogami, K. Okeya, Y. Morikawa, CANS 2008.
# History # History
* 2019/Feb/20 LagrangeInterpolation sets out = yVec[0] if k = 1
* 2019/Jan/31 add mclBnFp_mapToG1, mclBnFp2_mapToG2 * 2019/Jan/31 add mclBnFp_mapToG1, mclBnFp2_mapToG2
* 2019/Jan/31 fix crash on x64-CPU without AVX (thanks to mortdeus) * 2019/Jan/31 fix crash on x64-CPU without AVX (thanks to mortdeus)

@ -185,4 +185,6 @@ void testLagrange()
Fr s; Fr s;
mcl::LagrangeInterpolation(s, x, y, k); mcl::LagrangeInterpolation(s, x, y, k);
CYBOZU_TEST_EQUAL(s, c[0]); CYBOZU_TEST_EQUAL(s, c[0]);
mcl::LagrangeInterpolation(s, x, y, 1);
CYBOZU_TEST_EQUAL(s, y[0]);
} }

Loading…
Cancel
Save