From 3f7586378db76f15168e2238e443b7b974654836 Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Fri, 14 Nov 2025 16:16:22 +0100 Subject: [PATCH] working on add_permuted_contractions --- t.cc | 49 ++++++++++++++++++++++++++++++++++- tensor.cc | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- tensor.h | 9 ++++--- 3 files changed, 127 insertions(+), 7 deletions(-) diff --git a/t.cc b/t.cc index 78e50db..d31c91b 100644 --- a/t.cc +++ b/t.cc @@ -3568,7 +3568,7 @@ v.printsorted(cout,1,false); } -if(1) +if(0) { //grassmann product of n identical rank=2 tensors in m-dim space int n,m; @@ -4164,5 +4164,52 @@ cout<<"resulting index order = "<>nn; +int r=4; +NRVec s(r); +for(int i=0; i x(s); x.randomize(1.); +INDEXNAME xlist[] = {"i","j","k","l"}; +x.names=NRVec(xlist); +Tensor y(s); y.randomize(1.); +INDEXNAME ylist[] = {"n","m","j","i"}; +y.names=NRVec(ylist); + +Tensorz(s); z.clear(); +INDEXNAME zlist[] = {"k","l","m","n"}; +z.names=NRVec(zlist); +Tensorzz(z); + +INDEX i1[]={{0,0},{1,0}}; +INDEX i2[]={{3,0},{2,0}}; +NRVec il1(i1); +NRVec il2(i2); +Tensor zzz = x.contractions(il1,y,il2,1,false,false); +//cout <<"zzz names = "< u = conjugate1? (rhs1.unwind_index(group,index)).conjugate() : rhs1.unwind_index(group,index); @@ -1458,9 +1458,11 @@ if(rank()!=rhs.rank()) laerror("rank mismatch in apply_permutation_algebra"); if(rhs.is_named()) { - NRVec namperm = rhs.names.permuted(pa[0].perm,inverse); + NRVec namperm = rhs.names.permuted(pa[0].perm,!inverse); if(is_named()) { + std::cout <<"LHS names = "< allrhsnames=rhsvec[0].names; for(int i=1; i namperm = allrhsnames.permuted(pa[0].perm,inverse); + NRVec namperm = allrhsnames.permuted(pa[0].perm,!inverse); if(is_named()) { if(names!=namperm) laerror("inconsistent index names in apply_permutation_algebra"); @@ -1905,6 +1907,74 @@ std::istream & operator>>(std::istream &s, INDEX &x) s>>x.group>>x.index; return s; } + + +template +void Tensor::add_permuted_contractions(const char *antisymmetrizer, const Tensor &rhs1, const Tensor &rhs2, T alpha, T beta, bool conjugate1, bool conjugate2) +{ +if(!rhs1.is_uniquely_named()||!rhs2.is_uniquely_named()|| !is_uniquely_named()) laerror("tensors must have unique named indices in add_permuted_contractions"); + +//find contraction indices +int nc=0; +for(int i=0; i pa(1); +pa[0].weight=1; +pa[0].perm.resize(rank()); +pa[0].perm.identity(); + +//std::cout <<"LHS names = "< r; r.addcontractions(*this,il1,rhs2,il2,alpha,0,true,conjugate1, conjugate2); return r; }; inline Tensor contractions(const Tensor &rhs2, const NRVec &names, T alpha=1, bool conjugate1=false, bool conjugate2=false) const {return contractions(findindexlist(names),rhs2,rhs2.findindexlist(names),alpha,conjugate1,conjugate2); }; - void addgroupcontraction(const Tensor &rhs1, int group, const Tensor &rhs2, int rhsgroup, T alpha=1, T beta=1, bool doresize=false, bool conjugate1=false, bool conjugate=false); //over all indices in a group of same symmetry; rhs1 will have more significant non-contracted indices in the result than rhs2 - inline Tensor groupcontraction(int group, const Tensor &rhs, int rhsgroup, T alpha=1, bool conjugate1=false, bool conjugate=false) const {Tensor r; r.addgroupcontraction(*this,group,rhs,rhsgroup,alpha,0,true, conjugate1, conjugate); return r; }; + void addgroupcontraction(const Tensor &rhs1, int group, const Tensor &rhs2, int rhsgroup, T alpha=1, T beta=1, bool doresize=false, bool conjugate1=false, bool conjugate=false); //over all indices in a group of same symmetry; rhs1 will have more significant non-contracted indices in the result than rhs2 + inline Tensor groupcontraction(int group, const Tensor &rhs, int rhsgroup, T alpha=1, bool conjugate1=false, bool conjugate=false) const {Tensor r; r.addgroupcontraction(*this,group,rhs,rhsgroup,alpha,0,true, conjugate1, conjugate); return r; }; + + void add_permuted_contractions(const char *antisymmetrizer, const Tensor &rhs1, const Tensor &rhs2, T alpha=1, T beta=1, bool conjugate1=false, bool conjugate2=false); //must be used on named tensors, finds repeated indices to contract and antisymmetrizes and permutes remaining indices to match *this + Tensor innercontraction(const INDEXLIST &il1, const INDEXLIST &il2) const; //contraction(s) inside this tensor Tensor innercontraction(const INDEX &i1, const INDEX &i2) const {INDEXLIST il1(1); il1[0]=i1; INDEXLIST il2(1); il2[0]=i2; return innercontraction(il1,il2);};