
(/VERSIONCHECK 2) 

(DEFUN |LWORD;lyndon?;OfmB;1| (|w| $)
  (PROG (#0=#:G1828 |f|)
    (RETURN
      (SEQ (EXIT (COND
                   ((SPADCALL |w| (|spadConstant| $ 9) (QREFELT $ 11))
                    'NIL)
                   ('T
                    (SEQ (LETT |f| (SPADCALL |w| (QREFELT $ 12))
                               . #1=(|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 #0# 'NIL . #1#)
                                         (GO #0#)))
                                      ('T
                                       (LETT |f|
                                        (SPADCALL |f| (QREFELT $ 12)) . #1#)))))
                              NIL (GO G190) G191 (EXIT NIL))
                         (EXIT 'T)))))
           #0# (EXIT #0#))))) 

(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 (|d| |g| #0=#:G1846)
    (RETURN
      (SEQ (EXIT (SEQ (LETT |g| |gauche| . #1=(|LWORD;factor1|))
                      (LETT |d| |droite| . #1#)
                      (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)) . #1#)
                                          (EXIT
                                           (COND
                                             ((SPADCALL |d|
                                               (QREFELT $ 25))
                                              (LETT |g|
                                               (SPADCALL |g|
                                                (QREFELT $ 30)) . #1#))
                                             ('T
                                              (SEQ
                                               (LETT |g|
                                                (SPADCALL |x|
                                                 (SPADCALL |g|
                                                  (QREFELT $ 30))
                                                 (QREFELT $ 31)) . #1#)
                                               (LETT |x|
                                                (SPADCALL |d|
                                                 (QREFELT $ 20)) . #1#)
                                               (EXIT
                                                (LETT |d|
                                                 (SPADCALL |d|
                                                  (QREFELT $ 30)) . #1#))))))))
                                        ('T
                                         (SEQ
                                          (LETT |d|
                                           (SPADCALL |x| |d|
                                            (QREFELT $ 31)) . #1#)
                                          (LETT |x|
                                           (SPADCALL |g|
                                            (QREFELT $ 20)) . #1#)
                                          (EXIT
                                           (LETT |g|
                                            (SPADCALL |g|
                                             (QREFELT $ 30)) . #1#)))))))
                           NIL (GO G190) G191 (EXIT NIL))
                      (EXIT (PROGN
                              (LETT #0#
                                    (SPADCALL |x| |d| (QREFELT $ 31)) . #1#)
                              (GO #0#)))))
           #0# (EXIT #0#))))) 

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

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

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

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

(DEFUN |LyndonWord;| (|#1|)
  (PROG (DV$1 |dv$| $ |pv$|)
    (RETURN
      (PROGN
        (LETT DV$1 (|devaluate| |#1|) . #0=(|LyndonWord|))
        (LETT |dv$| (LIST '|LyndonWord| DV$1) . #0#)
        (LETT $ (GETREFV 62) . #0#)
        (QSETREFV $ 0 |dv$|)
        (QSETREFV $ 3 (LETT |pv$| (|buildPredVector| 0 0 NIL) . #0#))
        (|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 |right| 162 |retractable?| 167
             |retractIfCan| 172 |retract| 177 |min| 182 |max| 188
             |lyndonIfCan| 194 |lyndon?| 199 |lyndon| 204 |lexico| 209
             |length| 215 |left| 220 |latex| 225 |hash| 230 |factor|
             235 |coerce| 240 |LyndonWordsList1| 260 |LyndonWordsList|
             266 >= 272 > 278 = 284 <= 290 < 296)
          'NIL
          (CONS (|makeByteWordVec2| 1 '(0 0 0 0 0))
                (CONS '#(|OrderedSet&| |SetCategory&| |BasicType&|
                         |RetractableTo&| NIL)
                      (CONS '#((|OrderedSet|) (|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 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|)) 
