Skip to content

Commit

Permalink
chore: modify notation of superscript and subscript in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Inseon Yu(Merlyn) committed Oct 4, 2023
1 parent a084199 commit 9af55f4
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 47 deletions.
2 changes: 1 addition & 1 deletion benchmark/msm/msm_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bool MSMConfig::Parse(int argc, char** argv,
parser.AddFlag<base::Flag<std::vector<uint64_t>>>(&degrees_)
.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<base::BoolFlag>(&check_results_)
.set_long_name("--check_results")
Expand Down
4 changes: 2 additions & 2 deletions tachyon/base/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tachyon/base/memory/aligned_memory_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 1 addition & 1 deletion tachyon/base/numerics/math_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
24 changes: 12 additions & 12 deletions tachyon/base/ranges/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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 <typename ForwardIterator,
Expand Down Expand Up @@ -3125,7 +3125,7 @@ constexpr auto lower_bound(ForwardIterator first,
// `[begin(range), end(range)]` such that for every iterator `j` in the range
// `[begin(range), i)`, `bool(invoke(comp, invoke(proj, *j), value))` is true.
//
// Complexity: At most `log_2(size(range)) + O(1)` comparisons and projections.
// Complexity: At most `log₂(size(range)) + O(1)` comparisons and projections.
//
// Reference: https://wg21.link/lower.bound#:~:text=ranges::lower_bound(R
template <typename Range,
Expand All @@ -3151,7 +3151,7 @@ constexpr auto lower_bound(Range&& range,
// for every iterator `j` in the range `[first, i)`,
// `!bool(invoke(comp, value, invoke(proj, *j)))` 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/upper.bound#:~:text=ranges::upper_bound(I
template <typename ForwardIterator,
Expand Down Expand Up @@ -3179,7 +3179,7 @@ constexpr auto upper_bound(ForwardIterator first,
// `[begin(range), end(range)]` such that for every iterator `j` in the range
// `[begin(range), i)`, `!bool(invoke(comp, value, invoke(proj, *j)))` is true.
//
// Complexity: At most `log_2(size(range)) + O(1)` comparisons and projections.
// Complexity: At most `log₂(size(range)) + O(1)` comparisons and projections.
//
// Reference: https://wg21.link/upper.bound#:~:text=ranges::upper_bound(R
template <typename Range,
Expand All @@ -3205,7 +3205,7 @@ constexpr auto upper_bound(Range&& range,
// Returns: `{ranges::lower_bound(first, last, value, comp, proj),
// ranges::upper_bound(first, last, value, comp, proj)}`.
//
// Complexity: At most 2 ∗ log_2(last - first) + O(1) comparisons and
// Complexity: At most 2 ∗ log₂(last - first) + O(1) comparisons and
// projections.
//
// Reference: https://wg21.link/equal.range#:~:text=ranges::equal_range(I
Expand Down Expand Up @@ -3233,7 +3233,7 @@ constexpr auto equal_range(ForwardIterator first,
// Returns: `{ranges::lower_bound(range, value, comp, proj),
// ranges::upper_bound(range, value, comp, proj)}`.
//
// Complexity: At most 2 ∗ log_2(size(range)) + O(1) comparisons and
// Complexity: At most 2 ∗ log₂(size(range)) + O(1) comparisons and
// projections.
//
// Reference: https://wg21.link/equal.range#:~:text=ranges::equal_range(R
Expand Down Expand Up @@ -3261,7 +3261,7 @@ constexpr auto equal_range(Range&& range,
// `[first, last)`, `!bool(invoke(comp, invoke(proj, *i), value)) &&
// !bool(invoke(comp, value, invoke(proj, *i)))` 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/binary.search#:~:text=ranges::binary_search(I
template <typename ForwardIterator,
Expand All @@ -3287,7 +3287,7 @@ constexpr auto binary_search(ForwardIterator first,
// `!bool(invoke(comp, invoke(proj, *i), value)) &&
// !bool(invoke(comp, value, invoke(proj, *i)))` is true.
//
// Complexity: At most `log_2(size(range)) + O(1)` comparisons and projections.
// Complexity: At most `log₂(size(range)) + O(1)` comparisons and projections.
//
// Reference: https://wg21.link/binary.search#:~:text=ranges::binary_search(R
template <typename Range,
Expand Down
2 changes: 1 addition & 1 deletion tachyon/base/time/time_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ TEST(TimeDelta, MaxConversions) {

static_assert(
Microseconds(max_d).is_max(),
"Make sure that 2^63 correctly gets clamped to `max` (crbug.com/612601)");
"Make sure that 2⁶³ correctly gets clamped to `max` (crbug.com/612601)");

static_assert(Milliseconds(std::numeric_limits<double>::infinity()).is_max());

Expand Down
4 changes: 2 additions & 2 deletions tachyon/crypto/hashes/sponge/poseidon/poseidon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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++) {
Expand Down
14 changes: 7 additions & 7 deletions tachyon/math/finite_fields/modulus.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ class Modulus {
.template Shrink<N>();
}

// Compute -M^{-1} mod 2^B.
// Compute -M⁻¹ mod 2ᴮ.
template <typename T, size_t B = 8 * sizeof(T),
std::enable_if_t<std::is_unsigned_v<T>>* = nullptr>
constexpr static T Inverse(const BigInt<N>& 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) {
Expand Down
4 changes: 2 additions & 2 deletions tachyon/math/finite_fields/prime_field_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MultivariatePolynomialTest : public testing::Test {
} // Term
} // vector<Term>
)));
// poly1: 1 * x_0
// poly1: 1 * x₀
polys_.push_back(Poly(Coeffs(1,
{
{
Expand All @@ -45,7 +45,7 @@ class MultivariatePolynomialTest : public testing::Test {
} // Term
} // vector<Term>
)));
// poly2: 1 * x_0 (num_vars = 2)
// poly2: 1 * x₀ (num_vars = 2)
polys_.push_back(Poly(Coeffs(2,
{
{
Expand All @@ -58,7 +58,7 @@ class MultivariatePolynomialTest : public testing::Test {
} // Term
} // vector<Term>
)));
// poly3: 1 * x_0 + 1 * x_1
// poly3: 1 * x₀ + 1 * x₁
polys_.push_back(Poly(Coeffs(2,
{
{
Expand All @@ -79,7 +79,7 @@ class MultivariatePolynomialTest : public testing::Test {
} // Term
} // vector<Term>
)));
// poly4: 1 * x_1 + 1 * x_0
// poly4: 1 * x₁ + 1 * x₀
polys_.push_back(Poly(Coeffs(2,
{
{
Expand All @@ -100,7 +100,7 @@ class MultivariatePolynomialTest : public testing::Test {
} // Term
} // vector<Term>
)));
// 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,
{
{
Expand Down Expand Up @@ -138,7 +138,7 @@ class MultivariatePolynomialTest : public testing::Test {
} // Term
} // vector<Term>
)));
// 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,
{
{
Expand Down

0 comments on commit 9af55f4

Please sign in to comment.