
(/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) 

(PUT '|MATRIX;qelt;$2IR;3| '|SPADreplace|
     '(XLAM (|m| |i| |j|) (QAREF2O |m| |i| |j| 1 1))) 

(DEFUN |MATRIX;qelt;$2IR;3| (|m| |i| |j| $) (QAREF2O |m| |i| |j| 1 1)) 

(PUT '|MATRIX;qsetelt!;$2I2R;4| '|SPADreplace|
     '(XLAM (|m| |i| |j| |r|) (QSETAREF2O |m| |i| |j| |r| 1 1))) 

(DEFUN |MATRIX;qsetelt!;$2I2R;4| (|m| |i| |j| |r| $)
  (QSETAREF2O |m| |i| |j| |r| 1 1)) 

(DEFUN |MATRIX;swapRows!;$2I$;5| (|x| |i1| |i2| $)
  (PROG (|row1| |n2| |n1| |xx| |minRow|)
    (RETURN
     (SEQ
      (COND
       ((OR (< |i1| 1)
            (OR (< (SPADCALL |x| (QREFELT $ 12)) |i1|)
                (OR (< |i2| 1) (< (SPADCALL |x| (QREFELT $ 12)) |i2|))))
        (|error| "swapRows!: index out of range"))
       ('T
        (COND ((EQL |i1| |i2|) |x|)
              ('T
               (SEQ (LETT |minRow| 1 . #1=(|MATRIX;swapRows!;$2I$;5|))
                    (LETT |xx| |x| . #1#) (LETT |n1| (- |i1| |minRow|) . #1#)
                    (LETT |n2| (- |i2| |minRow|) . #1#)
                    (LETT |row1| (QAREF1 |xx| |n1|) . #1#)
                    (QSETAREF1 |xx| |n1| (QAREF1 |xx| |n2|))
                    (QSETAREF1 |xx| |n2| |row1|) (EXIT |xx|)))))))))) 

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

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

(DEFUN |MATRIX;determinant;$R;8| (|x| $) (SPADCALL |x| (QREFELT $ 27))) 

(DEFUN |MATRIX;minordet;$R;9| (|x| $) (SPADCALL |x| (QREFELT $ 29))) 

(DEFUN |MATRIX;rowEchelon;2$;10| (|x| $) (SPADCALL |x| (QREFELT $ 31))) 

(DEFUN |MATRIX;rank;$Nni;11| (|x| $) (SPADCALL |x| (QREFELT $ 33))) 

(DEFUN |MATRIX;nullity;$Nni;12| (|x| $) (SPADCALL |x| (QREFELT $ 35))) 

(DEFUN |MATRIX;nullSpace;$L;13| (|x| $) (SPADCALL |x| (QREFELT $ 38))) 

(DEFUN |MATRIX;inverse;$U;14| (|x| $) (SPADCALL |x| (QREFELT $ 41))) 

(DEFUN |MATRIX;^;$I$;15| (|x| |n| $)
  (PROG (|xInv| |nn|)
    (RETURN
     (SEQ (LETT |nn| (SPADCALL |x| (QREFELT $ 22)) . #1=(|MATRIX;^;$I$;15|))
          (COND
           ((NULL (EQL |nn| (SPADCALL |x| (QREFELT $ 23))))
            (EXIT (|error| "^: matrix must be square"))))
          (EXIT
           (COND
            ((ZEROP |n|) (SPADCALL |nn| (|spadConstant| $ 14) (QREFELT $ 24)))
            ((SPADCALL |n| (QREFELT $ 45))
             (|MATRIX;positivePower| |x| |n| |nn| $))
            (#2='T
             (SEQ (LETT |xInv| (SPADCALL |x| (QREFELT $ 43)) . #1#)
                  (EXIT
                   (COND
                    ((QEQCAR |xInv| 1)
                     (|error| "^: matrix must be invertible"))
                    (#2#
                     (|MATRIX;positivePower| (QCDR |xInv|) (- |n|) |nn|
                                             $)))))))))))) 

(DEFUN |MATRIX;diagonalMatrix;V$;16| (|v| $)
  (PROG (#1=#:G15985 |i| #2=#:G15986 |j| #3=#:G15987 |k| |ans| |n|)
    (RETURN
     (SEQ (LETT |n| (QVSIZE |v|) . #4=(|MATRIX;diagonalMatrix;V$;16|))
          (LETT |ans| (SPADCALL |n| |n| (QREFELT $ 47)) . #4#)
          (SEQ (LETT |k| (SPADCALL |v| (QREFELT $ 50)) . #4#)
               (LETT #3# (QVSIZE |v|) . #4#) (LETT |j| 1 . #4#)
               (LETT #2# (SPADCALL |ans| (QREFELT $ 48)) . #4#)
               (LETT |i| 1 . #4#)
               (LETT #1# (SPADCALL |ans| (QREFELT $ 12)) . #4#) G190
               (COND
                ((OR (QSGREATERP |i| #1#) (QSGREATERP |j| #2#) (> |k| #3#))
                 (GO G191)))
               (SEQ (EXIT (QSETAREF2O |ans| |i| |j| (QAREF1O |v| |k| 1) 1 1)))
               (LETT |i|
                     (PROG1 (QSADD1 |i|)
                       (LETT |j|
                             (PROG1 (QSADD1 |j|) (LETT |k| (+ |k| 1) . #4#))
                             . #4#))
                     . #4#)
               (GO G190) G191 (EXIT NIL))
          (EXIT |ans|))))) 

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

(DEFUN |Matrix| (#1=#:G15993)
  (PROG ()
    (RETURN
     (PROG (#2=#:G15994)
       (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|
                                                          (LIST '|Evalable|
                                                                (|devaluate|
                                                                 |#1|)))
                                           (|HasCategory| |#1|
                                                          '(|SetCategory|)))
                                          (OR
                                           (AND
                                            (|HasCategory| |#1|
                                                           (LIST '|Evalable|
                                                                 (|devaluate|
                                                                  |#1|)))
                                            (|HasCategory| |#1| '(|Field|)))
                                           (AND
                                            (|HasCategory| |#1|
                                                           (LIST '|Evalable|
                                                                 (|devaluate|
                                                                  |#1|)))
                                            (|HasCategory| |#1|
                                                           '(|SetCategory|))))))
                      . #1#))
      (|haddProp| |$ConstructorCache| '|Matrix| (LIST DV$1) (CONS 1 $))
      (|stuffDomainSlots| $)
      (QSETREFV $ 6 |#1|)
      (AND (|HasCategory| $ '(|finiteAggregate|)) (|augmentPredVector| $ 256))
      (AND (|HasCategory| |#1| '(|SetCategory|))
           (|HasCategory| $ '(|finiteAggregate|)) (|augmentPredVector| $ 512))
      (COND
       ((|testBitVector| |pv$| 5)
        (PROGN
         (QSETREFV $ 28
                   (CONS (|dispatchFunction| |MATRIX;determinant;$R;8|) $))
         (QSETREFV $ 30
                   (CONS (|dispatchFunction| |MATRIX;minordet;$R;9|) $)))))
      (COND
       ((|testBitVector| |pv$| 3)
        (QSETREFV $ 32
                  (CONS (|dispatchFunction| |MATRIX;rowEchelon;2$;10|) $))))
      (COND
       ((|testBitVector| |pv$| 4)
        (PROGN
         (QSETREFV $ 34 (CONS (|dispatchFunction| |MATRIX;rank;$Nni;11|) $))
         (QSETREFV $ 36 (CONS (|dispatchFunction| |MATRIX;nullity;$Nni;12|) $))
         (QSETREFV $ 39
                   (CONS (|dispatchFunction| |MATRIX;nullSpace;$L;13|) $)))))
      (COND
       ((|testBitVector| |pv$| 6)
        (PROGN
         (QSETREFV $ 43 (CONS (|dispatchFunction| |MATRIX;inverse;$U;14|) $))
         (QSETREFV $ 46 (CONS (|dispatchFunction| |MATRIX;^;$I$;15|) $)))))
      (COND
       ((|testBitVector| |pv$| 2)
        (QSETREFV $ 60 (CONS (|dispatchFunction| |MATRIX;convert;$If;17|) $))))
      $)))) 

(MAKEPROP '|Matrix| '|infovec|
          (LIST
           '#(NIL NIL NIL NIL NIL
              (|InnerIndexedTwoDimensionalArray| 6 (NRTEVAL 1) (NRTEVAL 1) 49
                                                 49)
              (|local| |#1|) (|Integer|) |MATRIX;minRowIndex;$I;1|
              |MATRIX;minColIndex;$I;2| |MATRIX;qelt;$2IR;3|
              |MATRIX;qsetelt!;$2I2R;4| (0 . |maxRowIndex|)
              |MATRIX;swapRows!;$2I$;5| (5 . |One|) (9 . *) (15 . |Zero|)
              (|NonNegativeInteger|) (|Matrix| 6) (19 . |new|)
              (|StorageEfficientMatrixOperations| 6) (26 . |power!|)
              (35 . |nrows|) (40 . |ncols|) (45 . |scalarMatrix|)
              |MATRIX;^;$Nni$;7| (|MatrixLinearAlgebraFunctions| 6 49 49 $$)
              (51 . |determinant|) (56 . |determinant|) (61 . |minordet|)
              (66 . |minordet|) (71 . |rowEchelon|) (76 . |rowEchelon|)
              (81 . |rank|) (86 . |rank|) (91 . |nullity|) (96 . |nullity|)
              (|List| 49) (101 . |nullSpace|) (106 . |nullSpace|)
              (|Union| $$ '"failed") (111 . |inverse|) (|Union| $ '"failed")
              (116 . |inverse|) (|Boolean|) (121 . |positive?|) (126 . ^)
              (132 . |zero|) (138 . |maxColIndex|) (|Vector| 6)
              (143 . |minIndex|) |MATRIX;diagonalMatrix;V$;16| (|Symbol|)
              (|InputForm|) (148 . |convert|) (|List| 61) (153 . |listOfLists|)
              (158 . |convert|) (|List| $) (163 . |convert|) (168 . |convert|)
              (|List| 6) (|Equation| 6) (|List| 62) (|Mapping| 44 6)
              (|SingleInteger|) (|OutputForm|) (|String|) (|List| 7)
              (|Mapping| 6 6 6) (|Mapping| 6 6))
           '#(|zero| 173 |swapRows!| 179 |scalarMatrix| 186 |rowEchelon| 192
              |rank| 197 |qsetelt!| 202 |qelt| 210 |nullity| 217 |nullSpace|
              222 |nrows| 227 |ncols| 232 |minordet| 237 |minRowIndex| 242
              |minColIndex| 247 |maxRowIndex| 252 |maxColIndex| 257
              |listOfLists| 262 |inverse| 267 |diagonalMatrix| 272
              |determinant| 277 |convert| 282 ^ 287 * 299)
           '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
                                       '(1 0 7 0 12 0 6 0 14 2 0 0 0 0 15 0 6 0
                                         16 3 18 0 17 17 6 19 5 20 18 18 18 18
                                         18 17 21 1 0 17 0 22 1 0 17 0 23 2 0 0
                                         17 6 24 1 26 6 2 27 1 0 6 0 28 1 26 6
                                         2 29 1 0 6 0 30 1 26 2 2 31 1 0 0 0 32
                                         1 26 17 2 33 1 0 17 0 34 1 26 17 2 35
                                         1 0 17 0 36 1 26 37 2 38 1 0 37 0 39 1
                                         26 40 2 41 1 0 42 0 43 1 7 44 0 45 2 0
                                         0 0 7 46 2 0 0 17 17 47 1 0 7 0 48 1
                                         49 7 0 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 17 17 47 3 0 0 0 7 7 13 2 0 0 17 6
                                         24 1 3 0 0 32 1 4 17 0 34 4 0 6 0 7 7
                                         6 11 3 0 6 0 7 7 10 1 4 17 0 36 1 4 37
                                         0 39 1 0 17 0 22 1 0 17 0 23 1 5 6 0
                                         30 1 0 7 0 8 1 0 7 0 9 1 0 7 0 12 1 0
                                         7 0 48 1 0 55 0 56 1 6 42 0 43 1 0 0
                                         49 51 1 5 6 0 28 1 2 53 0 60 2 6 0 0 7
                                         46 2 0 0 0 17 25 2 0 0 0 0 15)))))
           '|lookupIncomplete|)) 
