Documentation of MARTY
A Modern ARtificial Theoretical phYsicist
graph.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 #ifndef GRAPH_H_INCLUDED
25 #define GRAPH_H_INCLUDED
26 
27 #include "quantumField.h"
28 #include "fermionFlow.h"
29 
30 namespace mty {
31 class FeynruleMomentum;
32 class FeynmanDiagram;
33 class ConjugationList;
34 class Model;
35 }
36 
37 namespace mty::wick {
38 
53 class Node: public std::enable_shared_from_this<Node>{
54 
55  public:
56 
61  explicit
62  Node(const mty::QuantumField* t_field): field(t_field){};
63 
67  Node(const Node& node) = default;
68 
72  Node(Node&& node) = default;
73 
79  bool isFree() const {
80  return (not partner.lock());
81  };
82 
83  static std::vector<std::shared_ptr<Node>> copyGraph(
84  std::vector<std::shared_ptr<Node>> const& init);
85 
86  public:
87 
92 
97  std::weak_ptr<Node> partner;
98 };
99 
100 // Forward declaration of ConnectedComponent class
101 class ConnectedComponent;
102 
108 class Vertex: public std::vector<std::shared_ptr<Node>> {
109 
110  public:
111 
115  Vertex();
116 
123  explicit
124  Vertex(const std::vector<const mty::QuantumField*>& fields,
125  size_t id,
126  bool t_external=false);
127 
131  Vertex(const Vertex& other);
132 
136  bool isExternal() const;
137 
142  bool isFree() const;
143 
148  bool hasFreeNode() const;
149 
157  bool hasFreeNode(const mty::QuantumField* field) const;
158 
159  bool containsExplicit(const mty::QuantumField* field) const;
160 
166  bool isDegenerateWith(const Vertex& other) const;
167 
173  const mty::QuantumField* getFirstContractibleField() const;
174 
179  std::shared_ptr<Node> getFirstContractibleNode() const;
180 
188  std::shared_ptr<Node> getFirstContractibleNode(
189  const mty::QuantumField* field) const;
190 
195  std::vector<std::shared_ptr<Node>> getContractibleNodes() const;
196 
197  std::vector<std::shared_ptr<Node>> getContractibleNodes(
198  const mty::QuantumField* field) const;
199 
204  void setExternal(bool t_external);
205 
213  int getDegeneracy(const mty::QuantumField* t_field) const;
214 
215  int getTotalDegeneracyFactor() const;
216 
230  Vertex& operator=(const Vertex& other);
231 
239  bool operator==(const Vertex& other) const;
240 
246  bool operator!=(const Vertex& other) const;
247 
254  friend
255  std::ostream& operator<<(std::ostream& fout,
256  const Vertex& v);
257 
258  protected:
259 
264  bool external;
265 
266  size_t id;
267 };
268 
275 
276  IMPLEMENTS_STD_VECTOR(Vertex, vertices)
277 
278  public:
279 
284 
289  explicit
290  ConnectedComponent(const Vertex& firstVertex);
291 
295  ConnectedComponent(const ConnectedComponent& other) = default;
296 
297  std::vector<Vertex> const &getVertices() const;
298 
302  void addVertex(const Vertex& newVertex);
303 
312  bool hasValenceLeft() const;
313 
319  const mty::QuantumField* getFirstContractibleField() const;
320 
325  int getFirstContractibleVertex() const;
326 
341  std::vector<int> getContractibleVertices(
342  const mty::QuantumField* field) const;
343 
349  std::shared_ptr<Node> getFirstContractibleNode() const;
350 
356  std::vector<std::shared_ptr<Node>> getNodes() const;
357 
365  int connect(int indexVertex);
366 
374  bool connect(Vertex& other);
375 
382  friend
383  std::ostream& operator<<(std::ostream& fout,
384  const ConnectedComponent& c);
385 
386  private:
387 
388  std::vector<Vertex> vertices;
389 };
390 
396 class Graph {
397 
398  public:
399 
400  using Expr_type = std::pair<csl::Expr, ConjugationList>;
401 
405  Graph();
406 
411  explicit
412  Graph(const std::vector<mty::QuantumField>& field,
413  std::map<csl::Tensor, size_t>& vertexIds,
414  bool ruleMode);
415 
420  explicit
421  Graph(const csl::Expr& expr,
422  std::map<csl::Tensor, size_t>& vertexIds,
423  bool ruleMode);
424 
425  Graph(Graph const& other,
426  std::vector<std::shared_ptr<Node>> const& init);
427 
431  ~Graph(){};
432 
436  Graph(const Graph& other) = default;
437 
441  Graph& operator=(const Graph& other) = default;
442  // Graph(Graph const& other)
443  // :sortedNodes(other.sortedNodes),
444  // factor(other.factor),
445  // symmetrizeExternalLegs(other.symmetrizeExternalLegs),
446  // init(other.init),
447  // initialOrder(other.initialOrder),
448  // connectedCompo(other.connectedCompo),
449  // extVertex(other.extVertex),
450  // intVertex(other.intVertex),
451  // independentVertices(other.independentVertices),
452  // symmetry(other.symmetry),
453  // fixedExpression(other.fixedExpression),
454  // expression(other.expression)
455  // {
456  // ++countCopy;
457  // }
458 
459  // Graph& operator=(Graph const& other) {
460  // sortedNodes = other.sortedNodes;
461  // factor = other.factor;
462  // symmetrizeExternalLegs = other.symmetrizeExternalLegs;
463  // init = other.init;
464  // initialOrder = other.initialOrder;
465  // connectedCompo = other.connectedCompo;
466  // extVertex = other.extVertex;
467  // intVertex = other.intVertex;
468  // independentVertices = other.independentVertices;
469  // symmetry = other.symmetry;
470  // fixedExpression = other.fixedExpression;
471  // expression = other.expression;
472  // ++countCopy;
473  // return *this;
474  // }
475 
476  public:
477 
478  Graph copy() const;
479 
483  int getFactor() const;
484 
485  int getTotalDegeneracyFactor() const;
486 
487  std::vector<Vertex> const &getVertices() const;
488 
489  void addFactor(int t_factor);
490 
491  void setFactor(int t_factor);
492 
493  void setSymmetrizeExternalLegs(bool t_symmetrize);
494 
495  void multiply(int t_factor);
496 
497  void multiply(csl::Expr const &t_factor);
498 
503  bool isFullyConnected() const;
504 
511  bool isPhysical() const;
512 
513  bool isValid() const;
514 
515  int getNLoops() const;
516 
521  int getFieldDimension() const;
522 
530  std::vector<Expr_type> getExpression() const;
531 
532  std::vector<Expr_type> getExpression(
533  mty::FeynruleMomentum& witness
534  ) const;
535 
536  std::vector<const mty::QuantumField*> getFields() const;
537 
538  std::vector<const mty::QuantumField*> getConnectedFieldsInVertex(
539  const mty::QuantumField* init) const;
540 
541  const mty::QuantumField* getConnectedField(
542  const mty::QuantumField* init) const;
543 
544  std::vector<std::shared_ptr<Node>>& getNodes();
545 
546  std::vector<std::shared_ptr<Node>>const& getNodes() const;
547 
552  bool empty() const;
553 
563  std::vector<std::shared_ptr<Graph>> contractionStep() const;
564 
565  bool compare(const Graph& other,
566  std::map<csl::Tensor, csl::Tensor>& mapping,
567  bool fieldBlind = false) const;
568 
569  bool compare(const Graph& other,
570  bool fieldBlind = false) const;
571 
572  void contractHighMass(
573  mty::QuantumFieldParent const *field
574  );
575 
576  bool operator==(const Graph& other) const;
577 
584  friend std::ostream& operator<<(std::ostream& fout,
585  const Graph& g);
586 
587  static
588  Vertex const *getVertexOf(
589  std::shared_ptr<Node> const &node,
590  std::vector<Vertex> const &vertices
591  );
592 
593  static
594  std::vector<std::shared_ptr<Node>> nextNodes(
595  std::shared_ptr<Node> const &node,
596  std::vector<Vertex> const &vertices
597  );
598 
599  static
600  int countExternalLegs(
601  std::vector<csl::Tensor>::iterator first,
602  std::vector<csl::Tensor>::iterator last,
603  std::vector<Vertex> const &vertices
604  );
605 
606  static
607  int walk(
608  std::vector<csl::Tensor>::iterator first,
609  std::vector<csl::Tensor>::iterator last,
610  std::shared_ptr<Node> const &node,
611  std::vector<Vertex> const &vertices
612  );
613 
614  private:
615 
625  void isolateIndependantVertices();
626 
627  void removeIntVertex(int indexVertex);
628 
633  void initConnectedComponent();
634 
635  Expr_type getPartialExpression(
636  std::vector<std::shared_ptr<Node>>& nodes,
637  const std::vector<mty::QuantumField>& initialOrder,
638  mty::FeynruleMomentum& witnessMapping,
639  csl::Expr const& globalFactor) const;
640 
642  getSymmetry(const Vertex& vertex,
643  const mty::QuantumField* field) const;
644 
645  std::vector<std::vector<std::shared_ptr<Node>>> symmetrize() const;
646 
647  static std::vector<std::shared_ptr<Node>> copyNodes(
648  const std::vector<std::shared_ptr<Node>>& toCopy);
649 
650  static void applySymmetry(
651  std::vector<std::shared_ptr<Node>>& nodes,
653 
659  std::vector<int> getContractibleExtVertices(
660  const mty::QuantumField* field) const;
661 
667  std::vector<int> getContractibleIntVertices(
668  const mty::QuantumField* field) const;
669 
675  std::vector<int> getContractibleConnectedVertices(
676  const mty::QuantumField* field) const;
677 
687  bool contractExternal(const mty::QuantumField* field,
688  int indexVertex);
689 
699  bool contractInternal(const mty::QuantumField* field,
700  int indexVertex);
701 
712  bool contractConnected(const mty::QuantumField* field,
713  int indexVertex);
714 
715  static void addFoundNode(const std::shared_ptr<Node>& newNode,
716  std::vector<csl::Tensor>& foundNodes);
717 
718  static void sortNodes(std::vector<std::shared_ptr<Node>>& nodes);
719 
720  static bool compareFieldsDummyPoint(
721  const mty::QuantumField* fieldA,
722  const mty::QuantumField* fieldB,
723  std::map<csl::Tensor, csl::Tensor>& constraints,
724  bool fieldBlind = false);
725 
726  static bool compareNodesWithConstraints(
727  const std::shared_ptr<Node>& nodeA,
728  const std::shared_ptr<Node>& nodeB,
729  std::map<csl::Tensor, csl::Tensor>& constraints,
730  bool fieldBlind = false);
731 
732  private:
733 
734  mutable
735  std::vector<std::shared_ptr<Node>> sortedNodes;
740  long long int factor = 1;
741 
742  csl::Expr exprFactor = CSL_1;
743 
744  bool symmetrizeExternalLegs = false;
745 
746  bool ruleMode;
747 
753 
755 
760 
764  std::vector<Vertex> extVertex;
765 
769  std::vector<Vertex> intVertex;
770 
775  std::vector<int> independentVertices;
776 
778  = Id_Sym(const mty::QuantumField*);
779 
780  mutable bool fixedExpression = false;
781 
782  mutable std::vector<Expr_type> expression;
783 };
784 
793 
794  public:
795 
796  static csl::Expr applyWickTheoremOnDiagram(
797  const Graph& diagram,
798  std::vector<mty::FeynruleMomentum>& witnessMapping,
799  bool ruleMode = true);
800 
801  static csl::vector_expr applyWickTheoremOnDiagrams(
802  const std::vector<std::shared_ptr<Graph>>& diagrams,
803  std::vector<mty::FeynruleMomentum>& witnessMapping,
804  bool ruleMode = true);
805 
806  static std::vector<mty::FeynmanDiagram> getDiagrams(
807  mty::Model const *model,
808  const csl::Expr& initialExpr,
809  std::map<csl::Tensor, size_t>& vertexIds,
810  std::vector<mty::FeynruleMomentum>& witnessMapping,
811  bool symmetriseExternalLegs = false,
812  bool ruleMode = true);
813 
814  static std::vector<mty::FeynmanDiagram> getDiagrams(
815  mty::Model const *model,
816  const csl::Expr& initialExpr,
817  std::map<csl::Tensor, size_t>& vertexIds,
818  bool symmetriseExternalLegs = false,
819  bool ruleMode = true);
820 
830  static bool isContractionZero(
831  const std::vector<mty::QuantumField>& fields,
832  size_t maxLoops = size_t(-1),
833  size_t nVertices = size_t(-1));
834 
835  static bool isContractionZero(
836  const std::vector<mty::QuantumField const*>& fields,
837  size_t maxLoops = size_t(-1),
838  size_t nVertices = size_t(-1));
839 
840  private:
841 
851  static std::vector<std::vector<mty::QuantumField>> splitFields(
852  const std::vector<mty::QuantumField>& field);
853 
854  static std::vector<std::vector<mty::QuantumField const*>> splitFields(
855  const std::vector<mty::QuantumField const*>& field);
856 
857  private:
858 
862  WickCalculator();
863 
868  explicit
869  WickCalculator(const Graph& freeDiagram);
870 
874  WickCalculator(const WickCalculator& other) = default;
875 
880 
881  void setSymmetrizeExternalLegs(bool t_symmetrize);
882 
886  Graph getInitialDiagram() const;
887 
894  std::vector<std::shared_ptr<Graph>> getDiagrams();
895 
902  void eliminateNonPhysicalDiagrams(
903  std::vector<std::shared_ptr<Graph>>& diagrams);
904 
910  void calculateDiagrams();
911 
912  private:
913 
917  bool diagramsCalculated = false;
918 
919  bool symmetrizeExternalLegs = false;
920 
925 
930  std::vector<std::shared_ptr<Graph>> feynmanDiagram;
931 };
932 
934 /*************************************************/
935 // Functions //
936 /*************************************************/
938 
945 void contractNodes(const std::shared_ptr<Node>& node1,
946  const std::shared_ptr<Node>& node2);
947 
961 bool areDegenerate(const mty::QuantumField& f1,
962  const mty::QuantumField& f2);
963 
972  const mty::QuantumField& f2);
973 
980 std::ostream& operator<<(std::ostream& fout,
981  const std::shared_ptr<Node>& node);
982 
991 bool operator==(const std::shared_ptr<Node>& A,
992  const std::shared_ptr<Node>& B);
993 
994 bool comparePriority(const std::shared_ptr<Node>& A,
995  const std::shared_ptr<Node>& B,
996  const std::vector<csl::Tensor>& foundNodes);
997 
998 bool internal_comparePriority(const std::shared_ptr<Node>& A,
999  const std::shared_ptr<Node>& B,
1000  const std::vector<csl::Tensor>& foundNodes);
1001 
1012 std::vector<mty::QuantumField> convertExprToFields(const csl::Expr& expr);
1013 
1020 int countFermions(std::vector<const mty::QuantumField*>::const_iterator begin,
1021  std::vector<const mty::QuantumField*>::const_iterator end);
1022 
1032 int getCommutationSign(const std::vector<mty::QuantumField>& A,
1033  std::vector<const mty::QuantumField*> B);
1034 
1035 int getCommutationSign(const std::vector<const mty::QuantumField*>& A,
1036  std::vector<const mty::QuantumField*> B);
1037 
1044 csl::vector_expr convertGraphsToCorrelators(
1045  const std::vector<std::shared_ptr<Graph>>& diagrams,
1046  std::vector<mty::FeynruleMomentum>& witnessMapping,
1047  bool ruleMode = true);
1048 
1049 } // End of namespace mty::wick
1050 
1051 #endif
std::vector< Vertex > extVertex
List of external vertices not already contracted.
Definition: graph.h:764
Definition: feynruleMomentum.h:68
std::vector< int > independentVertices
Sets of integers spotting the independant internal vertices in intVertex.
Definition: graph.h:775
const mty::QuantumField * field
mty::QuantumField represented by the node in the graph.
Definition: graph.h:91
Node(const mty::QuantumField *t_field)
Constructor with one parameter. Initializes a NULL partner.
Definition: graph.h:62
int countFermions(std::vector< const mty::QuantumField *>::const_iterator begin, std::vector< const mty::QuantumField *>::const_iterator end)
Counts the number of fermions in a std::vector of mty::QuantumField.
Definition: graph.cpp:1914
std::ostream & operator<<(std::ostream &fout, csl::Type type)
Class handling the full application of Wick theorem. Starts from an initial Graph fully disconnected...
Definition: graph.h:792
Namespace of MARTY.
Definition: 2HDM.h:31
bool external
Tells if the Vertex is external, i.e. composed of field insertions.
Definition: graph.h:264
std::shared_ptr< std::vector< Vertex > > init
Initial order of vertices, in order to keep track of a possible sign of commutation between fields...
Definition: graph.h:752
~Graph()
Destructor.
Definition: graph.h:431
bool isFree() const
Tells if the Node is free or not.
Definition: graph.h:79
std::vector of Vertex that represents the connected component of a Graph. A Graph has typically one C...
Definition: graph.h:274
void contractNodes(const std::shared_ptr< Node > &node1, const std::shared_ptr< Node > &node2)
Contracts two Node together, i.e. sets the partner of each node equal to a std::weak_ptr to the other...
Definition: graph.cpp:1786
csl::vector_expr convertGraphsToCorrelators(const std::vector< std::shared_ptr< Graph >> &diagrams, std::vector< mty::FeynruleMomentum > &witnessMapping, bool ruleMode=true)
Converts a std::vector of fully connected graphs into a std::vector of expressions (one expression pe...
Definition: graph.cpp:1963
Represents a contractible mty::QuantumField in the context of Wick contraction.
Definition: graph.h:53
int getCommutationSign(const std::vector< mty::QuantumField > &A, std::vector< const mty::QuantumField *> B)
Computes and returns the sign cost of the commutation of two sets of mty::QuantumField. , with the number of fermion permutations necessary to Transform A to B.
Definition: graph.cpp:1933
bool areExactlyContractible(const mty::QuantumField &f1, const mty::QuantumField &f2)
Tells if the contraction of two mty::QuantumField is non zero.
Definition: graph.cpp:1804
std::vector< std::shared_ptr< Graph > > feynmanDiagram
All possible diagrams once contractions have been done. Result of the function calculateDiagrams()).
Definition: graph.h:930
Class deriving from csl::TensorFieldElement, may enter expressions. In contrary to QuantumFieldParent...
Definition: quantumField.h:1614
~WickCalculator()
Destructor.
Definition: graph.h:879
Handles wick contractions. A graph contains Vertices, and is able to connect them in all possible way...
Definition: graph.h:396
Represents a Vertex in feynman diagrams, i.e. a set of Nodes at the same space-time point...
Definition: graph.h:108
File containing the ConjugationInfo class. Used for Majorana amplitudes.
bool operator==(const Expr &a, const Expr &b)
Graph initialDiagram
Initial diagram for contractions.
Definition: graph.h:924
std::weak_ptr< Node > partner
std::weak_ptr to the Node with which it is contracted, if it is. Else the value is empty...
Definition: graph.h:97
Contains all objects in the theory. In particular QuantumField objects, Gauge, Flavor, Particle...
Definition: model.h:68
bool areDegenerate(const mty::QuantumField &f1, const mty::QuantumField &f2)
Tells if two mty::QuantumField are degenerate, i.e. have the same value in the contraction sens...
Definition: graph.cpp:1793
Base class for parents of QuantumField objects.
Definition: quantumField.h:152
ConnectedComponent connectedCompo
Connected component of the Graph (contains all its vertices).
Definition: graph.h:759
std::vector< Vertex > intVertex
List of internal vertices not already contracted.
Definition: graph.h:769
bool operator!=(const Expr &a, const Expr &b)
Contains QuantumField and QuantumFieldParent, basic objects handling quantum fields as csl expression...
std::vector< mty::QuantumField > convertExprToFields(const csl::Expr &expr)
Converts a csl csl::Expr that is just a product of field into a std::vector of mty::QuantumField obje...
Definition: graph.cpp:1867
Definition: feynmanDiagram.h:31