Documentation of MARTY
A Modern ARtificial Theoretical phYsicist
abstractgammasym.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
24 #pragma once
25 
26 #include "csl.h"
27 #include <vector>
28 #include <memory>
29 #include <iostream>
30 #include <functional>
31 
32 namespace sgl {
33 
34  class GExpr;
35  struct TensorSet;
36 
38  :public std::enable_shared_from_this<AbstractGammaSym>
39  {
40 
41  public:
42 
43  using iterator = std::vector<GExpr>::iterator;
44  using const_iterator = std::vector<GExpr>::const_iterator;
45 
46  virtual ~AbstractGammaSym() {};
47 
48  virtual size_t size() const = 0;
49  virtual GExpr const &argument(size_t i) const = 0;
50  virtual GExpr &argument(size_t i) = 0;
51  virtual iterator begin() = 0;
52  virtual const_iterator begin() const = 0;
53  virtual iterator end() = 0;
54  virtual const_iterator end() const = 0;
55 
56  virtual bool isZero() const = 0;
57 
58  virtual bool hasPropertyWith(GExpr const &other) const;
59  virtual GExpr propertyWith(GExpr const &other) const;
60 
61  virtual csl::Expr getFactor() const;
62  virtual GExpr getTerm() const;
63 
64  GExpr self();
65  virtual GExpr copy() const = 0;
66  virtual GExpr refresh() const = 0;
67 
68  virtual GExpr simplify();
69 
70  virtual std::vector<csl::Index> const &indices() const;
71  virtual std::vector<csl::Index> &indices() ;
72 
73  virtual bool contains(csl::Index const &) const = 0;
74  virtual void replace(csl::Index const &, csl::Index const &) = 0;
75 
76  virtual csl::Expr const &expr() const;
77  virtual csl::Expr &expr() ;
78 
79  virtual csl::Expr toCSL(TensorSet const &tensors) const = 0;
80 
81  virtual void print(std::ostream &out = std::cout) const = 0;
82  void errorPrint() const {
83  print(std::cerr);
84  }
85  };
86 
87  class GExpr: public std::shared_ptr<AbstractGammaSym> {
88 
89  public:
90 
91  using iterator = AbstractGammaSym::iterator;
92  using const_iterator = AbstractGammaSym::const_iterator;
93 
95 
96  GExpr(csl::Expr const &expr);
99  {}
100 
101  size_t size() const { return (**this).size(); }
102  GExpr &operator[](size_t i) { return (**this).argument(i); }
103  GExpr const &operator[](size_t i) const { return (**this).argument(i); }
104  iterator begin() { return (**this).begin(); }
105  const_iterator begin() const { return (**this).begin(); }
106  iterator end() { return (**this).end(); }
107  const_iterator end() const { return (**this).end(); }
108  };
109 
110  GExpr operator-(GExpr const &A);
111  GExpr operator+(GExpr const &A, GExpr const &B);
112  GExpr operator*(GExpr const &A, GExpr const &B);
113  GExpr operator-(GExpr const &A, GExpr const &B);
114  GExpr operator/(GExpr const &A, GExpr const &B);
115 
116  GExpr &operator+=(GExpr &A, GExpr const &B);
117  GExpr &operator*=(GExpr &A, GExpr const &B);
118  GExpr &operator-=(GExpr &A, GExpr const &B);
119  GExpr &operator/=(GExpr &A, GExpr const &B);
120 
121  GExpr operator+(csl::Expr const &A, GExpr const &B);
122  GExpr operator*(csl::Expr const &A, GExpr const &B);
123  GExpr operator-(csl::Expr const &A, GExpr const &B);
124  GExpr operator/(csl::Expr const &A, GExpr const &B);
125  GExpr operator+(GExpr const &A, csl::Expr const &B);
126  GExpr operator*(GExpr const &A, csl::Expr const &B);
127  GExpr operator-(GExpr const &A, csl::Expr const &B);
128  GExpr operator/(GExpr const &A, csl::Expr const &B);
129 
130  GExpr &operator+=(GExpr &A, csl::Expr const &B);
131  GExpr &operator*=(GExpr &A, csl::Expr const &B);
132  GExpr &operator-=(GExpr &A, csl::Expr const &B);
133  GExpr &operator/=(GExpr &A, csl::Expr const &B);
134 
135 
136  std::ostream &operator<<(
137  std::ostream &out,
138  GExpr const &expr
139  );
140 
141 
142 } // namespace sgl
Definition: tensorset.h:30
std::ostream & operator<<(std::ostream &fout, csl::Type type)
Expr operator+(const Expr &a, const Expr &b)
Definition: abstractgammasym.h:87
Expr operator-(const Expr &a, const Expr &b)
Definition: abstractgammasym.h:32
Expr operator/(const Expr &a, const Expr &b)
Expr operator*(const Expr &a, const Expr &b)
Definition: abstractgammasym.h:37