texlive[60926] Master/texmf-dist: xintsession (1nov21)

commits+karl at tug.org commits+karl at tug.org
Mon Nov 1 21:35:16 CET 2021


Revision: 60926
          http://tug.org/svn/texlive?view=revision&revision=60926
Author:   karl
Date:     2021-11-01 21:35:16 +0100 (Mon, 01 Nov 2021)
Log Message:
-----------
xintsession (1nov21)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/plain/xintsession/README.md
    trunk/Master/texmf-dist/tex/plain/xintsession/xintsession.tex

Modified: trunk/Master/texmf-dist/doc/plain/xintsession/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/plain/xintsession/README.md	2021-11-01 20:35:03 UTC (rev 60925)
+++ trunk/Master/texmf-dist/doc/plain/xintsession/README.md	2021-11-01 20:35:16 UTC (rev 60926)
@@ -1,6 +1,6 @@
 # xintsession README #
 
-Release: 0.3b (2021-07-01)
+Release: 0.4alpha (2021-11-01)
 
 ## Usage ##
 
@@ -12,22 +12,22 @@
 
 To start a session:
 
-1. Execute `etex xintsession`, or if available, `rlwrap etex xintsession`
-   to benefit from arrow keys navigation and other improvements such
-   as parentheses highlighting.\
-   \
-   Alternatively, execute `rlwrap etex` and enter `xintsession` at the `**`
-   prompt.\
-   \
-   One can also use the `-jobname` option of `etex` at this step.\
-   \
-   At my locale I added `alias xs="rlwrap etex xintsession"` to my `.bashrc`
-   so I only have to type `xs` at the command line.
+1. Execute `etex xintsession`,
 2. An `>>>` invite appears, and computations can begin!\
    \
    Start entering input, terminate it via a semi-colon `;`.
    Say `&help` for help and `&bye` to quit.
 
+In more details: if available at your locale use `rlwrap etex xintsession` to
+benefit from arrow keys navigation and other improvements such as parentheses
+highlighting. Alternatively, execute `rlwrap etex` and enter `xintsession` at
+the `**` prompt.
+
+One can also use the `-jobname` option of `etex` at this step.
+
+At my locale I added `alias xs="rlwrap etex xintsession"` to my `.bashrc`
+so I only have to type `xs` at the command line.
+
 The above explanations have been tested on a Unixen (Mac OS), and probably
 `rlwrap` is not available on all platforms, but it is not a requirement.
 
@@ -45,25 +45,38 @@
     @_4     4.499205338329425
     >>> add(1/i, i=1..1000);
     @_5     7.485470860550346
-    >>> 1
-    ... +
-    ... \message{xintsession is great!}
-    (executing \message {xintsession is great!} in background)
-    xintsession is great!
-    ... 2
-    ... ;
-    @_6     3.0
+    >>> &pol
+    pol mode (i.e. function definitions use \poldef)
+    >>> P(x):=(x-0.1)^3 (x+1.8)^2 (x^10 - (100x-1)^2);
+
+    P = x^15+33*x^14/10+219*x^13/100-865*x^12/1000+936*x^11/10000-324*x^10/100000-1
+    0000*x^7-328000*x^6/10-2124100*x^5/100+9084700*x^4/1000-11111900*x^3/10000+5198
+    500*x^2/100000-74160*x/100000+324/100000
+        --> &GenFloat(P) lets P become usable as function in fp mode
+        --> &ROOTS(P) (resp. &ROOTS(P,N)) finds all rational roots exactly and
+            all irrational roots with at least 10 (resp. N) fractional digits
+    >>> &ROOTS(P,30)
+    Solving for real roots of P and assigning them (please wait...)
+    (mult. 1) RootP_1 = -3.164772734675337090200909653480...
+    (mult. 2) RootP_2 = -1.8
+    (mult. 1) RootP_3 = 0.009999999999000000000499999999...
+    (mult. 1) RootP_4 = 0.010000000001000000000500000000...
+    (mult. 3) RootP_5 = 0.1
+    (mult. 1) RootP_6 = 3.159772703424837079727026834533...
+    Square-free irrational part: x^10-10000*x^2+200*x-1
+        --> &REFINEROOTS(P,N) to extend real irr. roots to N fractional digits
     >>> &bye
     Did I say something wrong?
