Macaulay2 Engine
Loading...
Searching...
No Matches

◆ find_weak_generators()

void MonomialTableZZ::find_weak_generators ( int nvars,
const VECTOR(mpz_srcptr) & coeffs,
const VECTOR(exponents_t) & exps,
const VECTOR(int) & comps,
VECTOR(int) & result_positions,
bool use_stable_sort = true )
static

Definition at line 513 of file montableZZ.cpp.

519{
520 // Find a set of elements which generate all of them, as a submodule.
521 // The indices for these are placed into result_positions.
522
523 // The plan for this is simple, although it could be easily optimized.
524 // First, sort the elements into increasing order, with coeffs for each
525 // specific
526 // exponent vector also in increasing order (ASSUMPTION: all coeffs are > 0).
527
528 // Second, loop through each one, checking whether it is in the submodule gen
529 // by the previous.
530 MonomialTableZZ *T = MonomialTableZZ::make(nvars);
531
532#if 0
533 // debugging
534 if (coeffs.size() != exps.size())
535 fprintf(stderr, "size mismatch\n");
536 if (coeffs.size() != exps.size())
537 fprintf(stderr, "size mismatch2\n");
538 if (coeffs.size() != comps.size())
539 fprintf(stderr, "size mismatch3\n");
540#endif
541#if 0
542 // debugging
543 fprintf(stderr, "-------------\n");
544 fprintf(stderr, "find_weak_generators %ld\n", coeffs.size());
545 for (size_t i = 0; i < coeffs.size(); i++)
546 T->show_weak(stderr, coeffs[i], exps[i], comps[i], i);
547#endif
548
549 VECTOR(int) positions;
550 positions.reserve(exps.size());
551 for (unsigned int i = 0; i < exps.size(); i++) positions.push_back(i);
552
553 /* The following sorts in ascending lex order, considering the component, exp
554 vector
555 and finally the coefficient */
556 if (use_stable_sort)
557 std::stable_sort(positions.begin(),
558 positions.end(),
559 montable_sorter_ZZ(nvars, coeffs, exps, comps));
560 else
561 std::sort(positions.begin(),
562 positions.end(),
563 montable_sorter_ZZ(nvars, coeffs, exps, comps));
564
565#if 0
566 // debugging
567 fprintf(stderr, "sorted find_weak_generators\n");
568 for (size_t i = 0; i < coeffs.size(); i++)
569 T->show_weak(stderr, coeffs[i], exps[i], comps[i], positions[i]);
570#endif
571
572#if 0
573// fprintf(stderr, "sorted terms: ");
574// for (int i=0; i<positions.size(); i++)
575// fprintf(stderr, "%d ", positions[i]);
576// fprintf(stderr, "\n");
577#endif
578
579 for (VECTOR(int)::iterator j = positions.begin(); j != positions.end(); j++)
580 if (!T->is_weak_member(coeffs[*j], exps[*j], comps[*j]))
581 {
582 result_positions.push_back(*j);
583 T->insert(coeffs[*j], exps[*j], comps[*j], *j);
584 }
585
586#if 0
587 // debugging
588 fprintf(stderr, "ones we take: find_weak_generators %ld\n", coeffs.size());
589 for (size_t i = 0; i < result_positions.size(); i++)
590 T->show_weak(stderr,
591 coeffs[result_positions[i]],
592 exps[result_positions[i]],
593 comps[result_positions[i]],
594 result_positions[i]);
595 fprintf(stderr, "\n\n");
596#endif
597 /* We could return T if that is desired */
598 // freemem(T);
599}
static MonomialTableZZ * make(int nvars)
#define VECTOR(T)
Definition newdelete.hpp:78
#define T
Definition table.c:13

References make(), T, and VECTOR.

Referenced by gbA::minimalize_pairs_ZZ().