Skip to content

Commit 34aab1f

Browse files
committed
Fixed \frac printing; fixed evaluate bug
1 parent a39172c commit 34aab1f

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

core/DisplayTeX.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ void DisplayTeX::print_fraclike(std::ostream& str, Ex::iterator it)
430430
if(mult * (*it->multiplier)!=1) {
431431
print_multiplier(str, it, mult);
432432
}
433-
434-
dispatch(str, num);
433+
if(num->is_rational()==false || (mult * (*it->multiplier))==1)
434+
dispatch(str, num);
435435
str << "}{";
436436
dispatch(str, den);
437437
str << "}";

core/DisplayTerminal.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ void DisplayTerminal::print_fraclike(std::ostream& str, Ex::iterator it)
352352
// if(needs_brackets(num))
353353
// str << "(";
354354

355-
dispatch(str, num);
355+
if(num->is_rational()==false || (*it->multiplier)==1)
356+
dispatch(str, num);
356357

357358
// if(needs_brackets(num))
358359
// str << ")";

core/algorithms/evaluate.cc

Lines changed: 29 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

@@ -539,8 +539,10 @@ Ex::iterator evaluate::handle_derivative(iterator it)
539539
size_t ni=number_of_direct_indices(it);
540540

541541
cadabra::do_list(tr, ivalues, [&](Ex::iterator iv) {
542-
// std::cerr << "====" << std::endl;
543-
// std::cerr << Ex(iv) << std::endl;
542+
#ifdef DEBUG
543+
std::cerr << "====" << std::endl;
544+
std::cerr << Ex(iv) << std::endl;
545+
#endif
544546
// For each internal dummy set, keep track of the
545547
// position in the permutation array where we generate
546548
// its value.
@@ -551,9 +553,11 @@ Ex::iterator evaluate::handle_derivative(iterator it)
551553
auto deps=dependencies(rhs);
552554

553555
// If the argument does not depend on anything, all derivatives
554-
// would produce zero.
555-
if(deps.size()==0)
556+
// would produce zero. Remove this \equals node from the tree.
557+
if(deps.size()==0) {
558+
tr.erase(iv);
556559
return true;
560+
}
557561

558562
// All indices on \partial can take any of the values of the
559563
// dependencies, EXCEPT when the index is a dummy index. In
@@ -568,7 +572,9 @@ Ex::iterator evaluate::handle_derivative(iterator it)
568572

569573
combin::combinations<Ex> cb;
570574
for(auto& obj: deps) {
571-
// std::cerr << "dep " << obj << std::endl;
575+
#ifdef DEBUG
576+
std::cerr << "dep " << obj << std::endl;
577+
#endif
572578
cb.original.push_back(obj);
573579
}
574580
cb.multiple_pick=true;
@@ -608,18 +614,24 @@ Ex::iterator evaluate::handle_derivative(iterator it)
608614
// derivative, create an entry in the \components node.
609615

610616
for(unsigned int i=0; i<cb.size() || cb.size()==0; ++i) {
611-
// std::cerr << "Index combination " << i << std::endl;
617+
#ifdef DEBUG
618+
std::cerr << "Index combination " << i << std::endl;
619+
#endif
612620
Ex eqcopy(iv);
613621
auto lhs=eqcopy.begin(eqcopy.begin());
614622
assert(*lhs->name=="\\comma");
615623

616624
if(cb.size()>0) {
625+
#ifdef DEBUG
626+
std::cerr << "Copying values of derivative indices" << std::endl;
627+
#endif
617628
// Setup the index values; simply copy from the cb array, but only
618629
// if the indices are not internal dummy.
619630
for(size_t j=0; j<cb[i].size(); ++j) {
620631
auto fd = ind_dummy.find(Ex(tr.child(it, j)));
621-
if(fd==ind_dummy.end())
632+
if(fd==ind_dummy.end()) {
622633
eqcopy.append_child(iterator(lhs), cb[i][j].begin() );
634+
}
623635
}
624636
}
625637
auto rhs=lhs;
@@ -684,14 +696,16 @@ Ex::iterator evaluate::handle_derivative(iterator it)
684696

685697
if(cb.size()==0) break;
686698
}
699+
700+
// Erase the original \equals entry (we generated a full replacement above).
687701
tr.erase(iv);
688702
return true;
689703
});
690704

691705
one(it->multiplier);
692706
// std::cerr << "now " << Ex(it) << std::endl;
693707

694-
708+
695709
// Now move the free (but not the internal dummy!) partial indices
696710
// to the components node, and then unwrap the partial node.
697711

@@ -719,11 +733,15 @@ Ex::iterator evaluate::handle_derivative(iterator it)
719733
++se;
720734
}
721735

722-
// std::cerr << "after index move " << Ex(it) << std::endl;
736+
#ifdef DEBUG
737+
std::cerr << "after index move " << Ex(it) << std::endl;
738+
#endif
723739

724740
merge_component_children(it);
725741

726-
// std::cerr << "after merge " << Ex(it) << std::endl;
742+
#ifdef DEBUG
743+
std::cerr << "after merge " << Ex(it) << std::endl;
744+
#endif
727745

728746
simplify_components(it);
729747
// std::cerr << "then " << Ex(it) << std::endl;

tests/components.cdb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,18 @@ ch:= \Gamma^{\alpha}_{\mu\nu} = 1/2 g^{\alpha\beta} ( \partial_{\nu}{g_{\beta\mu
468468
-\partial_{\beta}{g_{\mu\nu}} );
469469

470470
evaluate(ch, sphe, rhsonly=True);
471+
rm:= R^{\rho}_{\sigma\mu\nu} = +\partial_{\mu}{\Gamma^{\rho}_{\sigma\nu}}
472+
-\partial_{\nu}{\Gamma^{\rho}_{\sigma\mu}}
473+
+\Gamma^{\rho}_{\beta\mu} \Gamma^{\beta}_{\sigma\nu}
474+
-\Gamma^{\rho}_{\beta\nu} \Gamma^{\beta}_{\sigma\mu};
475+
476+
substitute(rm, ch);
477+
evaluate(rm, sphe, rhsonly=True);
478+
479+
ricci:= R_{\sigma\nu} = R^{\rho}_{\sigma\rho\nu};
480+
substitute(ricci, rm);
481+
evaluate(ricci, sphe, rhsonly=True);
482+
483+
R:= R = R_{\sigma\nu} g^{\sigma\nu};
484+
substitute(R, ricci);
485+
evaluate(R, sphe, rhsonly=True);

0 commit comments

Comments
 (0)