sigma  1.0.0
Loading...
Searching...
No Matches
hyperbolic.ipp
1#pragma once
3#include <algorithm>
4#include <stdexcept>
5
6namespace sigma {
7
8template<typename T>
10 if(a.empty()) { return GeneralInterval<T>(); }
12 boost::numeric::sinh(detail_::to_boost_(a)), a.left_open(),
13 a.right_open());
14}
15
16template<typename T>
18 if(a.empty()) { return GeneralInterval<T>(); }
19
20 bool left_open = a.left_open();
21 bool right_open = a.right_open();
22 if(a.upper() <= T(0)) {
23 // Entirely non-positive, where cosh is decreasing. A zero upper bound
24 // is an input bound, attained only if it is closed.
25 std::swap(left_open, right_open);
26 } else if(a.lower() < T(0)) {
27 // Spans zero, so the minimum is the interior point cosh(0) == 1 and
28 // the maximum comes from whichever bound is farther from zero.
29 const T abs_lower = -a.lower();
30 left_open = false;
31 if(abs_lower > a.upper()) {
32 right_open = a.left_open();
33 } else if(abs_lower < a.upper()) {
34 right_open = a.right_open();
35 } else {
36 right_open = a.left_open() && a.right_open();
37 }
38 }
39
41 boost::numeric::cosh(detail_::to_boost_(a)), left_open, right_open);
42}
43
44template<typename T>
46 if(a.empty()) { return GeneralInterval<T>(); }
48 boost::numeric::tanh(detail_::to_boost_(a)), a.left_open(),
49 a.right_open());
50}
51
52template<typename T>
54 if(a.empty()) { return GeneralInterval<T>(); }
56 boost::numeric::asinh(detail_::to_boost_(a)), a.left_open(),
57 a.right_open());
58}
59
60template<typename T>
62 if(a.empty()) { return GeneralInterval<T>(); }
63 // Trimming the argument back to the domain would answer a narrower
64 // question than the one asked. Boost would clamp the lower bound to one.
65 if(a.lower() < T(1)) {
66 throw std::domain_error("Interval has values less than 1.");
67 }
68 // Increasing, so the openness of each bound carries over.
70 boost::numeric::acosh(detail_::to_boost_(a)), a.left_open(),
71 a.right_open());
72}
73
74template<typename T>
76 if(a.empty()) { return GeneralInterval<T>(); }
77 // The domain is open, so a bound AT plus or minus one is out of domain
78 // only if it is closed -- the same rule log() applies at zero.
79 detail_::assert_within_unit_(a, true, "inverse hyperbolic tangent");
80 // Increasing. An open bound at either end of the domain leaves the result
81 // unbounded on that side, and from_boost_ opens that infinite bound.
83 boost::numeric::atanh(detail_::to_boost_(a)), a.left_open(),
84 a.right_open());
85}
86
87} // namespace sigma
Models an interval whose bounds may be open.
Definition general_interval.hpp:36
bool empty() const
Is *this the empty interval?
Definition general_interval.hpp:127
bool left_open() const
Is lower() NOT contained in the interval?
Definition general_interval.hpp:136
bool right_open() const
Is upper() NOT contained in the interval?
Definition general_interval.hpp:153
value_t lower() const
Returns the lower bound of the interval.
Definition general_interval.hpp:169
value_t upper() const
Returns the upper bound of the interval.
Definition general_interval.hpp:177
Conversions between sigma::GeneralInterval and the boost interval its closure wraps.
void assert_within_unit_(const Interval< T > &a, bool open, const std::string &name)
Throws unless every value in a lies in the unit interval.
Definition convert.hpp:74
GeneralInterval< T > general_from_boost_(const boost_interval_t< T > &x, bool left_open=false, bool right_open=false)
Convert a boost interval into a sigma::GeneralInterval.
Definition general_convert.hpp:65
boost_interval_t< T > to_boost_(const Interval< T > &a)
Convert a sigma::Interval into the boost interval it wraps.
Definition convert.hpp:31
The primary namespace for the sigma library.
Definition affine.hpp:12
GeneralInterval< T > atanh(const GeneralInterval< T > &a)
Calculate the inverse hyperbolic tangent of a general interval.
Definition hyperbolic.ipp:75
GeneralInterval< T > tanh(const GeneralInterval< T > &a)
Calculate the hyperbolic tangent of a general interval.
Definition hyperbolic.ipp:45
GeneralInterval< T > cosh(const GeneralInterval< T > &a)
Calculate the hyperbolic cosine of a general interval.
Definition hyperbolic.ipp:17
GeneralInterval< T > acosh(const GeneralInterval< T > &a)
Calculate the inverse hyperbolic cosine of a general interval.
Definition hyperbolic.ipp:61
GeneralInterval< T > asinh(const GeneralInterval< T > &a)
Calculate the inverse hyperbolic sine of a general interval.
Definition hyperbolic.ipp:53
GeneralInterval< T > sinh(const GeneralInterval< T > &a)
Calculate the hyperbolic sine of a general interval.
Definition hyperbolic.ipp:9