* Bug 10078 fixed: isinf(polynomials) was not reliable 35/20935/5
Samuel GOUGEON [Wed, 10 Apr 2019 19:21:20 +0000 (21:21 +0200)]
  http://bugzilla.scilab.org/10078

Change-Id: I763f0f35aa720f4c7333cfaf1024c68780de193c

scilab/CHANGES.md
scilab/modules/elementary_functions/help/en_US/floating_point/isinf.xml
scilab/modules/elementary_functions/help/fr_FR/floating_point/isinf.xml
scilab/modules/elementary_functions/help/ru_RU/floating_point/isinf.xml
scilab/modules/elementary_functions/macros/isinf.sci
scilab/modules/elementary_functions/tests/nonreg_tests/bug_10078.tst [new file with mode: 0644]

index 6a2f034..239ccca 100644 (file)
@@ -206,6 +206,7 @@ Bug Fixes
 * [#9007](http://bugzilla.scilab.org/show_bug.cgi?id=9007): On Linux, `sciargs()` included twice `-nw` when `-nw` is used.
 * [#9529](http://bugzilla.scilab.org/show_bug.cgi?id=9529): `assert_checkequal(list(1,,3), list(1,,3))` yielded an error.
 * [#9673](http://bugzilla.scilab.org/show_bug.cgi?id=9673): Priority of colon `:` operator was too low
+* [#10078](http://bugzilla.scilab.org/show_bug.cgi?id=10078): `isinf()` was not reliable for polynomials.
 * [#10353](http://bugzilla.scilab.org/show_bug.cgi?id=10353): Documentation: The referential for the uicontrol.position property was not provided. Moreover, gca().axes_bounds refered to fig.figure_size instead of fig.axes_size.
 * [#10723](http://bugzilla.scilab.org/show_bug.cgi?id=10723): `subplot`'s action was unclearly described in its help page. Page improved.
 * [#11852](http://bugzilla.scilab.org/show_bug.cgi?id=11852): File browser didn't update after file creation or remove.
index 5cc909d..6e23a57 100644 (file)
@@ -2,9 +2,8 @@
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2008 - INRIA
- * Copyright (C) 2016 - Samuel GOUGEON
- *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2016 - Samuel GOUGEON
  *
  * This file is hereby licensed under the terms of the GNU GPL v2.0,
  * pursuant to article 5.3.4 of the CeCILL v.2.1.
@@ -34,7 +33,9 @@
             <varlistentry>
                 <term>x</term>
                 <listitem>
-                    <para>matrix of real or complex numbers
+                    <para>
+                        matrix of real or complex numbers, or of polynomials with real or complex
+                        coefficients.
                     </para>
                 </listitem>
             </varlistentry>
@@ -42,7 +43,7 @@
                 <term>r</term>
                 <listitem>
                     <para>
-                        matrix of booleans of the same size as <varname>x</varname>
+                        matrix of booleans of the same size as <varname>x</varname>.
                     </para>
                 </listitem>
             </varlistentry>
     <refsection>
         <title>Description</title>
         <para>
-            <literal>isinf(x)</literal> returns the matrix <varname>r</varname>
-            of booleans such that, for each element <varname>x(i)</varname>,
-            <varname>r(i)</varname> is set to <literal>%T</literal> if and only if
-            <varname>x(i)</varname> is infinite.
+            <emphasis>
+                <varname>x</varname> are real or complex numbers:
+            </emphasis>
+            <literal>r = isinf(x)</literal> returns the matrix <varname>r</varname>
+            of booleans such that <literal>r(i)</literal> is <literal>%T</literal>
+            if <literal>abs(x(i))</literal> is infinite, and <literal>%F</literal> otherwise.
         </para>
         <para>
-            When <literal>x</literal> is complex-encoded, <literal>x(i)</literal>
-            is considered infinite if its real part or its imaginary part (or both)
-            are infinite.
+            <emphasis>
+                <varname>x</varname> are polynomials with real or complex coefficients:
+            </emphasis>
+            Then after <literal>r = isinf(x)</literal>, <literal>r(i)</literal> is <literal>%T</literal>
+            if at least one of the <literal>x(i)</literal> coefficients is infinite,
+            and <literal>%F</literal> otherwise.
         </para>
     </refsection>
     <refsection>
 [i, inf, nan] = (%i, %inf, %nan);
 isinf([-1  0.01 -inf  inf  nan])
 isinf([2+i, -10-inf, inf+i])
-isinf([nan-i, inf-nan*i, nan+i*inf])
+isinf([nan-i, nan+i*inf])
+isinf(inf-nan*i)
  ]]></programlisting>
+        <screen><![CDATA[
+--> isinf([-1  0.01 -inf  inf  nan])
+ ans  =
+  F F T T F
+
+--> isinf([2+i, -10-inf, inf+i])
+ ans  =
+  F T T
+
+--> isinf([nan-i, nan+i*inf])
+ ans  =
+  F T
+
+--> isinf(inf-nan*i)
+ ans  =
+  F
+]]></screen>
+        Please note that <literal>%inf-%nan*%i</literal> is computed as
+        <literal>%inf - %nan*complex(0,1) == %inf - complex(%nan*0, %nan*1) == %inf - complex(%nan, %nan)
+            == complex(%inf-%nan, -%nan) == complex(%nan, %nan)
+        </literal>
+        ,where Inf is eaten by Nan
+        and no longer appears.
+        <para/>
+        <para>
+            With polynomials :
+        </para>
+        <programlisting role="example"><![CDATA[
+p = poly([%nan -2 0 3],"x","coeff")
+q = poly([0 %inf %i],"x","coeff")
+r = poly([%nan %inf*%i 1],"x","coeff")
+isinf([p q r])
+ ]]></programlisting>
+        <screen><![CDATA[
+--> p = poly([%nan -2 0 3],"x","coeff")
+ p  =
+
+  Nan -2x +3x³
+
+--> q = poly([0 %inf %i],"x","coeff")
+ q  =
+
+  Infx +ix²
+
+--> r = poly([%nan %inf*%i 1],"x","coeff")
+ r  =
+
+  Nan -(Nan-Infi)x +x²
+
+--> isinf([p q r])
+ ans  =
+
+  F T F
+]]></screen>
     </refsection>
     <refsection role="see also">
         <title>See also</title>
         <simplelist type="inline">
             <member>
+                <link linkend="percentinf">percentinf</link>
+            </member>
+            <member>
                 <link linkend="isnan">isnan</link>
             </member>
             <member>
@@ -88,4 +152,15 @@ isinf([nan-i, inf-nan*i, nan+i*inf])
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    Extension to polynomials.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index f626062..878dce5 100644 (file)
@@ -2,9 +2,8 @@
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2008 - INRIA
- * Copyright (C) 2016 - Samuel GOUGEON
- *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2016 - Samuel GOUGEON
  *
  * This file is hereby licensed under the terms of the GNU GPL v2.0,
  * pursuant to article 5.3.4 of the CeCILL v.2.1.
             <varlistentry>
                 <term>x</term>
                 <listitem>
-                    <para>matrice de nombres décimaux ou complexes.
+                    <para>
+                        matrice de nombres décimaux ou complexes, ou de polynômes à coefficients
+                        réels ou complexes.
                     </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
                 <term>r</term>
                 <listitem>
-                  <para>matrice de booléens, de même taille que <varname>x</varname>
+                    <para>
+                        matrice de booléens, de même taille que <varname>x</varname>
                     </para>
                 </listitem>
             </varlistentry>
     <refsection>
         <title>Description</title>
         <para>
-            <literal>isinf(x)</literal> renvoie une matrice <literal>r</literal> dont chaque
+            Pour <literal>isinf(x)</literal> renvoie une matrice <literal>r</literal> dont chaque
             élément <literal>r(i)</literal> vaut <literal>%T</literal> (vrai) si et seulement si
             <literal>x(i)</literal> est infini.
-       </para>
-       <para>Pour <literal>x</literal> complexe, <literal>x(i)</literal> est considéré infini
-         dés que sa partie réelle ou complexe ou les deux sont infinies.
+        </para>
+        <para>
+            Pour <literal>x</literal> complexe, <literal>x(i)</literal> est considéré infini
+            dés que sa partie réelle ou complexe ou les deux sont infinies.
         </para>
     </refsection>
     <refsection>
 [i, inf, nan] = (%i, %inf, %nan);
 isinf([-1  0.01 -inf  inf  nan])
 isinf([2+i, -10-inf, inf+i])
-isinf([nan-i, inf-nan*i, nan+i*inf])
+isinf([nan-i, nan+i*inf])
+isinf(inf-nan*i)
  ]]></programlisting>
+        <screen><![CDATA[
+--> isinf([-1  0.01 -inf  inf  nan])
+ ans  =
+  F F T T F
+
+--> isinf([2+i, -10-inf, inf+i])
+ ans  =
+  F T T
+
+--> isinf([nan-i, nan+i*inf])
+ ans  =
+  F T
+
+--> isinf(inf-nan*i)
+ ans  =
+  F
+]]></screen>
+        Note : <literal>%inf-%nan*%i</literal> est évalué comme
+        <literal>%inf - %nan*complex(0,1) == %inf - complex(%nan*0, %nan*1) == %inf - complex(%nan, %nan)
+            == complex(%inf-%nan, -%nan) == complex(%nan, %nan)
+        </literal>
+        ,où Inf est effacé par Nan et
+        n'apparait plus.
+        <para/>
+        <para>
+            Avec des polynômes :
+        </para>
+        <programlisting role="example"><![CDATA[
+p = poly([%nan -2 0 3],"x","coeff")
+q = poly([0 %inf %i],"x","coeff")
+r = poly([%nan %inf*%i 1],"x","coeff")
+isinf([p q r])
+ ]]></programlisting>
+        <screen><![CDATA[
+--> p = poly([%nan -2 0 3],"x","coeff")
+ p  =
+
+  Nan -2x +3x³
+
+--> q = poly([0 %inf %i],"x","coeff")
+ q  =
+
+  Infx +ix²
+
+--> r = poly([%nan %inf*%i 1],"x","coeff")
+ r  =
+
+  Nan -(Nan-Infi)x +x²
+
+--> isinf([p q r])
+ ans  =
+
+  F T F
+]]></screen>
     </refsection>
     <refsection role="see also">
         <title>Voir aussi</title>
         <simplelist type="inline">
             <member>
+                <link linkend="percentinf">percentinf</link>
+            </member>
+            <member>
                 <link linkend="isnan">isnan</link>
             </member>
             <member>
@@ -81,5 +142,16 @@ isinf([nan-i, inf-nan*i, nan+i*inf])
                 <link linkend="type">type</link>
             </member>
         </simplelist>
+        <refsection role="history">
+            <title>Historique</title>
+            <revhistory>
+                <revision>
+                    <revnumber>6.1.0</revnumber>
+                    <revdescription>
+                        Extension aux polynômes.
+                    </revdescription>
+                </revision>
+            </revhistory>
+        </refsection>
     </refsection>
 </refentry>
index 569f476..db4e071 100644 (file)
@@ -2,8 +2,8 @@
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2008 - INRIA
- *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2016 - Samuel GOUGEON
  *
  * This file is hereby licensed under the terms of the GNU GPL v2.0,
  * pursuant to article 5.3.4 of the CeCILL v.2.1.
  * along with this program.
  *
  -->
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="isinf" xml:lang="ru">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
+          xmlns:scilab="http://www.scilab.org" xml:id="isinf" xml:lang="ru">
     <refnamediv>
         <refname>isinf</refname>
         <refpurpose>проверка на бесконечные элементы</refpurpose>
             <varlistentry>
                 <term>x</term>
                 <listitem>
-                    <para>матрица или вектор вещественных или комплексных значений</para>
+                    <para>
+                        матрица или вектор вещественных или комплексных значений
+                        или полиномов с вещественными или комплексными коэффициентами.
+                    </para>
                 </listitem>
                 <term>r</term>
                 <listitem>
     <refsection>
         <title>Описание</title>
         <para>
-            <literal>isinf(x)</literal> returns a matrix <varname>r</varname>
-            of booleans such that, for each element <varname>x(i)</varname>,
-            <varname>r(i)</varname> is set to <literal>%T</literal> as soon as
-            <varname>x(i)</varname> is infinite.
+            <emphasis>
+                <varname>x</varname> состоит из вещественных или комплексных чисел:
+            </emphasis>
+            <literal>r = isinf(x)</literal> возвращает матрицу <varname>r</varname>
+            логических значений таких, что <literal>r(i)</literal> равно <literal>%T</literal>,
+            если <literal>abs(x(i))</literal> равно бесконечности и <literal>%F</literal> в ином случае.
         </para>
         <para>
-            When <literal>x</literal> is complex-encoded, <literal>x(i)</literal>
-            is considered infinite as soon as its real or imaginary or both parts
-            are infinite.
+            <emphasis>
+                <varname>x</varname> состоит из полиномов с вещественными или комплексными коэффициентами:
+            </emphasis>
+            Затем после <literal>r = isinf(x)</literal>, <literal>r(i)</literal> равен <literal>%T</literal>,
+            если по крайней мере один из коэффициентов полинома <literal>x(i)</literal> равен бесконечности и
+            <literal>%F</literal> в ином случае.
         </para>
     </refsection>
     <refsection>
 [i, inf, nan] = (%i, %inf, %nan);
 isinf([-1  0.01 -inf  inf  nan])
 isinf([2+i, -10-inf, inf+i])
-isinf([nan-i, inf-nan*i, nan+i*inf])
+isinf([nan-i, nan+i*inf])
+isinf(inf-nan*i)
+ ]]></programlisting>
+        <screen><![CDATA[
+--> isinf([-1  0.01 -inf  inf  nan])
+ ans  =
+  F F T T F
+
+--> isinf([2+i, -10-inf, inf+i])
+ ans  =
+  F T T
+
+--> isinf([nan-i, nan+i*inf])
+ ans  =
+  F T
+
+--> isinf(inf-nan*i)
+ ans  =
+  F
+]]></screen>
+        Пожалуйста, обратите внимание, что <literal>%inf-%nan*%i</literal> вычисляется как
+        <literal>%inf - %nan*complex(0,1) == %inf - complex(%nan*0, %nan*1) == %inf - complex(%nan, %nan)
+            == complex(%inf-%nan, -%nan) == complex(%nan, %nan)
+        </literal>
+        ,где Inf съеден значениям Nan и
+        больше не появляется.
+        <para/>
+        <para>
+            С полиномами:
+        </para>
+        <programlisting role="example"><![CDATA[
+p = poly([%nan -2 0 3],"x","coeff")
+q = poly([0 %inf %i],"x","coeff")
+r = poly([%nan %inf*%i 1],"x","coeff")
+isinf([p q r])
  ]]></programlisting>
+        <screen><![CDATA[
+--> p = poly([%nan -2 0 3],"x","coeff")
+ p  =
+
+  Nan -2x +3x³
+
+--> q = poly([0 %inf %i],"x","coeff")
+ q  =
+
+  Infx +ix²
+
+--> r = poly([%nan %inf*%i 1],"x","coeff")
+ r  =
+
+  Nan -(Nan-Infi)x +x²
+
+--> isinf([p q r])
+ ans  =
+
+  F T F
+]]></screen>
     </refsection>
     <refsection role="see also">
         <title>Смотрите также</title>
         <simplelist type="inline">
             <member>
+                <link linkend="percentinf">percentinf</link>
+            </member>
+            <member>
                 <link linkend="isnan">isnan</link>
             </member>
             <member>
@@ -77,4 +146,15 @@ isinf([nan-i, inf-nan*i, nan+i*inf])
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>История</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    Расширение до полиномов.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 257a5f1..6441378 100644 (file)
@@ -1,8 +1,7 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) INRIA
-// Copyright (C) 2016 - Samuel GOUGEON
-//
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
+// Copyright (C) 2016, 2019 - Samuel GOUGEON
 //
 // This file is hereby licensed under the terms of the GNU GPL v2.0,
 // pursuant to article 5.3.4 of the CeCILL v.2.1.
