
(/VERSIONCHECK 2) 

(DEFUN |BEZOUT;sylvesterMatrix;2UPM;1| (|p| |q| $)
  (PROG (|n1| |n2| |n| |sylmat| |minR| |minC| |maxR| |maxC| |p0|
              #0=#:G1833 |coef| |deg| |q0| |i| #1=#:G1834)
    (RETURN
      (SEQ (LETT |n1| (SPADCALL |p| (QREFELT $ 12))
                 . #2=(|BEZOUT;sylvesterMatrix;2UPM;1|))
           (LETT |n2| (SPADCALL |q| (QREFELT $ 12)) . #2#)
           (LETT |n| (+ |n1| |n2|) . #2#)
           (LETT |sylmat|
                 (SPADCALL |n| |n| (|spadConstant| $ 13)
                     (QREFELT $ 15)) . #2#)
           (LETT |minR| (SPADCALL |sylmat| (QREFELT $ 17)) . #2#)
           (LETT |minC| (SPADCALL |sylmat| (QREFELT $ 18)) . #2#)
           (LETT |maxR| (SPADCALL |sylmat| (QREFELT $ 19)) . #2#)
           (LETT |maxC| (SPADCALL |sylmat| (QREFELT $ 20)) . #2#)
           (LETT |p0| |p| . #2#)
           (SEQ G190
                (COND
                  ((NULL (COND
                           ((SPADCALL |p0| (QREFELT $ 22)) 'NIL)
                           ('T 'T)))
                   #3=(GO G191)))
                (SEQ (LETT |coef| (SPADCALL |p0| (QREFELT $ 23)) . #2#)
                     (LETT |deg| (SPADCALL |p0| (QREFELT $ 12)) . #2#)
                     (LETT |p0| (SPADCALL |p0| (QREFELT $ 24)) . #2#)
                     (EXIT (SEQ (LETT |i| 0 . #2#)
                                (LETT #0# (- |n2| 1) . #2#) G190
                                (COND ((QSGREATERP |i| #0#) #3#))
                                (SEQ (EXIT
                                      (SPADCALL |sylmat| (+ |minR| |i|)
                                       (+ (- (+ |minC| |n1|) |deg|)
                                        |i|)
                                       |coef| (QREFELT $ 27))))
                                (LETT |i| (QSADD1 |i|) . #2#)
                                #4=(GO G190) G191 (EXIT NIL))))
                NIL #4# G191 (EXIT NIL))
           (LETT |q0| |q| . #2#)
           (SEQ G190
                (COND
                  ((NULL (COND
                           ((SPADCALL |q0| (QREFELT $ 22)) 'NIL)
                           ('T 'T)))
                   #3#))
                (SEQ (LETT |coef| (SPADCALL |q0| (QREFELT $ 23)) . #2#)
                     (LETT |deg| (SPADCALL |q0| (QREFELT $ 12)) . #2#)
                     (LETT |q0| (SPADCALL |q0| (QREFELT $ 24)) . #2#)
                     (EXIT (SEQ (LETT |i| 0 . #2#)
                                (LETT #1# (- |n1| 1) . #2#) G190
                                (COND ((QSGREATERP |i| #1#) #3#))
                                (SEQ (EXIT
                                      (SPADCALL |sylmat|
                                       (+ (+ |minR| |n2|) |i|)
                                       (+ (- (+ |minC| |n2|) |deg|)
                                        |i|)
                                       |coef| (QREFELT $ 27))))
                                (LETT |i| (QSADD1 |i|) . #2#) #4# G191
                                (EXIT NIL))))
                NIL #4# G191 (EXIT NIL))
           (EXIT |sylmat|))))) 

(DEFUN |BEZOUT;bezoutMatrix;2UPM;2| (|p| |q| $)
  (PROG (|n1| |n2| |n| |m1| |m2| |m| |sylmat| |minR| |minC| |maxR|
              |maxC| #0=#:G1862 #1=#:G1863 |bezmat| |bound| |q0| |deg|
              |coef| |c| |p0| |i| |k|)
    (RETURN
      (SEQ (LETT |n1| (SPADCALL |p| (QREFELT $ 12))
                 . #2=(|BEZOUT;bezoutMatrix;2UPM;2|))
           (LETT |n2| (SPADCALL |q| (QREFELT $ 12)) . #2#)
           (LETT |n| (+ |n1| |n2|) . #2#)
           (EXIT (COND
                   ((< |n1| |n2|) (SPADCALL |q| |p| (QREFELT $ 29)))
                   ('T
                    (SEQ (LETT |m1| (- |n1| 1) . #2#)
                         (LETT |m2| (- |n2| 1) . #2#)
                         (LETT |m| (- |n| 1) . #2#)
                         (LETT |sylmat|
                               (SPADCALL |n| |n1| (|spadConstant| $ 13)
                                   (QREFELT $ 15)) . #2#)
                         (LETT |minR|
                               (SPADCALL |sylmat| (QREFELT $ 17)) . #2#)
                         (LETT |minC|
                               (SPADCALL |sylmat| (QREFELT $ 18)) . #2#)
                         (LETT |maxR|
                               (SPADCALL |sylmat| (QREFELT $ 19)) . #2#)
                         (LETT |maxC|
                               (SPADCALL |sylmat| (QREFELT $ 20)) . #2#)
                         (LETT |p0| |p| . #2#)
                         (SEQ G190
                              (COND
                                ((NULL (COND
                                         ((SPADCALL |p0|
                                           (QREFELT $ 30))
                                          'NIL)
                                         ('T 'T)))
                                 #3=(GO G191)))
                              (SEQ (LETT |coef|
                                    (SPADCALL |p0| (QREFELT $ 23)) . #2#)
                                   (LETT |deg|
                                    (SPADCALL |p0| (QREFELT $ 12)) . #2#)
                                   (LETT |p0|
                                    (SPADCALL |p0| (QREFELT $ 24)) . #2#)
                                   (EXIT
                                    (SEQ (LETT |i| 0 . #2#)
                                     (LETT #0#
                                      (MIN |m2| (- |deg| 1)) . #2#)
                                     G190
                                     (COND ((QSGREATERP |i| #0#) #3#))
                                     (SEQ
                                      (EXIT
                                       (SPADCALL |sylmat|
                                        (+ |minR| |i|)
                                        (+ (- (+ |minC| |n1|) |deg|)
                                         |i|)
                                        |coef| (QREFELT $ 27))))
                                     (LETT |i| (QSADD1 |i|) . #2#)
                                     #4=(GO G190) G191 (EXIT NIL))))
                              NIL #4# G191 (EXIT NIL))
                         (LETT |q0| |q| . #2#)
                         (SEQ G190
                              (COND
                                ((NULL (COND
                                         ((SPADCALL |q0|
                                           (QREFELT $ 22))
                                          'NIL)
                                         ('T 'T)))
                                 #3#))
                              (SEQ (LETT |coef|
                                    (SPADCALL |q0| (QREFELT $ 23)) . #2#)
                                   (LETT |deg|
                                    (SPADCALL |q0| (QREFELT $ 12)) . #2#)
                                   (LETT |q0|
                                    (SPADCALL |q0| (QREFELT $ 24)) . #2#)
                                   (EXIT
                                    (SEQ (LETT |i| 0 . #2#)
                                     (LETT #1#
                                      (- (- (+ |deg| |n1|) |n2|) 1) . #2#)
                                     G190
                                     (COND ((QSGREATERP |i| #1#) #3#))
                                     (SEQ
                                      (EXIT
                                       (SPADCALL |sylmat|
                                        (+ (+ |minR| |n2|) |i|)
                                        (+ (- (+ |minC| |n2|) |deg|)
                                         |i|)
                                        |coef| (QREFELT $ 27))))
                                     (LETT |i| (QSADD1 |i|) . #2#) #4#
                                     G191 (EXIT NIL))))
                              NIL #4# G191 (EXIT NIL))
                         (LETT |bezmat|
                               (SPADCALL |n1| |n1|
                                   (|spadConstant| $ 13)
                                   (QREFELT $ 15)) . #2#)
                         (SEQ (LETT |i| 0 . #2#) G190
                              (COND ((QSGREATERP |i| |m2|) #3#))
                              (SEQ (LETT |bound| (- |n2| |i|) . #2#)
                                   (LETT |q0| |q| . #2#)
                                   (SEQ G190
                                    (COND
                                      ((NULL
                                        (COND
                                          ((SPADCALL |q0|
                                            (QREFELT $ 22))
                                           'NIL)
                                          ('T 'T)))
                                       #3#))
                                    (SEQ
                                     (LETT |deg|
                                      (SPADCALL |q0| (QREFELT $ 12)) . #2#)
                                     (COND
                                       ((< |deg| |bound|)
                                        (SEQ
                                         (LETT |coef|
                                          (SPADCALL |q0|
                                           (QREFELT $ 23)) . #2#)
                                         (EXIT
                                          (SEQ (LETT |k| |minC| . #2#)
                                           G190
                                           (COND ((> |k| |maxC|) #3#))
                                           (SEQ
                                            (LETT |c|
                                             (SPADCALL
                                              (SPADCALL |coef|
                                               (SPADCALL |sylmat|
                                                (-
                                                 (- (+ |minR| |m2|)
                                                  |i|)
                                                 |deg|)
                                                |k| (QREFELT $ 31))
                                               (QREFELT $ 32))
                                              (SPADCALL |bezmat|
                                               (- (+ |minR| |m2|) |i|)
                                               |k| (QREFELT $ 31))
                                              (QREFELT $ 33)) . #2#)
                                            (EXIT
                                             (SPADCALL |bezmat|
                                              (- (+ |minR| |m2|) |i|)
                                              |k| |c| (QREFELT $ 27))))
                                           (LETT |k| (+ |k| 1) . #2#)
                                           #4# G191 (EXIT NIL))))))
                                     (EXIT
                                      (LETT |q0|
                                       (SPADCALL |q0| (QREFELT $ 24)) . #2#)))
                                    NIL #4# G191 (EXIT NIL))
                                   (LETT |p0| |p| . #2#)
                                   (EXIT
                                    (SEQ G190
                                     (COND
                                       ((NULL
                                         (COND
                                           ((SPADCALL |p0|
                                             (QREFELT $ 22))
                                            'NIL)
                                           ('T 'T)))
                                        #3#))
                                     (SEQ
                                      (LETT |deg|
                                       (SPADCALL |p0| (QREFELT $ 12)) . #2#)
                                      (COND
                                        ((< |deg| |bound|)
                                         (SEQ
                                          (LETT |coef|
                                           (SPADCALL |p0|
                                            (QREFELT $ 23)) . #2#)
                                          (EXIT
                                           (SEQ (LETT |k| |minC| . #2#)
                                            G190
                                            (COND
                                              ((> |k| |maxC|) #3#))
                                            (SEQ
                                             (LETT |c|
                                              (SPADCALL
                                               (SPADCALL
                                                (SPADCALL |coef|
                                                 (SPADCALL |sylmat|
                                                  (-
                                                   (- (+ |minR| |m|)
                                                    |i|)
                                                   |deg|)
                                                  |k| (QREFELT $ 31))
                                                 (QREFELT $ 32))
                                                (QREFELT $ 34))
                                               (SPADCALL |bezmat|
                                                (- (+ |minR| |m2|) |i|)
                                                |k| (QREFELT $ 31))
                                               (QREFELT $ 33)) . #2#)
                                             (EXIT
                                              (SPADCALL |bezmat|
                                               (- (+ |minR| |m2|) |i|)
                                               |k| |c| (QREFELT $ 27))))
                                            (LETT |k| (+ |k| 1) . #2#)
                                            #4# G191 (EXIT NIL))))))
                                      (EXIT
                                       (LETT |p0|
                                        (SPADCALL |p0| (QREFELT $ 24)) . #2#)))
                                     NIL #4# G191 (EXIT NIL))))
                              (LETT |i| (QSADD1 |i|) . #2#) #4# G191
                              (EXIT NIL))
                         (SEQ (LETT |i| |n2| . #2#) G190
                              (COND ((> |i| |m1|) #3#))
                              (SEQ (EXIT
                                    (SEQ (LETT |k| |minC| . #2#) G190
                                     (COND ((> |k| |maxC|) #3#))
                                     (SEQ
                                      (EXIT
                                       (SPADCALL |bezmat|
                                        (+ |minR| |i|) |k|
                                        (SPADCALL |sylmat|
                                         (+ |minR| |i|) |k|
                                         (QREFELT $ 31))
                                        (QREFELT $ 27))))
                                     (LETT |k| (+ |k| 1) . #2#) #4#
                                     G191 (EXIT NIL))))
                              (LETT |i| (+ |i| 1) . #2#) #4# G191
                              (EXIT NIL))
                         (EXIT |bezmat|))))))))) 

(DEFUN |BEZOUT;bezoutResultant;2UPR;3| (|f| |g| $)
  (SPADCALL (SPADCALL |f| |g| (QREFELT $ 29)) (QREFELT $ 35))) 

(DEFUN |BEZOUT;bezoutDiscriminant;UPR;4| (|f| $)
  (PROG (|degMod4| #0=#:G1869)
    (RETURN
      (SEQ (LETT |degMod4| (REMAINDER2 (SPADCALL |f| (QREFELT $ 12)) 4)
                 . #1=(|BEZOUT;bezoutDiscriminant;UPR;4|))
           (COND
             ((OR (EQL |degMod4| 0) (EQL |degMod4| 1))
              (EXIT (PROG2 (LETT #0#
                                 (SPADCALL
                                     (SPADCALL |f|
                                      (SPADCALL |f| (QREFELT $ 37))
                                      (QREFELT $ 36))
                                     (SPADCALL |f| (QREFELT $ 23))
                                     (QREFELT $ 39)) . #1#)
                           (QCDR #0#)
                      (|check-union| (QEQCAR #0# 0) (QREFELT $ 6) #0#)))))
           (EXIT (SPADCALL
                     (PROG2 (LETT #0#
                                  (SPADCALL
                                      (SPADCALL |f|
                                       (SPADCALL |f| (QREFELT $ 37))
                                       (QREFELT $ 36))
                                      (SPADCALL |f| (QREFELT $ 23))
                                      (QREFELT $ 39)) . #1#)
                            (QCDR #0#)
                       (|check-union| (QEQCAR #0# 0) (QREFELT $ 6) #0#))
                     (QREFELT $ 34))))))) 

(DEFUN |BEZOUT;bezoutDiscriminant;UPR;5| (|f| $)
  (PROG (|degMod4|)
    (RETURN
      (SEQ (COND
             ((SPADCALL (SPADCALL |f| (QREFELT $ 23))
                  (|spadConstant| $ 25) (QREFELT $ 41))
              (SEQ (LETT |degMod4|
                         (REMAINDER2 (SPADCALL |f| (QREFELT $ 12)) 4)
                         |BEZOUT;bezoutDiscriminant;UPR;5|)
                   (COND
                     ((OR (EQL |degMod4| 0) (EQL |degMod4| 1))
                      (EXIT (SPADCALL |f| (SPADCALL |f| (QREFELT $ 37))
                                      (QREFELT $ 36)))))
                   (EXIT (SPADCALL
                             (SPADCALL |f|
                                 (SPADCALL |f| (QREFELT $ 37))
                                 (QREFELT $ 36))
                             (QREFELT $ 34)))))
             ('T
              (|error| "bezoutDiscriminant: leading coefficient must be 1"))))))) 

(DEFUN |BezoutMatrix| (&REST #0=#:G1876)
  (PROG ()
    (RETURN
      (PROG (#1=#:G1877)
        (RETURN
          (COND
            ((LETT #1#
                   (|lassocShiftWithFunction| (|devaluateList| #0#)
                       (HGET |$ConstructorCache| '|BezoutMatrix|)
                       '|domainEqualList|)
                   . #2=(|BezoutMatrix|))
             (|CDRwithIncrement| #1#))
            ('T
             (UNWIND-PROTECT
               (PROG1 (APPLY (|function| |BezoutMatrix;|) #0#)
                 (LETT #1# T . #2#))
               (COND
                 ((NOT #1#) (HREM |$ConstructorCache| '|BezoutMatrix|))))))))))) 

(DEFUN |BezoutMatrix;| (|#1| |#2| |#3| |#4| |#5|)
  (PROG (DV$1 DV$2 DV$3 DV$4 DV$5 |dv$| $ |pv$|)
    (RETURN
      (PROGN
        (LETT DV$1 (|devaluate| |#1|) . #0=(|BezoutMatrix|))
        (LETT DV$2 (|devaluate| |#2|) . #0#)
        (LETT DV$3 (|devaluate| |#3|) . #0#)
        (LETT DV$4 (|devaluate| |#4|) . #0#)
        (LETT DV$5 (|devaluate| |#5|) . #0#)
        (LETT |dv$|
              (LIST '|BezoutMatrix| DV$1 DV$2 DV$3 DV$4 DV$5) . #0#)
        (LETT $ (GETREFV 42) . #0#)
        (QSETREFV $ 0 |dv$|)
        (QSETREFV $ 3
            (LETT |pv$|
                  (|buildPredVector| 0 0
                      (LIST (|HasCategory| |#1| '(|CommutativeRing|)))) . #0#))
        (|haddProp| |$ConstructorCache| '|BezoutMatrix|
            (LIST DV$1 DV$2 DV$3 DV$4 DV$5) (CONS 1 $))
        (|stuffDomainSlots| $)
        (QSETREFV $ 6 |#1|)
        (QSETREFV $ 7 |#2|)
        (QSETREFV $ 8 |#3|)
        (QSETREFV $ 9 |#4|)
        (QSETREFV $ 10 |#5|)
        (COND
          ((|testBitVector| |pv$| 1)
           (PROGN
             (QSETREFV $ 36
                 (CONS (|dispatchFunction|
                           |BEZOUT;bezoutResultant;2UPR;3|)
                       $))
             (COND
               ((|HasCategory| |#1| '(|IntegralDomain|))
                (QSETREFV $ 40
                          (CONS (|dispatchFunction|
                                    |BEZOUT;bezoutDiscriminant;UPR;4|)
                                $)))
               ('T
                (QSETREFV $ 40
                    (CONS (|dispatchFunction|
                              |BEZOUT;bezoutDiscriminant;UPR;5|)
                          $)))))))
        $)))) 

(MAKEPROP '|BezoutMatrix| '|infovec|
    (LIST '#(NIL NIL NIL NIL NIL NIL (|local| |#1|) (|local| |#2|)
             (|local| |#3|) (|local| |#4|) (|local| |#5|)
             (|NonNegativeInteger|) (0 . |degree|) (5 . |Zero|)
             (9 . |Zero|) (13 . |new|) (|Integer|) (20 . |minRowIndex|)
             (25 . |minColIndex|) (30 . |maxRowIndex|)
             (35 . |maxColIndex|) (|Boolean|) (40 . |zero?|)
             (45 . |leadingCoefficient|) (50 . |reductum|) (55 . |One|)
             (59 . |One|) (63 . |qsetelt!|)
             |BEZOUT;sylvesterMatrix;2UPM;1|
             |BEZOUT;bezoutMatrix;2UPM;2| (71 . |ground?|)
             (76 . |qelt|) (83 . *) (89 . +) (95 . -)
             (100 . |determinant|) (105 . |bezoutResultant|)
             (111 . |differentiate|) (|Union| $ '"failed")
             (116 . |exquo|) (122 . |bezoutDiscriminant|) (127 . =))
          '#(|sylvesterMatrix| 133 |bezoutResultant| 139 |bezoutMatrix|
             145 |bezoutDiscriminant| 151)
          'NIL
          (CONS (|makeByteWordVec2| 1 'NIL)
                (CONS '#()
                      (CONS '#()
                            (|makeByteWordVec2| 41
                                '(1 7 11 0 12 0 6 0 13 0 7 0 14 3 8 0
                                  11 11 6 15 1 8 16 0 17 1 8 16 0 18 1
                                  8 16 0 19 1 8 16 0 20 1 7 21 0 22 1 7
                                  6 0 23 1 7 0 0 24 0 6 0 25 0 7 0 26 4
                                  8 6 0 16 16 6 27 1 7 21 0 30 3 8 6 0
                                  16 16 31 2 6 0 0 0 32 2 6 0 0 0 33 1
                                  6 0 0 34 1 8 6 0 35 2 0 6 7 7 36 1 7
                                  0 0 37 2 6 38 0 0 39 1 0 6 7 40 2 6
                                  21 0 0 41 2 0 8 7 7 28 2 1 6 7 7 36 2
                                  0 8 7 7 29 1 1 6 7 40)))))
          '|lookupComplete|)) 
