From 08148dcf605117f495545cdf3ce29afb1e9c963e Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Wed, 20 Feb 2019 09:51:34 +0900 Subject: [PATCH] LagrangeInterpolation sets out = yVec[0] if k = 1 --- include/mcl/bn.h | 1 + include/mcl/lagrange.hpp | 13 +++++++++---- readme.md | 1 + test/bench.hpp | 2 ++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/mcl/bn.h b/include/mcl/bn.h index 6499280..0044d9d 100644 --- a/include/mcl/bn.h +++ b/include/mcl/bn.h @@ -379,6 +379,7 @@ MCLBN_DLL_API void mclBn_precomputedMillerLoop2mixed(mclBnGT *f, const mclBnG1 * Lagrange interpolation recover out = y(0) by { (xVec[i], yVec[i]) } 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 */ MCLBN_DLL_API int mclBn_FrLagrangeInterpolation(mclBnFr *out, const mclBnFr *xVec, const mclBnFr *yVec, mclSize k); diff --git a/include/mcl/lagrange.hpp b/include/mcl/lagrange.hpp index 7c02188..feca80d 100644 --- a/include/mcl/lagrange.hpp +++ b/include/mcl/lagrange.hpp @@ -15,14 +15,19 @@ namespace mcl { template 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 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]; for (size_t i = 1; i < k; i++) { a *= S[i]; diff --git a/readme.md b/readme.md index 61e5e6e..87c06a1 100644 --- a/readme.md +++ b/readme.md @@ -443,6 +443,7 @@ Y. Sakemi, Y. Nogami, K. Okeya, Y. Morikawa, CANS 2008. # History +* 2019/Feb/20 LagrangeInterpolation sets out = yVec[0] if k = 1 * 2019/Jan/31 add mclBnFp_mapToG1, mclBnFp2_mapToG2 * 2019/Jan/31 fix crash on x64-CPU without AVX (thanks to mortdeus) diff --git a/test/bench.hpp b/test/bench.hpp index b12947a..12868d3 100644 --- a/test/bench.hpp +++ b/test/bench.hpp @@ -185,4 +185,6 @@ void testLagrange() Fr s; mcl::LagrangeInterpolation(s, x, y, k); CYBOZU_TEST_EQUAL(s, c[0]); + mcl::LagrangeInterpolation(s, x, y, 1); + CYBOZU_TEST_EQUAL(s, y[0]); }