
(/VERSIONCHECK 2) 

(DEFUN |PERM;smallerElement?| (|a| |b| $)
  (COND
   ((|HasCategory| (QREFELT $ 6) '(|OrderedSet|))
    (SPADCALL |a| |b| (QREFELT $ 9)))
   ((|HasCategory| (QREFELT $ 6) '(|Finite|))
    (< (SPADCALL |a| (QREFELT $ 11)) (SPADCALL |b| (QREFELT $ 11))))
   ('T 'NIL))) 

(DEFUN |PERM;rotateCycle| (|cyc| $)
  (PROG (#1=#:G1838 #2=#:G1837 |minpos| |min| #3=#:G1841 |i|)
    (RETURN
     (SEQ (LETT |min| (|SPADfirst| |cyc|) . #4=(|PERM;rotateCycle|))
          (LETT |minpos| 1 . #4#)
          (SEQ (LETT |i| 2 . #4#)
               (LETT #3# (SPADCALL |cyc| (QREFELT $ 14)) . #4#) G190
               (COND ((QSGREATERP |i| #3#) (GO G191)))
               (SEQ
                (EXIT
                 (COND
                  ((|PERM;smallerElement?| (SPADCALL |cyc| |i| (QREFELT $ 15))
                    |min| $)
                   (SEQ (LETT |min| (SPADCALL |cyc| |i| (QREFELT $ 15)) . #4#)
                        (EXIT (LETT |minpos| |i| . #4#)))))))
               (LETT |i| (QSADD1 |i|) . #4#) (GO G190) G191 (EXIT NIL))
          (EXIT
           (COND ((EQL |minpos| 1) |cyc|)
                 ('T
                  (SPADCALL
                   (SPADCALL |cyc|
                             (PROG1
                                 (LETT #2# (+ (- (LENGTH |cyc|) |minpos|) 1)
                                       . #4#)
                               (|check-subtype| (>= #2# 0)
                                                '(|NonNegativeInteger|) #2#))
                             (QREFELT $ 18))
                   (SPADCALL |cyc|
                             (PROG1 (LETT #1# (- |minpos| 1) . #4#)
                               (|check-subtype| (>= #1# 0)
                                                '(|NonNegativeInteger|) #1#))
                             (QREFELT $ 19))
                   (QREFELT $ 20))))))))) 

(DEFUN |PERM;coerceCycle| (|lls| $)
  (PROG (|perm| #1=#:G1845 |lists|)
    (RETURN
     (SEQ (LETT |perm| (|spadConstant| $ 16) . #2=(|PERM;coerceCycle|))
          (SEQ (LETT |lists| NIL . #2#) (LETT #1# (REVERSE |lls|) . #2#) G190
               (COND
                ((OR (ATOM #1#) (PROGN (LETT |lists| (CAR #1#) . #2#) NIL))
                 (GO G191)))
               (SEQ
                (EXIT
                 (LETT |perm|
                       (SPADCALL (SPADCALL |lists| (QREFELT $ 21)) |perm|
                                 (QREFELT $ 22))
                       . #2#)))
               (LETT #1# (CDR #1#) . #2#) (GO G190) G191 (EXIT NIL))
          (EXIT |perm|))))) 

(DEFUN |PERM;smallerCycle?| (|cyca| |cycb| $)
  (PROG (#1=#:G1847 #2=#:G1849 #3=#:G1850 |i| #4=#:G1851 |j|)
    (RETURN
     (SEQ
      (EXIT
       (COND
        ((NULL (EQL (LENGTH |cyca|) (LENGTH |cycb|)))
         (< (LENGTH |cyca|) (LENGTH |cycb|)))
        ('T
         (SEQ
          (SEQ
           (EXIT
            (SEQ (LETT |j| NIL . #5=(|PERM;smallerCycle?|))
                 (LETT #4# |cycb| . #5#) (LETT |i| NIL . #5#)
                 (LETT #3# |cyca| . #5#) G190
                 (COND
                  ((OR (ATOM #3#) (PROGN (LETT |i| (CAR #3#) . #5#) NIL)
                       (ATOM #4#) (PROGN (LETT |j| (CAR #4#) . #5#) NIL))
                   (GO G191)))
                 (SEQ
                  (EXIT
                   (COND
                    ((NULL (SPADCALL |i| |j| (QREFELT $ 23)))
                     (PROGN
                      (LETT #1#
                            (PROGN
                             (LETT #2# (|PERM;smallerElement?| |i| |j| $)
                                   . #5#)
                             (GO #2#))
                            . #5#)
                      (GO #1#))))))
                 (LETT #3# (PROG1 (CDR #3#) (LETT #4# (CDR #4#) . #5#)) . #5#)
                 (GO G190) G191 (EXIT NIL)))
           #1# (EXIT #1#))
          (EXIT 'NIL)))))
      #2# (EXIT #2#))))) 

(DEFUN |PERM;shorterCycle?| (|cyca| |cycb| $)
  (< (LENGTH |cyca|) (LENGTH |cycb|))) 

(DEFUN |PERM;permord| (|pa| |pb| $)
  (PROG (#1=#:G1854 #2=#:G1856 #3=#:G1857 |i| #4=#:G1858 |j|)
    (RETURN
     (SEQ
      (EXIT
       (SEQ
        (SEQ
         (EXIT
          (SEQ (LETT |j| NIL . #5=(|PERM;permord|))
               (LETT #4# (QCAR |pb|) . #5#) (LETT |i| NIL . #5#)
               (LETT #3# (QCAR |pa|) . #5#) G190
               (COND
                ((OR (ATOM #3#) (PROGN (LETT |i| (CAR #3#) . #5#) NIL)
                     (ATOM #4#) (PROGN (LETT |j| (CAR #4#) . #5#) NIL))
                 (GO G191)))
               (SEQ
                (EXIT
                 (COND
                  ((NULL (SPADCALL |i| |j| (QREFELT $ 24)))
                   (PROGN
                    (LETT #1#
                          (PROGN
                           (LETT #2# (|PERM;smallerCycle?| |i| |j| $) . #5#)
                           (GO #2#))
                          . #5#)
                    (GO #1#))))))
               (LETT #3# (PROG1 (CDR #3#) (LETT #4# (CDR #4#) . #5#)) . #5#)
               (GO G190) G191 (EXIT NIL)))
         #1# (EXIT #1#))
        (EXIT (< (LENGTH (QCAR |pa|)) (LENGTH (QCAR |pb|))))))
      #2# (EXIT #2#))))) 

(DEFUN |PERM;coerceToCycle| (|p| |doSorting?| $)
  (PROG (|cycles| |nextCycle| |im| |nextEltInCycle| |preim| |i|
         |firstEltInCycle|)
    (RETURN
     (SEQ
      (LETT |preim| (SPADCALL |p| 1 (QREFELT $ 25))
            . #1=(|PERM;coerceToCycle|))
      (LETT |im| (SPADCALL |p| 2 (QREFELT $ 25)) . #1#)
      (LETT |cycles| NIL . #1#)
      (SEQ G190
           (COND ((NULL (COND ((NULL |preim|) 'NIL) ('T 'T))) #2=(GO G191)))
           (SEQ (LETT |firstEltInCycle| (|SPADfirst| |preim|) . #1#)
                (LETT |nextCycle| (SPADCALL |firstEltInCycle| (QREFELT $ 26))
                      . #1#)
                (LETT |preim| (CDR |preim|) . #1#)
                (LETT |nextEltInCycle| (|SPADfirst| |im|) . #1#)
                (LETT |im| (CDR |im|) . #1#)
                (SEQ G190
                     (COND
                      ((NULL
                        (COND
                         ((SPADCALL |nextEltInCycle| |firstEltInCycle|
                                    (QREFELT $ 23))
                          'NIL)
                         ('T 'T)))
                       #2#))
                     (SEQ
                      (LETT |nextCycle| (CONS |nextEltInCycle| |nextCycle|)
                            . #1#)
                      (LETT |i|
                            (SPADCALL |nextEltInCycle| |preim| (QREFELT $ 27))
                            . #1#)
                      (LETT |preim| (SPADCALL |preim| |i| (QREFELT $ 28))
                            . #1#)
                      (LETT |nextEltInCycle| (SPADCALL |im| |i| (QREFELT $ 15))
                            . #1#)
                      (EXIT
                       (LETT |im| (SPADCALL |im| |i| (QREFELT $ 28)) . #1#)))
                     NIL #3=(GO G190) G191 (EXIT NIL))
                (LETT |nextCycle| (REVERSE |nextCycle|) . #1#)
                (EXIT
                 (COND
                  ((NULL (NULL (CDR |nextCycle|)))
                   (SEQ
                    (COND
                     (|doSorting?|
                      (COND
                       ((OR (|HasCategory| (QREFELT $ 6) '(|OrderedSet|))
                            (|HasCategory| (QREFELT $ 6) '(|Finite|)))
                        (LETT |nextCycle| (|PERM;rotateCycle| |nextCycle| $)
                              . #1#)))))
                    (EXIT
                     (LETT |cycles| (CONS |nextCycle| |cycles|) . #1#)))))))
           NIL #3# G191 (EXIT NIL))
      (EXIT
       (COND
        (|doSorting?|
         (COND
          ((OR (|HasCategory| (QREFELT $ 6) '(|OrderedSet|))
               (|HasCategory| (QREFELT $ 6) '(|Finite|)))
           (SPADCALL (CONS (|function| |PERM;smallerCycle?|) $) |cycles|
                     (QREFELT $ 31)))
          ('T
           (SPADCALL (CONS (|function| |PERM;shorterCycle?|) $) |cycles|
                     (QREFELT $ 31)))))
        ('T |cycles|))))))) 

(DEFUN |PERM;duplicates?| (|ls| $)
  (PROG (|x| #1=#:G1871)
    (RETURN
     (SEQ
      (EXIT
       (SEQ (LETT |x| (SPADCALL |ls| (QREFELT $ 32)) . #2=(|PERM;duplicates?|))
            (SEQ G190
                 (COND ((NULL (COND ((NULL |x|) 'NIL) ('T 'T))) (GO G191)))
                 (SEQ
                  (EXIT
                   (COND
                    ((SPADCALL (|SPADfirst| |x|) (CDR |x|) (QREFELT $ 33))
                     (PROGN (LETT #1# 'T . #2#) (GO #1#)))
                    ('T (LETT |x| (CDR |x|) . #2#)))))
                 NIL (GO G190) G191 (EXIT NIL))
            (EXIT 'NIL)))
      #1# (EXIT #1#))))) 

(DEFUN |PERM;listRepresentation;$R;9| (|p| $)
  (PROG (|s|)
    (RETURN
     (LETT |s|
           (CONS (SPADCALL |p| 1 (QREFELT $ 25))
                 (SPADCALL |p| 2 (QREFELT $ 25)))
           |PERM;listRepresentation;$R;9|)))) 

(DEFUN |PERM;coercePreimagesImages;L$;10| (|preImageAndImage| $)
  (PROG (|image| |preImage| #1=#:G1879 |i| #2=#:G1880 |pi|)
    (RETURN
     (SEQ (LETT |preImage| NIL . #3=(|PERM;coercePreimagesImages;L$;10|))
          (LETT |image| NIL . #3#)
          (SEQ (LETT |pi| NIL . #3#)
               (LETT #2# (SPADCALL |preImageAndImage| 2 (QREFELT $ 36)) . #3#)
               (LETT |i| NIL . #3#)
               (LETT #1# (SPADCALL |preImageAndImage| 1 (QREFELT $ 36)) . #3#)
               G190
               (COND
                ((OR (ATOM #1#) (PROGN (LETT |i| (CAR #1#) . #3#) NIL)
                     (ATOM #2#) (PROGN (LETT |pi| (CAR #2#) . #3#) NIL))
                 (GO G191)))
               (SEQ
                (EXIT
                 (COND
                  ((NULL (SPADCALL |i| |pi| (QREFELT $ 23)))
                   (SEQ (LETT |preImage| (CONS |i| |preImage|) . #3#)
                        (EXIT (LETT |image| (CONS |pi| |image|) . #3#)))))))
               (LETT #1# (PROG1 (CDR #1#) (LETT #2# (CDR #2#) . #3#)) . #3#)
               (GO G190) G191 (EXIT NIL))
          (EXIT (VECTOR |preImage| |image|)))))) 

(DEFUN |PERM;movedPoints;$S;11| (|p| $)
  (SPADCALL (SPADCALL |p| 1 (QREFELT $ 25)) (QREFELT $ 39))) 

(DEFUN |PERM;degree;$Nni;12| (|p| $)
  (SPADCALL (SPADCALL |p| (QREFELT $ 40)) (QREFELT $ 41))) 

(DEFUN |PERM;=;2$B;13| (|p| |q| $)
  (PROG (#1=#:G1884 #2=#:G1888 |pos| #3=#:G1889 |i| |preimq| |preimp|)
    (RETURN
     (SEQ
      (EXIT
       (COND
        ((NULL
          (EQL
           (LENGTH
            (LETT |preimp| (SPADCALL |p| 1 (QREFELT $ 25))
                  . #4=(|PERM;=;2$B;13|)))
           (LENGTH (LETT |preimq| (SPADCALL |q| 1 (QREFELT $ 25)) . #4#))))
         'NIL)
        ('T
         (SEQ
          (SEQ (LETT |i| 1 . #4#)
               (LETT #3# (SPADCALL |preimp| (QREFELT $ 14)) . #4#) G190
               (COND ((QSGREATERP |i| #3#) (GO G191)))
               (SEQ
                (LETT |pos|
                      (SPADCALL (SPADCALL |preimp| |i| (QREFELT $ 15)) |preimq|
                                (QREFELT $ 27))
                      . #4#)
                (EXIT
                 (COND ((EQL |pos| 0) (PROGN (LETT #2# 'NIL . #4#) (GO #2#)))
                       ('T
                        (SEQ
                         (EXIT
                          (COND
                           ((NULL
                             (SPADCALL
                              (SPADCALL (SPADCALL |p| 2 (QREFELT $ 25)) |i|
                                        (QREFELT $ 15))
                              (SPADCALL (SPADCALL |q| 2 (QREFELT $ 25)) |pos|
                                        (QREFELT $ 15))
                              (QREFELT $ 23)))
                            (PROGN
                             (LETT #1# (PROGN (LETT #2# 'NIL . #4#) (GO #2#))
                                   . #4#)
                             (GO #1#)))))
                         #1# (EXIT #1#))))))
               (LETT |i| (QSADD1 |i|) . #4#) (GO G190) G191 (EXIT NIL))
          (EXIT 'T)))))
      #2# (EXIT #2#))))) 

(DEFUN |PERM;orbit;$SS;14| (|p| |el| $)
  (PROG (|el2| |out|)
    (RETURN
     (SEQ
      (LETT |out| (SPADCALL (SPADCALL |el| (QREFELT $ 26)) (QREFELT $ 44))
            . #1=(|PERM;orbit;$SS;14|))
      (LETT |el2| (SPADCALL |p| |el| (QREFELT $ 45)) . #1#)
      (SEQ G190
           (COND
            ((NULL (COND ((SPADCALL |el2| |el| (QREFELT $ 23)) 'NIL) ('T 'T)))
             (GO G191)))
           (SEQ (SPADCALL |el2| |out| (QREFELT $ 46))
                (EXIT (LETT |el2| (SPADCALL |p| |el2| (QREFELT $ 45)) . #1#)))
           NIL (GO G190) G191 (EXIT NIL))
      (EXIT |out|))))) 

(DEFUN |PERM;cyclePartition;$P;15| (|p| $)
  (PROG (#1=#:G1897 |c| #2=#:G1896)
    (RETURN
     (SEQ
      (SPADCALL
       (PROGN
        (LETT #2# NIL . #3=(|PERM;cyclePartition;$P;15|))
        (SEQ (LETT |c| NIL . #3#)
             (LETT #1# (|PERM;coerceToCycle| |p| 'NIL $) . #3#) G190
             (COND
              ((OR (ATOM #1#) (PROGN (LETT |c| (CAR #1#) . #3#) NIL))
               (GO G191)))
             (SEQ (EXIT (LETT #2# (CONS (LENGTH |c|) #2#) . #3#)))
             (LETT #1# (CDR #1#) . #3#) (GO G190) G191 (EXIT (NREVERSE0 #2#))))
       (QREFELT $ 50)))))) 

(DEFUN |PERM;order;$Nni;16| (|p| $)
  (PROG (#1=#:G1898 |ord|)
    (RETURN
     (SEQ
      (LETT |ord|
            (SPADCALL
             (SPADCALL (SPADCALL (SPADCALL |p| (QREFELT $ 51)) (QREFELT $ 52))
                       (QREFELT $ 53))
             (QREFELT $ 55))
            . #2=(|PERM;order;$Nni;16|))
      (EXIT
       (PROG1 (LETT #1# |ord| . #2#)
         (|check-subtype| (>= #1# 0) '(|NonNegativeInteger|) #1#))))))) 

(DEFUN |PERM;sign;$I;17| (|p| $)
  (COND ((SPADCALL |p| (QREFELT $ 57)) 1) ('T -1))) 

(DEFUN |PERM;even?;$B;18| (|p| $)
  (SPADCALL
   (- (LENGTH (SPADCALL |p| 1 (QREFELT $ 25))) (SPADCALL |p| (QREFELT $ 59)))
   (QREFELT $ 60))) 

(DEFUN |PERM;odd?;$B;19| (|p| $)
  (ODDP
   (- (LENGTH (SPADCALL |p| 1 (QREFELT $ 25))) (SPADCALL |p| (QREFELT $ 59))))) 

(DEFUN |PERM;<;2$B;20| (|pa| |pb| $)
  (PROG (#1=#:G1905 #2=#:G1907 #3=#:G1908 |i| #4=#:G1909 |j| |pbcyc| |pacyc|)
    (RETURN
     (SEQ
      (EXIT
       (SEQ
        (LETT |pacyc| (|PERM;coerceToCycle| |pa| 'T $) . #5=(|PERM;<;2$B;20|))
        (LETT |pbcyc| (|PERM;coerceToCycle| |pb| 'T $) . #5#)
        (SEQ
         (EXIT
          (SEQ (LETT |j| NIL . #5#) (LETT #4# |pbcyc| . #5#)
               (LETT |i| NIL . #5#) (LETT #3# |pacyc| . #5#) G190
               (COND
                ((OR (ATOM #3#) (PROGN (LETT |i| (CAR #3#) . #5#) NIL)
                     (ATOM #4#) (PROGN (LETT |j| (CAR #4#) . #5#) NIL))
                 (GO G191)))
               (SEQ
                (EXIT
                 (COND
                  ((NULL (SPADCALL |i| |j| (QREFELT $ 24)))
                   (PROGN
                    (LETT #1#
                          (PROGN
                           (LETT #2# (|PERM;smallerCycle?| |i| |j| $) . #5#)
                           (GO #2#))
                          . #5#)
                    (GO #1#))))))
               (LETT #3# (PROG1 (CDR #3#) (LETT #4# (CDR #4#) . #5#)) . #5#)
               (GO G190) G191 (EXIT NIL)))
         #1# (EXIT #1#))
        (EXIT
         (< (SPADCALL |pacyc| (QREFELT $ 62))
            (SPADCALL |pbcyc| (QREFELT $ 62))))))
      #2# (EXIT #2#))))) 

(DEFUN |PERM;coerce;L$;21| (|lls| $) (|PERM;coerceCycle| |lls| $)) 

(DEFUN |PERM;coerce;L$;22| (|ls| $) (SPADCALL |ls| (QREFELT $ 21))) 

(DEFUN |PERM;sort;2L;23| (|inList| $)
  (PROG (|outList| #1=#:G1921 |rec| |ownList| #2=#:G1920 |sigma|)
    (RETURN
     (SEQ
      (COND
       ((NULL (|HasCategory| (QREFELT $ 6) '(|OrderedSet|)))
        (COND
         ((NULL (|HasCategory| (QREFELT $ 6) '(|Finite|))) (EXIT |inList|)))))
      (LETT |ownList| NIL . #3=(|PERM;sort;2L;23|))
      (SEQ (LETT |sigma| NIL . #3#) (LETT #2# |inList| . #3#) G190
           (COND
            ((OR (ATOM #2#) (PROGN (LETT |sigma| (CAR #2#) . #3#) NIL))
             #4=(GO G191)))
           (SEQ
            (EXIT
             (LETT |ownList|
                   (SPADCALL (CONS (|PERM;coerceToCycle| |sigma| 'T $) |sigma|)
                             |ownList| (QREFELT $ 68))
                   . #3#)))
           (LETT #2# (CDR #2#) . #3#) #5=(GO G190) G191 (EXIT NIL))
      (LETT |ownList|
            (SPADCALL (CONS (|function| |PERM;permord|) $) |ownList|
                      (QREFELT $ 70))
            . #3#)
      (LETT |outList| (SPADCALL (QREFELT $ 72)) . #3#)
      (SEQ (LETT |rec| NIL . #3#) (LETT #1# |ownList| . #3#) G190
           (COND
            ((OR (ATOM #1#) (PROGN (LETT |rec| (CAR #1#) . #3#) NIL)) #4#))
           (SEQ
            (EXIT
             (LETT |outList| (SPADCALL (QCDR |rec|) |outList| (QREFELT $ 73))
                   . #3#)))
           (LETT #1# (CDR #1#) . #3#) #5# G191 (EXIT NIL))
      (EXIT (SPADCALL |outList| (QREFELT $ 74))))))) 

(DEFUN |PERM;coerce;$Of;24| (|p| $)
  (PROG (|outfmL| |outcycL| #1=#:G1931 |elt| #2=#:G1930 |cycle| |cycles|)
    (RETURN
     (SEQ
      (LETT |cycles| (|PERM;coerceToCycle| |p| 'T $)
            . #3=(|PERM;coerce;$Of;24|))
      (LETT |outfmL| NIL . #3#)
      (SEQ (LETT |cycle| NIL . #3#) (LETT #2# |cycles| . #3#) G190
           (COND
            ((OR (ATOM #2#) (PROGN (LETT |cycle| (CAR #2#) . #3#) NIL))
             #4=(GO G191)))
           (SEQ (LETT |outcycL| NIL . #3#)
                (SEQ (LETT |elt| NIL . #3#) (LETT #1# |cycle| . #3#) G190
                     (COND
                      ((OR (ATOM #1#) (PROGN (LETT |elt| (CAR #1#) . #3#) NIL))
                       #4#))
                     (SEQ
                      (EXIT
                       (LETT |outcycL|
                             (CONS (SPADCALL |elt| (QREFELT $ 77)) |outcycL|)
                             . #3#)))
                     (LETT #1# (CDR #1#) . #3#) #5=(GO G190) G191 (EXIT NIL))
                (EXIT
                 (LETT |outfmL|
                       (CONS
                        (SPADCALL (SPADCALL (REVERSE |outcycL|) (QREFELT $ 78))
                                  (QREFELT $ 79))
                        |outfmL|)
                       . #3#)))
           (LETT #2# (CDR #2#) . #3#) #5# G191 (EXIT NIL))
      (EXIT
       (COND ((NULL |outfmL|) (SPADCALL 1 (QREFELT $ 80)))
             ((NULL (CDR |outfmL|)) (|SPADfirst| |outfmL|))
             ('T (SPADCALL (REVERSE |outfmL|) (QREFELT $ 81))))))))) 

(DEFUN |PERM;cycles;L$;25| (|vs| $) (|PERM;coerceCycle| |vs| $)) 

(DEFUN |PERM;cycle;L$;26| (|ls| $)
  (COND ((< (LENGTH |ls|) 2) (|spadConstant| $ 16))
        ((|PERM;duplicates?| |ls| $)
         (|error| "cycle: the input contains duplicates"))
        ('T
         (VECTOR |ls|
                 (APPEND (CDR |ls|)
                         (SPADCALL (|SPADfirst| |ls|) (QREFELT $ 26))))))) 

(DEFUN |PERM;coerceListOfPairs;L$;27| (|loP| $)
  (PROG (|im| |preim| #1=#:G1944 |pair|)
    (RETURN
     (SEQ (LETT |preim| NIL . #2=(|PERM;coerceListOfPairs;L$;27|))
          (LETT |im| NIL . #2#)
          (SEQ (LETT |pair| NIL . #2#) (LETT #1# |loP| . #2#) G190
               (COND
                ((OR (ATOM #1#) (PROGN (LETT |pair| (CAR #1#) . #2#) NIL))
                 (GO G191)))
               (SEQ
                (EXIT
                 (COND
                  ((NULL
                    (SPADCALL (|SPADfirst| |pair|)
                              (SPADCALL |pair| (QREFELT $ 84)) (QREFELT $ 23)))
                   (SEQ
                    (LETT |preim| (CONS (|SPADfirst| |pair|) |preim|) . #2#)
                    (EXIT
                     (LETT |im| (CONS (SPADCALL |pair| (QREFELT $ 84)) |im|)
                           . #2#)))))))
               (LETT #1# (CDR #1#) . #2#) (GO G190) G191 (EXIT NIL))
          (COND
           ((OR (|PERM;duplicates?| |preim| $)
                (OR (|PERM;duplicates?| |im| $)
                    (NULL
                     (SPADCALL (SPADCALL |preim| (QREFELT $ 44))
                               (SPADCALL |im| (QREFELT $ 44))
                               (QREFELT $ 85)))))
            (EXIT
             (|error|
              "coerceListOfPairs: the input cannot be interpreted as a permutation"))))
          (EXIT (VECTOR |preim| |im|)))))) 

(DEFUN |PERM;*;3$;28| (|q| |p| $)
  (PROG (|imOfq| |preimOfq| |imOfqp| |preimOfqp| |el| |j| #1=#:G1953 |i|
         |imOfp| |preimOfp|)
    (RETURN
     (SEQ
      (LETT |preimOfp|
            (SPADCALL (SPADCALL |p| 1 (QREFELT $ 25)) (QREFELT $ 88))
            . #2=(|PERM;*;3$;28|))
      (LETT |imOfp| (SPADCALL (SPADCALL |p| 2 (QREFELT $ 25)) (QREFELT $ 88))
            . #2#)
      (LETT |preimOfq| (SPADCALL |q| 1 (QREFELT $ 25)) . #2#)
      (LETT |imOfq| (SPADCALL |q| 2 (QREFELT $ 25)) . #2#)
      (LETT |preimOfqp| NIL . #2#) (LETT |imOfqp| NIL . #2#)
      (SEQ (LETT |i| 1 . #2#) (LETT #1# (QVSIZE |preimOfp|) . #2#) G190
           (COND ((QSGREATERP |i| #1#) (GO G191)))
           (SEQ
            (LETT |j|
                  (SPADCALL (SPADCALL |imOfp| |i| (QREFELT $ 89)) |preimOfq|
                            (QREFELT $ 27))
                  . #2#)
            (EXIT
             (COND
              ((EQL |j| 0)
               (SEQ
                (LETT |preimOfqp|
                      (CONS (SPADCALL |preimOfp| |i| (QREFELT $ 89))
                            |preimOfqp|)
                      . #2#)
                (EXIT
                 (LETT |imOfqp|
                       (CONS (SPADCALL |imOfp| |i| (QREFELT $ 89)) |imOfqp|)
                       . #2#))))
              ('T
               (SEQ (LETT |el| (SPADCALL |imOfq| |j| (QREFELT $ 15)) . #2#)
                    (COND
                     ((NULL
                       (SPADCALL |el| (SPADCALL |preimOfp| |i| (QREFELT $ 89))
                                 (QREFELT $ 23)))
                      (SEQ
                       (LETT |preimOfqp|
                             (CONS (SPADCALL |preimOfp| |i| (QREFELT $ 89))
                                   |preimOfqp|)
                             . #2#)
                       (EXIT (LETT |imOfqp| (CONS |el| |imOfqp|) . #2#)))))
                    (LETT |preimOfq| (SPADCALL |preimOfq| |j| (QREFELT $ 28))
                          . #2#)
                    (EXIT
                     (LETT |imOfq| (SPADCALL |imOfq| |j| (QREFELT $ 28))
                           . #2#)))))))
           (LETT |i| (QSADD1 |i|) . #2#) (GO G190) G191 (EXIT NIL))
      (EXIT
       (VECTOR (APPEND |preimOfqp| |preimOfq|) (APPEND |imOfqp| |imOfq|))))))) 

(PUT '|PERM;One;$;29| '|SPADreplace| '(XLAM NIL (MAKEARR1 2 NIL))) 

(DEFUN |PERM;One;$;29| ($) (MAKEARR1 2 NIL)) 

(DEFUN |PERM;inv;2$;30| (|p| $)
  (VECTOR (SPADCALL |p| 2 (QREFELT $ 25)) (SPADCALL |p| 1 (QREFELT $ 25)))) 

(DEFUN |PERM;eval;$2S;31| (|p| |el| $)
  (PROG (|pos|)
    (RETURN
     (SEQ
      (LETT |pos|
            (SPADCALL |el| (SPADCALL |p| 1 (QREFELT $ 25)) (QREFELT $ 27))
            |PERM;eval;$2S;31|)
      (EXIT
       (COND ((EQL |pos| 0) |el|)
             ('T
              (SPADCALL (SPADCALL |p| 2 (QREFELT $ 25)) |pos|
                        (QREFELT $ 15))))))))) 

(DEFUN |PERM;elt;$2S;32| (|p| |el| $) (SPADCALL |p| |el| (QREFELT $ 45))) 

(DEFUN |PERM;numberOfCycles;$Nni;33| (|p| $)
  (LENGTH (|PERM;coerceToCycle| |p| 'NIL $))) 

(DEFUN |PERM;coerceImages;L$;34| (|image| $)
  (PROG (|preImage| #1=#:G1964 |i| #2=#:G1963)
    (RETURN
     (SEQ
      (LETT |preImage|
            (PROGN
             (LETT #2# NIL . #3=(|PERM;coerceImages;L$;34|))
             (SEQ (LETT |i| 1 . #3#)
                  (LETT #1# (SPADCALL |image| (QREFELT $ 14)) . #3#) G190
                  (COND ((QSGREATERP |i| #1#) (GO G191)))
                  (SEQ
                   (EXIT
                    (LETT #2# (CONS (SPADCALL |i| (QREFELT $ 92)) #2#) . #3#)))
                  (LETT |i| (QSADD1 |i|) . #3#) (GO G190) G191
                  (EXIT (NREVERSE0 #2#))))
            . #3#)
      (EXIT (SPADCALL (LIST |preImage| |image|) (QREFELT $ 37))))))) 

(DEFUN |PERM;coerceImages;L$;35| (|image| $)
  (PROG (|preImage| #1=#:G1965 #2=#:G1970 |i| #3=#:G1969)
    (RETURN
     (SEQ
      (LETT |preImage|
            (PROGN
             (LETT #3# NIL . #4=(|PERM;coerceImages;L$;35|))
             (SEQ (LETT |i| 1 . #4#)
                  (LETT #2# (SPADCALL |image| (QREFELT $ 14)) . #4#) G190
                  (COND ((QSGREATERP |i| #2#) (GO G191)))
                  (SEQ
                   (EXIT
                    (LETT #3#
                          (CONS
                           (SPADCALL
                            (PROG1 (LETT #1# |i| . #4#)
                              (|check-subtype| (> #1# 0) '(|PositiveInteger|)
                                               #1#))
                            (QREFELT $ 94))
                           #3#)
                          . #4#)))
                  (LETT |i| (QSADD1 |i|) . #4#) (GO G190) G191
                  (EXIT (NREVERSE0 #3#))))
            . #4#)
      (EXIT (SPADCALL (LIST |preImage| |image|) (QREFELT $ 37))))))) 

(DEFUN |PERM;fixedPoints;$S;36| (|p| $)
  (SPADCALL (SPADCALL |p| (QREFELT $ 40)) (QREFELT $ 95))) 

(DEFUN |PERM;cyclePartition;$P;37| (|p| $)
  (PROG (|pt| #1=#:G1976 |c| #2=#:G1975)
    (RETURN
     (SEQ
      (LETT |pt|
            (SPADCALL
             (PROGN
              (LETT #2# NIL . #3=(|PERM;cyclePartition;$P;37|))
              (SEQ (LETT |c| NIL . #3#)
                   (LETT #1# (|PERM;coerceToCycle| |p| 'NIL $) . #3#) G190
                   (COND
                    ((OR (ATOM #1#) (PROGN (LETT |c| (CAR #1#) . #3#) NIL))
                     (GO G191)))
                   (SEQ (EXIT (LETT #2# (CONS (LENGTH |c|) #2#) . #3#)))
                   (LETT #1# (CDR #1#) . #3#) (GO G190) G191
                   (EXIT (NREVERSE0 #2#))))
             (QREFELT $ 50))
            . #3#)
      (EXIT
       (SPADCALL |pt|
                 (SPADCALL
                  (SPADCALL
                   (LIST
                    (SPADCALL (SPADCALL |p| (QREFELT $ 96)) (QREFELT $ 41)))
                   (QREFELT $ 50))
                  (QREFELT $ 97))
                 (QREFELT $ 98))))))) 

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

(DEFUN |Permutation;| (|#1|)
  (PROG (|pv$| #1=#:G1980 $ |dv$| DV$1)
    (RETURN
     (PROGN
      (LETT DV$1 (|devaluate| |#1|) . #2=(|Permutation|))
      (LETT |dv$| (LIST '|Permutation| DV$1) . #2#)
      (LETT $ (GETREFV 102) . #2#)
      (QSETREFV $ 0 |dv$|)
      (QSETREFV $ 3
                (LETT |pv$|
                      (|buildPredVector| 0 0
                                         (LIST
                                          (|HasCategory| |#1| '(|OrderedSet|))
                                          (LETT #1#
                                                (|HasCategory| |#1|
                                                               '(|Finite|))
                                                . #2#)
                                          (OR #1#
                                              (|HasCategory| |#1|
                                                             '(|OrderedSet|)))))
                      . #2#))
      (|haddProp| |$ConstructorCache| '|Permutation| (LIST DV$1) (CONS 1 $))
      (|stuffDomainSlots| $)
      (QSETREFV $ 6 |#1|)
      (QSETREFV $ 7 (|Vector| (|List| |#1|)))
      (COND
       ((|HasCategory| |#1| '(|IntegerNumberSystem|))
        (QSETREFV $ 93
                  (CONS (|dispatchFunction| |PERM;coerceImages;L$;34|) $))))
      (COND
       ((|testBitVector| |pv$| 2)
        (PROGN
         (QSETREFV $ 93
                   (CONS (|dispatchFunction| |PERM;coerceImages;L$;35|) $))
         (QSETREFV $ 96 (CONS (|dispatchFunction| |PERM;fixedPoints;$S;36|) $))
         (QSETREFV $ 51
                   (CONS (|dispatchFunction| |PERM;cyclePartition;$P;37|)
                         $)))))
      $)))) 

(MAKEPROP '|Permutation| '|infovec|
          (LIST
           '#(NIL NIL NIL NIL NIL NIL (|local| |#1|) '|Rep| (|Boolean|) (0 . <)
              (|PositiveInteger|) (6 . |lookup|) (|Integer|) (|List| 6)
              (11 . |maxIndex|) (16 . |elt|)
              (CONS IDENTITY (FUNCALL (|dispatchFunction| |PERM;One;$;29|) $))
              (|NonNegativeInteger|) (22 . |last|) (28 . |first|)
              (34 . |concat|) |PERM;cycle;L$;26| |PERM;*;3$;28| (40 . =)
              (46 . =) (52 . |elt|) (58 . |list|) (63 . |position|)
              (69 . |delete|) (|Mapping| 8 13 13) (|List| 13) (75 . |sort|)
              (81 . |copy|) (86 . |member?|)
              (|Record| (|:| |preimage| 13) (|:| |image| 13))
              |PERM;listRepresentation;$R;9| (92 . |elt|)
              |PERM;coercePreimagesImages;L$;10| (|Set| 6) (98 . |construct|)
              |PERM;movedPoints;$S;11| (103 . |#|) |PERM;degree;$Nni;12|
              |PERM;=;2$B;13| (108 . |brace|) |PERM;eval;$2S;31|
              (113 . |insert!|) |PERM;orbit;$SS;14| (|List| 12) (|Partition|)
              (119 . |partition|) |PERM;cyclePartition;$P;15| (124 . |convert|)
              (129 . |removeDuplicates|) (|List| $) (134 . |lcm|)
              |PERM;order;$Nni;16| |PERM;even?;$B;18| |PERM;sign;$I;17|
              |PERM;numberOfCycles;$Nni;33| (139 . |even?|) |PERM;odd?;$B;19|
              (144 . |maxIndex|) |PERM;<;2$B;20| |PERM;coerce;L$;21|
              |PERM;coerce;L$;22| (|Record| (|:| |cycl| 30) (|:| |permut| $$))
              (|List| 66) (149 . |cons|) (|Mapping| 8 66 66) (155 . |sort|)
              (|List| $$) (161 . |nil|) (165 . |cons|) (171 . |reverse|)
              |PERM;sort;2L;23| (|OutputForm|) (176 . |coerce|)
              (181 . |blankSeparate|) (186 . |paren|) (191 . |outputForm|)
              (196 . |hconcat|) |PERM;coerce;$Of;24| |PERM;cycles;L$;25|
              (201 . |second|) (206 . =) |PERM;coerceListOfPairs;L$;27|
              (|Vector| 6) (212 . |construct|) (217 . |elt|) |PERM;inv;2$;30|
              |PERM;elt;$2S;32| (223 . |coerce|) (228 . |coerceImages|)
              (233 . |index|) (238 . |complement|) (243 . |fixedPoints|)
              (248 . |conjugate|) (253 . +) (|Union| $ '"failed")
              (|SingleInteger|) (|String|))
           '#(~= 259 |sort| 265 |smaller?| 270 |sign| 276 |sample| 281 |recip|
              285 |order| 290 |orbit| 295 |one?| 301 |odd?| 306
              |numberOfCycles| 311 |movedPoints| 316 |min| 321 |max| 327
              |listRepresentation| 333 |latex| 338 |inv| 343 |hash| 348
              |fixedPoints| 353 |even?| 358 |eval| 363 |elt| 369 |degree| 375
              |cycles| 380 |cyclePartition| 385 |cycle| 390 |conjugate| 395
              |commutator| 401 |coercePreimagesImages| 407 |coerceListOfPairs|
              412 |coerceImages| 417 |coerce| 422 ^ 437 |One| 455 >= 459 > 465
              = 471 <= 477 < 483 / 489 * 495)
           'NIL
           (CONS (|makeByteWordVec2| 3 '(0 0 0 3 0 3 0 0 0 0))
                 (CONS
                  '#(NIL |Group&| |Monoid&| |OrderedSet&| |SemiGroup&| NIL
                     |SetCategory&| |BasicType&| NIL NIL)
                  (CONS
                   '#((|PermutationCategory| 6) (|Group|) (|Monoid|)
                      (|OrderedSet|) (|SemiGroup|) (|Comparable|)
                      (|SetCategory|) (|BasicType|) (|unitsKnown|)
                      (|CoercibleTo| 76))
                   (|makeByteWordVec2| 101
                                       '(2 6 8 0 0 9 1 6 10 0 11 1 13 12 0 14 2
                                         13 6 0 12 15 2 13 0 0 17 18 2 13 0 0
                                         17 19 2 13 0 0 0 20 2 6 8 0 0 23 2 13
                                         8 0 0 24 2 7 13 0 12 25 1 13 0 6 26 2
                                         13 12 6 0 27 2 13 0 0 12 28 2 30 0 29
                                         0 31 1 13 0 0 32 2 13 8 6 0 33 2 30 13
                                         0 12 36 1 38 0 13 39 1 38 17 0 41 1 38
                                         0 13 44 2 38 0 6 0 46 1 49 0 48 50 1
                                         49 48 0 52 1 48 0 0 53 1 12 0 54 55 1
                                         12 8 0 60 1 30 12 0 62 2 67 0 66 0 68
                                         2 67 0 69 0 70 0 71 0 72 2 71 0 2 0 73
                                         1 71 0 0 74 1 6 76 0 77 1 76 0 54 78 1
                                         76 0 0 79 1 76 0 12 80 1 76 0 54 81 1
                                         13 6 0 84 2 38 8 0 0 85 1 87 0 13 88 2
                                         87 6 0 12 89 1 6 0 12 92 1 0 0 13 93 1
                                         6 0 10 94 1 38 0 0 95 1 0 38 0 96 1 49
                                         0 0 97 2 49 0 0 0 98 2 0 8 0 0 1 1 0
                                         54 54 75 2 3 8 0 0 1 1 0 12 0 58 0 0 0
                                         1 1 0 99 0 1 1 0 17 0 56 2 0 38 0 6 47
                                         1 0 8 0 1 1 0 8 0 61 1 0 17 0 59 1 0
                                         38 0 40 2 3 0 0 0 1 2 3 0 0 0 1 1 0 34
                                         0 35 1 0 101 0 1 1 0 0 0 90 1 0 100 0
                                         1 1 2 38 0 96 1 0 8 0 57 2 0 6 0 6 45
                                         2 0 6 0 6 91 1 0 17 0 42 1 0 0 30 83 1
                                         0 49 0 51 1 0 0 13 21 2 0 0 0 0 1 2 0
                                         0 0 0 1 1 0 0 30 37 1 0 0 30 86 1 0 0
                                         13 93 1 0 0 13 65 1 0 0 30 64 1 0 76 0
                                         82 2 0 0 0 12 1 2 0 0 0 17 1 2 0 0 0
                                         10 1 0 0 0 16 2 3 8 0 0 1 2 3 8 0 0 1
                                         2 0 8 0 0 43 2 3 8 0 0 1 2 0 8 0 0 63
                                         2 0 0 0 0 1 2 0 0 0 0 22)))))
           '|lookupComplete|)) 
