
(/VERSIONCHECK 2) 

(PUT '|MATRIX;minRowIndex;$I;1| '|SPADreplace| '(XLAM (|x|) 1)) 

(DEFUN |MATRIX;minRowIndex;$I;1| (|x| $) 1) 

(PUT '|MATRIX;minColIndex;$I;2| '|SPADreplace| '(XLAM (|x|) 1)) 

(DEFUN |MATRIX;minColIndex;$I;2| (|x| $) 1) 

(DEFUN |MATRIX;swapRows!;$2I$;3| (|x| |i1| |i2| $)
  (PROG (|minRow| |xx| |n1| |n2| |row1|)
    (RETURN
      (SEQ (COND
             ((OR (< |i1| (SPADCALL |x| (QREFELT $ 9)))
                  (OR (< (SPADCALL |x| (QREFELT $ 11)) |i1|)
                      (OR (< |i2| (SPADCALL |x| (QREFELT $ 9)))
                          (< (SPADCALL |x| (QREFELT $ 11)) |i2|))))
              (|error| "swapRows!: index out of range"))
             ('T
              (COND
                ((EQL |i1| |i2|) |x|)
                ('T
                 (SEQ (LETT |minRow| (SPADCALL |x| (QREFELT $ 9))
                            . #0=(|MATRIX;swapRows!;$2I$;3|))
                      (LETT |xx| |x| . #0#)
                      (LETT |n1| (- |i1| |minRow|) . #0#)
                      (LETT |n2| (- |i2| |minRow|) . #0#)
                      (LETT |row1| (ELT |xx| |n1|) . #0#)
                      (SETELT |xx| |n1| (ELT |xx| |n2|))
                      (SETELT |xx| |n2| |row1|) (EXIT |xx|)))))))))) 

(DEFUN |MATRIX;positivePower| (|x| |n| |nn| $)
  (PROG (|y| |a| |b| |c| |xx| #0=#:G1836)
    (RETURN
      (SEQ (COND
             ((EQL |n| 1) |x|)
             ((EQL |n| 2) (SPADCALL |x| |x| (QREFELT $ 13)))
             ((EQL |n| 3)
              (SPADCALL (SPADCALL |x| |x| (QREFELT $ 13)) |x|
                  (QREFELT $ 13)))
             ((EQL |n| 4)
              (SEQ (LETT |y| (SPADCALL |x| |x| (QREFELT $ 13))
                         . #1=(|MATRIX;positivePower|))
                   (EXIT (SPADCALL |y| |y| (QREFELT $ 13)))))
             ('T
              (SEQ (LETT |a|
                         (SPADCALL |nn| |nn| (|spadConstant| $ 14)
                             (QREFELT $ 17)) . #1#)
                   (LETT |b|
                         (SPADCALL |nn| |nn| (|spadConstant| $ 14)
                             (QREFELT $ 17)) . #1#)
                   (LETT |c|
                         (SPADCALL |nn| |nn| (|spadConstant| $ 14)
                             (QREFELT $ 17)) . #1#)
                   (LETT |xx| |x| . #1#)
                   (EXIT (SPADCALL |a| |b| |c| |xx|
                             (PROG1 (LETT #0# |n| . #1#)
                               (|check-subtype| (>= #0# 0)
                                   '(|NonNegativeInteger|) #0#))
                             (QREFELT $ 19)))))))))) 

(DEFUN |MATRIX;**;$Nni$;5| (|x| |n| $)
  (PROG (|nn|)
    (RETURN
      (COND
        ((NULL (EQL (LETT |nn| (SPADCALL |x| (QREFELT $ 20))
                          |MATRIX;**;$Nni$;5|)
                    (SPADCALL |x| (QREFELT $ 21))))
         (|error| "**: matrix must be square"))
        ('T
         (COND
           ((ZEROP |n|)
            (SPADCALL |nn| (|spadConstant| $ 7) (QREFELT $ 22)))
           ('T (|MATRIX;positivePower| |x| |n| |nn| $)))))))) 

(DEFUN |MATRIX;determinant;$R;6| (|x| $)
  (SPADCALL |x| (QREFELT $ 25))) 

(DEFUN |MATRIX;minordet;$R;7| (|x| $) (SPADCALL |x| (QREFELT $ 27))) 

(DEFUN |MATRIX;rowEchelon;2$;8| (|x| $) (SPADCALL |x| (QREFELT $ 29))) 

(DEFUN |MATRIX;rank;$Nni;9| (|x| $) (SPADCALL |x| (QREFELT $ 31))) 

(DEFUN |MATRIX;nullity;$Nni;10| (|x| $) (SPADCALL |x| (QREFELT $ 33))) 

(DEFUN |MATRIX;nullSpace;$L;11| (|x| $) (SPADCALL |x| (QREFELT $ 36))) 

(DEFUN |MATRIX;inverse;$U;12| (|x| $) (SPADCALL |x| (QREFELT $ 39))) 

(DEFUN |MATRIX;**;$I$;13| (|x| |n| $)
  (PROG (|nn| |xInv|)
    (RETURN
      (SEQ (LETT |nn| (SPADCALL |x| (QREFELT $ 20))
                 . #0=(|MATRIX;**;$I$;13|))
           (COND
             ((NULL (EQL |nn| (SPADCALL |x| (QREFELT $ 21))))
              (EXIT (|error| "**: matrix must be square"))))
           (EXIT (COND
                   ((ZEROP |n|)
                    (SPADCALL |nn| (|spadConstant| $ 7) (QREFELT $ 22)))
                   ((SPADCALL |n| (QREFELT $ 43))
                    (|MATRIX;positivePower| |x| |n| |nn| $))
                   ('T
                    (SEQ (LETT |xInv|
                               (SPADCALL |x| (QREFELT $ 41)) . #0#)
                         (EXIT (COND
                                 ((QEQCAR |xInv| 1)
                                  (|error| "**: matrix must be invertible"))
                                 ('T
                                  (|MATRIX;positivePower| (QCDR |xInv|)
                                      (- |n|) |nn| $)))))))))))) 

(DEFUN |MATRIX;diagonalMatrix;V$;14| (|v| $)
  (PROG (|n| |ans| |k| #0=#:G1871 |j| #1=#:G1870 |i| #2=#:G1869)
    (RETURN
      (SEQ (LETT |n| (QVSIZE |v|) . #3=(|MATRIX;diagonalMatrix;V$;14|))
           (LETT |ans| (SPADCALL |n| |n| (QREFELT $ 45)) . #3#)
           (SEQ (LETT |k| (SPADCALL |v| (QREFELT $ 48)) . #3#)
                (LETT #0# (QVSIZE |v|) . #3#)
                (LETT |j| (SPADCALL |ans| (QREFELT $ 10)) . #3#)
                (LETT #1# (SPADCALL |ans| (QREFELT $ 46)) . #3#)
                (LETT |i| (SPADCALL |ans| (QREFELT $ 9)) . #3#)
                (LETT #2# (SPADCALL |ans| (QREFELT $ 11)) . #3#) G190
                (COND
                  ((OR (> |i| #2#) (> |j| #1#) (> |k| #0#)) (GO G191)))
                (SEQ (EXIT (SPADCALL |ans| |i| |j|
                               (SPADCALL |v| |k| (QREFELT $ 49))
                               (QREFELT $ 50))))
                (LETT |i|
                      (PROG1 (+ |i| 1)
                        (LETT |j|
                              (PROG1 (+ |j| 1)
                                (LETT |k| (+ |k| 1) . #3#)) . #3#)) . #3#)
                (GO G190) G191 (EXIT NIL))
           (EXIT |ans|))))) 

(DEFUN |MATRIX;convert;$If;15| (|x| $)
  (SPADCALL (LIST (SPADCALL (SPADCALL "matrix" (QREFELT $ 54))
                      (QREFELT $ 56))
                  (SPADCALL (SPADCALL |x| (QREFELT $ 58))
                      (QREFELT $ 59)))
            (QREFELT $ 61))) 

(DEFUN |Matrix| (#0=#:G1877)
  (PROG ()
    (RETURN
      (PROG (#1=#:G1878)
        (RETURN
          (COND
            ((LETT #1#
                   (|lassocShiftWithFunction| (LIST (|devaluate| #0#))
                       (HGET |$ConstructorCache| '|Matrix|)
                       '|domainEqualList|)
                   . #2=(|Matrix|))
             (|CDRwithIncrement| #1#))
            ('T
             (UNWIND-PROTECT
               (PROG1 (|Matrix;| #0#) (LETT #1# T . #2#))
               (COND ((NOT #1#) (HREM |$ConstructorCache| '|Matrix|))))))))))) 

(DEFUN |Matrix;| (|#1|)
  (PROG (DV$1 |dv$| $ |pv$|)
    (RETURN
      (PROGN
        (LETT DV$1 (|devaluate| |#1|) . #0=(|Matrix|))
        (LETT |dv$| (LIST '|Matrix| DV$1) . #0#)
        (LETT $ (GETREFV 72) . #0#)
        (QSETREFV $ 0 |dv$|)
        (QSETREFV $ 3
            (LETT |pv$|
                  (|buildPredVector| 0 0
                      (LIST (|HasCategory| |#1| '(|SetCategory|))
                            (|HasCategory| |#1|
                                '(|ConvertibleTo| (|InputForm|)))
                            (|HasCategory| |#1| '(|EuclideanDomain|))
                            (|HasCategory| |#1| '(|IntegralDomain|))
                            (|HasCategory| |#1| '(|CommutativeRing|))
                            (|HasCategory| |#1| '(|Field|))
                            (AND (|HasCategory| |#1| '(|SetCategory|))
                                 (|HasCategory| |#1|
                                     (LIST '|Evalable|
                                      (|devaluate| |#1|))))
                            (OR (AND (|HasCategory| |#1| '(|Field|))
                                     (|HasCategory| |#1|
                                      (LIST '|Evalable|
                                       (|devaluate| |#1|))))
                                (AND (|HasCategory| |#1|
                                      '(|SetCategory|))
                                     (|HasCategory| |#1|
                                      (LIST '|Evalable|
                                       (|devaluate| |#1|))))))) . #0#))
        (|haddProp| |$ConstructorCache| '|Matrix| (LIST DV$1)
            (CONS 1 $))
        (|stuffDomainSlots| $)
        (QSETREFV $ 6 |#1|)
        (AND (|HasCategory| $ '(|finiteAggregate|))
             (|augmentPredVector| $ 256))
        (AND (|HasCategory| $ '(|finiteAggregate|))
             (|HasCategory| |#1| '(|SetCategory|))
             (|augmentPredVector| $ 512))
        (COND
          ((|testBitVector| |pv$| 5)
           (PROGN
             (QSETREFV $ 26
                 (CONS (|dispatchFunction| |MATRIX;determinant;$R;6|)
                       $))
             (QSETREFV $ 28
                 (CONS (|dispatchFunction| |MATRIX;minordet;$R;7|) $)))))
        (COND
          ((|testBitVector| |pv$| 3)
           (QSETREFV $ 30
               (CONS (|dispatchFunction| |MATRIX;rowEchelon;2$;8|) $))))
        (COND
          ((|testBitVector| |pv$| 4)
           (PROGN
             (QSETREFV $ 32
                 (CONS (|dispatchFunction| |MATRIX;rank;$Nni;9|) $))
             (QSETREFV $ 34
                 (CONS (|dispatchFunction| |MATRIX;nullity;$Nni;10|) $))
             (QSETREFV $ 37
                 (CONS (|dispatchFunction| |MATRIX;nullSpace;$L;11|) $)))))
        (COND
          ((|testBitVector| |pv$| 6)
           (PROGN
             (QSETREFV $ 41
                 (CONS (|dispatchFunction| |MATRIX;inverse;$U;12|) $))
             (QSETREFV $ 44
                 (CONS (|dispatchFunction| |MATRIX;**;$I$;13|) $)))))
        (COND
          ((|testBitVector| |pv$| 2)
           (QSETREFV $ 62
               (CONS (|dispatchFunction| |MATRIX;convert;$If;15|) $))))
        $)))) 

(MAKEPROP '|Matrix| '|infovec|
    (LIST '#(NIL NIL NIL NIL NIL
             (|InnerIndexedTwoDimensionalArray| 6 (NRTEVAL 1)
                 (NRTEVAL 1) 47 47)
             (|local| |#1|) (0 . |One|) (|Integer|)
             |MATRIX;minRowIndex;$I;1| |MATRIX;minColIndex;$I;2|
             (4 . |maxRowIndex|) |MATRIX;swapRows!;$2I$;3| (9 . *)
             (15 . |Zero|) (|NonNegativeInteger|) (|Matrix| 6)
             (19 . |new|) (|StorageEfficientMatrixOperations| 6)
             (26 . |power!|) (35 . |nrows|) (40 . |ncols|)
             (45 . |scalarMatrix|) |MATRIX;**;$Nni$;5|
             (|MatrixLinearAlgebraFunctions| 6 47 47 $$)
             (51 . |determinant|) (56 . |determinant|)
             (61 . |minordet|) (66 . |minordet|) (71 . |rowEchelon|)
             (76 . |rowEchelon|) (81 . |rank|) (86 . |rank|)
             (91 . |nullity|) (96 . |nullity|) (|List| 47)
             (101 . |nullSpace|) (106 . |nullSpace|)
             (|Union| $$ '"failed") (111 . |inverse|)
             (|Union| $ '"failed") (116 . |inverse|) (|Boolean|)
             (121 . |positive?|) (126 . **) (132 . |zero|)
             (138 . |maxColIndex|) (|Vector| 6) (143 . |minIndex|)
             (148 . |qelt|) (154 . |qsetelt!|)
             |MATRIX;diagonalMatrix;V$;14| (|String|) (|Symbol|)
             (162 . |coerce|) (|InputForm|) (167 . |convert|)
             (|List| 63) (172 . |listOfLists|) (177 . |convert|)
             (|List| $) (182 . |convert|) (187 . |convert|) (|List| 6)
             (|Equation| 6) (|List| 64) (|Mapping| 42 6)
             (|SingleInteger|) (|OutputForm|) (|List| 8)
             (|Mapping| 6 6 6) (|Mapping| 6 6))
          '#(|zero| 192 |swapRows!| 198 |scalarMatrix| 205 |rowEchelon|
             211 |rank| 216 |qsetelt!| 221 |nullity| 229 |nullSpace|
             234 |nrows| 239 |ncols| 244 |minordet| 249 |minRowIndex|
             254 |minColIndex| 259 |maxRowIndex| 264 |maxColIndex| 269
             |listOfLists| 274 |inverse| 279 |diagonalMatrix| 284
             |determinant| 289 |convert| 294 ** 299 * 311)
          'NIL
          (CONS (|makeByteWordVec2| 8 '(0 0 0 0 8 1 0 0 0 8 1 1 2))
                (CONS '#(|MatrixCategory&|
                         |TwoDimensionalArrayCategory&|
                         |HomogeneousAggregate&| |Aggregate&|
                         |Evalable&| |SetCategory&| NIL NIL NIL
                         |InnerEvalable&| |BasicType&| NIL NIL)
                      (CONS '#((|MatrixCategory| 6 (|Vector| 6)
                                   (|Vector| 6))
                               (|TwoDimensionalArrayCategory| 6
                                   (|Vector| 6) (|Vector| 6))
                               (|HomogeneousAggregate| 6) (|Aggregate|)
                               (|Evalable| 6) (|SetCategory|) (|Type|)
                               (|finiteAggregate|) (|shallowlyMutable|)
                               (|InnerEvalable| 6 6) (|BasicType|)
                               (|CoercibleTo| 68) (|ConvertibleTo| 55))
                            (|makeByteWordVec2| 62
                                '(0 6 0 7 1 0 8 0 11 2 0 0 0 0 13 0 6 0
                                  14 3 16 0 15 15 6 17 5 18 16 16 16 16
                                  16 15 19 1 0 15 0 20 1 0 15 0 21 2 0
                                  0 15 6 22 1 24 6 2 25 1 0 6 0 26 1 24
                                  6 2 27 1 0 6 0 28 1 24 2 2 29 1 0 0 0
                                  30 1 24 15 2 31 1 0 15 0 32 1 24 15 2
                                  33 1 0 15 0 34 1 24 35 2 36 1 0 35 0
                                  37 1 24 38 2 39 1 0 40 0 41 1 8 42 0
                                  43 2 0 0 0 8 44 2 0 0 15 15 45 1 0 8
                                  0 46 1 47 8 0 48 2 47 6 0 8 49 4 0 6
                                  0 8 8 6 50 1 53 0 52 54 1 55 0 53 56
                                  1 0 57 0 58 1 57 55 0 59 1 55 0 60 61
                                  1 0 55 0 62 2 0 0 15 15 45 3 0 0 0 8
                                  8 12 2 0 0 15 6 22 1 3 0 0 30 1 4 15
                                  0 32 4 0 6 0 8 8 6 50 1 4 15 0 34 1 4
                                  35 0 37 1 0 15 0 20 1 0 15 0 21 1 5 6
                                  0 28 1 0 8 0 9 1 0 8 0 10 1 0 8 0 11
                                  1 0 8 0 46 1 0 57 0 58 1 6 40 0 41 1
                                  0 0 47 51 1 5 6 0 26 1 2 55 0 62 2 6
                                  0 0 8 44 2 0 0 0 15 23 2 0 0 0 0 13)))))
          '|lookupIncomplete|)) 
