
(/VERSIONCHECK 2) 

(PUT '|MODRING;modulus;$Mod;1| '|SPADreplace| 'QCDR) 

(DEFUN |MODRING;modulus;$Mod;1| (|x| $) (QCDR |x|)) 

(PUT '|MODRING;coerce;$R;2| '|SPADreplace| 'QCAR) 

(DEFUN |MODRING;coerce;$R;2| (|x| $) (QCAR |x|)) 

(DEFUN |MODRING;coerce;I$;3| (|i| $)
  (CONS (SPADCALL |i| (QREFELT $ 15)) (|spadConstant| $ 18))) 

(DEFUN |MODRING;*;I2$;4| (|i| |x| $)
  (SPADCALL (SPADCALL |i| (QREFELT $ 19)) |x| (QREFELT $ 20))) 

(DEFUN |MODRING;coerce;$Of;5| (|x| $)
  (SPADCALL (QCAR |x|) (QREFELT $ 23))) 

(DEFUN |MODRING;reduce;RMod$;6| (|a| |m| $)
  (CONS (SPADCALL |a| |m| (QREFELT $ 8)) |m|)) 

(DEFUN |MODRING;characteristic;Nni;7| ($) (SPADCALL (QREFELT $ 27))) 

(DEFUN |MODRING;Zero;$;8| ($)
  (CONS (|spadConstant| $ 17) (|spadConstant| $ 18))) 

(DEFUN |MODRING;One;$;9| ($)
  (CONS (|spadConstant| $ 29) (|spadConstant| $ 18))) 

(DEFUN |MODRING;zero?;$B;10| (|x| $)
  (SPADCALL (QCAR |x|) (QREFELT $ 32))) 

(DEFUN |MODRING;one?;$B;11| (|x| $)
  (SPADCALL (QCAR |x|) (|spadConstant| $ 29) (QREFELT $ 34))) 

(DEFUN |MODRING;newmodulo| (|m1| |m2| $)
  (PROG (|r|)
    (RETURN
      (SEQ (LETT |r| (SPADCALL |m1| |m2| (QREFELT $ 9))
                 |MODRING;newmodulo|)
           (EXIT (COND
                   ((QEQCAR |r| 1) (|error| "incompatible moduli"))
                   ('T (QCDR |r|)))))))) 

(DEFUN |MODRING;=;2$B;13| (|x| |y| $)
  (COND
    ((SPADCALL (QCAR |x|) (QCAR |y|) (QREFELT $ 34)) 'T)
    ((SPADCALL (QCDR |x|) (QCDR |y|) (QREFELT $ 36)) 'NIL)
    ('T
     (SPADCALL (QCAR (SPADCALL |x| |y| (QREFELT $ 37)))
         (|spadConstant| $ 17) (QREFELT $ 34))))) 

(DEFUN |MODRING;+;3$;14| (|x| |y| $)
  (SPADCALL (SPADCALL (QCAR |x|) (QCAR |y|) (QREFELT $ 39))
            (|MODRING;newmodulo| (QCDR |x|) (QCDR |y|) $)
            (QREFELT $ 25))) 

(DEFUN |MODRING;-;3$;15| (|x| |y| $)
  (SPADCALL (SPADCALL (QCAR |x|) (QCAR |y|) (QREFELT $ 41))
            (|MODRING;newmodulo| (QCDR |x|) (QCDR |y|) $)
            (QREFELT $ 25))) 

(DEFUN |MODRING;-;2$;16| (|x| $)
  (SPADCALL (SPADCALL (QCAR |x|) (QREFELT $ 42)) (QCDR |x|)
      (QREFELT $ 25))) 

(DEFUN |MODRING;*;3$;17| (|x| |y| $)
  (SPADCALL (SPADCALL (QCAR |x|) (QCAR |y|) (QREFELT $ 44))
            (|MODRING;newmodulo| (QCDR |x|) (QCDR |y|) $)
            (QREFELT $ 25))) 

(DEFUN |MODRING;exQuo;2$U;18| (|x| |y| $)
  (PROG (|xm| |r|)
    (RETURN
      (SEQ (LETT |xm| (QCDR |x|) . #0=(|MODRING;exQuo;2$U;18|))
           (COND
             ((NULL (SPADCALL |xm| (QCDR |y|) (QREFELT $ 36)))
              (LETT |xm| (|MODRING;newmodulo| |xm| (QCDR |y|) $) . #0#)))
           (LETT |r|
                 (SPADCALL (QCAR |x|) (QCAR |y|) |xm| (QREFELT $ 10)) . #0#)
           (EXIT (COND
                   ((QEQCAR |r| 1) (CONS 1 "failed"))
                   ('T (CONS 0 (CONS (QCDR |r|) |xm|))))))))) 

(DEFUN |MODRING;recip;$U;19| (|x| $)
  (PROG (|r|)
    (RETURN
      (SEQ (LETT |r|
                 (SPADCALL (|spadConstant| $ 29) (QCAR |x|) (QCDR |x|)
                     (QREFELT $ 10))
                 |MODRING;recip;$U;19|)
           (EXIT (COND
                   ((QEQCAR |r| 1) (CONS 1 "failed"))
                   ('T (CONS 0 (CONS (QCDR |r|) (QCDR |x|)))))))))) 

(DEFUN |MODRING;inv;2$;20| (|x| $)
  (PROG (|u|)
    (RETURN
      (SEQ (LETT |u| (SPADCALL |x| (QREFELT $ 47)) |MODRING;inv;2$;20|)
           (EXIT (COND
                   ((QEQCAR |u| 1) (|error| "not invertible"))
                   ('T (QCDR |u|)))))))) 

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

(DEFUN |ModularRing;| (|#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=(|ModularRing|))
        (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 '|ModularRing| DV$1 DV$2 DV$3 DV$4 DV$5) . #0#)
        (LETT $ (GETREFV 52) . #0#)
        (QSETREFV $ 0 |dv$|)
        (QSETREFV $ 3 (LETT |pv$| (|buildPredVector| 0 0 NIL) . #0#))
        (|haddProp| |$ConstructorCache| '|ModularRing|
            (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|)
        (QSETREFV $ 11 (|Record| (|:| |val| |#1|) (|:| |modulo| |#2|)))
        $)))) 

(MAKEPROP '|ModularRing| '|infovec|
    (LIST '#(NIL NIL NIL NIL NIL NIL (|local| |#1|) (|local| |#2|)
             (|local| |#3|) (|local| |#4|) (|local| |#5|) '|Rep|
             |MODRING;modulus;$Mod;1| |MODRING;coerce;$R;2| (|Integer|)
             (0 . |coerce|)
             (CONS IDENTITY
                   (FUNCALL (|dispatchFunction| |MODRING;Zero;$;8|) $))
             (5 . |Zero|) (9 . |Zero|) |MODRING;coerce;I$;3|
             |MODRING;*;3$;17| |MODRING;*;I2$;4| (|OutputForm|)
             (13 . |coerce|) |MODRING;coerce;$Of;5|
             |MODRING;reduce;RMod$;6| (|NonNegativeInteger|)
             (18 . |characteristic|) |MODRING;characteristic;Nni;7|
             (22 . |One|)
             (CONS IDENTITY
                   (FUNCALL (|dispatchFunction| |MODRING;One;$;9|) $))
             (|Boolean|) (26 . |zero?|) |MODRING;zero?;$B;10| (31 . =)
             |MODRING;one?;$B;11| (37 . =) |MODRING;-;3$;15|
             |MODRING;=;2$B;13| (43 . +) |MODRING;+;3$;14| (49 . -)
             (55 . -) |MODRING;-;2$;16| (60 . *) (|Union| $ '"failed")
             |MODRING;exQuo;2$U;18| |MODRING;recip;$U;19|
             |MODRING;inv;2$;20| (|PositiveInteger|) (|String|)
             (|SingleInteger|))
          '#(~= 66 |zero?| 72 |subtractIfCan| 77 |sample| 83 |reduce|
             87 |recip| 93 |one?| 98 |modulus| 103 |latex| 108 |inv|
             113 |hash| 118 |exQuo| 123 |coerce| 129 |characteristic|
             144 ^ 148 |Zero| 160 |One| 164 = 168 - 174 + 185 ** 191 *
             203)
          'NIL
          (CONS (|makeByteWordVec2| 1 '(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))
                (CONS '#(|Ring&| NIL NIL |AbelianGroup&| NIL NIL
                         |AbelianMonoid&| |Monoid&| NIL |SemiGroup&|
                         |AbelianSemiGroup&| |SetCategory&| NIL
                         |BasicType&| NIL)
                      (CONS '#((|Ring|) (|Rng|) (|LeftModule| $$)
                               (|AbelianGroup|)
                               (|CancellationAbelianMonoid|)
                               (|SemiRing|) (|AbelianMonoid|)
                               (|Monoid|) (|SemiRng|) (|SemiGroup|)
                               (|AbelianSemiGroup|) (|SetCategory|)
                               (|unitsKnown|) (|BasicType|)
                               (|CoercibleTo| 22))
                            (|makeByteWordVec2| 51
                                '(1 6 0 14 15 0 6 0 17 0 7 0 18 1 6 22
                                  0 23 0 6 26 27 0 6 0 29 1 6 31 0 32 2
                                  6 31 0 0 34 2 7 31 0 0 36 2 6 0 0 0
                                  39 2 6 0 0 0 41 1 6 0 0 42 2 6 0 0 0
                                  44 2 0 31 0 0 1 1 0 31 0 33 2 0 45 0
                                  0 1 0 0 0 1 2 0 0 6 7 25 1 0 45 0 47
                                  1 0 31 0 35 1 0 7 0 12 1 0 50 0 1 1 0
                                  0 0 48 1 0 51 0 1 2 0 45 0 0 46 1 0 6
                                  0 13 1 0 0 14 19 1 0 22 0 24 0 0 26
                                  28 2 0 0 0 26 1 2 0 0 0 49 1 0 0 0 16
                                  0 0 0 30 2 0 31 0 0 38 1 0 0 0 43 2 0
                                  0 0 0 37 2 0 0 0 0 40 2 0 0 0 26 1 2
                                  0 0 0 49 1 2 0 0 0 0 20 2 0 0 14 0 21
                                  2 0 0 26 0 1 2 0 0 49 0 1)))))
          '|lookupComplete|)) 
