%%
%% This is file `zeckendorfcore.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% zeckendorf.dtx  (with options: `core')
%% 
%% IMPORTANT NOTICE:
%% 
%% For the copyright see the source file.
%% 
%% Any modified versions of this file must be renamed
%% with new filenames distinct from zeckendorfcore.tex.
%% 
%% For distribution of the original source see the terms
%% for copying and modification in the file zeckendorf.dtx.
%% 
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
%% ---------------------------------------------------------------
%% The zeckendorf package: Zeckendorf representation of big integers
%% Copyright (C) 2025 Jean-Francois Burnol
%%
\input xintexpr.sty
\input xintbinhex.sty
\wlog{Package: zeckendorfcore 2025/11/16 v0.9d (JFB)}%
\edef\ZECKrestorecatcodes{\XINTrestorecatcodes}%
\def\ZECKrestorecatcodesendinput{\ZECKrestorecatcodes\endinput}%
\XINTsetcatcodes%
\def\zeck_done#1\xint:{\iffalse{\fi}}%
\let\zeck_abort\zeck_done
\def\Zeck@FPair#1{\expandafter\zeck@fpair\the\numexpr #1.}%
\def\zeck@fpair #1{%
   \xint_UDzerominusfork
      #1-\zeck@fpair_n
      0#1\zeck@fpair_n
      0-\zeck@fpair_p
   \krof #1%
}%
\def\zeck@fpair_p #1.{\Zeck@@FPair{#1}}%
\def\zeck@fpair_n #1.{%
    \ifodd#1 \expandafter\zeck@fpair_ei\else\expandafter\zeck@fpair_eii\fi
    \romannumeral`&&@\Zeck@@FPair{1-#1}%
}%
\def\zeck@fpair_ei{\expandafter\zeck@fpair_fi}%
\def\zeck@fpair_eii{\expandafter\zeck@fpair_fii}%
\def\zeck@fpair_fi#1#2{\expanded{{#2}{\XINT_Opp#1}}}%
\def\zeck@fpair_fii#1#2{\expanded{{\XINT_Opp#2}{#1}}}%
\def\Zeck@@FPair#1{%
    \expandafter\zeck@@fpair@start
    \romannumeral0\xintdectobin{\the\numexpr#1\relax};%
}%
\def\zeck@@fpair@start 1#1{%
    \xint_gob_til_sc#1\zeck@@fpair@done;%
    \xint_UDzerofork
        #1\zeck@@fpair@zero
         0\zeck@@fpair@one
    \krof
    {1}{0}%
}%
\def\zeck@@fpair@zero #1#2#3{%
    \zeck@@fpair@again#3%
    \expanded{%
      {\xintiiMul{#1}{\xintiiAdd{#1}{\xintDouble{#2}}}}%
      {\xintiiAdd{\xintiiSqr{#1}}{\xintiiSqr{#2}}}%
    }%
}%
\def\zeck@@fpair@one #1#2#3{%
    \zeck@@fpair@again#3%
    \expanded{%
      {\xintiiAdd{\xintDouble{\xintiiMul{\xintiiAdd{#1}{#2}}{#1}}}%
                 {\xintiiSqr{#2}}}%
      {\xintiiMul{#1}{\xintiiAdd{#1}{\xintDouble{#2}}}}%
    }%
}%
\def\zeck@@fpair@again#1{%
    \xint_gob_til_sc#1\zeck@@fpair@done;%
    \xint_UDzerofork
        #1{\expandafter\zeck@@fpair@zero}%
         0{\expandafter\zeck@@fpair@one}%
    \krof
}%
\def\zeck@@fpair@done#1\krof{}%
\def\zeck@bracedfirstoftwo  #1#2{{#1}}%
\def\zeck@bracedsecondoftwo #1#2{{#2}}%
\def\Zeck@FN{%
    \expandafter\zeck@bracedfirstoftwo\romannumeral`&&@\Zeck@FPair
}%
\def\Zeck@FNminusOne{%
    \expandafter\zeck@bracedsecondoftwo\romannumeral`&&@\Zeck@FPair
}%
\def\ZeckTheFN{\expandafter\xint_firstoftwo\romannumeral`&&@\Zeck@FPair}%
\def\Zeck@@FN{\expandafter\zeck@bracedfirstoftwo\romannumeral`&&@\Zeck@@FPair}%
\def\ZeckTheFSeq#1#2{%
    \expanded\bgroup\expandafter\zeckthefseq_a
    \the\numexpr #1\expandafter.\the\numexpr #2.%
}%
\def\zeckthefseq_a#1.#2.{\expandafter\zeckthefseq_b\the\numexpr#2-#1.#1.}%
\def\zeckthefseq_b #1{%
    \xint_UDzerominusfork
     0#1\zeckthefseq_n
     #1-\zeckthefseq_one
     0-\zeckthefseq_p
    \krof #1%
}%
\def\zeckthefseq_one0.#1.{{\ZeckTheFN{#1}}\iffalse{\fi}}%
\def\zeckthefseq_p #1.#2.{%
    \expandafter\zeckthefseq_loop
    \the\numexpr #1-1\expandafter.%
    \romannumeral`&&@\expandafter\zeck@sep@with@sc
    \romannumeral`&&@\Zeck@FPair{#2+1}\xintiiadd
}%
\def\zeck@sep@with@sc #1#2{#1;#2;}%
\def\zeckthefseq_n -#1.#2.{%
    \expandafter\zeckthefseq_loop
    \the\numexpr #1-1\expandafter.%
    \romannumeral`&&@\expandafter\zeck@exch@with@sc
    \romannumeral`&&@\Zeck@FPair{#2}\xintiisub
}%
\def\zeck@exch@with@sc #1#2{#2;#1;}%
\def\zeckthefseq_loop #1.#2;#3;#4{%
    {#3}\ifnum #1=\z@ \expandafter\zeckthefseq_end\fi
    \expandafter\zeckthefseq_loop\the\numexpr #1-1\expandafter.%
    \romannumeral0#4{#3}{#2};#2;#4%
}%
\def\zeckthefseq_end#1;#2;#3{{#2}\iffalse{\fi}}%
\def\ZeckNearIndex#1{\xintiRound{0}{%
    \xintFloatDiv[8]{\PoorManLogBaseTen_raw{\xintFloatMul[8]{2236068[-6]}{#1}}}%
                    {20898764[-8]}%
                          }%
}%
\def\ZeckMaxK{\expanded\zeckmaxk}%
\def\zeckmaxk#1{\expandafter\zeckmaxk_fork\romannumeral`&&@#1\xint:}%
\def\zeckmaxk_fork#1{%
  \xint_UDzerominusfork
    #1-{\bgroup\zeck_abort}%
    0#1\zeckmaxk_a
    0-{\zeckmaxk_a#1}%
  \krof
}%
\def\zeckmaxk_a #1\xint:{%
    \expandafter\zeckmaxk_b
    \the\numexpr\ZeckNearIndex{#1}\xint:#1\xint:
}%
\def\zeckmaxk_b #1\xint:{%
    \expandafter\zeckmaxk_c
    \romannumeral`&&@\Zeck@@FPair{#1}#1\xint:
}%
\def\zeckmaxk_c #1#2#3\xint:#4\xint:{%
    \xintiiifGt{#1}{#4}%
       {{\expandafter}\the\numexpr#3-1\relax}%
       {{}#3}%
}%
\def\ZeckIndices{\expanded\zeckindices}%
\let\ZeckZeck\ZeckIndices
\def\zeckindices#1{\bgroup\expandafter\zeckindices_fork\romannumeral`&&@#1\xint:}%
\def\zeckindices_fork#1{%
  \xint_UDzerominusfork
    #1-\zeck_abort
    0#1\zeckindices_a
    0-{\zeckindices_a#1}%
  \krof
}%
\def\zeckindices_a #1\xint:{%
    \expandafter\zeckindices_b
    \the\numexpr\ZeckNearIndex{#1}\xint:#1\xint:
}%
\def\zeckindices_b #1\xint:{%
    \expandafter\zeckindices_c
    \romannumeral`&&@\Zeck@@FPair{#1}#1\xint:
}%
\def\zeckindices_c #1#2#3\xint:#4\xint:{%
    \xintiiifGt{#1}{#4}\zeckindices_A\zeckindices_B
    #1;#2;#3\xint:#4\xint:
}%
\def\zeckindices_A#1;#2;#3\xint:{%
    \the\numexpr#3-1\relax\zeckindices_loop{#2}%
}%
\def\zeckindices_B#1;#2;#3\xint:{%
    #3\zeckindices_loop{#1}%
}%
\def\zeckindices_loop #1#2\xint:{%
    \expandafter\zeckindices_loop_i
    \romannumeral0\xintiisub{#2}{#1}\xint:
}%
\def\zeckindices_loop_i#1{%
    \xint_UDzerofork#1\zeck_done 0{, \zeckindices_a#1}\krof
}%
\def\ZeckBList{\expanded\zeckblist}%
\def\zeckblist#1{\bgroup\expandafter\zeckblist_fork\romannumeral`&&@#1\xint:}%
\def\zeckblist_fork#1{%
  \xint_UDzerominusfork
    #1-\zeck_abort
    0#1\zeckblist_a
    0-{\zeckblist_a#1}%
  \krof
}%
\def\zeckblist_a #1\xint:{%
    \expandafter\zeckblist_b
    \the\numexpr\ZeckNearIndex{#1}\xint:#1\xint:
}%
\def\zeckblist_b #1\xint:{%
    \expandafter\zeckblist_c
    \romannumeral`&&@\Zeck@@FPair{#1}#1\xint:
}%
\def\zeckblist_c #1#2#3\xint:#4\xint:{%
    \xintiiifGt{#1}{#4}\zeckblist_A\zeckblist_B
    #1;#2;#3\xint:#4\xint:
}%
\def\zeckblist_A#1;#2;#3\xint:{%
    {\the\numexpr#3-1\relax}\zeckblist_loop{#2}%
}%
\def\zeckblist_B#1;#2;#3\xint:{%
    {#3}\zeckblist_loop{#1}%
}%
\def\zeckblist_loop#1#2\xint:{%
    \expandafter\zeckblist_loop_i
    \romannumeral0\xintiisub{#2}{#1}\xint:
}%
\def\zeckblist_loop_i#1{\xint_UDzerofork#1\zeck_done 0{\zeckblist_a#1}\krof}%
\def\ZeckWord{\expanded\zeckword}%
\def\zeckword#1{\bgroup\expandafter\zeckword_fork\romannumeral`&&@#1\xint:}%
\def\zeckword_fork#1{%
  \xint_UDzerominusfork
    #1-\zeck_abort
    0#1\zeckword_a
    0-{\zeckword_a#1}%
  \krof
}%
\def\zeckword_a #1\xint:{%
    \expandafter\zeckword_b\the\numexpr\ZeckNearIndex{#1}\xint:
    #1\xint:
}%
\def\zeckword_b #1\xint:{%
    \expandafter\zeckword_c\romannumeral`&&@\Zeck@@FPair{#1}#1\xint:
}%
\def\zeckword_c #1#2#3\xint:#4\xint:{%
    \xintiiifGt{#1}{#4}\zeckword_A\zeckword_B
    #1;#2;#3\xint:#4\xint:
}%
\def\zeckword_A#1;#2;#3\xint:#4\xint:{%
    \expandafter\zeckword_d
    \romannumeral0\xintiisub{#4}{#2}\xint:
    \the\numexpr#3-1.%
}%
\def\zeckword_B#1;#2;#3\xint:#4\xint:{%
    \expandafter\zeckword_d
    \romannumeral0\xintiisub{#4}{#1}\xint:
    #3.%
}%
\def\zeckword_d #1%
    {\xint_UDzerofork#1\zeckword_done0{1\zeckword_e}\krof #1}%
\def\zeckword_done#1\xint:#2.{1\xintReplicate{#2-2}{0}\iffalse{\fi}}%
\def\zeckword_e #1\xint:{%
    \expandafter\zeckword_f\the\numexpr\ZeckNearIndex{#1}\xint:
    #1\xint:
}%
\def\zeckword_f #1\xint:{%
    \expandafter\zeckword_g\romannumeral`&&@\Zeck@@FPair{#1}#1\xint:
}%
\def\zeckword_g #1#2#3\xint:#4\xint:{%
    \xintiiifGt{#1}{#4}\zeckword_gA\zeckword_gB
    #1;#2;#3\xint:#4\xint:
}%
\def\zeckword_gA#1;#2;#3\xint:#4\xint:{%
    \expandafter\zeckword_h
    \the\numexpr#3-1\expandafter.%
    \romannumeral0\xintiisub{#4}{#2}%
    \xint:
}%
\def\zeckword_gB#1;#2;#3\xint:#4\xint:{%
    \expandafter\zeckword_h
    \the\numexpr#3\expandafter.%
    \romannumeral0\xintiisub{#4}{#1}%
    \xint:
}%
\def\zeckword_h #1.#2\xint:#3.{%
    \xintReplicate{#3-#1-1}{0}%
    \zeckword_d #2\xint:#1.%
}%
\def\ZeckHexWord{\romannumeral0\zeckhexword}%
\def\zeckhexword#1{%
  \xintbintohex{%
    \expanded\bgroup\expandafter\zeckword_fork\romannumeral`&&@#1\xint:
  }%
}%
\def\ZeckNFromIndices{\romannumeral0\zecknfromindices}%
\def\zecknfromindices{\zeck@applyandiisum\Zeck@FN}%
\def\zeck@applyandiisum {%
    \expandafter\xintiisum\expanded\zeck@applytocsv
}%
\def\zeck@applytocsv #1#2{%
    {{\expandafter\zeck@applytocsv_a\expandafter#1%
      \romannumeral`&&@#2,;}}%
}%
\def\zeck@applytocsv_a #1#2{%
    \if;#2\expandafter\zeck@applytocsv_done\fi
    \if,#2\expandafter\zeck@applytocsv_skip\fi
    \zeck@applytocsv_b #1#2%
}%
\def\zeck@applytocsv_b #1#2,{%
    #1{#2}%
    \expandafter\zeck@applytocsv_a\expandafter#1\romannumeral`&&@%
}%
\def\zeck@applytocsv_done#1\zeck@applytocsv_b#2;{}%
\def\zeck@applytocsv_skip #1#2,{%
    \expandafter\zeck@applytocsv_a\expandafter#2\romannumeral`&&@%
}%
\def\ZeckNfromWord{\romannumeral0\zecknfromword}%
\def\zecknfromword#1{%
    \expandafter\zecknfromword_a\romannumeral0\xintreversedigits{#1};%
}%
\def\zecknfromword_a{%
    \expandafter\xintiisum\expanded{{\iffalse}}\fi\zecknfromword_b 2.%
}%
\def\zecknfromword_b#1.#2{%
    \if;#2\expandafter\zecknfromword_done\fi
    \if#21\Zeck@@FN{#1}\fi
    \expandafter\zecknfromword_b\the\numexpr#1+1.%
}%
\def\zecknfromword_done#1.{\iffalse{{\fi}}}%
\def\ZeckNfromHexWord{\romannumeral0\zecknfromhexword}%
\def\zecknfromhexword#1{%
    \expandafter\zecknfromword_a\romannumeral0\xintreversedigits{\xintHexToBin{#1}};%
}%
\def\PhiIISign_ab {\romannumeral0\phiiisign_ab}%
\def\phiiisign_ab #1#2{%
    \xintiiifsgn{#1}%
    {% a < 0
     \xintiiifSgn{#2}%
           {-1}%
           {-1}%
           {% a < 0, b > 0, return 1 iff a^2+ab<b^2
            \xintiiifLt{\xintiiMul{#1}{\xintiiAdd{#1}{#2}}}{\xintiiSqr{#2}}%
            {1}%
            {-1}%
           }%
    }%
    {\xintiiSgn{#2}}%
    {% a > 0
     \xintiiifSgn{#2}%
           {% a > 0, b < 0, return 1 iff a^2+ab>b^2
            \xintiiifGt{\xintiiMul{#1}{\xintiiAdd{#1}{#2}}}{\xintiiSqr{#2}}%
            {1}%
            {-1}%
           }%
           {1}%
           {1}%
    }%
}%
\def\bergman_nearindex_A#1;#2;{%
  \xintiRound {0}{%
   \xintFloatDiv[8]{%
    \PoorManLogBaseTen_raw
     {\xintFloatAdd[8]{#1}%
                      {\xintFloatMul[8]{#2}{1618034[-6]}}}%
    }%
    {20898764[-8]}%
  }%
}%
\def\bergman_nearindex_B#1;#2;{%
  \xintiRound {0}{%
   \xintFloatDiv[8]{%
     \PoorManLogBaseTen_raw
     {\xintFloatDiv[8]%
          {\xintiiSub
             {\xintiiMul {#1}{\xintiiAdd{#1}{#2}}}%
             {\xintiiSqr {#2}}%
          }%
          {\xintFloatAdd[8]%
             {#1}{\xintFloatMul[8]{#2}{-618034[-6]}}%
          }%
     }%
    }%
    {20898764[-8]}%
  }%
}%
\def\PhiMaxE{\the\numexpr\phimaxe}%
\def\phimaxe #1{%
    \expandafter\phimaxe_a\expanded{{#1}}%
}%
\def\phimaxe_a #1{\expandafter\phimaxe_b\string#1;}%
\catcode`[=1 \catcode`]=2 \catcode`\{=12 % }
\def\phimaxe_b #1[\if#1{\expandafter\phimaxe_X % }
                   \else\expandafter\phimaxe_N\fi #1]%
\catcode`[=12 \catcode`]=12 \catcode`\{=1 % }
\def\phimaxe_N #1;{\phimaxe_ab {#1}{0};}%
\def\phimaxe_X #1{\expandafter\phimaxe_ab\expandafter{\iffalse}\fi}%
\def\PhiMaxE_ab {\romannumeral0\phimaxe_ab}%
\def\phimaxe_ab #1#2;{%
    \expandafter\phimaxe_i\romannumeral`&&@%
    \ifnum\numexpr\xintiiSgn{#1}*\xintiiSgn{#2}\relax=-1
          \expandafter\bergman_nearindex_B
    \else \expandafter\bergman_nearindex_A
    \fi #1;#2;;#1;#2;%
}%
\def\phimaxe_i #1;{%
    \expandafter\phimaxe_j\romannumeral`&&@\zeck@fpair #1.#1;%
}%
\def\phimaxe_j #1#2#3;#4;#5;{%
    #3\ifnum
        \expandafter\PhiIISign_ab
        \expanded{{\xintiiSub{#2}{#4}}{\xintiiSub{#1}{#5}}}>\xint_c_
    -1\fi\relax
}%
\def\PhiBList{\expanded\phiblist}%
\def\phiblist #1{%
    \expandafter\phiblist_a\expanded{{#1}}%
}%
\def\phiblist_a #1{\expandafter\phiblist_b\string#1;}%
\catcode`[=1 \catcode`]=2 \catcode`\{=12 % }
\def\phiblist_b #1[\if#1{\expandafter\phiblist_X % }
                   \else\expandafter\phiblist_N\fi #1]%
\catcode`[=12 \catcode`]=12 \catcode`\{=1 % }
\def\phiblist_N #1;{\phiblist_ab {#1}{0};}%
\def\phiblist_X #1{\expandafter\phiblist_ab\expandafter{\iffalse}\fi}%
\def\PhiBlist_ab {\expanded\phiblist_ab}%
\def\phiblist_ab #1#2;{{%
    \ifcase\PhiIISign_ab{#1}{#2} %
     0\expandafter\phiblist_stop
    \or
     +\expandafter\phiblist_i
    \else
     -\expandafter\phiblist_neg
    \fi
    #1;#2;%
}}%
\def\phiblist_stop#1;#2;{}%
\def\phiblist_neg#1;#2;{%
    \expandafter\phiblist_i\expanded{\XINT_Opp#1;\XINT_Opp#2;}%
}%
\def\phiblist_i#1;#2;{%
    \expandafter\phiblist_j\romannumeral`&&@%
    \ifnum\numexpr\xintiiSgn{#1}*\xintiiSgn{#2}\relax=-1
          \expandafter\bergman_nearindex_B
    \else \expandafter\bergman_nearindex_A
    \fi #1;#2;;#1;#2;%
}%
\def\phiblist_j #1;{%
    \expandafter\phiblist_k\romannumeral`&&@\zeck@fpair #1.#1;%
}%
\def\phiblist_k #1#2#3;#4;#5;{%
    \if1\expandafter\PhiIISign_ab
        \expanded{{\xintiiSub{#2}{#4}}{\xintiiSub{#1}{#5}}}%
      \expandafter\phiblist_ci
    \else
      \expandafter\phiblist_cii
    \fi
    #1;#2;#3;#4;#5;%
}%
\def\phiblist_ci #1;#2;#3;#4;#5;{%
    {\the\numexpr#3-1\relax}%
    \expandafter\phiblist_again\expanded{%
      {\xintiiSub{\xintiiAdd{#2}{#4}}{#1}}%
      {\xintiiSub{#5}{#2}}%
    }%
}%
\def\phiblist_cii #1;#2;#3;#4;#5;{%
    {#3}%
    \expandafter\phiblist_again
      {\xintiiSub{#4}{#2}}%
      {\xintiiSub{#5}{#1}}%
}%
\def\phiblist_again #1#2{%
    \if0\PhiIISign_ab{#1}{#2}%
        \expandafter\phiblist_stop
    \else
        \expandafter\phiblist_i
    \fi
    #1;#2;%
}%
\def\PhiExponents{\expanded\phiexponents}%
\def\phiexponents#1{{%
   \expandafter\phiexponents_a
   \expanded\expandafter\phiblist_a\expanded{{#1}}%
   ;%
}}%
\def\phiexponents_a #1{\if-#1.\fi\phiexponents_b}%
\def\phiexponents_b #1{%
    \if;#1\expandafter\phiexponents_done\fi
    #1\phiexponents_c
}%
\def\phiexponents_c #1{%
    \if;#1\expandafter\phiexponents_done\fi
    \PhiExponentsSep#1\phiexponents_c
}%
\def\phiexponents_done#1\phiexponents_c{}%
\def\PhiExponentsSep{, }%
\def\PhiBasePhi{\expanded\phibasephi}%
\def\phibasephi#1{{%
   \expandafter\phibasephi_a
   \expanded\expandafter\phiblist_a\expanded{{#1}}%
   ;%
}}%
\def\phibasephi_a #1{%
    \if-#1-\fi
    \if0#1\expandafter\xint_gob_til_sc\fi
    \phibasephi_b
}%
\def\phibasephi_b #1{\phibasephi_c #1.}%
\def\phibasephi_c #1#2.{%
  \if-#1%
     0\PhiBasePhiSep\xintReplicate{#2-1}{0}%
     1\expandafter\phibasephi_n
  \else
     1\expandafter\phibasephi_p
  \fi
  #1#2.%
}%
\def\phibasephi_p #1.#2{\phibasephi_pa #1.#2\xint:}%
\def\phibasephi_pa #1.#2{%
  \if;#2\xintReplicate{#1}{0}\expandafter\xint_gob_til_xint:\fi
  \phibasephi_pb #1.#2%
}%
\def\phibasephi_pb #1.#2#3\xint:{%
  \if-#2%
    \xintReplicate{#1}{0}\PhiBasePhiSep\xintReplicate{#3-1}{0}%
    1\expandafter\phibasephi_n
  \else
    \xintReplicate{#1-#2#3-1}{0}%
    1\expandafter\phibasephi_p
  \fi
  #2#3.%
}%
\def\phibasephi_n #1.#2{\phibasephi_na #1.#2\xint:}%
\def\phibasephi_na #1.#2{%
  \if;#2\expandafter\xint_gob_til_xint:\fi
  \phibasephi_nb #1.#2%
}%
\def\phibasephi_nb #1.#2#3\xint:{%
  \xintReplicate{#1+#3-1}{0}%
  1\phibasephi_n #2#3.%
}%
\def\PhiBasePhiSep{.}%
\def\PhiBaseHexPhi{\expanded\phibasehexphi}%
\def\phibasehexphi#1{\expandafter\phibasehexphi_a\expanded{%
   \expandafter\phibasephi_a
   \expanded\expandafter\phiblist_a\expanded{{#1}}%
   ;}..,;%
}%
\def\phibasehexphi_a #1.#2.#3#4;{{%
    \xintBinToHex{#1}%
    \if.#3.\xintBinToHex{\expanded{#2\expandafter\phibasehexphi_aux
         \romannumeral0\xintlength{#2}.}}\fi
}}%
\def\phibasehexphi_aux #1.{\xintReplicate{4*((#1+1)/4) - #1}{0}}%
\def\PhiXfromExponents{\expanded\phixfromexponents}%
\def\phixfromexponents#1{%
    \expandafter\phixfromexponents_a\romannumeral`&&@#1,;%
}%
\def\phixfromexponents_a #1{%
    \if.#1\expandafter\phixfromexponents_n
     \else\expandafter\phixfromexponents_p
    \fi #1%
}%
\def\phixfromexponents_p #1;{{%
    {\xintiiSum{\expanded{\zeck@applytocsv_a\Zeck@FNminusOne#1;}}}%
    {\xintiiSum{\expanded{\zeck@applytocsv_a\Zeck@FN#1;}}}%
}}%
\def\phixfromexponents_n .#1;{{%
    {\xintiiOpp{\xintiiSum{\expanded{\zeck@applytocsv_a\Zeck@FNminusOne#1;}}}}%
    {\xintiiOpp{\xintiiSum{\expanded{\zeck@applytocsv_a\Zeck@FN#1;}}}}%
}}%
\def\PhiXfromBasePhi{\expanded\phixfrombasephi}%
\def\phixfrombasephi{\expandafter\phixfromexponents\expanded\phiexponentsfromrep}%
\def\phiexponentsfromrep#1{%
    {{\iffalse}\fi\expandafter\phiexponentsfromrep_a\romannumeral`&&@#1.;\xint:}%
}%
\def\phiexponentsfromrep_a #1{%
    \if-#1.\xint_dothis\phiexponentsfromrep_a\fi
    \if.#1\xint_dothis\zeck_done\fi
    \xint_orthat{\phiexponentsfromrep_b #1}%
}%
\def\phiexponentsfromrep_b #1.#2{%
    \expandafter\phiexponentsfromrep_c\romannumeral0\xintreversedigits{#1};%
    \if;#2\expandafter\zeck_done\else
          \expandafter\phiexponentsfromrep_i\fi #2%
}%
\def\phiexponentsfromrep_c{\phiexponentsfromrep_d 0.}%
\def\phiexponentsfromrep_d#1.#2{%
    \if;#2\expandafter\xint_gob_til_dot\fi
    \if#21#1,\fi
    \expandafter\phiexponentsfromrep_d\the\numexpr#1+1.%
}%
\def\phiexponentsfromrep_i{\phiexponentsfromrep_j -1.}%
\def\phiexponentsfromrep_j#1.#2{%
    \if;#2\expandafter\zeck_done\fi
    \if#21#1,\fi
    \expandafter\phiexponentsfromrep_j\the\numexpr#1-1.%
}%
\def\PhiXfromBaseHexPhi{\expanded\phixfrombasehexphi}%
\def\phixfrombasehexphi{\expandafter\phixfromexponents
                        \expanded\phiexponentsfromhexrep}%
\def\phiexponentsfromhexrep#1{%
    {{\iffalse}\fi\expandafter\phiexponentsfromhexrep_a\romannumeral`&&@#1.;\xint:}%
}%
\def\phiexponentsfromhexrep_a #1{%
    \if-#1.\xint_dothis\phiexponentsfromhexrep_a\fi
    \if.#1\xint_dothis\zeck_done\fi
    \xint_orthat{\phiexponentsfromhexrep_b #1}%
}%
\def\phiexponentsfromhexrep_b #1.#2{%
    \expandafter\phiexponentsfromrep_c
        \romannumeral0\xintreversedigits{\xintHexToBin{#1}};%
    \if;#2\expandafter\zeck_done\else
          \expandafter\phiexponentsfromhexrep_i\fi #2%
}%
\def\phiexponentsfromhexrep_i#1;{%
    \expanded{\noexpand\phiexponentsfromrep_j -1.\xintCHexToBin{#1}};%
}%
\def\ZeckKMul{\romannumeral0\zeckkmul}%
\def\zeckkmul#1#2{\expandafter\zeckkmul_a
                  \expanded{\ZeckIndices{#1}%
                            ,;%
                            \ZeckIndices{#2}%
                            ,,}%
}%
\def\ZeckKMulNum#1#2{\romannumeral0\zeckkmul{\xintNum{#1}}{\xintNum{#2}}}%
\def\zeckkmul_a{\expandafter\xintiisum\expanded{{\iffalse}}\fi
                \zeckkmul_b}%
\def\zeckkmul_b#1;#2,{%
    \if\relax#2\relax\expandafter\zeckkmul_done\fi
    \zeckkmul_c{#2}#1,\zeckkmul_b#1;%
}%
\def\zeckkmul_c#1#2,{%
    \if\relax#2\relax\expandafter\xint_gobble_iv\fi
    \Zeck@@FN{#1+#2}\zeckkmul_c{#1}%
}%
\def\zeckkmul_done#1;{\iffalse{{\fi}}}%
\def\ZeckAMul{\romannumeral0\zeckamul}%
\def\ZeckAMulNum#1#2{\romannumeral0\zeckamul{\xintNum{#1}}{\xintNum{#2}}}%
\def\zeckamul#1{\expandafter\zeckamul_in\romannumeral`&&@#1;}%
\def\zeckamul_in#1;#2{\expandafter\zeckamul_a\romannumeral`&&@#2;#1;}%
\def\zeckamul_a #1;#2;{\xintiiadd
    {\xintiiMul{#1}{#2}}
    {\xintiiAdd{\xintiiMul{#1}{\ZeckB{#2}}}{\xintiiMul{\ZeckB{#1}}{#2}}}%
}%
\def\ZeckB{\romannumeral0\zeckb}%
\def\zeckb#1{\xintiisum{\expanded{\iffalse}\fi
             \expandafter\zeckb_a\expanded\zeckindices{#1},,}}%
\def\zeckb_a#1,{%
    \if\relax#1\relax\expandafter\zeckb_done\fi
    \Zeck@@FN{#1-1}\zeckb_a
}%
\def\zeckb_done#1\zeckb_a{\iffalse{\fi}}%
\def\ZeckPrintIndexedSumSep{+\allowbreak}%
\def\ZeckPrintOne#1{F\sb{#1}}%
\def\ZeckPrintIndexedSum#1{%
    \expandafter\zeckprintindexedsum\romannumeral`&&@#1,;%
}%
\def\zeckprintindexedsum#1{%
    \if,#1\expandafter\xint_gob_til_sc\fi \zeckprintindexedsum_a#1%
}%
\def\zeckprintindexedsum_a#1,{\ZeckPrintOne{#1}\zeckprintindexedsum_b}%
\def\zeckprintindexedsum_b #1{%
    \if;#1\expandafter\xint_gob_til_sc\fi
    \ZeckPrintIndexedSumSep\zeckprintindexedsum_a#1%
}%
\let\PhiPrintIndexedSumSep\ZeckPrintIndexedSumSep
\def\PhiPrintOne#1{\phi\sp{#1}}%
\def\PhiPrintIndexedSum#1{%
    \expandafter\phiprintindexedsum\romannumeral`&&@#1,;%
}%
\def\phiprintindexedsum#1{%
    \if,#1\expandafter\xint_gob_til_sc\fi \phiprintindexedsum_a#1%
}%
\def\phiprintindexedsum_a#1,{\PhiPrintOne{#1}\phiprintindexedsum_b}%
\def\phiprintindexedsum_b #1{%
    \if;#1\expandafter\xint_gob_til_sc\fi
    \PhiPrintIndexedSumSep\phiprintindexedsum_a#1%
}%
\def\PhiTypesetX #1{%
    \expandafter\PhiTypesetXPrint\expanded{#1}%
}%
\def\PhiTypesetXPrint #1#2{%
    \xintiiifSgn{#1}%
      {#1\xintiiifSgn{#2}{#2\phi}{}{+#2\phi}}%
      {\xintiiifSgn{#2}{#2\phi}{0}{#2\phi}}%
      {#1\xintiiifSgn{#2}{#2\phi}{}{+#2\phi}}%
}%
\ifdefined\xintdefinfix
  \def\zeckdefinfix{\xintdefinfix {expr}}%
\else
\ifdefined\xint_noxpd\else\let\xint_noxpd\unexpanded\fi % support old xint
\def\ZECK_defbin_c #1#2#3#4#5#6#7#8%
{%
  \XINT_global\def #1##1% \XINT_#8_op_<op>
  {%
    \expanded{\xint_noxpd{#2{##1}}\expandafter}%
    \romannumeral`&&@\expandafter#3\romannumeral`&&@\XINT_expr_getnext
  }%
  \XINT_global\def #2##1##2##3##4% \XINT_#8_exec_<op>
  {%
    \expandafter##2\expandafter##3\expandafter
      {\romannumeral`&&@\XINT:NEhook:f:one:from:two{\romannumeral`&&@#7##1##4}}%
  }%
  \XINT_global\def #3##1% \XINT_#8_check-_<op>
  {%
    \xint_UDsignfork
      ##1{\expandafter#4\romannumeral`&&@#5}%
        -{#4##1}%
    \krof
  }%
  \XINT_global\def #4##1##2% \XINT_#8_checkp_<op>
  {%
    \ifnum ##1>#6%
      \expandafter#4%
      \romannumeral`&&@\csname XINT_#8_op_##2\expandafter\endcsname
    \else
      \expandafter ##1\expandafter ##2%
    \fi
  }%
}%
\def\ZECK_defbin_b #1#2#3#4#5%
{%
  \expandafter\ZECK_defbin_c
  \csname XINT_#1_op_#2\expandafter\endcsname
  \csname XINT_#1_exec_#2\expandafter\endcsname
  \csname XINT_#1_check-_#2\expandafter\endcsname
  \csname XINT_#1_checkp_#2\expandafter\endcsname
  \csname XINT_#1_op_-\romannumeral\ifnum#4>12 #4\else12\fi\expandafter\endcsname
  \csname xint_c_\romannumeral#4\endcsname
  #5%
  {#1}% #8 for \ZECK_defbin_c
  \XINT_global
  \expandafter
  \let\csname XINT_expr_precedence_#2\expandafter\endcsname
      \csname xint_c_\romannumeral#3\endcsname
}%
\def\zeckdefinfix #1#2#3#4%
{%
    \edef\ZECK_tmpa{#1}%
    \edef\ZECK_tmpa{\xint_zapspaces_o\ZECK_tmpa}%
    \edef\ZECK_tmpL{\the\numexpr#3\relax}%
    \edef\ZECK_tmpL
         {\ifnum\ZECK_tmpL<4 4\else\ifnum\ZECK_tmpL<23 \ZECK_tmpL\else 22\fi\fi}%
    \edef\ZECK_tmpR{\the\numexpr#4\relax}%
    \edef\ZECK_tmpR
         {\ifnum\ZECK_tmpR<4 4\else\ifnum\ZECK_tmpR<23 \ZECK_tmpR\else 22\fi\fi}%
    \ZECK_defbin_b {expr}\ZECK_tmpa\ZECK_tmpL\ZECK_tmpR #2%
    \expandafter\ZECK_dotheitselves\ZECK_tmpa\relax
  \unless\ifcsname
    XINT_expr_exec_-\romannumeral\ifnum\ZECK_tmpR>12 \ZECK_tmpR\else 12\fi
  \endcsname
    \xintMessage{zeckendorf}{Error}{Right precedence not among accepted values.}%
    \errhelp{Accepted values include 12, 14, and 17.}%
    \errmessage{Sorry, you can not use \ZECK_tmpR\space as right precedence.}%
  \fi
  \ifxintverbose
    \xintMessage{zeckendorf}{info}{infix operator \ZECK_tmpa\space
    \ifxintglobaldefs globally \fi
        does
        \xint_noxpd{#2}\MessageBreak with precedences \ZECK_tmpL, \ZECK_tmpR;}%
  \fi
}%
\def\ZECK_dotheitselves#1#2%
{%
    \if#2\relax\expandafter\xint_gobble_ii
    \else
  \XINT_global
      \expandafter\edef\csname XINT_expr_itself_#1#2\endcsname{#1#2}%
      \unless\ifcsname XINT_expr_precedence_#1\endcsname
  \XINT_global
        \expandafter\edef\csname XINT_expr_precedence_#1\endcsname
                        {\csname XINT_expr_precedence_\ZECK_tmpa\endcsname}%
  \XINT_global
        \expandafter\odef\csname XINT_expr_op_#1\endcsname
                        {\csname XINT_expr_op_\ZECK_tmpa\endcsname}%
      \fi
    \fi
    \ZECK_dotheitselves{#1#2}%
}%
\def\ZECK_undefbin_b #1#2%
{%
  \XINT_global\expandafter\let
    \csname XINT_#1_op_#2\endcsname\xint_undefined
  \XINT_global\expandafter\let
    \csname XINT_#1_exec_#2\endcsname\xint_undefined
  \XINT_global\expandafter\let
    \csname XINT_#1_check-_#2\endcsname\xint_undefined
  \XINT_global\expandafter\let
    \csname XINT_#1_checkp_#2\endcsname\xint_undefined
  \XINT_global\expandafter\let
    \csname XINT_expr_precedence_#2\endcsname\xint_undefined
  \XINT_global\expandafter\let
    \csname XINT_expr_itself_#2\endcsname\xint_undefined
}%
\def\zeckundefinfix #1%
{%
    \edef\ZECK_tmpa{#1}%
    \edef\ZECK_tmpa{\xint_zapspaces_o\ZECK_tmpa}%
    \ZECK_undefbin_b {expr}\ZECK_tmpa
%%  \ifxintverbose
    \xintMessage{zeckendorf}{Warning}{infix operator \ZECK_tmpa\space
        has been DELETED!}%
%%  \fi
}%
\fi
\def\ZeckDeleteOperator#1{\zeckundefinfix{#1}}%
\def\ZeckSetAsKnuthOp#1{\zeckdefinfix{#1}{\ZeckKMulNum}{14}{14}}%
\def\ZeckSetAsArnouxOp#1{\zeckdefinfix{#1}{\ZeckAMulNum}{14}{14}}%
\ZeckSetAsArnouxOp{$}% $ (<-only to tame Emacs/AUCTeX highlighting)
\ZeckSetAsKnuthOp{$$}% $$
\def\PhiSign{\romannumeral0\phisign}%
\def\phisign #1{%
    \expandafter\phisign_a\expanded{{#1}}%
}%
\def\phisign_a #1{\expandafter\phisign_b\string#1;}%
\catcode`[=1 \catcode`]=2 \catcode`\{=12 % }
\def\phisign_b #1[\if#1{\expandafter\phisign_X % }
                   \else\expandafter\phisign_N\fi #1]%
\catcode`[=12 \catcode`]=12 \catcode`\{=1 % }
\def\phisign_N #1;{\XINT_sgn #1\xint:}%
\def\phisign_X #1{\expandafter\phisign_ab\expandafter{\iffalse}\fi}%
\def\PhiSign_ab {\romannumeral0\phisign_ab}%
\def\phisign_ab #1#2{%
    \xintiiifsgn{#1}%
    {% a < 0
     \xintiiifSgn{#2}%
           {-1}%
           {-1}%
           {% a < 0, b > 0, return 1 iff a^2+ab<b^2
            \xintifLt{\xintMul{#1}{\xintAdd{#1}{#2}}}{\xintSqr{#2}}%
            {1}%
            {-1}%
           }%
    }%
    {\xintiiSgn{#2}}%
    {% a > 0
     \xintiiifSgn{#2}%
           {% a > 0, b < 0, return 1 iff a^2+ab>b^2
            \xintifGt{\xintMul{#1}{\xintAdd{#1}{#2}}}{\xintSqr{#2}}%
            {1}%
            {-1}%
           }%
           {1}%
           {1}%
    }%
}%
\def\PhiAbs{\romannumeral0\phiabs}%
\def\phiabs #1{%
    \expandafter\phiabs_a\expanded{{#1}}%
}%
\def\phiabs_a #1{\expandafter\phiabs_b\string#1}%
\catcode`[=1 \catcode`]=2 \catcode`\{=12 % }
\def\phiabs_b #1[\if#1{\expandafter\phiabs_X % }
                  \else\expandafter\phiabs_N\fi #1]%
\catcode`[=12 \catcode`]=12 \catcode`\{=1 % }
\let\phiabs_N \XINT_abs
\def\phiabs_X #1{\expandafter\phiabs_x\expandafter{\iffalse}\fi}%
\def\phiabs_x #1#2{\expanded{%
   \ifnum\PhiSign_ab {#1}{#2}<\xint_c_
    \expandafter\xint_firstoftwo\else\expandafter\xint_secondoftwo\fi
    {{\XINT_Opp#1}{\XINT_Opp#2}}{{#1}{#2}}%
   }%
}%
\def\PhiNorm{\romannumeral0\phinorm}%
\def\phinorm #1{%
    \expandafter\phinorm_a\expanded{{#1}}%
}%
\def\phinorm_a #1{\expandafter\phinorm_b\detokenize{#1;}{#1}}%
\catcode`[=1 \catcode`]=2 \catcode`\{=12 % }
\def\phinorm_b #1#2;[\if#1{\expandafter\phinorm_X % }
                     \else\expandafter\phinorm_N\fi]%
\catcode`[=12 \catcode`]=12 \catcode`\{=1 % }
\let\phinorm_N\xintsqr
\def\phinorm_X #1{\phinorm_x #1}%
\def\phinorm_x #1#2{\xintsub
  {\xintMul{#1}{\xintAdd{#1}{#2}}}%
  {\xintSqr{#2}}%
}%
\def\PhiConj{\romannumeral0\phiconj}%
\def\phiconj #1{%
    \expandafter\phiconj_a\expanded{{#1}}%
}%
\def\phiconj_a #1{\expandafter\phiconj_b\detokenize{#1;}#1}%
\catcode`[=1 \catcode`]=2 \catcode`\{=12 % }
\def\phiconj_b #1#2;[\if#1{\expandafter\phiconj_X % }
                     \else\expandafter\phiconj_N\fi]%
\catcode`[=12 \catcode`]=12 \catcode`\{=1 % }
\let\phiconj_N\space
\def\phiconj_X #1#2{\expanded{%
  {\xintAdd{#1}{#2}}{\XINT_Opp #2}%
}}%
\def\PhiOpp{\romannumeral0\phiopp}%
\def\phiopp #1{%
    \expandafter\phiopp_a\expanded{{#1}}%
}%
\def\phiopp_a #1{\expandafter\phiopp_b\string#1}%
\catcode`[=1 \catcode`]=2 \catcode`\{=12 % }
\def\phiopp_b #1[\if#1{\expandafter\phiopp_X % }
                  \else\expandafter\phiopp_N\fi #1]%
\catcode`[=12 \catcode`]=12 \catcode`\{=1 % }
\let\phiopp_N \XINT_opp
\def\phiopp_X #1{\expandafter\phiopp_x\expandafter{\iffalse}\fi}%
\def\phiopp_x #1#2{\expanded{%
    {\XINT_Opp #1}{\XINT_Opp #2}%
}}%
\def\PhiAdd{\romannumeral0\phiadd}%
\def\phiadd #1#2{%
    \expandafter\phiadd_a\expanded{{#1}{#2}}%
}%
\def\phiadd_a #1{\expandafter\phiadd_b\string#1;}%
\catcode`[=1 \catcode`]=2 \catcode`\{=12 % }
\def\phiadd_b #1[\if#1{\expandafter\phiadd_X % }
                  \else\expandafter\phiadd_N\fi #1]%
\def\phiadd_N #1;#2[\expandafter\phiadd_n\string#2;[#1]]%
\def\phiadd_n #1[\if#1{\expandafter\phiadd_nX % }
                  \else\expandafter\phiadd_nn\fi #1]%
\def\phiadd_nX #1[\expandafter\phiadd_nx\expandafter[\iffalse]\fi]%
\def\phiadd_X #1[\expandafter\phiadd_x\expandafter[\iffalse]\fi]%
\def\phiadd_x #1;#2[\expandafter\phiadd_xa\string#2;#1]%
\def\phiadd_xa#1[\if#1{\expandafter\phiadd_XX % }
                  \else\expandafter\phiadd_xn\fi #1]%
\def\phiadd_XX #1[\expandafter\phiadd_xx\expandafter[\iffalse]\fi]%
\catcode`[=12 \catcode`]=12 \catcode`\{=1 % }
\def\phiadd_nn #1;{\xintadd{#1}}%
\def\phiadd_nx #1#2;#3{\expandafter
   {\romannumeral0\xintadd{#1}{#3}}{#2}%
}%
\def\phiadd_xn #1;#2{\expandafter
   {\romannumeral0\xintadd{#1}{#2}}%
}%
\def\phiadd_xx #1#2;#3#4{\expanded{%
    {\xintAdd{#1}{#3}}%
    {\xintAdd{#2}{#4}}%
}}%
\def\PhiSub{\romannumeral0\phisub}%
\def\phisub #1#2{%
    \expandafter\phisub_a\expanded{{#1}{#2}}%
}%
\def\phisub_a #1{\expandafter\phisub_b\string#1;}%
\catcode`[=1 \catcode`]=2 \catcode`\{=12 % }
\def\phisub_b #1[\if#1{\expandafter\phisub_X % }
                  \else\expandafter\phisub_N\fi #1]%
\def\phisub_N #1;#2[\expandafter\phisub_n\string#2;[#1]]%
\def\phisub_n #1[\if#1{\expandafter\phisub_nX % }
                  \else\expandafter\phisub_nn\fi #1]%
\def\phisub_nX #1[\expandafter\phisub_nx\expandafter[\iffalse]\fi]%
\def\phisub_X #1[\expandafter\phisub_x\expandafter[\iffalse]\fi]%
\def\phisub_x #1;#2[\expandafter\phisub_xa\string#2;#1]%
\def\phisub_xa#1[\if#1{\expandafter\phisub_XX % }
                  \else\expandafter\phisub_xn\fi #1]%
\def\phisub_XX #1[\expandafter\phisub_xx\expandafter[\iffalse]\fi]%
\catcode`[=12 \catcode`]=12 \catcode`\{=1 % }
\def\phisub_nn #1;#2{\xintsub{#2}{#1}}%
\def\phisub_nx #1#2;#3{\expanded{%
   {\xintSub{#3}{#1}}{\XINT_Opp#2}%
}}%
\def\phisub_xn #1;#2{\expandafter
   {\romannumeral0\xintsub{#2}{#1}}%
}%
\def\phisub_xx #1#2;#3#4{\expanded{%
    {\xintSub{#3}{#1}}%
    {\xintSub{#4}{#2}}%
}}%
\def\PhiMul{\romannumeral0\phimul}%
\def\phimul #1#2{%
    \expandafter\phimul_a\expanded{{#1}{#2}}%
}%
\def\phimul_a #1{\expandafter\phimul_b\string#1;}%
\catcode`[=1 \catcode`]=2 \catcode`\{=12 % }
\def\phimul_b #1[\if#1{\expandafter\phimul_X % }
                  \else\expandafter\phimul_N\fi #1]%
\def\phimul_N #1;#2[\expandafter\phimul_n\string#2;[#1]]%
\def\phimul_n #1[\if#1{\expandafter\phimul_nX % }
                  \else\expandafter\phimul_nn\fi #1]%
\def\phimul_nX #1[\expandafter\phimul_nx\expandafter[\iffalse]\fi]%
\def\phimul_X #1[\expandafter\phimul_x\expandafter[\iffalse]\fi]%
\def\phimul_x #1;#2[\expandafter\phimul_xa\string#2;#1]%
\def\phimul_xa#1[\if#1{\expandafter\phimul_XX % }
                  \else\expandafter\phimul_xn\fi #1]%
\def\phimul_XX #1[\expandafter\phimul_xx\expandafter[\iffalse]\fi]%
\catcode`[=12 \catcode`]=12 \catcode`\{=1 % }
\def\phimul_nn#1;{\xintmul{#1}}%
\def\phimul_nx#1#2;#3{\expanded{%
    {\xintMul{#1}{#3}}{\xintMul{#2}{#3}}%
}}%
\def\phimul_xn#1;#2#3{\expanded{%
    {\xintMul{#1}{#2}}{\xintMul{#1}{#3}}%
}}%
\def\phimul_xx #1#2;#3#4{%
    \expandafter\phimul_xx_a\expanded{%
      \xintMul{#1}{#3};% ca
      \xintMul{#2}{#4};% db
      \xintMul{#1}{#4};% da
      \xintMul{#2}{#3};% cb
    }%
}%
\def\phimul_xx_a #1;#2;#3;#4;{\expanded{%
    {\xintAdd{#1}{#2}}%
    {\xintAdd{#3}{\xintAdd{#4}{#2}}}%
}}%
\def\PhiDiv{\romannumeral0\phidiv}%
\def\phidiv #1#2{%
    \expandafter\phidiv_a\expanded{{#1}{#2}}%
}%
\def\phidiv_a #1{\expandafter\phidiv_b\string#1;}%
\catcode`[=1 \catcode`]=2 \catcode`\{=12 % }
\def\phidiv_b #1[\if#1{\expandafter\phidiv_X % }
                  \else\expandafter\phidiv_N\fi #1]%
\def\phidiv_N #1;#2[\expandafter\phidiv_n\string#2;[#1]]%
\def\phidiv_n #1[\if#1{\expandafter\phidiv_nX % }
                  \else\expandafter\phidiv_nn\fi #1]%
\def\phidiv_nX #1[\expandafter\phidiv_nx\expandafter[\iffalse]\fi]%
\def\phidiv_X #1[\expandafter\phidiv_x\expandafter[\iffalse]\fi]%
\def\phidiv_x #1;#2[\expandafter\phidiv_xa\string#2;#1]%
\def\phidiv_xa#1[\if#1{\expandafter\phidiv_XX % }
                  \else\expandafter\phidiv_xn\fi #1]%
\def\phidiv_XX #1[\expandafter\phidiv_xx\expandafter[\iffalse]\fi]%
\catcode`[=12 \catcode`]=12 \catcode`\{=1 % }
\def\phidiv_nn#1;#2{\xintdiv{#2}{#1}}%
\def\phidiv_nx#1#2{%
    \expandafter\phidiv_nx_a\expanded{%
     {\xintSub{\xintMul{#1}{\xintAdd{#1}{#2}}}{\xintSqr{#2}}}%
    }{#1}{#2}%
}%
\def\phidiv_nx_a#1#2#3;#4{\expanded{%
    {\xintIrr{\xintDiv{\xintMul{#4}{\xintAdd{#2}{#3}}}{#1}}[0]}%
    {\xintIrr{\xintOpp{\xintDiv{\xintMul{#4}{#3}}{#1}}}[0]}%
}}%
\def\phidiv_xn #1;#2#3{\expanded{%
    {\xintIrr{\xintDiv{#2}{#1}}[0]}%
    {\xintIrr{\xintDiv{#3}{#1}}[0]}%
}}%
\def\phidiv_xx #1#2;#3#4{%
    \expandafter\phidiv_xx_a\expanded{%
     \expandafter\phimul_xx
       \expanded{{\xintAdd{#1}{#2}}{\XINT_Opp #2}};{#3}{#4}%
     {\xintSub{\xintMul{#1}{\xintAdd{#1}{#2}}}{\xintSqr{#2}}}%
    }%
}%
\def\phidiv_xx_a #1#2#3{%
    \expanded{%
    {\xintIrr{\xintDiv{#1}{#3}}[0]}%
    {\xintIrr{\xintDiv{#2}{#3}}[0]}%
   }%
}%
\def\PhiPow{\romannumeral0\phipow}%
\def\phipow #1#2{%
    \expandafter\phipow_a\expanded
    {{#1}{\xintNum{#2}}}%
}%
\def\phipow_a #1{\expandafter\phipow_b\string#1;}%
\catcode`[=1 \catcode`]=2 \catcode`\{=12 % }
\def\phipow_b #1[\if#1{\expandafter\phipow_X % }
                  \else\expandafter\phipow_N\fi #1]%
\catcode`[=12 \catcode`]=12 \catcode`\{=1 % }
\def\phipow_N #1;{\xintpow{#1}}%
\def\phipow_X #1{\expandafter\phipow_x\expandafter{\iffalse}\fi}%
\def\phipow_x #1;#2{\phipow_fork #2;#1}%
\def\phipow_fork #1{%
    \xint_UDzerominusfork
       0#1\phipow_neg
       #1-\phipow_zero
        0-\phipow_pos
    \krof #1%
}%
\def\phipow_zero 0;#1#2{{1}{0}}%
\def\phipow_neg -{%
    \expandafter\phiinv_ab\romannumeral0\phipow_pos
}%
\def\phiinv_ab #1#2{%
    \expandafter\phiinv_c\expanded{%
     {\xintSub{\xintMul{#1}{\xintAdd{#1}{#2}}}{\xintSqr{#2}}}%
    }{#1}{#2}%
}%
\def\phiinv_c #1#2#3{\expanded{%
    {\xintIrr{\xintDiv{\xintAdd{#2}{#3}}{#1}}[0]}%
    {\xintIrr{\xintOpp{\xintDiv{#3}{#1}}}[0]}%
}}%
\def\phipow_pos #1;{%
    \expandafter\phipow_xa
    \expanded{10\xintDecToBin{#1}},;%
}%
\def\phipow_xa #1#2#3#4;{%
  \if#3,\expandafter\phipow_done\fi
  \if#31\expandafter\phipow_xo
   \else\expandafter\phipow_xe\fi
  {#1}{#2}#4;%
}%
\def\phipow_done \if#1\fi #2#3;#4#5{{#2}{#3}}%
\def\phipow_xo #1#2{%
  \expandafter\phipow_xo_a\expanded{%
  \xintSqr{#1};\xintMul{#1}{#2};\xintSqr{#2};%
  }%
}%
\def\phipow_xo_a #1;#2;#3;{%
  \expandafter\phipow_xo_b\expanded{%
  \xintAdd{#1}{#3};\xintAdd{#2}{\xintAdd{#2}{#3}};%
  }%
}%
\def\phipow_xo_b#1;#2;#3;#4#5{%
  \expandafter\phipow_xa\romannumeral0%
  \phimul_xx {#1}{#2};{#4}{#5}#3;{#4}{#5}%
}%
\def\phipow_xe #1#2{%
  \expandafter\phipow_xe_a\expanded{%
  \xintSqr{#1};\xintMul{#1}{#2};\xintSqr{#2};%
  }%
}%
\def\phipow_xe_a #1;#2;#3;{%
  \expandafter\phipow_xa\expanded{%
  {\xintAdd{#1}{#3}}{\xintAdd{#2}{\xintAdd{#2}{#3}}}%
  }%
}%
\zeckdefinfix{+}{\PhiAdd}{12}{12}%
\zeckdefinfix{-}{\PhiSub}{12}{12}%
\xintFor #1 in {xii,xiv,xvii}\do{%
    \expandafter\def\csname XINT_expr_exec_-#1\endcsname
    ##1##2##3%
    {%
      \expandafter ##1\expandafter ##2\expandafter
       {%
        \romannumeral`&&@\XINT:NEhook:f:one:from:one
        {\romannumeral`&&@\PhiOpp##3}%
       }%
    }%
}%
\zeckdefinfix{*}{\PhiMul}{14}{14}%
\zeckdefinfix{/}{\PhiDiv}{14}{14}%
\zeckdefinfix{^}{\PhiPow}{18}{17}%
\xintdefvar phi:=[0,1];%
\xintdefvar psi:=[1,-1];%
\def\XINT_expr_func_phinorm #1#2#3%
{%
    \expandafter #1\expandafter #2\expandafter{%
    \romannumeral`&&@\XINT:NEhook:f:one:from:one
    {\romannumeral`&&@\PhiNorm#3}}%
}%
\def\XINT_expr_func_phiconj #1#2#3%
{%
    \expandafter #1\expandafter #2\expandafter{%
    \romannumeral`&&@\XINT:NEhook:f:one:from:one
    {\romannumeral`&&@\PhiConj#3}}%
}%
\def\XINT_expr_func_phisign #1#2#3%
{%
    \expandafter #1\expandafter #2\expandafter{%
    \romannumeral`&&@\XINT:NEhook:f:one:from:one
    {\romannumeral`&&@\PhiSign#3}}%
}%
\def\XINT_expr_func_phiabs #1#2#3%
{%
    \expandafter #1\expandafter #2\expandafter{%
    \romannumeral`&&@\XINT:NEhook:f:one:from:one
    {\romannumeral`&&@\PhiAbs#3}}%
}%
\def\ZeckTheFNNum#1{\ZeckTheFN{\xintNum{#1}}}%
\def\XINT_expr_func_fib #1#2#3%
{%
    \expandafter #1\expandafter #2\expandafter{%
    \romannumeral`&&@\XINT:NEhook:f:one:from:one
    {\romannumeral`&&@\ZeckTheFNNum#3}}%
}%
\def\ZeckTheFSeqNum#1#2{\ZeckTheFSeq{\xintNum{#1}}{\xintNum{#2}}}%
\def\XINT_expr_func_fibseq #1#2#3%
{%
    \expandafter #1\expandafter #2\expandafter{%
    \romannumeral`&&@\XINT:NEhook:f:one:from:two
    {\romannumeral`&&@\ZeckTheFSeqNum#3}}%
}%
\def\ZeckBListNum #1{%
  \expanded\bgroup\expandafter\zeckblist_fork\romannumeral0\xintnum{#1}\xint:
}%
\def\XINT_expr_func_zeckindices #1#2#3%
{%
    \expandafter #1\expandafter #2\expandafter{%
    \romannumeral`&&@\XINT:NEhook:f:one:from:one
    {\romannumeral`&&@\ZeckBListNum#3}}%
}%
\def\Phi@BList#1{\expandafter\expandafter\expandafter
     \phi@blist_b\expandafter\string\romannumeral`&&@#1;}%
\catcode`[=1 \catcode`]=2 \catcode`\{=12 % }
\def\phi@blist_b #1[\if#1{\expandafter\phi@blist_X % }
                    \else\expandafter\phi@blist_N\fi #1]%
\catcode`[=12 \catcode`]=12 \catcode`\{=1 % }
\def\phi@blist_N #1;{%
    \expandafter\xint_gobble_i\expanded
    \expandafter\phiblist_ab \expanded{{\xintNum{#1}}}{0};%
}%
\def\phi@blist_X #1{%
    \expandafter\phi@blist_x\expandafter{\iffalse}\fi
}%
\def\phi@blist_x #1#2;{%
    \expandafter\xint_gobble_i\expanded
    \expandafter\phiblist_ab \expanded{{\xintNum{#1}}{\xintNum{#2}}};%
}%
\def\XINT_expr_func_phiexponents #1#2#3%
{%
    \expandafter #1\expandafter #2\expandafter{%
    \romannumeral`&&@\XINT:NEhook:f:one:from:one
    {\romannumeral`&&@\Phi@BList#3}}%
}%
\endinput
%%
%% End of file `zeckendorfcore.tex'.