-    Session transcript written on xintsession-210531_09h08.tex
+    Session transcript written on xintsession-211101_18h17.tex
      )
     No pages of output.
     Transcript written on xintsession.log.
 
 As this example illustrates, the computational engine can work in
-various modes: exact, fp, int, and pol.  Say `&fp=number` at the
-`>>>` prompt to activate floating point mode with `number` digits
-of precision.
+various modes: exact, fp, int, and pol (the `&ROOTS()` will work in
+any mode the same once the polynomial as been defined in pol mode).
+Say `&fp=number` at the `>>>` prompt to activate floating point mode
+with `number` digits of precision.
 
 If ill-formed input drops you deep into TeX error interaction mode,
 try hitting `S`  as it may work to bring you back to normal session.
@@ -72,6 +85,13 @@
 
 ## Change log ##
 
+- 0.4alpha (2021-11-01)
+  - add `&GenFloat` interface to `\PolGenFloatVariant`
+  - add `&ROOTS` and `&REFINEROOTS` interface to under-the-hood
+    usage of the
+    [polexpr](http://www.ctan.org/pkg/polexpr) facilities
+    allowing to get all real roots of the given polynomial
+    to arbitrary precision (and all rational roots exactly)
 - 0.3b (2021-07-01)
   - fix output still uses `(@_<n>)` when a variable is defined
     but the parentheses were dropped a while ago in general

Modified: trunk/Master/texmf-dist/tex/plain/xintsession/xintsession.tex
===================================================================
--- trunk/Master/texmf-dist/tex/plain/xintsession/xintsession.tex	2021-11-01 20:35:03 UTC (rev 60925)
+++ trunk/Master/texmf-dist/tex/plain/xintsession/xintsession.tex	2021-11-01 20:35:16 UTC (rev 60926)
@@ -1,4 +1,4 @@
-% Release 0.3b (2021-07-01) of xintsession.tex
+% Release 0.4alpha (2021-11-01) of xintsession.tex
 % author: Jean-Francois Burnol
 % License: LPPL 1.3c (author-maintained)
 % Usage: execute "etex (or pdftex) xintsession"
@@ -55,7 +55,7 @@
 /_/  /_/ /_/\__/ \___//_/    \__,_/ \___/ \__/ /_/  _____/ \___//_/%
 }%
 ?xdef?xs_copyright{%
-  xintsession 0.3a (2021-06-08)
+  xintsession 0.4alpha (2021-11-01)
   Copyright (c) Jean-Francois Burnol, 2021.%
 }}%
 \def\xs_no{0}%
@@ -170,6 +170,7 @@
    \edef\xs_funcname{\expandafter\xint_zapspaces\detokenize{#1} \xint_gobble_i}%
    \xint_gob_til_sc#2\xs_defvar;\xs_deffunc
 }%
+\edef\xs_fourspaces{\space\space\space\space}%
 \def\xs_deffunc #1;%
 {%
 % attention: \xs_xintdeffunc needs to see parentheses immediately
@@ -179,8 +180,16 @@
                 \detokenize\expandafter{\xs_right};}%
    \expandafter\ifx\xs_xintdeffunc\poldef
         \xs_message{\xs_funcname\space = \PolToExpr{\xs_funcname}}%
-        \xs_message{Issue \string\PolGenFloatVariant{\xs_funcname} if fp evaluations
-                 with \xs_funcname\space are intended}%
+        \xs_message{\xs_fourspaces -->
+                    &GenFloat(\xs_funcname) lets
+                    \xs_funcname\space become usable as function in fp mode}%
+        \xs_message{\xs_fourspaces
+                    --> &ROOTS(\xs_funcname) (resp. &ROOTS(\xs_funcname,N))
+                       finds all rational roots exactly and}%
+        \xs_message{\xs_fourspaces\xs_fourspaces
+                    all irrational roots with at least
+                    \xintsessiondefaultrootsprecision\space(resp. N)
+                    fractional digits}%
    \else\xs_message{Function \xs_funcname\space defined}%
    \fi\xs_fetch
 }%
@@ -247,6 +256,106 @@
    \def\xs_xinteval{\xinteval}%
 }%
 \def\xs_magic@&mod{\xs_message{current mode: \xs_mode}}%
