Loading...
Searching...
No Matches
is_real.cpp
1#include <symengine/basic.h>
2#include <symengine/assumptions.h>
3#include <symengine/visitor.h>
4#include <symengine/test_visitors.h>
5
6namespace SymEngine
7{
8
9class MatrixRealVisitor : public BaseVisitor<MatrixRealVisitor>
10{
11private:
12 tribool is_real_;
13 const Assumptions *assumptions_;
14
15public:
16 MatrixRealVisitor(const Assumptions *assumptions)
17 : assumptions_(assumptions)
18 {
19 }
20
21 void bvisit(const Basic &x){};
22 void bvisit(const MatrixExpr &x)
23 {
24 is_real_ = tribool::indeterminate;
25 }
26
27 void bvisit(const IdentityMatrix &x)
28 {
29 is_real_ = tribool::tritrue;
30 }
31
32 void bvisit(const ZeroMatrix &x)
33 {
34 is_real_ = tribool::tritrue;
35 }
36
37 void bvisit(const DiagonalMatrix &x)
38 {
39 tribool current = tribool::tritrue;
40 for (auto &e : x.get_container()) {
41 tribool next = is_real(*e, assumptions_);
42 if (is_false(next)) {
43 is_real_ = next;
44 return;
45 }
46 current = andwk_tribool(current, next);
47 }
48 is_real_ = current;
49 }
50
51 void bvisit(const ImmutableDenseMatrix &x)
52 {
53 RealVisitor visitor(assumptions_);
54 tribool cur = tribool::tritrue;
55 for (auto &e : x.get_values()) {
56 cur = and_tribool(cur, visitor.apply(*e));
57 if (is_false(cur)) {
58 is_real_ = cur;
59 return;
60 }
61 }
62 is_real_ = cur;
63 }
64
65 tribool apply(const MatrixExpr &s)
66 {
67 s.accept(*this);
68 return is_real_;
69 }
70};
71
72tribool is_real(const MatrixExpr &m, const Assumptions *assumptions)
73{
74 MatrixRealVisitor visitor(assumptions);
75 return visitor.apply(m);
76}
77
78} // namespace SymEngine
The base class for SymEngine.
The lowest unit of symbolic representation.
Definition: basic.h:97
Main namespace for SymEngine package.
Definition: add.cpp:19