HPCombi
High Performance Combinatorics in C++ using vector instructions v1.1.2
Toggle main menu visibility
Loading...
Searching...
No Matches
include
hpcombi
power.hpp
Go to the documentation of this file.
1
//****************************************************************************//
2
// Copyright (C) 2016-2024 Florent Hivert <Florent.Hivert@lisn.fr>, //
3
// //
4
// This file is part of HP-Combi <https://github.com/libsemigroups/HPCombi> //
5
// //
6
// HP-Combi is free software: you can redistribute it and/or modify it //
7
// under the terms of the GNU General Public License as published by the //
8
// Free Software Foundation, either version 3 of the License, or //
9
// (at your option) any later version. //
10
// //
11
// HP-Combi is distributed in the hope that it will be useful, but WITHOUT //
12
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or //
13
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License //
14
// for more details. //
15
// //
16
// You should have received a copy of the GNU General Public License along //
17
// with HP-Combi. If not, see <https://www.gnu.org/licenses/>. //
18
//****************************************************************************//
19
46
47
#ifndef HPCOMBI_POWER_HPP_
48
#define HPCOMBI_POWER_HPP_
49
50
namespace
HPCombi
{
51
52
namespace
power_helper
{
53
54
// Forward declaration
55
template
<
typename
T>
struct
Monoid
;
56
57
}
// namespace power_helper
58
69
template
<
typename
T,
typename
M = power_helper::Mono
id
<T>>
70
const
T
square
(
const
T x) {
71
return
M::prod(x, x);
72
}
73
90
template
<
unsigned
exp,
typename
T,
typename
M = power_helper::Mono
id
<T>>
91
const
T
pow
(
const
T x) {
92
return
(exp == 0) ? M::one()
93
: (exp % 2 == 0)
94
?
square<T, M>
(
pow
<
unsigned
(exp / 2), T, M>(x))
95
: M::prod(x,
square<T, M>
(
pow
<
unsigned
(exp / 2), T, M>(x)));
96
}
97
98
namespace
power_helper {
99
111
template
<
typename
T>
struct
Monoid
{
113
static
const
T
one
() {
return
1; }
114
120
static
const
T
prod
(T a, T b) {
return
a * b; }
121
};
122
123
}
// namespace power_helper
124
125
}
// namespace HPCombi
126
127
#endif
// HPCOMBI_POWER_HPP_
HPCombi::power_helper
Definition
perm16_impl.hpp:236
HPCombi
Definition
bmat16.hpp:39
HPCombi::square
const T square(const T x)
A generic compile time squaring function.
Definition
power.hpp:70
HPCombi::pow
const T pow(const T x)
A generic compile time exponentiation function.
Definition
power.hpp:91
HPCombi::power_helper::Monoid
Algebraic monoid structure used by default for type T by the pow function and prod function.
Definition
power.hpp:111
HPCombi::power_helper::Monoid::prod
static const T prod(T a, T b)
the product of two elements of type T
Definition
power.hpp:120
HPCombi::power_helper::Monoid::one
static const T one()
The one of type T.
Definition
power.hpp:113
Generated by
1.17.0