fmatvec 0.0.0

symbolic_function1_temp.h
1 template<TEMPLATE>
2 class SymbolicFunction<RET(ARG)> : public virtual Function<RET(ARG)> {
3 public:
4 using DRetDArg = typename Function<RET(ARG)>::DRetDArg;
5 using DRetDDir = typename Function<RET(ARG)>::DRetDDir;
6 using DDRetDDArg = typename Function<RET(ARG)>::DDRetDDArg;
7 using ArgS = typename ReplaceAT<ARG, IndependentVariable>::Type;
8 using RetS = typename ReplaceAT<RET, SymbolicExpression>::Type;
9
10 SymbolicFunction();
11 SymbolicFunction(const ArgS &argS_, const RetS &retS_); // calls init() at the end
12 void setIndependentVariable(const ArgS &argS_);
13 void setDependentFunction(const RetS &retS_);
14 ArgS& getIndependentVariable();
15 RetS& getDependentFunction();
16 void init(); // must be called after setIndependentVariable/setDependentFunction.
17
18 std::pair<int, int> getRetSize() const override;
19 int getArgSize() const override;
20
21 RET operator()(const ARG &arg) override;
22 #ifdef PARDER
23 DRetDArg parDer(const ARG &arg) override;
24 #endif
25 DRetDDir dirDer(const ARG &argDir, const ARG &arg) override;
26 #ifdef PARDERPARDER
27 DDRetDDArg parDerParDer(const ARG &arg) override;
28 #endif
29 #ifdef PARDER
30 DRetDArg parDerDirDer(const ARG &argDir, const ARG &arg) override;
31 #endif
32 DRetDDir dirDerDirDer(const ARG &argDir_1, const ARG &argDir_2, const ARG &arg) override;
33 bool constParDer() const override;
34
35 protected:
36
37 ArgS argS;
38 ArgS argDirS;
39 ArgS argDirS_2;
40 RetS retS;
41 std::unique_ptr<Eval<decltype(retS)>> retSEval;
42 #ifdef PARDER
43 std::unique_ptr<Eval<typename ReplaceAT<DRetDArg, SymbolicExpression>::Type>> pdEval;
44 #endif
45 std::unique_ptr<Eval<typename ReplaceAT<DRetDDir, SymbolicExpression>::Type>> ddEval;
46 #ifdef PARDERPARDER
47 std::unique_ptr<Eval<typename ReplaceAT<DDRetDDArg, SymbolicExpression>::Type>> pdpdEval;
48 #endif
49 #ifdef PARDER
50 std::unique_ptr<Eval<typename ReplaceAT<DRetDArg, SymbolicExpression>::Type>> pdddEval;
51 #endif
52 std::unique_ptr<Eval<typename ReplaceAT<DRetDDir, SymbolicExpression>::Type>> ddddEval;
53 bool isParDerConst = false;
54 };
55
56 template<TEMPLATE>
57 SymbolicFunction<RET(ARG)>::SymbolicFunction() {
58 #ifdef PARDER
59 isParDerConst=false;
60 #endif
61 }
62
63 template<TEMPLATE>
64 SymbolicFunction<RET(ARG)>::SymbolicFunction(const ArgS &argS_, const RetS &retS_) : argS(argS_), retS(retS_) {
65 #ifdef PARDER
66 isParDerConst=false;
67 #endif
68 init();
69 }
70
71 template<TEMPLATE>
72 void SymbolicFunction<RET(ARG)>::setIndependentVariable(const ArgS &argS_) {
73 argS<<=argS_;
74 }
75
76 template<TEMPLATE>
77 void SymbolicFunction<RET(ARG)>::setDependentFunction(const RetS &retS_) {
78 retS<<=retS_;
79 }
80
81 template<TEMPLATE>
82 typename SymbolicFunction<RET(ARG)>::ArgS& SymbolicFunction<RET(ARG)>::getIndependentVariable() {
83 return argS;
84 }
85
86 template<TEMPLATE>
87 typename SymbolicFunction<RET(ARG)>::RetS& SymbolicFunction<RET(ARG)>::getDependentFunction() {
88 return retS;
89 }
90
91 template<TEMPLATE>
92 void SymbolicFunction<RET(ARG)>::init() {
93 Helper<ArgS>::initIndep(argDirS, Helper<ArgS>::size1(argS));
94 Helper<ArgS>::initIndep(argDirS, Helper<ArgS>::size1(argS));
95 Helper<ArgS>::initIndep(argDirS_2, Helper<ArgS>::size1(argS));
96 retSEval.reset(new Eval<decltype(retS)>{retS});
97 #ifdef PARDER
98 pdEval.reset(new Eval<typename ReplaceAT<DRetDArg, SymbolicExpression>::Type>{fmatvec::parDer(retS, argS)});
99 #endif
100 ddEval.reset(new Eval<typename ReplaceAT<DRetDDir, SymbolicExpression>::Type>{fmatvec::dirDer(retS, argDirS*1, argS)});
101 #ifdef PARDERPARDER
102 pdpdEval.reset(new Eval<typename ReplaceAT<DDRetDDArg, SymbolicExpression>::Type>{fmatvec::parDer(fmatvec::parDer(retS, argS), argS)});
103 #endif
104 #ifdef PARDER
105 pdddEval.reset(new Eval<typename ReplaceAT<DRetDArg, SymbolicExpression>::Type>{fmatvec::dirDer(fmatvec::parDer(retS, argS), argDirS*1, argS)});
106 #endif
107 ddddEval.reset(new Eval<typename ReplaceAT<DRetDDir, SymbolicExpression>::Type>{fmatvec::dirDer(fmatvec::dirDer(retS, argDirS*1, argS), argDirS_2*1, argS)});
108 }
109
110 template<TEMPLATE>
111 std::pair<int, int> SymbolicFunction<RET(ARG)>::getRetSize() const {
112 return std::make_pair(Helper<RetS>::size1(retS), Helper<RetS>::size2(retS));
113 }
114
115 template<TEMPLATE>
116 int SymbolicFunction<RET(ARG)>::getArgSize() const {
117 return Helper<ArgS>::size1(argS);
118 }
119
120 template<TEMPLATE>
121 RET SymbolicFunction<RET(ARG)>::operator()(const ARG &arg) {
122 argS^=arg;
123 return (*retSEval)();
124 }
125
126 #ifdef PARDER
127 template<TEMPLATE>
128 auto SymbolicFunction<RET(ARG)>::parDer(const ARG &arg) -> DRetDArg {
129 argS^=arg;
130 return (*pdEval)();
131 }
132 #endif
133
134 template<TEMPLATE>
135 auto SymbolicFunction<RET(ARG)>::dirDer(const ARG &argDir, const ARG &arg) -> DRetDDir {
136 argDirS^=argDir;
137 argS^=arg;
138 return (*ddEval)();
139 }
140
141 #ifdef PARDERPARDER
142 template<TEMPLATE>
143 auto SymbolicFunction<RET(ARG)>::parDerParDer(const ARG &arg) -> DDRetDDArg {
144 argS^=arg;
145 return (*pdpdEval)();
146 }
147 #endif
148
149 #ifdef PARDER
150 template<TEMPLATE>
151 auto SymbolicFunction<RET(ARG)>::parDerDirDer(const ARG &argDir, const ARG &arg) -> DRetDArg {
152 argDirS^=argDir;
153 argS^=arg;
154 return (*pdddEval)();
155 }
156 #endif
157
158 template<TEMPLATE>
159 auto SymbolicFunction<RET(ARG)>::dirDerDirDer(const ARG &argDir_1, const ARG &argDir_2, const ARG &arg) -> DRetDDir {
160 argDirS^=argDir_1;
161 argDirS_2^=argDir_2;
162 argS^=arg;
163 return (*ddddEval)();
164 }
165
166 template<TEMPLATE>
167 bool SymbolicFunction<RET(ARG)>::constParDer() const {
168 return isParDerConst;
169 }
fmatvec::parDer
SymbolicExpression parDer(const SymbolicExpression &dep, const IndependentVariable &indep)
Definition: ast.cc:299