From 9af55f445ce52d1dd315928f55d8fd684595fd3e Mon Sep 17 00:00:00 2001 From: "Inseon Yu(Merlyn)" Date: Wed, 4 Oct 2023 15:29:30 +0900 Subject: [PATCH] chore: modify notation of superscript and subscript in comments --- benchmark/msm/msm_config.cc | 2 +- tachyon/base/bits.h | 4 ++-- .../base/memory/aligned_memory_unittest.cc | 2 +- tachyon/base/numerics/math_constants.h | 2 +- tachyon/base/ranges/algorithm.h | 24 +++++++++---------- tachyon/base/time/time_unittest.cc | 2 +- .../crypto/hashes/sponge/poseidon/poseidon.h | 4 ++-- .../kernels/bellman/bellman_msm_kernels.cu.h | 23 +++++++++--------- tachyon/math/finite_fields/modulus.h | 14 +++++------ .../math/finite_fields/prime_field_util.cc | 4 ++-- .../multivariate_polynomial_unittest.cc | 12 +++++----- 11 files changed, 46 insertions(+), 47 deletions(-) diff --git a/benchmark/msm/msm_config.cc b/benchmark/msm/msm_config.cc index 4e56bdaaf..7cc78610a 100644 --- a/benchmark/msm/msm_config.cc +++ b/benchmark/msm/msm_config.cc @@ -61,7 +61,7 @@ bool MSMConfig::Parse(int argc, char** argv, parser.AddFlag>>(°rees_) .set_short_name("-n") .set_required() - .set_help("Specify the exponent 'n' where the number of points to test is 2^n."); + .set_help("Specify the exponent 'n' where the number of points to test is 2ⁿ."); // clang-format on parser.AddFlag(&check_results_) .set_long_name("--check_results") diff --git a/tachyon/base/bits.h b/tachyon/base/bits.h index 3f33e2b33..7f63cc61b 100644 --- a/tachyon/base/bits.h +++ b/tachyon/base/bits.h @@ -107,7 +107,7 @@ ALWAYS_INLINE constexpr : bits; } -// Returns the integer i such as 2^i <= n < 2^(i+1). +// Returns the integer i such as 2ⁱ <= n < 2ⁱ⁺¹. // // There is a common `BitLength` function, which returns the number of bits // required to represent a value. Rather than implement that function, @@ -116,7 +116,7 @@ ALWAYS_INLINE constexpr // TODO(pkasting): When C++20 is available, replace with std::bit_xxx(). constexpr int Log2Floor(uint32_t n) { return 31 - CountLeadingZeroBits(n); } -// Returns the integer i such as 2^(i-1) < n <= 2^i. +// Returns the integer i such as 2ⁱ⁻¹ < n <= 2ⁱ. constexpr int Log2Ceiling(uint32_t n) { // When n == 0, we want the function to return -1. // When n == 0, (n - 1) will underflow to 0xFFFFFFFF, which is diff --git a/tachyon/base/memory/aligned_memory_unittest.cc b/tachyon/base/memory/aligned_memory_unittest.cc index ded2c3620..587e12629 100644 --- a/tachyon/base/memory/aligned_memory_unittest.cc +++ b/tachyon/base/memory/aligned_memory_unittest.cc @@ -50,7 +50,7 @@ TEST(AlignedMemoryTest, IsAligned) { // Walk back down all lower powers of two checking alignment. for (int j = i - 1; j >= 0; --j) { - // n is aligned on all powers of two less than or equal to 2^i. + // n is aligned on all powers of two less than or equal to 2ⁱ. EXPECT_TRUE(IsAligned(n, n >> j)) << "Expected " << n << " to be " << (n >> j) << " aligned"; diff --git a/tachyon/base/numerics/math_constants.h b/tachyon/base/numerics/math_constants.h index f0cfebdc4..ac4874bf3 100644 --- a/tachyon/base/numerics/math_constants.h +++ b/tachyon/base/numerics/math_constants.h @@ -22,7 +22,7 @@ constexpr float kRadToDegFloat = 57.295779513082320876798f; constexpr double kSqrtHalfDouble = 0.70710678118654752440; constexpr float kSqrtHalfFloat = 0.70710678118654752440f; -// The mean acceleration due to gravity on Earth in m/s^2. +// The mean acceleration due to gravity on Earth in m/s². constexpr double kMeanGravityDouble = 9.80665; constexpr float kMeanGravityFloat = 9.80665f; diff --git a/tachyon/base/ranges/algorithm.h b/tachyon/base/ranges/algorithm.h index 7471f53da..494f0e3c1 100644 --- a/tachyon/base/ranges/algorithm.h +++ b/tachyon/base/ranges/algorithm.h @@ -999,7 +999,7 @@ constexpr bool equal(Range1&& range1, // `last1 - first1` applications of the corresponding predicate and projections // if `ranges::equal(first1, last1, first2, last2, pred, proj, proj)` would // return true; -// otherwise, at worst `O(N^2)`, where `N` has the value `last1 - first1`. +// otherwise, at worst `O(N²)`, where `N` has the value `last1 - first1`. // // Reference: // https://wg21.link/alg.is.permutation#:~:text=ranges::is_permutation(I1 @@ -1038,7 +1038,7 @@ constexpr bool is_permutation(ForwardIterator1 first1, // `size(range1) != size(range2)`. Otherwise, exactly `size(range1)` // applications of the corresponding predicate and projections if // `ranges::equal(range1, range2, pred, proj, proj)` would return true; -// otherwise, at worst `O(N^2)`, where `N` has the value `size(range1)`. +// otherwise, at worst `O(N²)`, where `N` has the value `size(range1)`. // // Reference: // https://wg21.link/alg.is.permutation#:~:text=ranges::is_permutation(R1 @@ -2726,7 +2726,7 @@ constexpr auto sort(Range&& range, Comp comp = {}, Proj proj = {}) { // Returns: `last`. // // Complexity: Let `N` be `last - first`. If enough extra memory is available, -// `N log (N)` comparisons. Otherwise, at most `N log^2 (N)` comparisons. In +// `N log (N)` comparisons. Otherwise, at most `N log² (N)` comparisons. In // either case, twice as many projections as the number of comparisons. // // Remarks: Stable. @@ -2753,7 +2753,7 @@ constexpr auto stable_sort(RandomAccessIterator first, // Returns: `end(rang)`. // // Complexity: Let `N` be `size(range)`. If enough extra memory is available, -// `N log (N)` comparisons. Otherwise, at most `N log^2 (N)` comparisons. In +// `N log (N)` comparisons. Otherwise, at most `N log² (N)` comparisons. In // either case, twice as many projections as the number of comparisons. // // Remarks: Stable. @@ -3097,7 +3097,7 @@ constexpr auto nth_element(Range&& range, // for every iterator `j` in the range `[first, i)`, // `bool(invoke(comp, invoke(proj, *j), value))` is true. // -// Complexity: At most `log_2(last - first) + O(1)` comparisons and projections. +// Complexity: At most `log₂(last - first) + O(1)` comparisons and projections. // // Reference: https://wg21.link/lower.bound#:~:text=ranges::lower_bound(I template ::infinity()).is_max()); diff --git a/tachyon/crypto/hashes/sponge/poseidon/poseidon.h b/tachyon/crypto/hashes/sponge/poseidon/poseidon.h index 14cd14f17..000a47f68 100644 --- a/tachyon/crypto/hashes/sponge/poseidon/poseidon.h +++ b/tachyon/crypto/hashes/sponge/poseidon/poseidon.h @@ -57,12 +57,12 @@ struct PoseidonSponge void ApplySBox(bool is_full_round) { if (is_full_round) { - // Full rounds apply the S-Box (x^alpha) to every element of |state|. + // Full rounds apply the S-Box (xᵅ) to every element of |state|. for (F& elem : state.elements) { elem = elem.Pow(math::BigInt<1>(config.alpha)); } } else { - // Partial rounds apply the S-Box (x^alpha) to just the first element of + // Partial rounds apply the S-Box (xᵅ) to just the first element of // |state|. state[0] = state[0].Pow(math::BigInt<1>(config.alpha)); } diff --git a/tachyon/math/elliptic_curves/msm/kernels/bellman/bellman_msm_kernels.cu.h b/tachyon/math/elliptic_curves/msm/kernels/bellman/bellman_msm_kernels.cu.h index 611c3d294..6a178529f 100644 --- a/tachyon/math/elliptic_curves/msm/kernels/bellman/bellman_msm_kernels.cu.h +++ b/tachyon/math/elliptic_curves/msm/kernels/bellman/bellman_msm_kernels.cu.h @@ -90,11 +90,11 @@ __global__ void ComputeBucketIndexesKernel( // degree is 20. // Consequently, scalar decomposition appears as follows: // - // S = S_0 + S_1 * 2^16 + S_2 * 2^32 + ... + S_15 * 2^240 + // S = S₀ + S₁ * 2¹⁶ + S₂ * 2³² + ... + S₁₅ * 2²⁴⁰ // - // Even with the addition of a borrow to S_15, the resulting value remains - // below 2^14 - 1. This ensures that it remains within the bounds of - // |top_bucket_index|, which is 2^15. + // Even with the addition of a borrow to S₁₅, the resulting value remains + // below 2¹⁴ - 1. This ensures that it remains within the bounds of + // |top_bucket_index|, which is 2¹⁵. if (bucket_index > top_bucket_index) { // When |window_bits| is 4 bits, the value of |top_bucket_index| is 8. In // a scenario where |bucket_index| surpasses 8(let's assume it's 10), the @@ -110,7 +110,7 @@ __global__ void ComputeBucketIndexesKernel( bool is_top_window = window_index == windows_count - 1; // Ultimately, a dot product is required between the scalar and the base: // - // (S_0, S_1 * 2^16, S_2 * 2^32, ..., S_15 * 2^240) * (B, B, B, ..., B) + // (S₀, S₁ * 2¹⁶, S₂ * 2³², ..., S₁₅ * 2²⁴⁰) * (B, B, B, ..., B) // // When |bucket_index| is zero, it indicates the potential to optimize the // computation of the dot product by subsequently reducing the required @@ -218,21 +218,20 @@ __global__ void AggregateBucketsKernel( } // What we need to compute is as follows: // - // B_0 * S_0 + B_1 * S_1 + B_2 * S_2 + ... + B_{N - 1} * S_{N - 1} + // B₀ * S₀ + B₁ * S₁ + B₂ * S₂ + ... + Bₙ₋₁ * Sₙ₋₁ // // For each scalar, it's decomposed based on the window bits. // Let's take the example of the bn254 curve again: // - // S_0 = S_0_0 + S_0_1 * 2^16 + S_0_2 * 2^32 + ... + S_0_15 * 2^240 - // S_1 = S_1_0 + S_1_1 * 2^16 + S_1_2 * 2^32 + ... + S_1_15 * 2^240 + // S_0 = S₀,₀ + S₀,₁ * 2¹⁶ + S₀,₂ * 2³² + ... + S₀,₁₅ * 2²⁴⁰ + // S_1 = S₁,₀ + S₁,₁ * 2¹⁶ + S₁,₂ * 2³² + ... + S₁,₁₅ * 2²⁴⁰ // ... - // S_{N - 1} = S_{N - 1}_0 + S_{N - 1}_1 * 2^16 + S_{N - 1}_2 * 2^32 + ... + - // S_{N - 1}_15 * 2^240 + // Sₙ₋₁, = Sₙ₋₁,₀ + Sₙ₋₁,₁ * 2¹⁶ + Sₙ₋₁,₂ * 2³² + ... + Sₙ₋₁,₁₅ * 2²⁴⁰ // - // S_{i}_{j} ranges from 0 to 2^15. (Be cautious, it's not 2^16.) + // Sᵢ,ⱼ ranges from 0 to 2¹⁵. (Be cautious, it's not 2¹⁶.) // The bucket index can be calculated as follows: // - // bucket_index = j * 2^16 + S_{i}_{j}. + // bucket_index = j * 2¹⁶ + Sᵢ,ⱼ. // // This accumulates the base belonging to the same |bucket_index|. for (unsigned int i = IsFirst ? 1 : 0; i < length; i++) { diff --git a/tachyon/math/finite_fields/modulus.h b/tachyon/math/finite_fields/modulus.h index 683c0a8cc..216afa4fc 100644 --- a/tachyon/math/finite_fields/modulus.h +++ b/tachyon/math/finite_fields/modulus.h @@ -49,18 +49,18 @@ class Modulus { .template Shrink(); } - // Compute -M^{-1} mod 2^B. + // Compute -M⁻¹ mod 2ᴮ. template >* = nullptr> constexpr static T Inverse(const BigInt& modulus) { // We compute this as follows. - // First, modulus mod 2^B is just the lower B bits of modulus. - // Hence modulus mod 2^B = modulus[0] mod 2^B. + // First, modulus mod 2ᴮ is just the lower B bits of modulus. + // Hence modulus mod 2ᴮ = modulus[0] mod 2ᴮ. // - // Next, computing the inverse mod 2^B involves exponentiating by - // the multiplicative group order, which is euler_totient(2^B) - 1. - // Now, euler_totient(2^B) = 1 << (B - 1), and so - // euler_totient(2^B) - 1 = (1 << (B - 1)) - 1 = 1111111... ((B - 1) + // Next, computing the inverse mod 2ᴮ involves exponentiating by + // the multiplicative group order, which is euler_totient(2ᴮ) - 1. + // Now, euler_totient(2ᴮ) = 1 << (B - 1), and so + // euler_totient(2ᴮ) - 1 = (1 << (B - 1)) - 1 = 1111111... ((B - 1) // digits). We compute this powering via standard square and multiply. T inv = 1; for (size_t i = 0; i < (B - 1); ++i) { diff --git a/tachyon/math/finite_fields/prime_field_util.cc b/tachyon/math/finite_fields/prime_field_util.cc index f5b609489..bd4b37b57 100644 --- a/tachyon/math/finite_fields/prime_field_util.cc +++ b/tachyon/math/finite_fields/prime_field_util.cc @@ -2,7 +2,7 @@ namespace tachyon::math { -// The integer s such that |n| = |k|^s * t for some odd integer t. +// The integer s such that |n| = |k|ˢ * t for some odd integer t. uint32_t ComputeAdicity(uint32_t k, mpz_class n) { uint32_t adicity = 0; while (n > 1) { @@ -16,7 +16,7 @@ uint32_t ComputeAdicity(uint32_t k, mpz_class n) { return adicity; } -// The integer t such that |n| = |k|^s * t for some odd integer t. +// The integer t such that |n| = |k|ˢ * t for some odd integer t. mpz_class ComputeTrace(size_t k, mpz_class n) { mpz_class trace = 0; while (n > 1) { diff --git a/tachyon/math/polynomials/multivariate/multivariate_polynomial_unittest.cc b/tachyon/math/polynomials/multivariate/multivariate_polynomial_unittest.cc index 15b4d50dc..82832c0c8 100644 --- a/tachyon/math/polynomials/multivariate/multivariate_polynomial_unittest.cc +++ b/tachyon/math/polynomials/multivariate/multivariate_polynomial_unittest.cc @@ -32,7 +32,7 @@ class MultivariatePolynomialTest : public testing::Test { } // Term } // vector ))); - // poly1: 1 * x_0 + // poly1: 1 * x₀ polys_.push_back(Poly(Coeffs(1, { { @@ -45,7 +45,7 @@ class MultivariatePolynomialTest : public testing::Test { } // Term } // vector ))); - // poly2: 1 * x_0 (num_vars = 2) + // poly2: 1 * x₀ (num_vars = 2) polys_.push_back(Poly(Coeffs(2, { { @@ -58,7 +58,7 @@ class MultivariatePolynomialTest : public testing::Test { } // Term } // vector ))); - // poly3: 1 * x_0 + 1 * x_1 + // poly3: 1 * x₀ + 1 * x₁ polys_.push_back(Poly(Coeffs(2, { { @@ -79,7 +79,7 @@ class MultivariatePolynomialTest : public testing::Test { } // Term } // vector ))); - // poly4: 1 * x_1 + 1 * x_0 + // poly4: 1 * x₁ + 1 * x₀ polys_.push_back(Poly(Coeffs(2, { { @@ -100,7 +100,7 @@ class MultivariatePolynomialTest : public testing::Test { } // Term } // vector ))); - // poly5: 1 * x_0 ^ 2 + 2 * x_0x_1 + 3 * x_1^2 + 4 + // poly5: 1 * x₀² + 2 * x₀x₁ + 3 * x₁² + 4 polys_.push_back(Poly(Coeffs(2, { { @@ -138,7 +138,7 @@ class MultivariatePolynomialTest : public testing::Test { } // Term } // vector ))); - // poly6: 1 * x_0^3 + 2 * x_0x_1^2 + 3 * x_1^3 + 4 + // poly6: 1 * x₀³ + 2 * x₀x₁² + 3 * x₁³ + 4 polys_.push_back(Poly(Coeffs(2, { {