math/include/nil/crypto3/math/type_traits.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2020-2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020-2021 Nikita Kaskov <nbering@nil.foundation>
4 //
5 // MIT License
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 //---------------------------------------------------------------------------//
25 
26 #ifndef CRYPTO3_MATH_TYPE_TRAITS_HPP
27 #define CRYPTO3_MATH_TYPE_TRAITS_HPP
28 
29 #include <vector>
30 
37 
39 
40 namespace nil {
41  namespace crypto3 {
42  namespace math {
43  namespace detail {
44 
53  using namespace nil::crypto3::algebra;
54 
55  template<typename FieldType>
56  bool is_basic_radix2_domain(std::size_t m) {
57  const std::size_t log_m = static_cast<std::size_t>(std::ceil(std::log2(m)));
58 
59  return (m > 1) && (log_m <= fields::arithmetic_params<FieldType>::s) && (m == (1ul << log_m));
60  }
61 
62  template<typename FieldType>
63  bool is_extended_radix2_domain(std::size_t m) {
64  const std::size_t log_m = static_cast<std::size_t>(std::ceil(std::log2(m)));
65  const std::size_t small_m = m / 2;
66  const std::size_t log_small_m = static_cast<std::size_t>(std::ceil(std::log2(small_m)));
67 
68  return (m > 1) && (log_m == fields::arithmetic_params<FieldType>::s + 1) &&
69  (small_m == (1ul << log_small_m)) &&
71  }
72 
73  template<typename FieldType>
74  bool is_step_radix2_domain(std::size_t m) {
75  const std::size_t log_m = static_cast<std::size_t>(std::ceil(std::log2(m)));
76  const std::size_t shift_log_m = (1ul << log_m);
77  const std::size_t log_shift_log_m = static_cast<std::size_t>(std::ceil(std::log2(shift_log_m)));
78  const std::size_t small_m = m - (1ul << (static_cast<std::size_t>(std::ceil(std::log2(m))) - 1));
79  const std::size_t log_small_m = static_cast<std::size_t>(std::ceil(std::log2(small_m)));
80 
81  return (m > 1) && (small_m == (1ul << log_small_m)) && (shift_log_m == (1ul << log_shift_log_m)) &&
82  (log_shift_log_m <= fields::arithmetic_params<FieldType>::s);
83  }
84 
85  template<typename FieldType>
86  bool is_geometric_sequence_domain(std::size_t m) {
87  return (m > 1) &&
88  (typename FieldType::value_type(fields::arithmetic_params<FieldType>::geometric_generator) !=
89  FieldType::value_type::zero());
90  }
91 
92  template<typename FieldType>
93  bool is_arithmetic_sequence_domain(std::size_t m) {
94  return (m > 1) && (typename FieldType::value_type(
96  FieldType::value_type::zero());
97  }
98 
99  } // namespace detail
100  } // namespace math
101  } // namespace crypto3
102 } // namespace nil
103 
104 #endif // CRYPTO3_MATH_TYPE_TRAITS_HPP
Definition: pair.hpp:33
bool is_basic_radix2_domain(std::size_t m)
Definition: math/include/nil/crypto3/math/type_traits.hpp:56
bool is_step_radix2_domain(std::size_t m)
Definition: math/include/nil/crypto3/math/type_traits.hpp:74
bool is_arithmetic_sequence_domain(std::size_t m)
Definition: math/include/nil/crypto3/math/type_traits.hpp:93
bool is_extended_radix2_domain(std::size_t m)
Definition: math/include/nil/crypto3/math/type_traits.hpp:63
bool is_geometric_sequence_domain(std::size_t m)
Definition: math/include/nil/crypto3/math/type_traits.hpp:86
Definition: pair.hpp:31
Definition: fields/params.hpp:58