E.V.E
v2023.02.15
Loading...
Searching...
No Matches
Combinatorial functions

Detailed Description

Combinatorial functions.

This module provides implementation for scalar and SIMD versions of combinatorial functions and related operations.

Convenience header:

#include <eve/module/combinatorial.hpp>

Variables

constexpr auto eve::bernoulli = functor<bernoulli_t>
 elementwise_callable object computing the nth Bernoulli number \(b_n\) as a double.
constexpr auto eve::fibonacci = functor<fibonacci_t>
 Computes the nth element of the Fibonacci sequence \((f_i)_{i\in \mathbb{N}}\).
constexpr auto eve::gcd = functor<gcd_t>
 elementwise_callable object computing the greatest common divisor of the inputs.
constexpr auto eve::lcm = functor<lcm_t>
 elementwise_callable object computing the least common multiple of the inputs.
constexpr auto eve::nth_prime = functor<nth_prime_t>
 Returns the nth prime number.
constexpr auto eve::prime_ceil = functor<prime_ceil_t>
 strict_elementwise_callable object computing the smallest prime greater or equal to the input.
constexpr auto eve::prime_floor = functor<prime_floor_t>
 strict_elementwise_callable object computing the greatest prime less or equal to the input.

Variable Documentation

◆ bernoulli

auto eve::bernoulli = functor<bernoulli_t>
inlineconstexpr

elementwise_callable object computing the nth Bernoulli number \(b_n\) as a double.

Header file

#include <eve/module/combinatorial.hpp>

Callable Signatures

namespace eve
{
// Regular overload
template<unsigned_value N, floating_value T>
constexpr as_wide_as_t<T,N> bernoulli(unsigned_value auto n) noexcept; // 1
// Lanes masking
constexpr auto bernoulli[conditional_expr auto c](unsigned_value auto n) noexcept; // 2
constexpr auto bernoulli[logical_value auto m](unsigned_value auto n) noexcept; // 2
}
Specifies that a type is a Conditional Expression.
Definition conditional.hpp:28
The concept logical_value<T> is satisfied if and only if T satisfies eve::value and the element type ...
Definition value.hpp:134
The concept unsigned_value<T> is satisfied if and only if T satisfies eve::value and the element type...
Definition value.hpp:84
constexpr auto bernoulli
elementwise_callable object computing the nth Bernoulli number as a double.
Definition bernoulli.hpp:74
EVE Main Namespace.
Definition abi.hpp:19

Parameters

Return value The result's element type is double to avoid overflow as possible and its cardinal is the same as n.

  1. The value of the nth Bernoulli number is returned.
  2. The operation is performed conditionally.

External references

Example

#include <eve/eve.hpp>
#include <eve/module/combinatorial.hpp>
#include <iostream>
int main() {
eve::wide<std::uint32_t> wu([](auto i, auto )->std::uint32_t{ return i;});
eve::wide n{90u, 25u, 32u, 180u, 8u, 10u, 12u, 14u};
std::cout << "<- wu = " << wu << "\n";
std::cout << "<- n = " << n << "\n";
std::cout << "-> bernoulli(wu) = " << eve::bernoulli(wu) << "\n";
std::cout << "-> bernoulli[ignore_last(2)](wu)= " << eve::bernoulli[eve::ignore_last(2)](wu) << "\n";
std::cout << "-> bernoulli[wu != 2u](wu) = " << eve::bernoulli[wu != 2u](wu) << "\n";
std::cout << "-> bernoulli(n) = " << eve::bernoulli(n) << "\n";
}
Conditional expression ignoring the k last lanes from a eve::simd_value.
Definition conditional.hpp:361
Wrapper for SIMD registers.
Definition wide.hpp:94

◆ fibonacci

auto eve::fibonacci = functor<fibonacci_t>
inlineconstexpr

Computes the nth element of the Fibonacci sequence \((f_i)_{i\in \mathbb{N}}\).

The sequence is defined by the recurrence relations :

  • \(f_0 = x\)
  • \(f_1 = y\)
  • \(f_{n+2} = f_{n+1} + f_{n}, n > 0\)

but is computed using the Binet formula.

Header file

#include <eve/module/combinatorial.hpp>

Callable Signatures

namespace eve
{
// Regular overload
template <floating_value T0, floating_value T1, unsigned_value N>
constexpr as_wide_as_t<common_value_t<T0, T1>, N> fibonacci(unsigned_value n,
floating_value x, floating_value y) noexcept; //1
// Lanes masking
constexpr auto fibonacci[conditional_expr auto c](/*any of the above overloads*/) noexcept; // 2
constexpr auto fibonacci[logical_value auto m](/*any of the above overloads*/) noexcept; // 2
}
The concept floating_value<T> is satisfied if and only if T satisfies eve::value and the element type...
Definition value.hpp:116
constexpr auto fibonacci
Computes the nth element of the Fibonacci sequence .
Definition fibonacci.hpp:86

Parameters

Return value

  1. The value of the nth element of the Fibonacci sequence beginning by x and y is returned.
  2. The operation is performed conditionally.

External references

Example

