Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refac: refactor math #64

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions tachyon/math/base/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ tachyon_cc_library(
deps = [":semigroups"],
)

tachyon_cc_library(
name = "identities",
hdrs = ["identities.h"],
)

tachyon_cc_library(
name = "rings",
hdrs = ["rings.h"],
Expand Down
12 changes: 0 additions & 12 deletions tachyon/math/base/gmp/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ tachyon_cc_library(
],
)

tachyon_cc_library(
name = "gmp_identities",
hdrs = ["gmp_identities.h"],
deps = [
"//tachyon/base:no_destructor",
"//tachyon/math/base:identities",
"@local_config_gmp//:gmp",
],
)

tachyon_cc_library(
name = "gmp_util",
srcs = ["gmp_util.cc"],
Expand All @@ -56,11 +46,9 @@ tachyon_cc_test(
name = "gmp_unittests",
size = "small",
srcs = [
"gmp_identities_unittest.cc",
"gmp_util_unittest.cc",
],
deps = [
":gmp_identities",
":gmp_util",
"//tachyon/build:build_config",
],
Expand Down
35 changes: 0 additions & 35 deletions tachyon/math/base/gmp/gmp_identities.h

This file was deleted.

19 changes: 0 additions & 19 deletions tachyon/math/base/gmp/gmp_identities_unittest.cc

This file was deleted.

34 changes: 0 additions & 34 deletions tachyon/math/base/identities.h

This file was deleted.

5 changes: 1 addition & 4 deletions tachyon/math/elliptic_curves/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@ tachyon_cc_library(
"projective_point.h",
"semigroups.h",
],
deps = [
"//tachyon/base:no_destructor",
"//tachyon/math/base:identities",
],
deps = ["//tachyon/base:no_destructor"],
)
26 changes: 0 additions & 26 deletions tachyon/math/elliptic_curves/affine_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,6 @@ JacobianPoint<Curve> operator*(const ScalarField& v,
return point * v;
}

template <typename Curve>
class MultiplicativeIdentity<AffinePoint<Curve>> {
public:
using P = AffinePoint<Curve>;

static const P& One() {
static base::NoDestructor<P> one(P::One());
return *one;
}

constexpr static bool IsOne(const P& value) { return value.IsOne(); }
};

template <typename Curve>
class AdditiveIdentity<AffinePoint<Curve>> {
public:
using P = AffinePoint<Curve>;

static const P& Zero() {
static base::NoDestructor<P> zero(P::Zero());
return *zero;
}

constexpr static bool IsZero(const P& value) { return value.IsZero(); }
};

template <typename Curve>
struct PointConversions<AffinePoint<Curve>, AffinePoint<Curve>> {
constexpr static const AffinePoint<Curve>& Convert(
Expand Down
27 changes: 0 additions & 27 deletions tachyon/math/elliptic_curves/jacobian_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <ostream>

#include "tachyon/base/no_destructor.h"
#include "tachyon/math/base/identities.h"
#include "tachyon/math/elliptic_curves/point_conversions_forward.h"

namespace tachyon::math {
Expand All @@ -23,32 +22,6 @@ JacobianPoint<Curve> operator*(const ScalarField& v,
return point * v;
}

template <typename Curve>
class MultiplicativeIdentity<JacobianPoint<Curve>> {
public:
using P = JacobianPoint<Curve>;

static const P& One() {
static base::NoDestructor<P> one(P::One());
return *one;
}

constexpr static bool IsOne(const P& value) { return value.IsOne(); }
};

template <typename Curve>
class AdditiveIdentity<JacobianPoint<Curve>> {
public:
using P = JacobianPoint<Curve>;

static const P& Zero() {
static base::NoDestructor<P> zero(P::Zero());
return *zero;
}

constexpr static bool IsZero(const P& value) { return value.IsZero(); }
};

template <typename Curve>
struct PointConversions<JacobianPoint<Curve>, JacobianPoint<Curve>> {
constexpr static const JacobianPoint<Curve>& Convert(
Expand Down
1 change: 0 additions & 1 deletion tachyon/math/elliptic_curves/msm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ tachyon_cc_library(
"//tachyon/base:static_storage",
"//tachyon/math/base:bit_iterator",
"//tachyon/math/base/gmp:bit_traits",
"//tachyon/math/base/gmp:gmp_identities",
"//tachyon/math/base/gmp:signed_value",
"//tachyon/math/elliptic_curves:points",
"//tachyon/math/matrix:gmp_num_traits",
Expand Down
1 change: 0 additions & 1 deletion tachyon/math/elliptic_curves/msm/glv.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "tachyon/base/static_storage.h"
#include "tachyon/math/base/bit_iterator.h"
#include "tachyon/math/base/gmp/bit_traits.h"
#include "tachyon/math/base/gmp/gmp_identities.h"
#include "tachyon/math/base/gmp/signed_value.h"
#include "tachyon/math/elliptic_curves/affine_point.h"
#include "tachyon/math/elliptic_curves/jacobian_point.h"
Expand Down
27 changes: 0 additions & 27 deletions tachyon/math/elliptic_curves/point_xyzz.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <ostream>

#include "tachyon/base/no_destructor.h"
#include "tachyon/math/base/identities.h"
#include "tachyon/math/elliptic_curves/point_conversions_forward.h"

namespace tachyon::math {
Expand All @@ -23,32 +22,6 @@ PointXYZZ<Curve> operator*(const ScalarField& v,
return point * v;
}

template <typename Curve>
class MultiplicativeIdentity<PointXYZZ<Curve>> {
public:
using P = PointXYZZ<Curve>;

static const P& One() {
static base::NoDestructor<P> one(P::One());
return *one;
}

constexpr static bool IsOne(const P& value) { return value.IsOne(); }
};

template <typename Curve>
class AdditiveIdentity<PointXYZZ<Curve>> {
public:
using P = PointXYZZ<Curve>;

static const P& Zero() {
static base::NoDestructor<P> zero(P::Zero());
return *zero;
}

constexpr static bool IsZero(const P& value) { return value.IsZero(); }
};

template <typename Curve>
struct PointConversions<PointXYZZ<Curve>, PointXYZZ<Curve>> {
constexpr static const PointXYZZ<Curve>& Convert(
Expand Down
27 changes: 0 additions & 27 deletions tachyon/math/elliptic_curves/projective_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <ostream>

#include "tachyon/base/no_destructor.h"
#include "tachyon/math/base/identities.h"
#include "tachyon/math/elliptic_curves/point_conversions_forward.h"

namespace tachyon::math {
Expand All @@ -24,32 +23,6 @@ ProjectivePoint<Curve> operator*(const ScalarField& v,
return point * v;
}

template <typename Curve>
class MultiplicativeIdentity<ProjectivePoint<Curve>> {
public:
using P = ProjectivePoint<Curve>;

static const P& One() {
static base::NoDestructor<P> one(P::One());
return *one;
}

constexpr static bool IsOne(const P& value) { return value.IsOne(); }
};

template <typename Curve>
class AdditiveIdentity<ProjectivePoint<Curve>> {
public:
using P = ProjectivePoint<Curve>;

static const P& Zero() {
static base::NoDestructor<P> zero(P::Zero());
return *zero;
}

constexpr static bool IsZero(const P& value) { return value.IsZero(); }
};

template <typename Curve>
struct PointConversions<ProjectivePoint<Curve>, ProjectivePoint<Curve>> {
constexpr static const ProjectivePoint<Curve>& Convert(
Expand Down
2 changes: 0 additions & 2 deletions tachyon/math/finite_fields/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ tachyon_cc_library(
"//tachyon/base:no_destructor",
"//tachyon/base/strings:string_util",
"//tachyon/math/base:field",
"//tachyon/math/base:identities",
"//tachyon/math/base/gmp:gmp_util",
],
)
Expand All @@ -72,7 +71,6 @@ tachyon_cc_library(
"//tachyon/base/containers:adapters",
"//tachyon/base/strings:string_util",
"//tachyon/math/base:arithmetics",
"//tachyon/math/base:identities",
"//tachyon/math/base/gmp:gmp_util",
"@com_google_googletest//:gtest_prod",
],
Expand Down
27 changes: 0 additions & 27 deletions tachyon/math/finite_fields/prime_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "tachyon/math/base/arithmetics.h"
#include "tachyon/math/base/big_int.h"
#include "tachyon/math/base/gmp/gmp_util.h"
#include "tachyon/math/base/identities.h"
#include "tachyon/math/finite_fields/modulus.h"
#include "tachyon/math/finite_fields/prime_field_base.h"
#include "tachyon/math/finite_fields/prime_field_forward.h"
Expand Down Expand Up @@ -297,32 +296,6 @@ std::ostream& operator<<(std::ostream& os, const PrimeField<Config>& f) {
return os << f.ToString();
}

template <typename Config>
class MultiplicativeIdentity<PrimeField<Config>> {
public:
using F = PrimeField<Config>;

static const F& One() {
static F one(F::One());
return one;
}

constexpr static bool IsOne(const F& value) { return value.IsOne(); }
};

template <typename Config>
class AdditiveIdentity<PrimeField<Config>> {
public:
using F = PrimeField<Config>;

static const F& Zero() {
static F zero(F::Zero());
return zero;
}

constexpr static bool IsZero(const F& value) { return value.IsZero(); }
};

} // namespace tachyon::math

#endif // TACHYON_MATH_FINITE_FIELDS_PRIME_FIELD_H_
Loading