codac 2.0.0
Loading...
Searching...
No Matches
codac2_asin.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 AsinOp
19 {
20 template<typename X1>
21 static std::string str(const X1& x1)
22 {
23 return "asin(" + x1->str() + ")";
24 }
25
26 template<typename X1>
27 static std::pair<Index,Index> output_shape([[maybe_unused]] const X1& s1)
28 {
29 return {1,1};
30 }
31
32 static Interval fwd(const Interval& x1);
33 static ScalarType fwd_natural(const ScalarType& x1);
34 static ScalarType fwd_centered(const ScalarType& x1);
35 static void bwd(const Interval& y, Interval& x1);
36 };
37
38 // Analytic operator
39 // The following function can be used to build analytic expressions.
40
41 inline ScalarExpr
42 asin(const ScalarExpr& x1)
43 {
44 return { std::make_shared<AnalyticOperationExpr<AsinOp,ScalarType,ScalarType>>(x1) };
45 }
46
47 // Inline functions
48
49 inline Interval AsinOp::fwd(const Interval& x1)
50 {
51 return asin(x1);
52 }
53
54 inline ScalarType AsinOp::fwd_natural(const ScalarType& x1)
55 {
56 return {
57 fwd(x1.a),
58 x1.a.is_subset({-1,1}) // def domain of asin
59 && x1.a != 1. // def domain of the derivative of asin
60 && x1.def_domain
61 };
62 }
63
64 inline ScalarType AsinOp::fwd_centered(const ScalarType& x1)
65 {
66 if(centered_form_not_available_for_args(x1))
67 return fwd_natural(x1);
68
69 IntervalMatrix d(1,x1.da.size());
70 for(Index i = 0 ; i < d.size() ; i++)
71 d(0,i) = x1.da(0,i)/sqrt(1.-sqr(x1.a));
72
73 return {
74 fwd(x1.m),
75 fwd(x1.a),
76 d,
77 x1.a.is_subset({-1,1}) // def domain of asin
78 && x1.a != 1. // def domain of the derivative of asin
79 && x1.def_domain
80 };
81 }
82
83 inline void AsinOp::bwd(const Interval& y, Interval& x1)
84 {
85 x1 &= sin(y);
86 }
87}
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:62
Interval sqrt(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:26
Interval sqr(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:21
Interval asin(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:126
Interval sin(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:105