@@ -12,7 +11,6 @@
 // along with this program.
 
 function r = isinf(x)
-
     rhs = argn(2);
 
     if rhs <> 1 then
@@ -23,12 +21,22 @@ function r = isinf(x)
     if x==[] then
         r = []
     else
-        if isreal(x)
-            r = abs(x)==%inf;
+        select typeof(x)
+        case "polynomial"
+            // polynomials : http://bugzilla.scilab.org/10078
+            r = matrix(or(isinf(coeff(x(:))),"c"), size(x))
+        case "rational"
+            msg = _("%s: Argument #%d: %s not supported.\n")
+            error(msprintf(msg, "isinf", 1, "rationals"))
+            // Possible implementation: a rational is inf if at least
+            // one coefficient of its numerator is infinite
         else
-            // workaround of http://bugzilla.scilab.org/14062
-            r = abs(real(x))==%inf | abs(imag(x))==%inf
+            if isreal(x)
+                r = abs(x)==%inf;
+            else
+                // workaround of http://bugzilla.scilab.org/14062
+                r = abs(real(x))==%inf | abs(imag(x))==%inf
+            end
         end
     end
-
 endfunction
diff --git a/scilab/modules/elementary_functions/tests/nonreg_tests/bug_10078.tst b/scilab/modules/elementary_functions/tests/nonreg_tests/bug_10078.tst
new file mode 100644 (file)
index 0000000..255f03a
--- /dev/null
@@ -0,0 +1,31 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2019 - Samuel GOUGEON
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- CLI SHELL MODE -->
+// <-- NO CHECK REF -->
+//
+// <-- Non-regression test for bug 10078 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/10078
+//
+// <-- Short Description -->
+// isinf() was not reliable for polynomials
+
+p = poly([1 %inf],"s","coeff");
+assert_checktrue(isinf(p));
+p = poly([1 %inf %i],"s","coeff");
+assert_checktrue(isinf(p));
+p = poly([1 %nan %inf],"x","coeff");
+assert_checktrue(isinf(p));
+p = poly([1 %nan %inf %i],"x","coeff");
+assert_checktrue(isinf(p));
+
+assert_checkequal(isinf(poly(%inf,"x","coeff")), %t);
+assert_checkequal(isinf([p p]), [%t %t]);
+assert_checkequal(isinf([p ; p]), [%t ; %t]);
+assert_checkequal(isinf(cat(3,p,p)), cat(3,%t,%t));