codac 1.5.6
Loading...
Searching...
No Matches
codac2_sign.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 SignOp
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 sign(const ScalarExpr& x1)
31 {
32 return { std::make_shared<AnalyticOperationExpr<SignOp,ScalarType,ScalarType>>(x1) };
33 }
34
35 // Inline functions
36
37 inline Interval SignOp::fwd(const Interval& x1)
38 {
39 return sign(x1);
40 }
41
42 inline ScalarType SignOp::fwd_natural(const ScalarType& x1)
43 {
44 return {
45 fwd(x1.a),
46 x1.def_domain && x1.a != 0. // def domain of the derivative of sign
47 };
48 }
49
50 inline ScalarType SignOp::fwd_centered(const ScalarType& x1)
51 {
52 if(centered_form_not_available_for_args(x1))
53 return fwd_natural(x1);
54
55 return {
56 fwd(x1.m),
57 fwd(x1.a),
58 IntervalMatrix::zero(1,x1.da.size()),
59 x1.def_domain && x1.a != 0. // def domain of the derivative of sign
60 };
61 }
62
63 inline void SignOp::bwd(const Interval& y, Interval& x1)
64 {
65 if(y.is_empty())
66 x1.set_empty();
67
68 if(y.lb() > 0)
69 x1 &= Interval(0,oo);
70
71 else if(y.ub() < 0)
72 x1 &= Interval(-oo,0);
73 }
74}
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:62
Interval sign(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:279