#include <eve/eve.hpp>
#include <eve/module/combinatorial.hpp>
#include <iostream>
int main() {
eve::wide<std::uint32_t> n([](auto i, auto )->std::uint32_t{ return i+2;});
eve::wide m{13u, 25u, 32u, 80u, 1u, 2u, 3u, 4u};
eve::wide a{1.0f, 2.0f, 3.0f, 4.0f, 0.5f, 0.33f, -4.5f, 0.0f};
eve::wide b{2.0f, 3.0f, 4.0f, 0.5f, 0.33f, -4.5f, 0.0f, 1.0f};
std::cout << "<- n = " << n << "\n";
std::cout << "<- m = " << m << "\n";
std::cout << "<- a = " << a << "\n";
std::cout << "<- b = " << b << "\n";
std::cout << "-> fibonacci(n, 1.0f, 1.0f)= " << eve::fibonacci(n, 1.0f, 1.0f) << "\n";
std::cout << "-> fibonacci(m, a, b) = " << eve::fibonacci(m, a, b) << "\n";
}

◆ gcd

auto eve::gcd = functor<gcd_t>
inlineconstexpr

elementwise_callable object computing the greatest common divisor of the inputs.

Header file

#include <eve/module/combinatorial.hpp>

Callable Signatures

namespace eve
{
// Regular overload
template <integral_value T0, integral_value T1> constexpr common_value_t<T0, T1> gcd(T0 p, T1 n) noexcept; // 1
// Lanes masking
constexpr auto gcd[conditional_expr auto c](integral_value auto p, integral_value auto n) noexcept; // 2
constexpr auto gcd[logical_value auto m](integral_value auto p, integral_value auto n) noexcept; // 2
}
The concept integral_value<T> is satisfied if and only if T satisfies eve::value and the element type...
Definition value.hpp:51
constexpr auto gcd
elementwise_callable object computing the greatest common divisor of the inputs.
Definition gcd.hpp:76
typename eve::_::common_value_impl< void, Ts... >::type common_value_t
Computes the SIMD-compatible common type between all Ts.
Definition common_value.hpp:75

Parameters

Return value

  1. If both p and n are zero, returns zero. Otherwise, returns the greatest common divisor of |p| and |n|.
  2. The operation is performed conditionally.

External references

Example

