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

◆ diffNodeInput()

template<class Field>
int SLP< Field >::diffNodeInput ( int n,
int v,
gc_vector< int > & prog )
private

Definition at line 450 of file NAG.cpp.

453{
454 int i = node_index[n];
455 switch (prog[i])
456 {
457 /* case slpCOPY:
458 break;*/
459 case slpMULTIsum:
460 {
461 int n_summands = prog[(++i)++];
463 int c = 0; // count nonzeroes
465 for (int j = 0; j < n_summands; j++)
466 {
468 if (part_pos[j] != ZERO_CONST)
469 {
470 c++;
472 }
473 }
474 if (c == 0) return ZERO_CONST;
475 if (c == 1) return last_non_zero;
476 int cur_p = num_operations++;
477 node_index.push_back(prog.size());
478 prog.push_back(slpMULTIsum);
479 prog.push_back(c);
480 for (int j = 0; j < n_summands; j++)
481 {
482 if (part_pos[j] != ZERO_CONST)
483 prog.push_back(part_pos[j] -
484 cur_p); // relative position of the j-th part
485 }
486 return cur_p;
487 }
488 case slpPRODUCT:
489 {
490 int a = prog[(++i)++];
491 int b = prog[i++];
492 int da = diffPartReference(n, a, v, prog);
493 int db = diffPartReference(n, b, v, prog);
494 if (db == ZERO_CONST)
495 {
496 if (da == ZERO_CONST) return ZERO_CONST;
497 if (da == ONE_CONST)
498 {
499 if (b < 0) // if refers to operation node
500 return n + b;
501 else if (b >= CONST_OFFSET)
502 { // ... constant
503 int cur_p = num_operations++;
504 node_index.push_back(prog.size());
505 prog.push_back(slpCOPY); // is there better way?
506 prog.push_back(b);
507 return cur_p;
508 }
509 else
510 { // ... input
511 ERROR("input node not expected");
512 return ZERO_CONST;
513 };
514 }
515 else
516 {
517 int cur_p = num_operations++;
518 node_index.push_back(prog.size());
519 prog.push_back(slpPRODUCT);
520 prog.push_back(da - cur_p);
521 if (b < 0) // if refers to an operation node
522 b = n + b - cur_p; // recalculate wrt cur_p
523 prog.push_back(b);
524 return cur_p;
525 }
526 }
527 else if (da == ZERO_CONST)
528 { // ... and db != 0
529 if (db == ONE_CONST)
530 {
531 if (a < 0) // if refers to an operation node
532 return n + a;
533 else if (a >= CONST_OFFSET)
534 { // ... constant
535 int cur_p = num_operations++;
536 node_index.push_back(prog.size());
537 prog.push_back(slpCOPY); // is there a better way ?
538 if (a < 0) // if refers to an operation node
539 a = n + a - cur_p; // recalculate wrt cur_p
540 prog.push_back(a);
541 return cur_p;
542 }
543 else
544 { // ... input
545 ERROR("input node not expected");
546 return ZERO_CONST;
547 };
548 }
549 else
550 { // db!=0 and db!=1
551 int cur_p = num_operations++;
552 node_index.push_back(prog.size());
553 prog.push_back(slpPRODUCT);
554 prog.push_back(db - cur_p);
555 if (a < 0) // if refers to an operation node
556 a = n + a - cur_p; // recalculate wrt cur_p
557 prog.push_back(a);
558 return cur_p;
559 }
560 }
561 else
562 { // da |=0 and db !=0
563 int part1 = ZERO_CONST;
564 int is_part1_created = (da != ONE_CONST);
566 {
567 int cur_p = num_operations++;
568 node_index.push_back(prog.size());
569 prog.push_back(slpPRODUCT);
570 prog.push_back(da - cur_p);
571 if (b < 0) // if refers to an operation node
572 b = n + b - cur_p; // recalculate wrt cur_p
573 prog.push_back(b);
574 part1 = cur_p;
575 }
576 int part2 = ZERO_CONST;
577 int is_part2_created = (db != ONE_CONST);
579 {
580 int cur_p = num_operations++;
581 node_index.push_back(prog.size());
582 prog.push_back(slpPRODUCT);
583 prog.push_back(db - cur_p);
584 if (a < 0) // if refers to an operation node
585 a = n + a - cur_p; // recalculate wrt cur_p
586 prog.push_back(a);
587 part2 = cur_p;
588 }
589 int cur_p = num_operations++;
590 node_index.push_back(prog.size());
591 prog.push_back(slpMULTIsum);
592 prog.push_back(2);
594 prog.push_back(part1 - cur_p);
595 else
596 prog.push_back((b < 0) ? b + n - cur_p : b);
598 prog.push_back(part2 - cur_p);
599 else
600 prog.push_back((a < 0) ? a + n - cur_p : a);
601 return cur_p;
602 }
603 }
604 default:
605 ERROR("unknown SLP operation");
606 printf("i = %d, a[i] = %d\n", i, prog[i]);
607 return 0;
608 }
609}
int num_operations
Definition NAG.hpp:502
gc_vector< int > node_index
Definition NAG.hpp:500
int diffPartReference(int n, int ref, int v, gc_vector< int > &prog)
Definition NAG.cpp:434
Definition NAG.hpp:485
const int ERROR
Definition m2-mem.cpp:55

References CONST_OFFSET, diffPartReference(), node_index, num_operations, ONE_CONST, slpCOPY, slpMULTIsum, slpPRODUCT, and ZERO_CONST.

Referenced by diffPartReference(), and jacobian().