1 /** @file expairseq.cpp
3 * Implementation of sequences of expression pairs. */
6 * GiNaC Copyright (C) 1999-2007 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 #include "expairseq.h"
33 #include "relational.h"
36 #include "operators.h"
40 #if EXPAIRSEQ_USE_HASHTAB
42 #endif // EXPAIRSEQ_USE_HASHTAB
47 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(expairseq, basic,
48 print_func<print_context>(&expairseq::do_print).
49 print_func<print_tree>(&expairseq::do_print_tree))
59 bool operator()(const epp &lh, const epp &rh) const
61 return (*lh).is_less(*rh);
66 // default constructor
71 expairseq::expairseq() : inherited(&expairseq::tinfo_static)
72 #if EXPAIRSEQ_USE_HASHTAB
74 #endif // EXPAIRSEQ_USE_HASHTAB
80 /** For use by copy ctor and assignment operator. */
81 void expairseq::copy(const expairseq &other)
84 overall_coeff = other.overall_coeff;
85 #if EXPAIRSEQ_USE_HASHTAB
87 hashtabsize = other.hashtabsize;
89 hashmask = other.hashmask;
90 hashtab.resize(hashtabsize);
91 epvector::const_iterator osb = other.seq.begin();
92 for (unsigned i=0; i<hashtabsize; ++i) {
94 for (epplist::const_iterator cit=other.hashtab[i].begin();
95 cit!=other.hashtab[i].end(); ++cit) {
96 hashtab[i].push_back(seq.begin()+((*cit)-osb));
102 #endif // EXPAIRSEQ_USE_HASHTAB
107 // other constructors
110 expairseq::expairseq(const ex &lh, const ex &rh) : inherited(&expairseq::tinfo_static)
112 construct_from_2_ex(lh,rh);
113 GINAC_ASSERT(is_canonical());
116 expairseq::expairseq(const exvector &v) : inherited(&expairseq::tinfo_static)
118 construct_from_exvector(v);
119 GINAC_ASSERT(is_canonical());
122 expairseq::expairseq(const epvector &v, const ex &oc, bool do_index_renaming)
123 : inherited(&expairseq::tinfo_static), overall_coeff(oc)
125 GINAC_ASSERT(is_a<numeric>(oc));
126 construct_from_epvector(v, do_index_renaming);
127 GINAC_ASSERT(is_canonical());
130 expairseq::expairseq(std::auto_ptr<epvector> vp, const ex &oc, bool do_index_renaming)
131 : inherited(&expairseq::tinfo_static), overall_coeff(oc)
133 GINAC_ASSERT(vp.get()!=0);
134 GINAC_ASSERT(is_a<numeric>(oc));
135 construct_from_epvector(*vp, do_index_renaming);
136 GINAC_ASSERT(is_canonical());
143 expairseq::expairseq(const archive_node &n, lst &sym_lst) : inherited(n, sym_lst)
144 #if EXPAIRSEQ_USE_HASHTAB
148 archive_node::archive_node_cit first = n.find_first("rest");
149 archive_node::archive_node_cit last = n.find_last("coeff");
151 seq.reserve((last-first)/2);
153 for (archive_node::archive_node_cit loc = first; loc < last;) {
156 n.find_ex_by_loc(loc++, rest, sym_lst);
157 n.find_ex_by_loc(loc++, coeff, sym_lst);
158 seq.push_back(expair(rest, coeff));
161 n.find_ex("overall_coeff", overall_coeff, sym_lst);
164 GINAC_ASSERT(is_canonical());
167 void expairseq::archive(archive_node &n) const
169 inherited::archive(n);
170 epvector::const_iterator i = seq.begin(), iend = seq.end();
172 n.add_ex("rest", i->rest);
173 n.add_ex("coeff", i->coeff);
176 n.add_ex("overall_coeff", overall_coeff);
179 DEFAULT_UNARCHIVE(expairseq)
182 // functions overriding virtual functions from base classes
187 void expairseq::do_print(const print_context & c, unsigned level) const
190 printseq(c, ',', precedence(), level);
194 void expairseq::do_print_tree(const print_tree & c, unsigned level) const
196 c.s << std::string(level, ' ') << class_name() << " @" << this
197 << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
198 << ", nops=" << nops()
200 size_t num = seq.size();
201 for (size_t i=0; i<num; ++i) {
202 seq[i].rest.print(c, level + c.delta_indent);
203 seq[i].coeff.print(c, level + c.delta_indent);
205 c.s << std::string(level + c.delta_indent, ' ') << "-----" << std::endl;
207 if (!overall_coeff.is_equal(default_overall_coeff())) {
208 c.s << std::string(level + c.delta_indent, ' ') << "-----" << std::endl
209 << std::string(level + c.delta_indent, ' ') << "overall_coeff" << std::endl;
210 overall_coeff.print(c, level + c.delta_indent);
212 c.s << std::string(level + c.delta_indent,' ') << "=====" << std::endl;
213 #if EXPAIRSEQ_USE_HASHTAB
214 c.s << std::string(level + c.delta_indent,' ')
215 << "hashtab size " << hashtabsize << std::endl;
216 if (hashtabsize == 0) return;
218 unsigned count[MAXCOUNT+1];
219 for (int i=0; i<MAXCOUNT+1; ++i)
221 unsigned this_bin_fill;
222 unsigned cum_fill_sq = 0;
223 unsigned cum_fill = 0;
224 for (unsigned i=0; i<hashtabsize; ++i) {
226 if (hashtab[i].size() > 0) {
227 c.s << std::string(level + c.delta_indent, ' ')
228 << "bin " << i << " with entries ";
229 for (epplist::const_iterator it=hashtab[i].begin();
230 it!=hashtab[i].end(); ++it) {
231 c.s << *it-seq.begin() << " ";
235 cum_fill += this_bin_fill;
236 cum_fill_sq += this_bin_fill*this_bin_fill;
238 if (this_bin_fill<MAXCOUNT)
239 ++count[this_bin_fill];
245 double lambda = (1.0*seq.size()) / hashtabsize;
246 for (int k=0; k<MAXCOUNT; ++k) {
249 double prob = std::pow(lambda,k)/fact * std::exp(-lambda);
251 c.s << std::string(level + c.delta_indent, ' ') << "bins with " << k << " entries: "
252 << int(1000.0*count[k]/hashtabsize)/10.0 << "% (expected: "
253 << int(prob*1000)/10.0 << ")" << std::endl;
255 c.s << std::string(level + c.delta_indent, ' ') << "bins with more entries: "
256 << int(1000.0*count[MAXCOUNT]/hashtabsize)/10.0 << "% (expected: "
257 << int((1-cum_prob)*1000)/10.0 << ")" << std::endl;
259 c.s << std::string(level + c.delta_indent, ' ') << "variance: "
260 << 1.0/hashtabsize*cum_fill_sq-(1.0/hashtabsize*cum_fill)*(1.0/hashtabsize*cum_fill)
262 c.s << std::string(level + c.delta_indent, ' ') << "average fill: "
263 << (1.0*cum_fill)/hashtabsize
264 << " (should be equal to " << (1.0*seq.size())/hashtabsize << ")" << std::endl;
265 #endif // EXPAIRSEQ_USE_HASHTAB
268 bool expairseq::info(unsigned inf) const
270 return inherited::info(inf);
273 size_t expairseq::nops() const
275 if (overall_coeff.is_equal(default_overall_coeff()))
281 ex expairseq::op(size_t i) const
284 return recombine_pair_to_ex(seq[i]);
285 GINAC_ASSERT(!overall_coeff.is_equal(default_overall_coeff()));
286 return overall_coeff;
289 ex expairseq::map(map_function &f) const
291 std::auto_ptr<epvector> v(new epvector);
292 v->reserve(seq.size()+1);
294 epvector::const_iterator cit = seq.begin(), last = seq.end();
295 while (cit != last) {
296 v->push_back(split_ex_to_pair(f(recombine_pair_to_ex(*cit))));
300 if (overall_coeff.is_equal(default_overall_coeff()))
301 return thisexpairseq(v, default_overall_coeff(), true);
303 ex newcoeff = f(overall_coeff);
304 if(is_a<numeric>(newcoeff))
305 return thisexpairseq(v, newcoeff, true);
307 v->push_back(split_ex_to_pair(newcoeff));
308 return thisexpairseq(v, default_overall_coeff(), true);
313 /** Perform coefficient-wise automatic term rewriting rules in this class. */
314 ex expairseq::eval(int level) const
316 if ((level==1) && (flags &status_flags::evaluated))
319 std::auto_ptr<epvector> vp = evalchildren(level);
323 return (new expairseq(vp, overall_coeff))->setflag(status_flags::dynallocated | status_flags::evaluated);
326 epvector* conjugateepvector(const epvector&epv)
328 epvector *newepv = 0;
329 for (epvector::const_iterator i=epv.begin(); i!=epv.end(); ++i) {
331 newepv->push_back(i->conjugate());
334 expair x = i->conjugate();
335 if (x.is_equal(*i)) {
338 newepv = new epvector;
339 newepv->reserve(epv.size());
340 for (epvector::const_iterator j=epv.begin(); j!=i; ++j) {
341 newepv->push_back(*j);
343 newepv->push_back(x);
348 ex expairseq::conjugate() const
350 epvector* newepv = conjugateepvector(seq);
351 ex x = overall_coeff.conjugate();
352 if (!newepv && are_ex_trivially_equal(x, overall_coeff)) {
355 ex result = thisexpairseq(newepv ? *newepv : seq, x);
362 bool expairseq::is_polynomial(const ex & var) const
364 if (!is_exactly_a<add>(*this) && !is_exactly_a<mul>(*this))
365 return basic::is_polynomial(var);
366 for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
367 if (!(i->rest).is_polynomial(var))
373 bool expairseq::match(const ex & pattern, lst & repl_lst) const
375 // This differs from basic::match() because we want "a+b+c+d" to
376 // match "d+*+b" with "*" being "a+c", and we want to honor commutativity
378 if (this->tinfo() == ex_to<basic>(pattern).tinfo()) {
380 // Check whether global wildcard (one that matches the "rest of the
381 // expression", like "*" above) is present
382 bool has_global_wildcard = false;
384 for (size_t i=0; i<pattern.nops(); i++) {
385 if (is_exactly_a<wildcard>(pattern.op(i))) {
386 has_global_wildcard = true;
387 global_wildcard = pattern.op(i);
392 // Unfortunately, this is an O(N^2) operation because we can't
393 // sort the pattern in a useful way...
398 for (size_t i=0; i<nops(); i++)
399 ops.push_back(op(i));
401 // Now, for every term of the pattern, look for a matching term in
402 // the expression and remove the match
403 for (size_t i=0; i<pattern.nops(); i++) {
404 ex p = pattern.op(i);
405 if (has_global_wildcard && p.is_equal(global_wildcard))
407 exvector::iterator it = ops.begin(), itend = ops.end();
408 while (it != itend) {
409 lst::const_iterator last_el = repl_lst.end();
411 if (it->match(p, repl_lst)) {
416 lst::const_iterator next_el = last_el;
418 if(next_el == repl_lst.end())
421 repl_lst.remove_last();
425 return false; // no match found
429 if (has_global_wildcard) {
431 // Assign all the remaining terms to the global wildcard (unless
432 // it has already been matched before, in which case the matches
434 size_t num = ops.size();
435 std::auto_ptr<epvector> vp(new epvector);
437 for (size_t i=0; i<num; i++)
438 vp->push_back(split_ex_to_pair(ops[i]));
439 ex rest = thisexpairseq(vp, default_overall_coeff());
440 for (lst::const_iterator it = repl_lst.begin(); it != repl_lst.end(); ++it) {
441 if (it->op(0).is_equal(global_wildcard))
442 return rest.is_equal(it->op(1));
444 repl_lst.append(global_wildcard == rest);
449 // No global wildcard, then the match fails if there are any
450 // unmatched terms left
454 return inherited::match(pattern, repl_lst);
457 ex expairseq::subs(const exmap & m, unsigned options) const
459 std::auto_ptr<epvector> vp = subschildren(m, options);
461 return ex_to<basic>(thisexpairseq(vp, overall_coeff, true));
462 else if ((options & subs_options::algebraic) && is_exactly_a<mul>(*this))
463 return static_cast<const mul *>(this)->algebraic_subs_mul(m, options);
465 return subs_one_level(m, options);
470 int expairseq::compare_same_type(const basic &other) const
472 GINAC_ASSERT(is_a<expairseq>(other));
473 const expairseq &o = static_cast<const expairseq &>(other);
477 // compare number of elements
478 if (seq.size() != o.seq.size())
479 return (seq.size()<o.seq.size()) ? -1 : 1;
481 // compare overall_coeff
482 cmpval = overall_coeff.compare(o.overall_coeff);
486 #if EXPAIRSEQ_USE_HASHTAB
487 GINAC_ASSERT(hashtabsize==o.hashtabsize);
488 if (hashtabsize==0) {
489 #endif // EXPAIRSEQ_USE_HASHTAB
490 epvector::const_iterator cit1 = seq.begin();
491 epvector::const_iterator cit2 = o.seq.begin();
492 epvector::const_iterator last1 = seq.end();
493 epvector::const_iterator last2 = o.seq.end();
495 for (; (cit1!=last1)&&(cit2!=last2); ++cit1, ++cit2) {
496 cmpval = (*cit1).compare(*cit2);
497 if (cmpval!=0) return cmpval;
500 GINAC_ASSERT(cit1==last1);
501 GINAC_ASSERT(cit2==last2);
504 #if EXPAIRSEQ_USE_HASHTAB
507 // compare number of elements in each hashtab entry
508 for (unsigned i=0; i<hashtabsize; ++i) {
509 unsigned cursize=hashtab[i].size();
510 if (cursize != o.hashtab[i].size())
511 return (cursize < o.hashtab[i].size()) ? -1 : 1;
514 // compare individual (sorted) hashtab entries
515 for (unsigned i=0; i<hashtabsize; ++i) {
516 unsigned sz = hashtab[i].size();
518 const epplist &eppl1 = hashtab[i];
519 const epplist &eppl2 = o.hashtab[i];
520 epplist::const_iterator it1 = eppl1.begin();
521 epplist::const_iterator it2 = eppl2.begin();
522 while (it1!=eppl1.end()) {
523 cmpval = (*(*it1)).compare(*(*it2));
533 #endif // EXPAIRSEQ_USE_HASHTAB
536 bool expairseq::is_equal_same_type(const basic &other) const
538 const expairseq &o = static_cast<const expairseq &>(other);
540 // compare number of elements
541 if (seq.size()!=o.seq.size())
544 // compare overall_coeff
545 if (!overall_coeff.is_equal(o.overall_coeff))
548 #if EXPAIRSEQ_USE_HASHTAB
549 // compare number of elements in each hashtab entry
550 if (hashtabsize!=o.hashtabsize) {
551 std::cout << "this:" << std::endl;
552 print(print_tree(std::cout));
553 std::cout << "other:" << std::endl;
554 other.print(print_tree(std::cout));
557 GINAC_ASSERT(hashtabsize==o.hashtabsize);
559 if (hashtabsize==0) {
560 #endif // EXPAIRSEQ_USE_HASHTAB
561 epvector::const_iterator cit1 = seq.begin();
562 epvector::const_iterator cit2 = o.seq.begin();
563 epvector::const_iterator last1 = seq.end();
565 while (cit1!=last1) {
566 if (!(*cit1).is_equal(*cit2)) return false;
572 #if EXPAIRSEQ_USE_HASHTAB
575 for (unsigned i=0; i<hashtabsize; ++i) {
576 if (hashtab[i].size() != o.hashtab[i].size())
580 // compare individual sorted hashtab entries
581 for (unsigned i=0; i<hashtabsize; ++i) {
582 unsigned sz = hashtab[i].size();
584 const epplist &eppl1 = hashtab[i];
585 const epplist &eppl2 = o.hashtab[i];
586 epplist::const_iterator it1 = eppl1.begin();
587 epplist::const_iterator it2 = eppl2.begin();
588 while (it1!=eppl1.end()) {
589 if (!(*(*it1)).is_equal(*(*it2))) return false;
597 #endif // EXPAIRSEQ_USE_HASHTAB
600 unsigned expairseq::return_type() const
602 return return_types::noncommutative_composite;
605 unsigned expairseq::calchash() const
607 unsigned v = golden_ratio_hash((p_int)this->tinfo());
608 epvector::const_iterator i = seq.begin();
609 const epvector::const_iterator end = seq.end();
611 v ^= i->rest.gethash();
612 #if !EXPAIRSEQ_USE_HASHTAB
613 // rotation spoils commutativity!
615 v ^= i->coeff.gethash();
616 #endif // !EXPAIRSEQ_USE_HASHTAB
620 v ^= overall_coeff.gethash();
622 // store calculated hash value only if object is already evaluated
623 if (flags &status_flags::evaluated) {
624 setflag(status_flags::hash_calculated);
631 ex expairseq::expand(unsigned options) const
633 std::auto_ptr<epvector> vp = expandchildren(options);
635 return thisexpairseq(vp, overall_coeff);
637 // The terms have not changed, so it is safe to declare this expanded
638 return (options == 0) ? setflag(status_flags::expanded) : *this;
643 // new virtual functions which can be overridden by derived classes
648 /** Create an object of this type.
649 * This method works similar to a constructor. It is useful because expairseq
650 * has (at least) two possible different semantics but we want to inherit
651 * methods thus avoiding code duplication. Sometimes a method in expairseq
652 * has to create a new one of the same semantics, which cannot be done by a
653 * ctor because the name (add, mul,...) is unknown on the expaiseq level. In
654 * order for this trick to work a derived class must of course override this
656 ex expairseq::thisexpairseq(const epvector &v, const ex &oc, bool do_index_renaming) const
658 return expairseq(v, oc, do_index_renaming);
661 ex expairseq::thisexpairseq(std::auto_ptr<epvector> vp, const ex &oc, bool do_index_renaming) const
663 return expairseq(vp, oc, do_index_renaming);
666 void expairseq::printpair(const print_context & c, const expair & p, unsigned upper_precedence) const
669 p.rest.print(c, precedence());
671 p.coeff.print(c, precedence());
675 void expairseq::printseq(const print_context & c, char delim,
676 unsigned this_precedence,
677 unsigned upper_precedence) const
679 if (this_precedence <= upper_precedence)
681 epvector::const_iterator it, it_last = seq.end() - 1;
682 for (it=seq.begin(); it!=it_last; ++it) {
683 printpair(c, *it, this_precedence);
686 printpair(c, *it, this_precedence);
687 if (!overall_coeff.is_equal(default_overall_coeff())) {
689 overall_coeff.print(c, this_precedence);
692 if (this_precedence <= upper_precedence)
697 /** Form an expair from an ex, using the corresponding semantics.
698 * @see expairseq::recombine_pair_to_ex() */
699 expair expairseq::split_ex_to_pair(const ex &e) const
701 return expair(e,_ex1);
705 expair expairseq::combine_ex_with_coeff_to_pair(const ex &e,
708 GINAC_ASSERT(is_exactly_a<numeric>(c));
714 expair expairseq::combine_pair_with_coeff_to_pair(const expair &p,
717 GINAC_ASSERT(is_exactly_a<numeric>(p.coeff));
718 GINAC_ASSERT(is_exactly_a<numeric>(c));
720 return expair(p.rest,ex_to<numeric>(p.coeff).mul_dyn(ex_to<numeric>(c)));
724 /** Form an ex out of an expair, using the corresponding semantics.
725 * @see expairseq::split_ex_to_pair() */
726 ex expairseq::recombine_pair_to_ex(const expair &p) const
728 return lst(p.rest,p.coeff);
731 bool expairseq::expair_needs_further_processing(epp it)
733 #if EXPAIRSEQ_USE_HASHTAB
734 //# error "FIXME: expair_needs_further_processing not yet implemented for hashtabs, sorry. A.F."
735 #endif // EXPAIRSEQ_USE_HASHTAB
739 ex expairseq::default_overall_coeff() const
744 void expairseq::combine_overall_coeff(const ex &c)
746 GINAC_ASSERT(is_exactly_a<numeric>(overall_coeff));
747 GINAC_ASSERT(is_exactly_a<numeric>(c));
748 overall_coeff = ex_to<numeric>(overall_coeff).add_dyn(ex_to<numeric>(c));
751 void expairseq::combine_overall_coeff(const ex &c1, const ex &c2)
753 GINAC_ASSERT(is_exactly_a<numeric>(overall_coeff));
754 GINAC_ASSERT(is_exactly_a<numeric>(c1));
755 GINAC_ASSERT(is_exactly_a<numeric>(c2));
756 overall_coeff = ex_to<numeric>(overall_coeff).
757 add_dyn(ex_to<numeric>(c1).mul(ex_to<numeric>(c2)));
760 bool expairseq::can_make_flat(const expair &p) const
767 // non-virtual functions in this class
770 void expairseq::construct_from_2_ex_via_exvector(const ex &lh, const ex &rh)
776 construct_from_exvector(v);
777 #if EXPAIRSEQ_USE_HASHTAB
778 GINAC_ASSERT((hashtabsize==0)||(hashtabsize>=minhashtabsize));
779 GINAC_ASSERT(hashtabsize==calc_hashtabsize(seq.size()));
780 #endif // EXPAIRSEQ_USE_HASHTAB
783 void expairseq::construct_from_2_ex(const ex &lh, const ex &rh)
785 if (ex_to<basic>(lh).tinfo()==this->tinfo()) {
786 if (ex_to<basic>(rh).tinfo()==this->tinfo()) {
787 #if EXPAIRSEQ_USE_HASHTAB
788 unsigned totalsize = ex_to<expairseq>(lh).seq.size() +
789 ex_to<expairseq>(rh).seq.size();
790 if (calc_hashtabsize(totalsize)!=0) {
791 construct_from_2_ex_via_exvector(lh,rh);
793 #endif // EXPAIRSEQ_USE_HASHTAB
796 ex newrh=rename_dummy_indices_uniquely(lh, rh);
797 construct_from_2_expairseq(ex_to<expairseq>(lh),
798 ex_to<expairseq>(newrh));
801 construct_from_2_expairseq(ex_to<expairseq>(lh),
802 ex_to<expairseq>(rh));
803 #if EXPAIRSEQ_USE_HASHTAB
805 #endif // EXPAIRSEQ_USE_HASHTAB
808 #if EXPAIRSEQ_USE_HASHTAB
809 unsigned totalsize = ex_to<expairseq>(lh).seq.size()+1;
810 if (calc_hashtabsize(totalsize)!=0) {
811 construct_from_2_ex_via_exvector(lh, rh);
813 #endif // EXPAIRSEQ_USE_HASHTAB
814 construct_from_expairseq_ex(ex_to<expairseq>(lh), rh);
815 #if EXPAIRSEQ_USE_HASHTAB
817 #endif // EXPAIRSEQ_USE_HASHTAB
820 } else if (ex_to<basic>(rh).tinfo()==this->tinfo()) {
821 #if EXPAIRSEQ_USE_HASHTAB
822 unsigned totalsize=ex_to<expairseq>(rh).seq.size()+1;
823 if (calc_hashtabsize(totalsize)!=0) {
824 construct_from_2_ex_via_exvector(lh,rh);
826 #endif // EXPAIRSEQ_USE_HASHTAB
827 construct_from_expairseq_ex(ex_to<expairseq>(rh),lh);
828 #if EXPAIRSEQ_USE_HASHTAB
830 #endif // EXPAIRSEQ_USE_HASHTAB
834 #if EXPAIRSEQ_USE_HASHTAB
835 if (calc_hashtabsize(2)!=0) {
836 construct_from_2_ex_via_exvector(lh,rh);
840 #endif // EXPAIRSEQ_USE_HASHTAB
842 if (is_exactly_a<numeric>(lh)) {
843 if (is_exactly_a<numeric>(rh)) {
844 combine_overall_coeff(lh);
845 combine_overall_coeff(rh);
847 combine_overall_coeff(lh);
848 seq.push_back(split_ex_to_pair(rh));
851 if (is_exactly_a<numeric>(rh)) {
852 combine_overall_coeff(rh);
853 seq.push_back(split_ex_to_pair(lh));
855 expair p1 = split_ex_to_pair(lh);
856 expair p2 = split_ex_to_pair(rh);
858 int cmpval = p1.rest.compare(p2.rest);
860 p1.coeff = ex_to<numeric>(p1.coeff).add_dyn(ex_to<numeric>(p2.coeff));
861 if (!ex_to<numeric>(p1.coeff).is_zero()) {
862 // no further processing is necessary, since this
863 // one element will usually be recombined in eval()
880 void expairseq::construct_from_2_expairseq(const expairseq &s1,
883 combine_overall_coeff(s1.overall_coeff);
884 combine_overall_coeff(s2.overall_coeff);
886 epvector::const_iterator first1 = s1.seq.begin();
887 epvector::const_iterator last1 = s1.seq.end();
888 epvector::const_iterator first2 = s2.seq.begin();
889 epvector::const_iterator last2 = s2.seq.end();
891 seq.reserve(s1.seq.size()+s2.seq.size());
893 bool needs_further_processing=false;
895 while (first1!=last1 && first2!=last2) {
896 int cmpval = (*first1).rest.compare((*first2).rest);
900 const numeric &newcoeff = ex_to<numeric>(first1->coeff).
901 add(ex_to<numeric>(first2->coeff));
902 if (!newcoeff.is_zero()) {
903 seq.push_back(expair(first1->rest,newcoeff));
904 if (expair_needs_further_processing(seq.end()-1)) {
905 needs_further_processing = true;
910 } else if (cmpval<0) {
911 seq.push_back(*first1);
914 seq.push_back(*first2);
919 while (first1!=last1) {
920 seq.push_back(*first1);
923 while (first2!=last2) {
924 seq.push_back(*first2);
928 if (needs_further_processing) {
931 construct_from_epvector(v);
935 void expairseq::construct_from_expairseq_ex(const expairseq &s,
938 combine_overall_coeff(s.overall_coeff);
939 if (is_exactly_a<numeric>(e)) {
940 combine_overall_coeff(e);
945 epvector::const_iterator first = s.seq.begin();
946 epvector::const_iterator last = s.seq.end();
947 expair p = split_ex_to_pair(e);
949 seq.reserve(s.seq.size()+1);
950 bool p_pushed = false;
952 bool needs_further_processing=false;
954 // merge p into s.seq
955 while (first!=last) {
956 int cmpval = (*first).rest.compare(p.rest);
959 const numeric &newcoeff = ex_to<numeric>(first->coeff).
960 add(ex_to<numeric>(p.coeff));
961 if (!newcoeff.is_zero()) {
962 seq.push_back(expair(first->rest,newcoeff));
963 if (expair_needs_further_processing(seq.end()-1))
964 needs_further_processing = true;
969 } else if (cmpval<0) {
970 seq.push_back(*first);
980 // while loop exited because p was pushed, now push rest of s.seq
981 while (first!=last) {
982 seq.push_back(*first);
986 // while loop exited because s.seq was pushed, now push p
990 if (needs_further_processing) {
993 construct_from_epvector(v);
997 void expairseq::construct_from_exvector(const exvector &v)
999 // simplifications: +(a,+(b,c),d) -> +(a,b,c,d) (associativity)
1000 // +(d,b,c,a) -> +(a,b,c,d) (canonicalization)
1001 // +(...,x,*(x,c1),*(x,c2)) -> +(...,*(x,1+c1+c2)) (c1, c2 numeric())
1002 // (same for (+,*) -> (*,^)
1005 #if EXPAIRSEQ_USE_HASHTAB
1006 combine_same_terms();
1009 combine_same_terms_sorted_seq();
1010 #endif // EXPAIRSEQ_USE_HASHTAB
1013 void expairseq::construct_from_epvector(const epvector &v, bool do_index_renaming)
1015 // simplifications: +(a,+(b,c),d) -> +(a,b,c,d) (associativity)
1016 // +(d,b,c,a) -> +(a,b,c,d) (canonicalization)
1017 // +(...,x,*(x,c1),*(x,c2)) -> +(...,*(x,1+c1+c2)) (c1, c2 numeric())
1018 // (same for (+,*) -> (*,^)
1020 make_flat(v, do_index_renaming);
1021 #if EXPAIRSEQ_USE_HASHTAB
1022 combine_same_terms();
1025 combine_same_terms_sorted_seq();
1026 #endif // EXPAIRSEQ_USE_HASHTAB
1029 /** Combine this expairseq with argument exvector.
1030 * It cares for associativity as well as for special handling of numerics. */
1031 void expairseq::make_flat(const exvector &v)
1033 exvector::const_iterator cit;
1035 // count number of operands which are of same expairseq derived type
1036 // and their cumulative number of operands
1037 int nexpairseqs = 0;
1041 while (cit!=v.end()) {
1042 if (ex_to<basic>(*cit).tinfo()==this->tinfo()) {
1044 noperands += ex_to<expairseq>(*cit).seq.size();
1049 // reserve seq and coeffseq which will hold all operands
1050 seq.reserve(v.size()+noperands-nexpairseqs);
1052 // copy elements and split off numerical part
1053 make_flat_inserter mf(v, this->tinfo() == &mul::tinfo_static);
1055 while (cit!=v.end()) {
1056 if (ex_to<basic>(*cit).tinfo()==this->tinfo()) {
1057 ex newfactor = mf.handle_factor(*cit, _ex1);
1058 const expairseq &subseqref = ex_to<expairseq>(newfactor);
1059 combine_overall_coeff(subseqref.overall_coeff);
1060 epvector::const_iterator cit_s = subseqref.seq.begin();
1061 while (cit_s!=subseqref.seq.end()) {
1062 seq.push_back(*cit_s);
1066 if (is_exactly_a<numeric>(*cit))
1067 combine_overall_coeff(*cit);
1069 ex newfactor = mf.handle_factor(*cit, _ex1);
1070 seq.push_back(split_ex_to_pair(newfactor));
1077 /** Combine this expairseq with argument epvector.
1078 * It cares for associativity as well as for special handling of numerics. */
1079 void expairseq::make_flat(const epvector &v, bool do_index_renaming)
1081 epvector::const_iterator cit;
1083 // count number of operands which are of same expairseq derived type
1084 // and their cumulative number of operands
1085 int nexpairseqs = 0;
1089 while (cit!=v.end()) {
1090 if (ex_to<basic>(cit->rest).tinfo()==this->tinfo()) {
1092 noperands += ex_to<expairseq>(cit->rest).seq.size();
1097 // reserve seq and coeffseq which will hold all operands
1098 seq.reserve(v.size()+noperands-nexpairseqs);
1099 make_flat_inserter mf(v, do_index_renaming);
1101 // copy elements and split off numerical part
1103 while (cit!=v.end()) {
1104 if (ex_to<basic>(cit->rest).tinfo()==this->tinfo() &&
1105 this->can_make_flat(*cit)) {
1106 ex newrest = mf.handle_factor(cit->rest, cit->coeff);
1107 const expairseq &subseqref = ex_to<expairseq>(newrest);
1108 combine_overall_coeff(ex_to<numeric>(subseqref.overall_coeff),
1109 ex_to<numeric>(cit->coeff));
1110 epvector::const_iterator cit_s = subseqref.seq.begin();
1111 while (cit_s!=subseqref.seq.end()) {
1112 seq.push_back(expair(cit_s->rest,
1113 ex_to<numeric>(cit_s->coeff).mul_dyn(ex_to<numeric>(cit->coeff))));
1114 //seq.push_back(combine_pair_with_coeff_to_pair(*cit_s,
1119 if (cit->is_canonical_numeric())
1120 combine_overall_coeff(mf.handle_factor(cit->rest, _ex1));
1122 ex rest = cit->rest;
1123 ex newrest = mf.handle_factor(rest, cit->coeff);
1124 if (are_ex_trivially_equal(newrest, rest))
1125 seq.push_back(*cit);
1127 seq.push_back(expair(newrest, cit->coeff));
1134 /** Brings this expairseq into a sorted (canonical) form. */
1135 void expairseq::canonicalize()
1137 std::sort(seq.begin(), seq.end(), expair_rest_is_less());
1141 /** Compact a presorted expairseq by combining all matching expairs to one
1142 * each. On an add object, this is responsible for 2*x+3*x+y -> 5*x+y, for
1144 void expairseq::combine_same_terms_sorted_seq()
1149 bool needs_further_processing = false;
1151 epvector::iterator itin1 = seq.begin();
1152 epvector::iterator itin2 = itin1+1;
1153 epvector::iterator itout = itin1;
1154 epvector::iterator last = seq.end();
1155 // must_copy will be set to true the first time some combination is
1156 // possible from then on the sequence has changed and must be compacted
1157 bool must_copy = false;
1158 while (itin2!=last) {
1159 if (itin1->rest.compare(itin2->rest)==0) {
1160 itin1->coeff = ex_to<numeric>(itin1->coeff).
1161 add_dyn(ex_to<numeric>(itin2->coeff));
1162 if (expair_needs_further_processing(itin1))
1163 needs_further_processing = true;
1166 if (!ex_to<numeric>(itin1->coeff).is_zero()) {
1175 if (!ex_to<numeric>(itin1->coeff).is_zero()) {
1181 seq.erase(itout,last);
1183 if (needs_further_processing) {
1186 construct_from_epvector(v);
1190 #if EXPAIRSEQ_USE_HASHTAB
1192 unsigned expairseq::calc_hashtabsize(unsigned sz) const
1195 unsigned nearest_power_of_2 = 1 << log2(sz);
1196 // if (nearest_power_of_2 < maxhashtabsize/hashtabfactor) {
1197 // size = nearest_power_of_2*hashtabfactor;
1198 size = nearest_power_of_2/hashtabfactor;
1199 if (size<minhashtabsize)
1202 // hashtabsize must be a power of 2
1203 GINAC_ASSERT((1U << log2(size))==size);
1207 unsigned expairseq::calc_hashindex(const ex &e) const
1209 // calculate hashindex
1211 if (is_a<numeric>(e)) {
1212 hashindex = hashmask;
1214 hashindex = e.gethash() & hashmask;
1215 // last hashtab entry is reserved for numerics
1216 if (hashindex==hashmask) hashindex = 0;
1218 GINAC_ASSERT((hashindex<hashtabsize)||(hashtabsize==0));
1222 void expairseq::shrink_hashtab()
1224 unsigned new_hashtabsize;
1225 while (hashtabsize!=(new_hashtabsize=calc_hashtabsize(seq.size()))) {
1226 GINAC_ASSERT(new_hashtabsize<hashtabsize);
1227 if (new_hashtabsize==0) {
1234 // shrink by a factor of 2
1235 unsigned half_hashtabsize = hashtabsize/2;
1236 for (unsigned i=0; i<half_hashtabsize-1; ++i)
1237 hashtab[i].merge(hashtab[i+half_hashtabsize],epp_is_less());
1238 // special treatment for numeric hashes
1239 hashtab[0].merge(hashtab[half_hashtabsize-1],epp_is_less());
1240 hashtab[half_hashtabsize-1] = hashtab[hashtabsize-1];
1241 hashtab.resize(half_hashtabsize);
1242 hashtabsize = half_hashtabsize;
1243 hashmask = hashtabsize-1;
1247 void expairseq::remove_hashtab_entry(epvector::const_iterator element)
1250 return; // nothing to do
1252 // calculate hashindex of element to be deleted
1253 unsigned hashindex = calc_hashindex((*element).rest);
1255 // find it in hashtab and remove it
1256 epplist &eppl = hashtab[hashindex];
1257 epplist::iterator epplit = eppl.begin();
1258 bool erased = false;
1259 while (epplit!=eppl.end()) {
1260 if (*epplit == element) {
1268 std::cout << "tried to erase " << element-seq.begin() << std::endl;
1269 std::cout << "size " << seq.end()-seq.begin() << std::endl;
1271 unsigned hashindex = calc_hashindex(element->rest);
1272 epplist &eppl = hashtab[hashindex];
1273 epplist::iterator epplit = eppl.begin();
1274 bool erased = false;
1275 while (epplit!=eppl.end()) {
1276 if (*epplit == element) {
1283 GINAC_ASSERT(erased);
1285 GINAC_ASSERT(erased);
1288 void expairseq::move_hashtab_entry(epvector::const_iterator oldpos,
1289 epvector::iterator newpos)
1291 GINAC_ASSERT(hashtabsize!=0);
1293 // calculate hashindex of element which was moved
1294 unsigned hashindex=calc_hashindex((*newpos).rest);
1296 // find it in hashtab and modify it
1297 epplist &eppl = hashtab[hashindex];
1298 epplist::iterator epplit = eppl.begin();
1299 while (epplit!=eppl.end()) {
1300 if (*epplit == oldpos) {
1306 GINAC_ASSERT(epplit!=eppl.end());
1309 void expairseq::sorted_insert(epplist &eppl, epvector::const_iterator elem)
1311 epplist::const_iterator current = eppl.begin();
1312 while ((current!=eppl.end()) && ((*current)->is_less(*elem))) {
1315 eppl.insert(current,elem);
1318 void expairseq::build_hashtab_and_combine(epvector::iterator &first_numeric,
1319 epvector::iterator &last_non_zero,
1320 std::vector<bool> &touched,
1321 unsigned &number_of_zeroes)
1323 epp current = seq.begin();
1325 while (current!=first_numeric) {
1326 if (is_exactly_a<numeric>(current->rest)) {
1328 iter_swap(current,first_numeric);
1330 // calculate hashindex
1331 unsigned currenthashindex = calc_hashindex(current->rest);
1333 // test if there is already a matching expair in the hashtab-list
1334 epplist &eppl=hashtab[currenthashindex];
1335 epplist::iterator epplit = eppl.begin();
1336 while (epplit!=eppl.end()) {
1337 if (current->rest.is_equal((*epplit)->rest))
1341 if (epplit==eppl.end()) {
1342 // no matching expair found, append this to end of list
1343 sorted_insert(eppl,current);
1346 // epplit points to a matching expair, combine it with current
1347 (*epplit)->coeff = ex_to<numeric>((*epplit)->coeff).
1348 add_dyn(ex_to<numeric>(current->coeff));
1350 // move obsolete current expair to end by swapping with last_non_zero element
1351 // if this was a numeric, it is swapped with the expair before first_numeric
1352 iter_swap(current,last_non_zero);
1354 if (first_numeric!=last_non_zero) iter_swap(first_numeric,current);
1357 // test if combined term has coeff 0 and can be removed is done later
1358 touched[(*epplit)-seq.begin()] = true;
1364 void expairseq::drop_coeff_0_terms(epvector::iterator &first_numeric,
1365 epvector::iterator &last_non_zero,
1366 std::vector<bool> &touched,
1367 unsigned &number_of_zeroes)
1369 // move terms with coeff 0 to end and remove them from hashtab
1370 // check only those elements which have been touched
1371 epp current = seq.begin();
1373 while (current!=first_numeric) {
1377 } else if (!ex_to<numeric>((*current).coeff).is_zero()) {
1381 remove_hashtab_entry(current);
1383 // move element to the end, unless it is already at the end
1384 if (current!=last_non_zero) {
1385 iter_swap(current,last_non_zero);
1387 bool numeric_swapped = first_numeric!=last_non_zero;
1388 if (numeric_swapped)
1389 iter_swap(first_numeric,current);
1390 epvector::iterator changed_entry;
1392 if (numeric_swapped)
1393 changed_entry = first_numeric;
1395 changed_entry = last_non_zero;
1400 if (first_numeric!=current) {
1402 // change entry in hashtab which referred to first_numeric or last_non_zero to current
1403 move_hashtab_entry(changed_entry,current);
1404 touched[current-seq.begin()] = touched[changed_entry-seq.begin()];
1413 GINAC_ASSERT(i==current-seq.begin());
1416 /** True if one of the coeffs vanishes, otherwise false.
1417 * This would be an invariant violation, so this should only be used for
1418 * debugging purposes. */
1419 bool expairseq::has_coeff_0() const
1421 epvector::const_iterator i = seq.begin(), end = seq.end();
1423 if (i->coeff.is_zero())
1430 void expairseq::add_numerics_to_hashtab(epvector::iterator first_numeric,
1431 epvector::const_iterator last_non_zero)
1433 if (first_numeric == seq.end()) return; // no numerics
1435 epvector::const_iterator current = first_numeric, last = last_non_zero + 1;
1436 while (current != last) {
1437 sorted_insert(hashtab[hashmask], current);
1442 void expairseq::combine_same_terms()
1444 // combine same terms, drop term with coeff 0, move numerics to end
1446 // calculate size of hashtab
1447 hashtabsize = calc_hashtabsize(seq.size());
1449 // hashtabsize is a power of 2
1450 hashmask = hashtabsize-1;
1454 hashtab.resize(hashtabsize);
1456 if (hashtabsize==0) {
1458 combine_same_terms_sorted_seq();
1459 GINAC_ASSERT(!has_coeff_0());
1463 // iterate through seq, move numerics to end,
1464 // fill hashtab and combine same terms
1465 epvector::iterator first_numeric = seq.end();
1466 epvector::iterator last_non_zero = seq.end()-1;
1468 size_t num = seq.size();
1469 std::vector<bool> touched(num);
1471 unsigned number_of_zeroes = 0;
1473 GINAC_ASSERT(!has_coeff_0());
1474 build_hashtab_and_combine(first_numeric,last_non_zero,touched,number_of_zeroes);
1476 // there should not be any terms with coeff 0 from the beginning,
1477 // so it should be safe to skip this step
1478 if (number_of_zeroes!=0) {
1479 drop_coeff_0_terms(first_numeric,last_non_zero,touched,number_of_zeroes);
1482 add_numerics_to_hashtab(first_numeric,last_non_zero);
1484 // pop zero elements
1485 for (unsigned i=0; i<number_of_zeroes; ++i) {
1489 // shrink hashtabsize to calculated value
1490 GINAC_ASSERT(!has_coeff_0());
1494 GINAC_ASSERT(!has_coeff_0());
1497 #endif // EXPAIRSEQ_USE_HASHTAB
1499 /** Check if this expairseq is in sorted (canonical) form. Useful mainly for
1500 * debugging or in assertions since being sorted is an invariance. */
1501 bool expairseq::is_canonical() const
1503 if (seq.size() <= 1)
1506 #if EXPAIRSEQ_USE_HASHTAB
1507 if (hashtabsize > 0) return 1; // not canoncalized
1508 #endif // EXPAIRSEQ_USE_HASHTAB
1510 epvector::const_iterator it = seq.begin(), itend = seq.end();
1511 epvector::const_iterator it_last = it;
1512 for (++it; it!=itend; it_last=it, ++it) {
1513 if (!(it_last->is_less(*it) || it_last->is_equal(*it))) {
1514 if (!is_exactly_a<numeric>(it_last->rest) ||
1515 !is_exactly_a<numeric>(it->rest)) {
1516 // double test makes it easier to set a breakpoint...
1517 if (!is_exactly_a<numeric>(it_last->rest) ||
1518 !is_exactly_a<numeric>(it->rest)) {
1519 printpair(std::clog, *it_last, 0);
1521 printpair(std::clog, *it, 0);
1523 std::clog << "pair1:" << std::endl;
1524 it_last->rest.print(print_tree(std::clog));
1525 it_last->coeff.print(print_tree(std::clog));
1526 std::clog << "pair2:" << std::endl;
1527 it->rest.print(print_tree(std::clog));
1528 it->coeff.print(print_tree(std::clog));
1538 /** Member-wise expand the expairs in this sequence.
1540 * @see expairseq::expand()
1541 * @return pointer to epvector containing expanded pairs or zero pointer,
1542 * if no members were changed. */
1543 std::auto_ptr<epvector> expairseq::expandchildren(unsigned options) const
1545 const epvector::const_iterator last = seq.end();
1546 epvector::const_iterator cit = seq.begin();
1548 const ex &expanded_ex = cit->rest.expand(options);
1549 if (!are_ex_trivially_equal(cit->rest,expanded_ex)) {
1551 // something changed, copy seq, eval and return it
1552 std::auto_ptr<epvector> s(new epvector);
1553 s->reserve(seq.size());
1555 // copy parts of seq which are known not to have changed
1556 epvector::const_iterator cit2 = seq.begin();
1558 s->push_back(*cit2);
1562 // copy first changed element
1563 s->push_back(combine_ex_with_coeff_to_pair(expanded_ex,
1568 while (cit2!=last) {
1569 s->push_back(combine_ex_with_coeff_to_pair(cit2->rest.expand(options),
1578 return std::auto_ptr<epvector>(0); // signalling nothing has changed
1582 /** Member-wise evaluate the expairs in this sequence.
1584 * @see expairseq::eval()
1585 * @return pointer to epvector containing evaluated pairs or zero pointer,
1586 * if no members were changed. */
1587 std::auto_ptr<epvector> expairseq::evalchildren(int level) const
1589 // returns a NULL pointer if nothing had to be evaluated
1590 // returns a pointer to a newly created epvector otherwise
1591 // (which has to be deleted somewhere else)
1594 return std::auto_ptr<epvector>(0);
1596 if (level == -max_recursion_level)
1597 throw(std::runtime_error("max recursion level reached"));
1600 epvector::const_iterator last = seq.end();
1601 epvector::const_iterator cit = seq.begin();
1603 const ex &evaled_ex = cit->rest.eval(level);
1604 if (!are_ex_trivially_equal(cit->rest,evaled_ex)) {
1606 // something changed, copy seq, eval and return it
1607 std::auto_ptr<epvector> s(new epvector);
1608 s->reserve(seq.size());
1610 // copy parts of seq which are known not to have changed
1611 epvector::const_iterator cit2=seq.begin();
1613 s->push_back(*cit2);
1617 // copy first changed element
1618 s->push_back(combine_ex_with_coeff_to_pair(evaled_ex,
1623 while (cit2!=last) {
1624 s->push_back(combine_ex_with_coeff_to_pair(cit2->rest.eval(level),
1633 return std::auto_ptr<epvector>(0); // signalling nothing has changed
1636 /** Member-wise substitute in this sequence.
1638 * @see expairseq::subs()
1639 * @return pointer to epvector containing pairs after application of subs,
1640 * or NULL pointer if no members were changed. */
1641 std::auto_ptr<epvector> expairseq::subschildren(const exmap & m, unsigned options) const
1643 // When any of the objects to be substituted is a product or power
1644 // we have to recombine the pairs because the numeric coefficients may
1645 // be part of the search pattern.
1646 if (!(options & (subs_options::pattern_is_product | subs_options::pattern_is_not_product))) {
1648 // Search the list of substitutions and cache our findings
1649 for (exmap::const_iterator it = m.begin(); it != m.end(); ++it) {
1650 if (is_exactly_a<mul>(it->first) || is_exactly_a<power>(it->first)) {
1651 options |= subs_options::pattern_is_product;
1655 if (!(options & subs_options::pattern_is_product))
1656 options |= subs_options::pattern_is_not_product;
1659 if (options & subs_options::pattern_is_product) {
1661 // Substitute in the recombined pairs
1662 epvector::const_iterator cit = seq.begin(), last = seq.end();
1663 while (cit != last) {
1665 const ex &orig_ex = recombine_pair_to_ex(*cit);
1666 const ex &subsed_ex = orig_ex.subs(m, options);
1667 if (!are_ex_trivially_equal(orig_ex, subsed_ex)) {
1669 // Something changed, copy seq, subs and return it
1670 std::auto_ptr<epvector> s(new epvector);
1671 s->reserve(seq.size());
1673 // Copy parts of seq which are known not to have changed
1674 s->insert(s->begin(), seq.begin(), cit);
1676 // Copy first changed element
1677 s->push_back(split_ex_to_pair(subsed_ex));
1681 while (cit != last) {
1682 s->push_back(split_ex_to_pair(recombine_pair_to_ex(*cit).subs(m, options)));
1693 // Substitute only in the "rest" part of the pairs
1694 epvector::const_iterator cit = seq.begin(), last = seq.end();
1695 while (cit != last) {
1697 const ex &subsed_ex = cit->rest.subs(m, options);
1698 if (!are_ex_trivially_equal(cit->rest, subsed_ex)) {
1700 // Something changed, copy seq, subs and return it
1701 std::auto_ptr<epvector> s(new epvector);
1702 s->reserve(seq.size());
1704 // Copy parts of seq which are known not to have changed
1705 s->insert(s->begin(), seq.begin(), cit);
1707 // Copy first changed element
1708 s->push_back(combine_ex_with_coeff_to_pair(subsed_ex, cit->coeff));
1712 while (cit != last) {
1713 s->push_back(combine_ex_with_coeff_to_pair(cit->rest.subs(m, options), cit->coeff));
1723 // Nothing has changed
1724 return std::auto_ptr<epvector>(0);
1728 // static member variables
1731 #if EXPAIRSEQ_USE_HASHTAB
1732 unsigned expairseq::maxhashtabsize = 0x4000000U;
1733 unsigned expairseq::minhashtabsize = 0x1000U;
1734 unsigned expairseq::hashtabfactor = 1;
1735 #endif // EXPAIRSEQ_USE_HASHTAB
1737 } // namespace GiNaC