Skip to content

Commit a39172c

Browse files
committed
Problem roughly localised
1 parent fa0aced commit a39172c

File tree

4 files changed

+38
-21
lines changed

4 files changed

+38
-21
lines changed

core/Permutations.hh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ class Perm {
2424
std::vector<int> perm;
2525

2626
/// Find the permutation that takes [start1, end1> to [start2, end2>.
27+
/// This will be available in 'perm' afterwards.
2728
template<class iterator>
2829
void find(iterator start1, iterator end1, iterator start2, iterator end2);
2930

30-
/// Apply the permutation on the range.
31+
/// Apply the permutation 'perm' on the given range.
3132
template<class iterator>
3233
void apply(iterator start1, iterator end1);
3334

@@ -81,7 +82,11 @@ void Perm::apply(iterator start, iterator end)
8182
}
8283

8384
// std::cerr << orig.size() << ", " << perm.size() << std::endl;
84-
assert(orig.size()==perm.size());
85+
if(orig.size()!=perm.size()) {
86+
std::cerr << "Perm::apply: orig.size()=" << orig.size() << ", "
87+
<< "perm.size()=" << perm.size() << std::endl;
88+
assert(orig.size()==perm.size());
89+
}
8590

8691
for(unsigned int i=0; i<orig.size(); ++i) {
8792
*start=orig[perm[i]];

core/algorithms/evaluate.cc

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "properties/Accent.hh"
1313
#include <functional>
1414

15-
//#define DEBUG
15+
#define DEBUG
1616

1717
using namespace cadabra;
1818

@@ -364,18 +364,24 @@ void evaluate::merge_components(iterator it1, iterator it2)
364364
// we can be assured that the free indices match; they just may not be
365365
// in the same order).
366366

367+
#ifdef DEBUG
368+
std::cerr << "merge_components on " << Ex(it1) << " and " << Ex(it2) << std::endl;
369+
#endif
370+
367371
assert(*it1->name=="\\components");
368372
assert(*it2->name=="\\components");
369373
sibling_iterator sib1=tr.end(it1);
370374
--sib1;
371375
sibling_iterator sib2=tr.end(it2);
372376
--sib2;
377+
assert(*sib1->name=="\\comma");
378+
assert(*sib2->name=="\\comma");
373379

374-
// We cannot directly compare the lhs of this equals node with the lhs
375-
// of the equals node of the other components node, because the index
376-
// order on the two components nodes may be different. We first
377-
// have to ensure that the orders are the same (but only, of course)
378-
// if we have anything to permutate in the first place.
380+
// We cannot directly compare the lhs of the equals nodes of it1
381+
// with the lhs of the equals node of it2, because the index order
382+
// on the two components nodes may be different. We first have to
383+
// ensure that the orders are the same (but only, of course) if we
384+
// have anything to permutate in the first place.
379385

380386
if(*tr.begin(it1)->name!="\\comma") {
381387
// Look at all indices on the two components nodes. Find
@@ -384,14 +390,20 @@ void evaluate::merge_components(iterator it1, iterator it2)
384390
Perm perm;
385391
perm.find(tr.begin(it2), sib2, tr.begin(it1), sib1);
386392

387-
//perm.apply(tr.begin(it2), sib2);
388-
//std::cerr << "after permutation " << Ex(tr) << std::endl;
389-
393+
// For each \equals node in the it2 comma node, permute
394+
// the values so they agree with the index order on it1.
390395
cadabra::do_list(tr, sib2, [&](Ex::iterator nd) {
391-
auto lhs2 = tr.begin(nd);
392-
perm.apply(tr.begin(lhs2), tr.end(lhs2));
396+
// nd is an \equals node.
397+
assert(*nd->name=="\\equals");
398+
auto comma = tr.begin(nd);
399+
assert(*comma->name=="\\comma");
400+
perm.apply(tr.begin(comma), tr.end(comma));
393401
return true;
394402
});
403+
404+
#ifdef DEBUG
405+
std::cerr << "permutations done" << std::endl;
406+
#endif
395407
}
396408

397409
// Now all index orders match and we can simply compare index value sets.

doc/cadabra2_hep.tex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,9 @@ \subsection{Bianchi, Ricci and Schouten identities}
493493
494494
\toprule
495495
\begin{cdbin}
496-
\tableau{#}::FilledTableau(dimension=10).
497-
\tableau{0,0}{1,1} \tableau{a,a}{b,b}:
498-
@lr_tensor!(%);
496+
\ftableau{#}::FilledTableau(dimension=10).
497+
ex:=\ftableau{0,0}{1,1} \ftableau{a,a}{b,b}:
498+
lr_tensor(_);
499499
\end{cdbin}
500500
\begin{cdbout}
501501
\ftableau{{0}{0}{a}{a},{1}{1}{b}{b}} + \ftableau{{0}{0}{a}{a},{1}{1}{b},{b}} + \ftableau{{0}{0}{a}{a},{1}{1},{b}{b}} + \ftableau{{0}{0}{a},{1}{1}{b},{a},{b}} + \ftableau{{0}{0}{a},{1}{1},{a}{b},{b}} + \ftableau{{0}{0},{1}{1},{a}{a},{b}{b}};

tests/components.cdb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,10 @@ g^{\alpha\beta}::InverseMetric.
461461

462462
sphe:={ g_{\theta\theta} = r**2,
463463
g_{\varphi\varphi} = r**2 \sin(\theta)**2 }.
464-
# complete(sphe, $g^{\alpha\beta}$);
464+
complete(sphe, $g^{\alpha\beta}$);
465465

466-
#ch:= \Gamma^{\alpha}_{\mu\nu} = 1/2 g^{\alpha\beta} ( \partial_{\nu}{g_{\beta\mu}}
467-
# +\partial_{\mu}{g_{\beta\nu}}
468-
# -\partial_{\beta}{g_{\mu\nu}} );
466+
ch:= \Gamma^{\alpha}_{\mu\nu} = 1/2 g^{\alpha\beta} ( \partial_{\nu}{g_{\beta\mu}}
467+
+\partial_{\mu}{g_{\beta\nu}}
468+
-\partial_{\beta}{g_{\mu\nu}} );
469469

470-
# evaluate(ch, sphe, rhsonly=True);
470+
evaluate(ch, sphe, rhsonly=True);

0 commit comments

Comments
 (0)