+\def\xs_getpolname#1(#2#3)#4\xint_bye{\edef\xs_polname{\xint_zapspaces #2#3 \xint_gobble_i}}%
+\def\xs_magic@&Gen
+{%
+   \expandafter\xs_getpolname\xs_magic_inb\xint_bye
+   \PolGenFloatVariant{\xs_polname}%
+   \immediate\write\xs_out{\string\PolGenFloatVariant{\xs_polname}}%
+   \xs_message{Polynomial function \xs_polname\space for &fp mode usage now defined}%
+}%
+\def\xintsessiondefaultrootsprecision{10}%
+\def\xs_getpolandE#1(#2#3)#4\xint_bye
+{%
+   \xs_getpolandE_i#2#3,,\xint_bye
+}%
+\def\xs_getpolandE_i#1,#2,#3\xint_bye
+{%
+   \edef\xs_polname{\xint_zapspaces #1 \xint_gobble_i}%
+   \edef\xs_rootsprecision{\if\relax#3\relax
+                           \xintsessiondefaultrootsprecision\else
+        \xint_zapspaces #2 \xint_gobble_i\fi}%
+}%
+\expandafter\def\csname xs_magic@&ROO\endcsname
+{%
+   \expandafter\xs_getpolandE\xs_magic_inb\xint_bye
+   \xs_message{Solving for real roots of \xs_polname\space and assigning them (please wait...)}%
+   \PolToSturm{\xs_polname}{@\xs_polname}%
+   \PolSturmIsolateZerosGetMultiplicitiesAndRationalRoots{@\xs_polname}%
+   \PolEnsureIntervalLengths{@\xs_polname}{-\xs_rootsprecision}%
+     \immediate\write\xs_out{\string\PolToSturm{\xs_polname}{@\xs_polname}}%
+     \immediate\write\xs_out{\string\PolSturmIsolateZerosGetMultiplicitiesAndRationalRoots{@\xs_polname}}%
+     \immediate\write\xs_out{\string\PolEnsureIntervalLengths{@\xs_polname}{-\xs_rootsprecision}}%
+     \immediate\write\xs_out{\string\PolPrintIntervals{@\xs_polname}}%
+   \xs_polprintintervals
+   \xs_message{Square-free irrational part: \PolToExpr{@\xs_polname _sqf_norr}}%
+   \ifnum\PolSturmNbOfIsolatedZeros{@\xs_polname}>\PolSturmNbOfRationalRoots{@\xs_polname}
+     \xs_message{\xs_fourspaces -->
+                 &REFINEROOTS(\xs_polname,N) to extend real irr. roots to N fractional digits}%
+   \else
+    \xs_message{No irrational real roots.}%
+   \fi
+}%
+\expandafter\def\csname xs_magic@&REF\endcsname
+{%
+   \expandafter\xs_getpolandE\xs_magic_inb\xint_bye
+   \xs_message{Refining real roots of \xs_polname\space to \xs_rootsprecision\space
+   digits (please wait...)}%
+   \PolEnsureIntervalLengths{@\xs_polname}{-\xs_rootsprecision}%
+     \immediate\write\xs_out{\string\PolEnsureIntervalLengths{@\xs_polname}{-\xs_rootsprecision}}%
+     \immediate\write\xs_out{\string\PolPrintIntervals{@\xs_polname}}%
+   \xs_polprintintervals
+}%
+\def\xs_polprintintervals
+{%
+   \begingroup\xintglobaldefstrue
+   \def\PolPrintIntervalsNoRealRoots{\xs_message{No real roots.}}%
+   \let\PolPrintIntervalsBeginEnv\empty
+   \let\PolPrintIntervalsEndEnv\empty
+   \def\PolPrintIntervalsKnownRoot{\PolPrintIntervalsPrintExactZero}%
+   \def\PolPrintIntervalsUnknownRoot{\xintifSgn{\PolPrintIntervalsTheLeftEndPoint}%
+          {\PolPrintIntervalsPrintRightEndPoint}%
+          {\PolPrintIntervalsPrintLeftEndPoint}%
+          {\PolPrintIntervalsPrintLeftEndPoint}%
+       }%
+   \def\PolPrintIntervalsPrintExactZero
+     {\xs_message{(mult. \PolPrintIntervalsTheMultiplicity)
+                  Root\xs_polname _\PolPrintIntervalsTheIndex\space = \PolPrintIntervalsTheLeftEndPoint}%
+      \immediate\write\xs_out{\string\xintdefvar\space
+         Root\xs_polname _\PolPrintIntervalsTheIndex:=\PolPrintIntervalsTheLeftEndPoint;}%
+      \XINT_expr_defvar_one{Root\xs_polname _\PolPrintIntervalsTheIndex}%
+         {{\xintRaw{\PolPrintIntervalsTheLeftEndPoint}}}%
+     }%
+   \def\PolPrintIntervalsPrintLeftEndPoint
+     {\xs_message{(mult. \PolPrintIntervalsTheMultiplicity)
+                  Root\xs_polname _\PolPrintIntervalsTheIndex\space = \PolPrintIntervalsTheLeftEndPoint...}%
+      \immediate\write\xs_out{\string\xintdefvar\space
+         Root\xs_polname _\PolPrintIntervalsTheIndex:=\PolPrintIntervalsTheLeftEndPoint;}%
+      \XINT_expr_defvar_one{Root\xs_polname _\PolPrintIntervalsTheIndex}%
+         {{\xintRaw{\PolPrintIntervalsTheLeftEndPoint}}}%
+     }%
+   \def\PolPrintIntervalsPrintRightEndPoint
+     {\xs_message{(mult. \PolPrintIntervalsTheMultiplicity)
+                  Root\xs_polname _\PolPrintIntervalsTheIndex\space = \PolPrintIntervalsTheRightEndPoint...}%
+      \immediate\write\xs_out{\string\xintdefvar\space
+         Root\xs_polname _\PolPrintIntervalsTheIndex:=\PolPrintIntervalsTheRightEndPoint;}%
+      \XINT_expr_defvar_one{Root\xs_polname _\PolPrintIntervalsTheIndex}%
+         {{\xintRaw{\PolPrintIntervalsTheRightEndPoint}}}%
+     }%
+   \def\POL at PrintIntervals@Loop{%
+      \POL at SturmIfZeroExactlyKnown\PolPrintIntervalsTheSturmName\PolPrintIntervalsTheIndex
+          \PolPrintIntervalsKnownRoot
+          \PolPrintIntervalsUnknownRoot
+      \xdef\PolPrintIntervalsTheIndex{\the\numexpr\PolPrintIntervalsTheIndex+\@ne}%
+        \unless\ifnum\PolPrintIntervalsTheIndex>
+               \@nameuse{POL_ZL\PolPrintIntervalsTheSturmName*0}
+        \POL at PrintIntervals@DoDefs
+        \expandafter\POL at PrintIntervals@Loop
+      \fi
+   }%
+   \PolPrintIntervals{@\xs_polname}%
+   \endgroup       
+}%
 \def\xs_setenv
 {%
     \newlinechar10\endlinechar-1\errorcontextlines0\relax
@@ -276,16 +385,15 @@
 \xs_logo
 
   - input is `;'-terminated and can extend over multiple lines
-    ("\xs_prime_invite" is main input invite, "\xs_second_invite" is continuation prompt)
-  - definitions are done with `:=' not with `='.
-%  - any line starting with a control sequence is executed in the
-%    background, the interrupted numerical input resumes at prompt.
+  - definitions of variables and functions are done with `:='.
 
-  Magic words: `&pause' (or `;'), `&help', `&bye',
-               `&exact', `&fp', `&int', `&pol'.
-
   \string\jobname is \jobname
   Transcript will go to log and to \xs_name
+  Typing at the prompt
+  - `&pause' or `;' exits to normal TeX (typesetting) interaction,
+  - `&bye' terminates the session,
+  - `&help' triggers help panels,
+  - `&exact', `&fp', `&int', or `&pol' switches among modes.
 }}%
 \xdef\xs_welcome_back{\noexpand\message{%
   You are back to the xintexpr interactive session!
@@ -353,7 +461,7 @@
   - Polynomials in pol mode are defined using polname(x):=expression;
     (or with another letter).  They can serve as functions in the exact
     mode.  To use a polynomial also as an fp mode function, issue
-    \PolGenFloatVariant{<polname>} at the prompt.
+    &GenFloat(<polname>) at the prompt.
 
   - Whenever a variable is defined, or a computation is performed,
     the result is assigned a label @_<integer>.  These labels are



More information about the tex-live-commits mailing list.