#include <eve/eve.hpp>
#include <eve/module/combinatorial.hpp>
#include <iostream>
int main() {
eve::wide<float> wf0([](auto i, auto c)->float{ return (i-c/2);});
eve::wide<float> wf1([](auto i, auto )->float{ return 10*i; });
eve::wide n{93, 25, 32, 368, 216, 43, 18, 25};
eve::wide p{42, 30, 27, 1024, 36, 12, 51, 44};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- n = " << n << "\n";
std::cout << "<- p = " << p << "\n";
std::cout << "-> gcd(wf0, wf1) = " << eve::gcd(wf0, wf1) << "\n";
std::cout << "-> gcd[ignore_last(2)](wf0, wf1)= " << eve::gcd[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> gcd[wf0 != -2.0f](wf0, wf1) = " << eve::gcd[wf0 != -2.0f](wf0, wf1) << "\n";
std::cout << "-> gcd(p, n) = " << eve::gcd(p, n) << "\n";
}

◆ lcm

auto eve::lcm = functor<lcm_t>
inlineconstexpr

elementwise_callable object computing the least common multiple of the inputs.

Callable Signatures

#include <eve/module/combinatorial.hpp>

Callable Signatures

namespace eve
{
// Regular overload
template <integral_value T0, integral_value T1> constexpr common_value_t<T0, T1> lcm(T0 p, T1 n) noexcept; // 1
// Lanes masking
constexpr auto lcm[conditional_expr auto c](integral_value auto p, integral_value auto n) noexcept; // 2
constexpr auto lcm[logical_value auto m](integral_value auto p, integral_value auto n) noexcept; // 2
}
constexpr auto lcm
elementwise_callable object computing the least common multiple of the inputs.
Definition lcm.hpp:77

Parameters

Return value

  1. Returns the least common multiple of |p| and |n|.
  2. The operation is performed conditionally

External references

Example

#include <eve/eve.hpp>
#include <eve/module/combinatorial.hpp>
#include <iostream>
int main() {
eve::wide<float> wf0([](auto i, auto c)->float{ return (i-c/2);});
eve::wide<float> wf1([](auto i, auto )->float{ return 10*i; });
eve::wide n{93, 25, 32, 368, 216, 43, 18, 25};
eve::wide p{42, 30, 27, 1024, 36, 12, 51, 44};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- n = " << n << "\n";
std::cout << "<- p = " << p << "\n";
std::cout << "-> lcm(wf0, wf1) = " << eve::lcm(wf0, wf1) << "\n";
std::cout << "-> lcm[ignore_last(2)](wf0, wf1)= " << eve::lcm[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> lcm[wf0 != -2.0f](wf0, wf1) = " << eve::lcm[wf0 != -2.0f](wf0, wf1) << "\n";
std::cout << "-> lcm(p, n) = " << eve::lcm(p, n) << "\n";
}

◆ nth_prime

auto eve::nth_prime = functor<nth_prime_t>
inlineconstexpr

Returns the nth prime number.

Header file

#include <eve/module/combinatorial.hpp>

Callable Signatures

namespace eve
{
constexpr auto nth_prime(unsigned_value auto x) -> decltype(x) noexcept; //1
template < integral_value T, floating_scalar_value U>
constexpr as_wide_as_t<U, T> nth_prime(T x, as<U>) noexcept; //2
template < integral_value T, unsigned_scalar_value U>
constexpr as_wide_as_t<U, T> nth_prime(T x, as<U>) noexcept; //2
}
constexpr auto nth_prime
Returns the nth prime number.
Definition nth_prime.hpp:86
Lightweight type-wrapper.
Definition as.hpp:29

Parameters

  • n : unsigned argument. If n is greater than 10'000, behavior is undefined.

Return value

  1. The nth prime is returned.
  2. Same, but the element type of the result is deduced from U.

Notes

  • 2 is the first prime. It is returned for n=0.
  • Almost no computations are made, the results are from a lookup table.

External references

Example

#include <eve/eve.hpp>
#include <eve/module/combinatorial.hpp>
#include <iostream>
int main() {
eve::wide<std::uint32_t> wu([](auto i, auto )->std::uint32_t{ return i;});
eve::wide n{52u, 53u, 6541u, 6542u, 0u, 1u, 999u, 10000u};
std::cout << "<- wu = " << wu << "\n";
std::cout << "<- n = " << n << "\n";
std::cout << "-> nth_prime(wu)= " << eve::nth_prime(wu) << "\n";
std::cout << "-> nth_prime(n) = " << eve::nth_prime(n) << "\n";
}

◆ prime_ceil

auto eve::prime_ceil = functor<prime_ceil_t>
inlineconstexpr

strict_elementwise_callable object computing the smallest prime greater or equal to the input.

Header file

#include <eve/module/combinatorial.hpp>

Callable Signatures

namespace eve
{
constexpr auto prime_floor(unsigned_value auto x) -> decltype(x) noexcept; //1
template < integral_value T, floating_scalar_value U>
constexpr as_wide_as_t<U, T> prime_floor(T x, as<U>) noexcept; //2
template < integral_value T, unsigned_scalar_value U>
constexpr as_wide_as_t<U, T> prime_floor(T x, as<U>) noexcept; //2
}
constexpr auto prime_floor
strict_elementwise_callable object computing the greatest prime less or equal to the input.
Definition prime_floor.hpp:80

Parameters

  • n: unsigned argument. If n is greater than 104'729, returns 0.

Return value

  1. The smallest prime greater or equal to n.
  2. Same, but the element type of the result is deduced from U.

External references

Example

#include <eve/eve.hpp>
#include <eve/module/combinatorial.hpp>
#include <iostream>
int main() {
eve::wide<std::uint32_t> wu([](auto i, auto )->std::uint32_t{ return i;});
eve::wide n{0u, 6u, 6542u, 15u, 104729u, 104730u, 10000u, 1000u};
std::cout << "<- wu = " << wu << "\n";
std::cout << "<- n = " << n << "\n";
std::cout << "-> prime_ceil(wu)= " << eve::prime_ceil(wu) << "\n";
std::cout << "-> prime_ceil(n) = " << eve::prime_ceil(n) << "\n";
std::cout << "note 0 answer meaning 'out of implemented range'\n";
}
constexpr auto prime_ceil
strict_elementwise_callable object computing the smallest prime greater or equal to the input.
Definition prime_ceil.hpp:80

◆ prime_floor

auto eve::prime_floor = functor<prime_floor_t>
inlineconstexpr

strict_elementwise_callable object computing the greatest prime less or equal to the input.

Header file

#include <eve/module/combinatorial.hpp>

Callable Signatures

namespace eve
{
constexpr auto prime_floor(unsigned_value auto x) -> decltype(x) noexcept; //1
template < integral_value T, floating_scalar_value U>
constexpr as_wide_as_t<U, T> prime_floor(T x, as<U>) noexcept; //2
template < integral_value T, unsigned_scalar_value U>
constexpr as_wide_as_t<U, T> prime_floor(T x, as<U>) noexcept; //2
}

Parameters

  • n: unsigned argument. If n is greater than 104'729, or less than 2 returns 0.

Return value

  1. The greatest prime less or equal to n.
  2. Same, but the element of the result type is deduced from U.

External references

Example

#include <eve/eve.hpp>
#include <eve/module/combinatorial.hpp>
#include <iostream>
int main() {
eve::wide<std::uint32_t> wu([](auto i, auto )->std::uint32_t{ return i;});
eve::wide n{2u, 6u, 6542u, 15u, 1u, 200000u, 10000u, 1000u};
std::cout << "<- wu = " << wu << "\n";
std::cout << "<- n = " << n << "\n";
std::cout << "-> prime_floor(wu)= " << eve::prime_floor(wu) << "\n";
std::cout << "-> prime_floor(n) = " << eve::prime_floor(n) << "\n";
std::cout << "note 0 answer meaning 'out of implemented range'\n";
}