codac 1.5.6
Loading...
Searching...
No Matches
codac2_log.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include "codac2_Interval.h"
13#include "codac2_AnalyticType.h"
15
16namespace codac2
17{
18 struct LogOp
19 {
20 static Interval fwd(const Interval& x1);
21 static ScalarType fwd_natural(const ScalarType& x1);
22 static ScalarType fwd_centered(const ScalarType& x1);
23 static void bwd(const Interval& y, Interval& x1);
24 };
25
26 // Analytic operator
27 // The following function can be used to build analytic expressions.
28
29 inline ScalarExpr
30 log(const ScalarExpr& x1)
31 {
32 return { std::make_shared<AnalyticOperationExpr<LogOp,ScalarType,ScalarType>>(x1) };
33 }
34
35 // Inline functions
36
37 inline Interval LogOp::fwd(const Interval& x1)
38 {
39 return log(x1);
40 }
41
42 inline ScalarType LogOp::fwd_natural(const ScalarType& x1)
43 {
44 if(centered_form_not_available_for_args(x1))
45 return fwd_natural(x1);
46
47 return {
48 fwd(x1.a),
49 x1.a.is_subset({0,oo}) // def domain of log
50 && x1.a != 0. // def domain of the derivative of log
51 && x1.def_domain
52 };
53 }
54
55 inline ScalarType LogOp::fwd_centered(const ScalarType& x1)
56 {
57 if(centered_form_not_available_for_args(x1))
58 return fwd_natural(x1);
59
60 IntervalMatrix d(1,x1.da.size());
61 for(Index i = 0 ; i < d.size() ; i++)
62 d(0,i) = x1.da(0,i)/x1.a;
63
64 return {
65 fwd(x1.m),
66 fwd(x1.a),
67 d,
68 x1.a.is_subset({0,oo}) // def domain of log
69 && x1.a != 0. // def domain of the derivative of log
70 && x1.def_domain
71 };
72 }
73
74 inline void LogOp::bwd(const Interval& y, Interval& x1)
75 {
76 x1 &= exp(y);
77 }
78}
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:62
Interval log(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:85
Interval exp(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:78