
(/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 (|row1| |n2| |n1| |xx| |minRow|)
    (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))
                      . #1=(|MATRIX;swapRows!;$2I$;3|))
                (LETT |xx| |x| . #1#) (LETT |n1| (- |i1| |minRow|) . #1#)
                (LETT |n2| (- |i2| |minRow|) . #1#)
                (LETT |row1| (ELT |xx| |n1|) . #1#)
                (SETELT |xx| |n1| (ELT |xx| |n2|)) (SETELT |xx| |n2| |row1|)
                (EXIT |xx|)))))))))) 

(DEFUN |MATRIX;positivePower| (|x| |n| |nn| $)
  (PROG (#1=#:G682 |xx| |c| |b| |a| |y|)
    (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))
                    . #2=(|MATRIX;positivePower|))
              (EXIT (SPADCALL |y| |y| (QREFELT $ 13)))))
            ('T
             (SEQ
              (LETT |a|
                    (SPADCALL |nn| |nn| (|spadConstant| $ 14) (QREFELT $ 17))
                    . #2#)
              (LETT |b|
                    (SPADCALL |nn| |nn| (|spadConstant| $ 14) (QREFELT $ 17))
                    . #2#)
              (LETT |c|
                    (SPADCALL |nn| |nn| (|spadConstant| $ 14) (QREFELT $ 17))
                    . #2#)
              (LETT |xx| |x| . #2#)
              (EXIT
               (SPADCALL |a| |b| |c| |xx|
                         (PROG1 (LETT #1# |n| . #2#)
                           (|check-subtype| (>= #1# 0) '(|NonNegativeInteger|)
                                            #1#))
                         (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 (|xInv| |nn|)
    (RETURN
     (SEQ (LETT |nn| (SPADCALL |x| (QREFELT $ 20)) . #1=(|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| $))
            (#2='T
             (SEQ (LETT |xInv| (SPADCALL |x| (QREFELT $ 41)) . #1#)
                  (EXIT
                   (COND
                    ((QEQCAR |xInv| 1)
                     (|error| "^: matrix must be invertible"))
                    (#2#
                     (|MATRIX;positivePower| (QCDR |xInv|) (- |n|) |nn|
                      $)))))))))))) 

(DEFUN |MATRIX;diagonalMatrix;V$;14| (|v| $)
  (PROG (#1=#:G715 |i| #2=#:G716 |j| #3=#:G717 |k| |ans| |n|)
    (RETURN
     (SEQ (LETT |n| (QVSIZE |v|) . #4=(|MATRIX;diagonalMatrix;V$;14|))
          (LETT |ans| (SPADCALL |n| |n| (QREFELT $ 45)) . #4#)
          (SEQ (LETT |k| (SPADCALL |v| (QREFELT $ 48)) . #4#)
               (LETT #3# (QVSIZE |v|) . #4#)
               (LETT |j| (SPADCALL |ans| (QREFELT $ 10)) . #4#)
               (LETT #2# (SPADCALL |ans| (QREFELT $ 46)) . #4#)
               (LETT |i| (SPADCALL |ans| (QREFELT $ 9)) . #4#)
               (LETT #1# (SPADCALL |ans| (QREFELT $ 11)) . #4#) G190
               (COND ((OR (> |i| #1#) (> |j| #2#) (> |k| #3#)) (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) . #4#))
                             . #4#))
                     . #4#)
               (GO G190) G191 (EXIT NIL))
          (EXIT |ans|))))) 

(DEFUN |MATRIX;convert;$If;15| (|x| $)
  (SPADCALL
   (LIST (SPADCALL '|matrix| (QREFELT $ 54))
         (SPADCALL (SPADCALL |x| (QREFELT $ 56)) (QREFELT $ 57)))
   (QREFELT $ 59))) 

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

(DEFUN |Matrix;| (|#1|)
  (PROG (|pv$| $ |dv$| DV$1)
    (RETURN
     (PROGN
      (LETT DV$1 (|devaluate| |#1|) . #1=(|Matrix|))
      (LETT |dv$| (LIST '|Matrix| DV$1) . #1#)
      (LETT $ (GETREFV 71) . #1#)
      (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|)))))))
                      . #1#))
      (|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 $ 60 (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| (|Symbol|) (|InputForm|)
              (162 . |convert|) (|List| 61) (167 . |listOfLists|)
              (172 . |convert|) (|List| $) (177 . |convert|) (182 . |convert|)
              (|List| 6) (|Equation| 6) (|List| 62) (|Mapping| 42 6)
              (|SingleInteger|) (|OutputForm|) (|String|) (|List| 8)
              (|Mapping| 6 6 6) (|Mapping| 6 6))
           '#(|zero| 187 |swapRows!| 193 |scalarMatrix| 200 |rowEchelon| 206
              |rank| 211 |qsetelt!| 216 |nullity| 224 |nullSpace| 229 |nrows|
              234 |ncols| 239 |minordet| 244 |minRowIndex| 249 |minColIndex|
              254 |maxRowIndex| 259 |maxColIndex| 264 |listOfLists| 269
              |inverse| 274 |diagonalMatrix| 279 |determinant| 284 |convert|
              289 ^ 294 * 306)
           '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| 66) (|ConvertibleTo| 53))
                   (|makeByteWordVec2| 60
                                       '(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 0 55 0 56 1 55 53 0
                                         57 1 53 0 58 59 1 0 53 0 60 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 55 0 56 1
                                         6 40 0 41 1 0 0 47 51 1 5 6 0 26 1 2
                                         53 0 60 2 6 0 0 8 44 2 0 0 0 15 23 2 0
                                         0 0 0 13)))))
           '|lookupIncomplete|)) 
