
(/VERSIONCHECK 2) 

(DEFUN |LWORD;lyndon?;OfmB;1| (|w| $)
  (PROG (|f| #1=#:G1805)
    (RETURN
     (SEQ
      (EXIT
       (COND ((SPADCALL |w| (|spadConstant| $ 9) (QREFELT $ 11)) 'NIL)
             ('T
              (SEQ
               (LETT |f| (SPADCALL |w| (QREFELT $ 12))
                     . #2=(|LWORD;lyndon?;OfmB;1|))
               (SEQ G190
                    (COND
                     ((NULL
                       (COND
                        ((SPADCALL |f| (|spadConstant| $ 9) (QREFELT $ 11))
                         'NIL)
                        ('T 'T)))
                      (GO G191)))
                    (SEQ
                     (EXIT
                      (COND
                       ((NULL (SPADCALL |w| |f| (QREFELT $ 13)))
                        (PROGN (LETT #1# 'NIL . #2#) (GO #1#)))
                       ('T (LETT |f| (SPADCALL |f| (QREFELT $ 12)) . #2#)))))
                    NIL (GO G190) G191 (EXIT NIL))
               (EXIT 'T)))))
      #1# (EXIT #1#))))) 

(DEFUN |LWORD;lyndonIfCan;OfmU;2| (|w| $)
  (PROG (|l|)
    (RETURN
     (SEQ (LETT |l| (SPADCALL |w| (QREFELT $ 16)) |LWORD;lyndonIfCan;OfmU;2|)
          (EXIT
           (COND
            ((EQL (SPADCALL |l| (QREFELT $ 19)) 1)
             (CONS 0 (SPADCALL |l| (QREFELT $ 20))))
            ('T (CONS 1 "failed")))))))) 

(DEFUN |LWORD;lyndon;Ofm$;3| (|w| $)
  (PROG (|l|)
    (RETURN
     (SEQ (LETT |l| (SPADCALL |w| (QREFELT $ 16)) |LWORD;lyndon;Ofm$;3|)
          (EXIT
           (COND
            ((EQL (SPADCALL |l| (QREFELT $ 19)) 1)
             (SPADCALL |l| (QREFELT $ 20)))
            ('T (|error| "This word is not a Lyndon word")))))))) 

(DEFUN |LWORD;LetterList| (|w| $)
  (COND ((SPADCALL |w| (|spadConstant| $ 9) (QREFELT $ 11)) NIL)
        ('T
         (CONS (SPADCALL |w| (QREFELT $ 24))
               (|LWORD;LetterList| (SPADCALL |w| (QREFELT $ 12)) $))))) 

(DEFUN |LWORD;factor1| (|gauche| |x| |droite| $)
  (PROG (#1=#:G1842 |g| |d|)
    (RETURN
     (SEQ
      (EXIT
       (SEQ (LETT |g| |gauche| . #2=(|LWORD;factor1|))
            (LETT |d| |droite| . #2#)
            (SEQ G190
                 (COND
                  ((NULL (COND ((SPADCALL |g| (QREFELT $ 25)) 'NIL) ('T 'T)))
                   (GO G191)))
                 (SEQ
                  (EXIT
                   (COND
                    ((SPADCALL (SPADCALL |g| '|first| (QREFELT $ 27)) |x|
                               (QREFELT $ 28))
                     (SEQ
                      (LETT |x|
                            (SPADCALL (SPADCALL |g| '|first| (QREFELT $ 27))
                                      |x| (QREFELT $ 29))
                            . #2#)
                      (EXIT
                       (COND
                        ((SPADCALL |d| (QREFELT $ 25))
                         (LETT |g| (SPADCALL |g| (QREFELT $ 30)) . #2#))
                        ('T
                         (SEQ
                          (LETT |g|
                                (SPADCALL |x| (SPADCALL |g| (QREFELT $ 30))
                                          (QREFELT $ 31))
                                . #2#)
                          (LETT |x| (SPADCALL |d| (QREFELT $ 20)) . #2#)
                          (EXIT
                           (LETT |d| (SPADCALL |d| (QREFELT $ 30))
                                 . #2#))))))))
                    ('T
                     (SEQ (LETT |d| (SPADCALL |x| |d| (QREFELT $ 31)) . #2#)
                          (LETT |x| (SPADCALL |g| (QREFELT $ 20)) . #2#)
                          (EXIT
                           (LETT |g| (SPADCALL |g| (QREFELT $ 30)) . #2#)))))))
                 NIL (GO G190) G191 (EXIT NIL))
            (EXIT
             (PROGN
              (LETT #1# (SPADCALL |x| |d| (QREFELT $ 31)) . #2#)
              (GO #1#)))))
      #1# (EXIT #1#))))) 

(DEFUN |LWORD;factor;OfmL;6| (|w| $)
  (PROG (|l| #1=#:G1847 |u| #2=#:G1846)
    (RETURN
     (SEQ
      (COND ((SPADCALL |w| (|spadConstant| $ 9) (QREFELT $ 11)) NIL)
            ('T
             (SEQ
              (LETT |l|
                    (SPADCALL
                     (PROGN
                      (LETT #2# NIL . #3=(|LWORD;factor;OfmL;6|))
                      (SEQ (LETT |u| NIL . #3#)
                           (LETT #1# (|LWORD;LetterList| |w| $) . #3#) G190
                           (COND
                            ((OR (ATOM #1#)
                                 (PROGN (LETT |u| (CAR #1#) . #3#) NIL))
                             (GO G191)))
                           (SEQ
                            (EXIT
                             (LETT #2# (CONS (SPADCALL |u| (QREFELT $ 32)) #2#)
                                   . #3#)))
                           (LETT #1# (CDR #1#) . #3#) (GO G190) G191
                           (EXIT (NREVERSE0 #2#))))
                     (QREFELT $ 33))
                    . #3#)
              (EXIT
               (|LWORD;factor1| (SPADCALL |l| (QREFELT $ 30))
                (SPADCALL |l| (QREFELT $ 20)) NIL $))))))))) 

(DEFUN |LWORD;<;2$B;7| (|x| |y| $)
  (PROG (|ly| |lx|)
    (RETURN
     (SEQ (LETT |lx| (SPADCALL |x| (QREFELT $ 35)) . #1=(|LWORD;<;2$B;7|))
          (LETT |ly| (SPADCALL |y| (QREFELT $ 35)) . #1#)
          (EXIT
           (COND ((EQL |lx| |ly|) (SPADCALL |x| |y| (QREFELT $ 28)))
                 ('T (< |lx| |ly|)))))))) 

(DEFUN |LWORD;coerce;$Of;8| (|x| $)
  (SPADCALL (SPADCALL (SPADCALL |x| (QREFELT $ 37)) (QREFELT $ 39))
            (QREFELT $ 40))) 

(PUT '|LWORD;coerce;$M;9| '|SPADreplace| '(XLAM (|x|) |x|)) 

(DEFUN |LWORD;coerce;$M;9| (|x| $) |x|) 

(DEFUN |LWORD;LyndonWordsList1;LPiOda;10| (|vl| |n| $)
  (PROG (#1=#:G1870 |lbase1| #2=#:G1877 |b| #3=#:G1876 |a| #4=#:G1875 |i|
         #5=#:G1874 #6=#:G1873 |ll| #7=#:G1872 |w| #8=#:G1871 |base|
         #9=#:G1852)
    (RETURN
     (SEQ
      (EXIT
       (COND ((NULL |vl|) (|error| "empty list"))
             ('T
              (SEQ
               (LETT |base|
                     (SPADCALL
                      (PROG1
                          (LETT #9# |n|
                                . #10=(|LWORD;LyndonWordsList1;LPiOda;10|))
                        (|check-subtype| (>= #9# 0) '(|NonNegativeInteger|)
                                         #9#))
                      NIL (QREFELT $ 44))
                     . #10#)
               (LETT |lbase1|
                     (PROGN
                      (LETT #8# NIL . #10#)
                      (SEQ (LETT |w| NIL . #10#)
                           (LETT #7# (SPADCALL |vl| (QREFELT $ 46)) . #10#)
                           G190
                           (COND
                            ((OR (ATOM #7#)
                                 (PROGN (LETT |w| (CAR #7#) . #10#) NIL))
                             #11=(GO G191)))
                           (SEQ
                            (EXIT
                             (LETT #8# (CONS (SPADCALL |w| (QREFELT $ 32)) #8#)
                                   . #10#)))
                           (LETT #7# (CDR #7#) . #10#) #12=(GO G190) G191
                           (EXIT (NREVERSE0 #8#))))
                     . #10#)
               (SPADCALL |base| 1 |lbase1| (QREFELT $ 48))
               (SEQ (LETT |ll| 2 . #10#) G190
                    (COND ((QSGREATERP |ll| |n|) #11#))
                    (SEQ (LETT |lbase1| NIL . #10#)
                         (SEQ (LETT |a| NIL . #10#)
                              (LETT #6# (SPADCALL |base| 1 (QREFELT $ 49))
                                    . #10#)
                              G190
                              (COND
                               ((OR (ATOM #6#)
                                    (PROGN (LETT |a| (CAR #6#) . #10#) NIL))
                                #11#))
                              (SEQ
                               (EXIT
                                (SEQ (LETT |b| NIL . #10#)
                                     (LETT #5#
                                           (SPADCALL |base| (- |ll| 1)
                                                     (QREFELT $ 49))
                                           . #10#)
                                     G190
                                     (COND
                                      ((OR (ATOM #5#)
                                           (PROGN
                                            (LETT |b| (CAR #5#) . #10#)
                                            NIL))
                                       #11#))
                                     (SEQ
                                      (EXIT
                                       (COND
                                        ((SPADCALL |a| |b| (QREFELT $ 28))
                                         (LETT |lbase1|
                                               (SPADCALL
                                                (SPADCALL |a| |b|
                                                          (QREFELT $ 29))
                                                |lbase1| (QREFELT $ 31))
                                               . #10#)))))
                                     (LETT #5# (CDR #5#) . #10#) #12# G191
                                     (EXIT NIL))))
                              (LETT #6# (CDR #6#) . #10#) #12# G191 (EXIT NIL))
                         (SEQ (LETT |i| 2 . #10#) (LETT #4# (- |ll| 1) . #10#)
                              G190 (COND ((QSGREATERP |i| #4#) #11#))
                              (SEQ
                               (EXIT
                                (SEQ (LETT |a| NIL . #10#)
                                     (LETT #3#
                                           (SPADCALL |base| |i| (QREFELT $ 49))
                                           . #10#)
                                     G190
                                     (COND
                                      ((OR (ATOM #3#)
                                           (PROGN
                                            (LETT |a| (CAR #3#) . #10#)
                                            NIL))
                                       #11#))
                                     (SEQ
                                      (EXIT
                                       (SEQ (LETT |b| NIL . #10#)
                                            (LETT #2#
                                                  (SPADCALL |base| (- |ll| |i|)
                                                            (QREFELT $ 49))
                                                  . #10#)
                                            G190
                                            (COND
                                             ((OR (ATOM #2#)
                                                  (PROGN
                                                   (LETT |b| (CAR #2#) . #10#)
                                                   NIL))
                                              #11#))
                                            (SEQ
                                             (EXIT
                                              (COND
                                               ((SPADCALL |a| |b|
                                                          (QREFELT $ 28))
                                                (COND
                                                 ((OR
                                                   (SPADCALL |b|
                                                             (SPADCALL |a|
                                                                       (QREFELT
                                                                        $ 50))
                                                             (QREFELT $ 28))
                                                   (SPADCALL |b|
                                                             (SPADCALL |a|
                                                                       (QREFELT
                                                                        $ 50))
                                                             (QREFELT $ 51)))
                                                  (LETT |lbase1|
                                                        (SPADCALL
                                                         (SPADCALL |a| |b|
                                                                   (QREFELT $
                                                                            29))
                                                         |lbase1|
                                                         (QREFELT $ 31))
                                                        . #10#)))))))
                                            (LETT #2# (CDR #2#) . #10#) #12#
                                            G191 (EXIT NIL))))
                                     (LETT #3# (CDR #3#) . #10#) #12# G191
                                     (EXIT NIL))))
                              (LETT |i| (QSADD1 |i|) . #10#) #12# G191
                              (EXIT NIL))
                         (EXIT
                          (SPADCALL |base| |ll|
                                    (SPADCALL (ELT $ 28) |lbase1|
                                              (QREFELT $ 53))
                                    (QREFELT $ 48))))
                    (LETT |ll| (QSADD1 |ll|) . #10#) #12# G191 (EXIT NIL))
               (EXIT (PROGN (LETT #1# |base| . #10#) (GO #1#)))))))
      #1# (EXIT #1#))))) 

(DEFUN |LWORD;LyndonWordsList;LPiL;11| (|vl| |n| $)
  (PROG (#1=#:G1879 #2=#:G1878 #3=#:G1880 |i| |v|)
    (RETURN
     (SEQ
      (LETT |v| (SPADCALL |vl| |n| (QREFELT $ 55))
            . #4=(|LWORD;LyndonWordsList;LPiL;11|))
      (EXIT
       (PROGN
        (LETT #1# NIL . #4#)
        (SEQ (LETT |i| 1 . #4#) G190 (COND ((QSGREATERP |i| |n|) (GO G191)))
             (SEQ
              (EXIT
               (PROGN
                (LETT #3# (SPADCALL |v| |i| (QREFELT $ 49)) . #4#)
                (COND (#1# (LETT #2# (SPADCALL #2# #3# (QREFELT $ 56)) . #4#))
                      ('T (PROGN (LETT #2# #3# . #4#) (LETT #1# 'T . #4#)))))))
             (LETT |i| (QSADD1 |i|) . #4#) (GO G190) G191 (EXIT NIL))
        (COND (#1# #2#) ('T (SPADCALL (QREFELT $ 57)))))))))) 

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

(DEFUN |LyndonWord;| (|#1|)
  (PROG (|pv$| $ |dv$| DV$1)
    (RETURN
     (PROGN
      (LETT DV$1 (|devaluate| |#1|) . #1=(|LyndonWord|))
      (LETT |dv$| (LIST '|LyndonWord| DV$1) . #1#)
      (LETT $ (GETREFV 62) . #1#)
      (QSETREFV $ 0 |dv$|)
      (QSETREFV $ 3 (LETT |pv$| (|buildPredVector| 0 0 NIL) . #1#))
      (|haddProp| |$ConstructorCache| '|LyndonWord| (LIST DV$1) (CONS 1 $))
      (|stuffDomainSlots| $)
      (QSETREFV $ 6 |#1|)
      (QSETREFV $ 7 (|Magma| |#1|))
      $)))) 

(MAKEPROP '|LyndonWord| '|infovec|
          (LIST
           '#(NIL NIL NIL NIL NIL (|Magma| 6) (|local| |#1|) '|Rep|
              (|OrderedFreeMonoid| 6) (0 . |One|) (|Boolean|) (4 . =)
              (10 . |rest|) (15 . |lexico|) |LWORD;lyndon?;OfmB;1| (|List| $)
              |LWORD;factor;OfmL;6| (|NonNegativeInteger|) (|List| $$)
              (21 . |#|) (26 . |first|) (|Union| $ '"failed")
              |LWORD;lyndonIfCan;OfmU;2| |LWORD;lyndon;Ofm$;3| (31 . |first|)
              (36 . |null|) '"first" (41 . |elt|) (47 . |lexico|) (53 . *)
              (59 . |rest|) (64 . |cons|) (70 . |coerce|) (75 . |reverse|)
              (|PositiveInteger|) (80 . |length|) |LWORD;<;2$B;7|
              (85 . |coerce|) (|OutputForm|) (90 . |coerce|) (95 . |bracket|)
              |LWORD;coerce;$Of;8| |LWORD;coerce;$M;9|
              (|OneDimensionalArray| 18) (100 . |new|) (|List| 6)
              (106 . |sort|) (|Integer|) (111 . |setelt|) (118 . |elt|)
              (124 . |right|) (129 . =) (|Mapping| 10 $$ $$) (135 . |sort!|)
              (|OneDimensionalArray| 15) |LWORD;LyndonWordsList1;LPiOda;10|
              (141 . |append|) (147 . |nil|) |LWORD;LyndonWordsList;LPiL;11|
              (|Union| 6 '"failed") (|String|) (|SingleInteger|))
           '#(~= 151 |varList| 157 |smaller?| 162 |right| 168 |retractable?|
              173 |retractIfCan| 178 |retract| 183 |min| 188 |max| 194
              |lyndonIfCan| 200 |lyndon?| 205 |lyndon| 210 |lexico| 215
              |length| 221 |left| 226 |latex| 231 |hash| 236 |factor| 241
              |coerce| 246 |LyndonWordsList1| 266 |LyndonWordsList| 272 >= 278
              > 284 = 290 <= 296 < 302)
           'NIL
           (CONS (|makeByteWordVec2| 1 '(0 0 0 0 0 0))
                 (CONS
                  '#(|OrderedSet&| NIL |SetCategory&| |BasicType&|
                     |RetractableTo&| NIL)
                  (CONS
                   '#((|OrderedSet|) (|Comparable|) (|SetCategory|)
                      (|BasicType|) (|RetractableTo| 6) (|CoercibleTo| 38))
                   (|makeByteWordVec2| 61
                                       '(0 8 0 9 2 8 10 0 0 11 1 8 0 0 12 2 8
                                         10 0 0 13 1 18 17 0 19 1 18 2 0 20 1 8
                                         6 0 24 1 18 10 0 25 2 18 2 0 26 27 2 0
                                         10 0 0 28 2 7 0 0 0 29 1 18 0 0 30 2
                                         18 0 2 0 31 1 0 0 6 32 1 18 0 0 33 1 0
                                         34 0 35 1 0 8 0 37 1 8 38 0 39 1 38 0
                                         0 40 2 43 0 17 18 44 1 45 0 0 46 3 43
                                         18 0 47 18 48 2 43 18 0 47 49 1 0 0 0
                                         50 2 0 10 0 0 51 2 18 0 52 0 53 2 18 0
                                         0 0 56 0 18 0 57 2 0 10 0 0 1 1 0 45 0
                                         1 2 0 10 0 0 1 1 0 0 0 50 1 0 10 0 1 1
                                         0 59 0 1 1 0 6 0 1 2 0 0 0 0 1 2 0 0 0
                                         0 1 1 0 21 8 22 1 0 10 8 14 1 0 0 8 23
                                         2 0 10 0 0 28 1 0 34 0 35 1 0 0 0 1 1
                                         0 60 0 1 1 0 61 0 1 1 0 15 8 16 1 0 5
                                         0 42 1 0 8 0 37 1 0 0 6 32 1 0 38 0 41
                                         2 0 54 45 34 55 2 0 15 45 34 58 2 0 10
                                         0 0 1 2 0 10 0 0 1 2 0 10 0 0 51 2 0
                                         10 0 0 1 2 0 10 0 0 36)))))
           '|lookupComplete|)) 
