* Bug 15370 fixed: bezout() badly handled its number of outputs 72/19672/6
Samuel GOUGEON [Sun, 14 Jan 2018 05:29:13 +0000 (06:29 +0100)]
  http://bugzilla.scilab.org/15370

Change-Id: I98df9ba2f26a23072a9273e37ba1c0aa381b35fe

scilab/CHANGES.md
scilab/modules/polynomials/help/en_US/bezout.xml
scilab/modules/polynomials/help/fr_FR/bezout.xml
scilab/modules/polynomials/help/ja_JP/bezout.xml
scilab/modules/polynomials/help/pt_BR/bezout.xml
scilab/modules/polynomials/sci_gateway/cpp/sci_bezout.cpp
scilab/modules/polynomials/tests/unit_tests/polelm.tst

index 5296c34..4dd2929 100644 (file)
@@ -512,6 +512,7 @@ Known issues
 * [#15347](http://bugzilla.scilab.org/show_bug.cgi?id=15347): `toeplitz` failed with rationals.
 * [#15354](http://bugzilla.scilab.org/show_bug.cgi?id=15354): `invr(%s^2)` returned 0 instead of `1/%s^2`. For any scalar number, polynomial or rational `a`, `coffg(a)` returned `0` instead of `1`. `coffg([])` yielded an error. `invr` and `coffg` had no unitary tests. The `coffg` help page was inaccurate and unclear.
 * [#15360](http://bugzilla.scilab.org/show_bug.cgi?id=15360): `numer()` and `denom()` were almost useless, unused, and with more handy replacements. They are declared obsolete to be removed in Scilab 6.1.0.
+* [#15370](http://bugzilla.scilab.org/show_bug.cgi?id=15370): `bezout()` mishandled its output arguments.
 * [#15375](http://bugzilla.scilab.org/show_bug.cgi?id=15375): A .zcos file opened as a palette was greyed out.
 
 
index cd4ece5..8c9c702 100644 (file)
  * 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:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="en" xml:id="bezout">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
+          xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
+          xml:lang="en" xml:id="bezout">
     <refnamediv>
         <refname>bezout</refname>
-        <refpurpose>Bezout equation for polynomials or integers</refpurpose>
+        <refpurpose>GCD of two polynomials or two integers, by the Bezout method</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Syntax</title>
-        <synopsis>[thegcd,U]=bezout(p1,p2)</synopsis>
+        <synopsis>
+          thegcd = bezout(p1,p2)
+          [thegcd, U] = bezout(p1,p2)
+        </synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>Arguments</title>
@@ -35,7 +41,8 @@
                 <term>thegcd</term>
                 <listitem>
                     <para>
-                        scalar of the same type as <literal>p1</literal> and <literal>p2</literal>
+                        scalar with the type of <literal>p1</literal>:
+                        The Greatest Common Divisor of <literal>p1</literal> and <literal>p2</literal>.
                     </para>
                 </listitem>
             </varlistentry>
@@ -43,7 +50,8 @@
                 <term>U</term>
                 <listitem>
                     <para>
-                        <literal>2x2</literal> matrix of the same type as <literal>p1</literal> and <literal>p2</literal>
+                        <literal>2x2</literal> unimodular matrix of the type of <literal>p1</literal>,
+                        such that <literal>[p1 p2]*U = [thegcd 0]</literal>.
                     </para>
                 </listitem>
             </varlistentry>
     <refsection>
         <title>Description</title>
         <para>
-            <literal>[thegcd, U] = bezout(p1, p2)</literal> computes the GCD <literal>thegcd</literal> of <literal>p1</literal> and <literal>p2</literal>, and in addition a (2x2)
-            unimodular matrix <literal>U</literal> such that:
+            <literal>thegcd = bezout(p1, p2)</literal> computes the GCD
+            <literal>thegcd</literal> of <literal>p1</literal> and <literal>p2</literal>.
         </para>
         <para>
-            <literal>[p1 p2]*U = [thegcd 0]</literal>
+            In addition, <literal>[thegcd, U] = bezout(p1, p2)</literal> computes and returns a
+            (2x2) unimodular matrix <varname>U</varname> such that
+            <literal>[p1 p2]*U = [thegcd 0]</literal>.
         </para>
         <para>
             The lcm of <literal>p1</literal> and <literal>p2</literal> is given by:
@@ -65,8 +75,8 @@
             <literal>p1*U(1,2)</literal> (or <literal>-p2*U(2,2)</literal>)
         </para>
         <para>
-            If <literal>p1</literal> or <literal>p2</literal> are given as doubles (type 1), then they are treated as
-            null degree polynomials.
+            If <literal>p1</literal> or <literal>p2</literal> are given as doubles (type 1),
+            then they are processed as null degree polynomials.
         </para>
     </refsection>
     <refsection>
@@ -82,7 +92,7 @@ clean([p1 p2]*U)
 thelcm = p1*U(1,2)
 lcm([p1 p2])
 
-// Double case
+// With decimal numbers
 i1 = 2*3^5;
 i2 = 2^3*3^2;
 [thegcd,U] = bezout(i1, i2)
@@ -105,6 +115,12 @@ lcm(V)
         <title>See also</title>
         <simplelist type="inline">
             <member>
+                <link linkend="gcd">gcd</link>
+            </member>
+            <member>
+                <link linkend="lcm">lcm</link>
+            </member>
+            <member>
                 <link linkend="poly">poly</link>
             </member>
             <member>
@@ -116,9 +132,6 @@ lcm(V)
             <member>
                 <link linkend="clean">clean</link>
             </member>
-            <member>
-                <link linkend="lcm">lcm</link>
-            </member>
         </simplelist>
     </refsection>
 </refentry>
index 5603c00..d6c230e 100644 (file)
@@ -1,12 +1,18 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="fr" xml:id="bezout">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
+          xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
+          xml:lang="fr" xml:id="bezout">
     <refnamediv>
         <refname>bezout</refname>
         <refpurpose>équation de Bezout pour les polynômes  </refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Séquence d'appel</title>
-        <synopsis>[pgcd,U]=bezout(p1,p2)</synopsis>
+        <synopsis>
+           pgcd = bezout(p1,p2)
+          [pgcd, U] = bezout(p1,p2)
+        </synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>Paramètres</title>
                     </para>
                 </listitem>
             </varlistentry>
+            <varlistentry>
+                <term>pgcd</term>
+                <listitem>
+                    <para>
+                        élément unique du type de <literal>p1</literal> : Plus Grand Commun
+                        Diviseur de <literal>p1</literal> et <literal>p2</literal>.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>U</term>
+                <listitem>
+                    <para>
+                        Matrice Unimodulaire <literal>2x2</literal> du type de <literal>p1</literal>,
+                        telle que <literal>[p1 p2]*U = [pgcd 0]</literal>.
+                    </para>
+                </listitem>
+            </varlistentry>
         </variablelist>
     </refsection>
     <refsection>
         <title>Description</title>
         <para>
-            <literal>[thegcd,U]=bezout(p1,p2)</literal> calcule le PGCD <literal>pgcd</literal> de <literal>p1</literal> et <literal>p2</literal> et de plus une matrice
-            unimodulaire (2x2) <literal>U</literal> telle que :
+            <literal>thegcd = bezout(p1,p2)</literal> calcule le PGCD <literal>pgcd</literal> de
+            <literal>p1</literal> et <literal>p2</literal>
         </para>
         <para>
-            <literal>[p1,p2]*U = [pgcd,0]</literal>
+            <literal>[thegcd,U] = bezout(p1,p2)</literal> calcule et retourne en outre une matrice
+            unimodulaire (2x2) <literal>U</literal> telle que <literal>[p1,p2]*U = [pgcd,0]</literal>.
         </para>
         <para>
-            Le PPCM de <literal>p1</literal> et <literal>p2</literal> est donné par
+            Le PPCM de <literal>p1</literal> et <literal>p2</literal> est alors aussi donné par
+            <literal>p1*U(1,2)</literal> (ou <literal>-p2*U(2,2)</literal>).
         </para>
         <para>
-            <literal>p1*U(1,2)</literal> (ou <literal>-p2*U(2,2)</literal>)
-        </para>
-        <para>
-            Si <literal>p1</literal> ou <literal>p2</literal> sont donnés comme des flottants (type 1), alors ils sont traités
-            comme des polynômes de degré nul.
+            Si <literal>p1</literal> ou <literal>p2</literal> sont donnés comme des entiers décimaux
+            (type 1), ils sont alors traités comme des polynômes de degré nul.
         </para>
     </refsection>
     <refsection>
@@ -53,7 +76,7 @@ clean([p1,p2]*U)
 ppcm = p1*U(1,2)
 lcm([p1,p2])
 
-// Cas des doubles
+// Cas des entiers décimaux
 i1 = 2*3^5;
 i2 = 2^3*3^2;
 [thegcd, U] = bezout(i1, i2)
@@ -62,7 +85,7 @@ V = [2^2*3^5 2^3*3^2 2^2*3^4*5];
 V*U
 lcm(V)
 
-// Cas des entiers
+// Cas des entiers encodés
 i1 = int32(2*3^5);
 i2 = int32(2^3*3^2);
 [thegcd, U] = bezout(i1, i2)
@@ -76,6 +99,12 @@ lcm(V)
         <title>Voir aussi</title>
         <simplelist type="inline">
             <member>
+                <link linkend="gcd">gcd</link>
+            </member>
+            <member>
+                <link linkend="lcm">lcm</link>
+            </member>
+            <member>
                 <link linkend="poly">poly</link>
             </member>
             <member>
@@ -87,9 +116,6 @@ lcm(V)
             <member>
                 <link linkend="clean">clean</link>
             </member>
-            <member>
-                <link linkend="lcm">lcm</link>
-            </member>
         </simplelist>
     </refsection>
 </refentry>
index 97c1905..7dc17d9 100644 (file)
  * 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:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="ja" xml:id="bezout">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
+          xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
+          xml:lang="ja" xml:id="bezout">
     <refnamediv>
         <refname>bezout</refname>
-        <refpurpose>多項式またh整数のべズー方程式</refpurpose>
+        <refpurpose>Bezout法により、2つの多項式または2つの整数の最大公約数を計算します</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Syntax</title>
-        <synopsis>[thegcd,U]=bezout(p1,p2)</synopsis>
+        <synopsis>
+           thegcd = bezout(p1,p2)
+          [thegcd, U] = bezout(p1,p2)
+        </synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>Parameters</title>
                     <para>2つの実数多項式または2つの整数スカラー(8型)</para>
                 </listitem>
             </varlistentry>
+            <varlistentry>
+                <term>thegcd</term>
+                <listitem>
+                    <para>
+                        scalar with the type of <literal>p1</literal>:
+                        The Greatest Common Divisor of <literal>p1</literal> and <literal>p2</literal>.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>U</term>
+                <listitem>
+                    <para>
+                        <literal>2x2</literal> unimodular matrix of the type of <literal>p1</literal>,
+                        such that <literal>[p1 p2]*U = [thegcd 0]</literal>.
+                    </para>
+                </listitem>
+            </varlistentry>
         </variablelist>
     </refsection>
     <refsection>
         <title>例</title>
         <programlisting role="example"><![CDATA[
 // 多項式の場合
-x=poly(0,'x');
-p1=(x+1)*(x-3)^5;p2=(x-2)*(x-3)^3;
-[thegcd,U]=bezout(p1,p2)
+x = poly(0,'x');
+p1 = (x+1)*(x-3)^5;
+p2 = (x-2)*(x-3)^3;
+[thegcd, U] = bezout(p1,p2)
 det(U)
 clean([p1,p2]*U)
-thelcm=p1*U(1,2)
+thelcm = p1*U(1,2)
 lcm([p1,p2])
+
 // 整数の場合
-i1=int32(2*3^5); i2=int32(2^3*3^2);
-[thegcd,U]=bezout(i1,i2)
-V=int32([2^2*3^5, 2^3*3^2,2^2*3^4*5]);
-[thegcd,U]=gcd(V)
+i1 = int32(2*3^5);
+i2 = int32(2^3*3^2);
+[thegcd, U] = bezout(i1,i2)
+V = int32([2^2*3^5, 2^3*3^2,2^2*3^4*5]);
+[thegcd, U] = gcd(V)
 V*U
 lcm(V)
  ]]></programlisting>
@@ -77,6 +104,12 @@ lcm(V)
         <title>参照</title>
         <simplelist type="inline">
             <member>
+                <link linkend="gcd">gcd</link>
+            </member>
+            <member>
+                <link linkend="lcm">lcm</link>
+            </member>
+            <member>
                 <link linkend="poly">poly</link>
             </member>
             <member>
@@ -88,9 +121,6 @@ lcm(V)
             <member>
                 <link linkend="clean">clean</link>
             </member>
-            <member>
-                <link linkend="lcm">lcm</link>
-            </member>
         </simplelist>
     </refsection>
 </refentry>
index d8ed70f..6bb726b 100644 (file)
  * 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:ns3="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="bezout" xml:lang="pt">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns3="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="bezout" xml:lang="pt">
     <refnamediv>
         <refname>bezout</refname>
-        <refpurpose>equação de Bezout para polinômios ou inteiros</refpurpose>
+        <refpurpose>Maior Comum Divisor de dois polinômios ou dois inteiros, pelo método Bezout</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
-        <title> Seqüência de Chamamento</title>
-        <synopsis>[thegcd,U]=bezout(p1,p2)</synopsis>
+        <title> Seqüência de Chamamento</title>
+        <synopsis>
+           thegcd = bezout(p1,p2)
+          [thegcd,U] = bezout(p1,p2)
+        </synopsis>
     </refsynopsisdiv>
     <refsection>
-        <title>Parâmetros</title>
+        <title>Parâmetros</title>
         <variablelist>
             <varlistentry>
                 <term>p1, p2</term>
                 <listitem>
-                    <para>dois polinômios reais ou dois escalares inteiros (tipo igual a
-                        8)
+                    <para>dois polinômios reais ou dois escalares inteiros (tipo igual a 1 ou 8)
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>thegcd</term>
+                <listitem>
+                    <para>
+                        scalar with the type of <literal>p1</literal>:
+                        The Greatest Common Divisor of <literal>p1</literal> and <literal>p2</literal>.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>U</term>
+                <listitem>
+                    <para>
+                        <literal>2x2</literal> unimodular matrix of the type of <literal>p1</literal>,
+                        such that <literal>[p1 p2]*U = [thegcd 0]</literal>.
                     </para>
                 </listitem>
             </varlistentry>
         </variablelist>
     </refsection>
     <refsection>
-        <title>Descrição</title>
+        <title>Descrição</title>
         <para>
-            <literal>[thegcd,U]=bezout(p1,p2)</literal> computa o MDC
-            <literal>thegcd</literal> de <literal>p1</literal> e <literal>p2</literal>
-            e também uma matriz (2x2) unimodular <literal>U</literal> tal quet:
+            <literal>thegcd = bezout(p1,p2)</literal> computa o MDC
+            <literal>thegcd</literal> de <literal>p1</literal> e <literal>p2</literal>.
         </para>
         <para>
-            <literal>[p1,p2]*U = [thegcd,0]</literal>
+             Além disso, <literal>[thegcd,U] = bezout(p1,p2)</literal> calcula e retorna uma matriz
+             unimodular (2x2) <varname>U</varname> tal que <literal>[p1 p2]*U = [thegcd 0]</literal>.
         </para>
         <para>
-            O MMC de <literal>p1</literal> e <literal>p2</literal> é dado
+            O MMC de <literal>p1</literal> e <literal>p2</literal> é dado
             por:
         </para>
         <para>
         <title>Exemplos</title>
         <programlisting role="example"><![CDATA[
 // caso polinomial
-x=poly(0,'x');
-p1=(x+1)*(x-3)^5;p2=(x-2)*(x-3)^3;
-[thegcd,U]=bezout(p1,p2)
+x = poly(0,'x');
+p1 = (x+1)*(x-3)^5;
+p2 = (x-2)*(x-3)^3;
+[thegcd,U] = bezout(p1,p2)
 det(U)
 clean([p1,p2]*U)
-thelcm=p1*U(1,2)
+thelcm = p1*U(1,2)
 lcm([p1,p2])
 
+// Double case
+i1 = 2*3^5;
+i2 = 2^3*3^2;
+[thegcd,U] = bezout(i1, i2)
+V = [2^2*3^5 2^3*3^2 2^2*3^4*5];
+[thegcd,U] = gcd(V)
+V*U
+lcm(V)
+
 // caso inteiro
-i1=int32(2*3^5); i2=int32(2^3*3^2);
-[thegcd,U]=bezout(i1,i2)
-V=int32([2^2*3^5, 2^3*3^2,2^2*3^4*5]);
-[thegcd,U]=gcd(V)
+i1 = int32(2*3^5);
+i2 = int32(2^3*3^2);
+[thegcd,U] = bezout(i1,i2)
+V = int32([2^2*3^5, 2^3*3^2,2^2*3^4*5]);
+[thegcd,U] = gcd(V)
 V*U
 lcm(V)
  ]]></programlisting>
     </refsection>
     <refsection>
-        <title> Ver Também</title>
+        <title> Ver Também</title>
         <simplelist type="inline">
             <member>
+                <link linkend="gcd">gcd</link>
+            </member>
+            <member>
+                <link linkend="lcm">lcm</link>
+            </member>
+            <member>
                 <link linkend="poly">poly</link>
             </member>
             <member>
@@ -90,9 +130,6 @@ lcm(V)
             <member>
                 <link linkend="clean">clean</link>
             </member>
-            <member>
-                <link linkend="lcm">lcm</link>
-            </member>
         </simplelist>
     </refsection>
 </refentry>
index cc289cb..19d563a 100644 (file)
@@ -42,10 +42,11 @@ types::Function::ReturnValue sci_bezout(types::typed_list &in, int _iRetCount, t
         return types::Function::Error;
     }
 
-    if (_iRetCount != 2 && _iRetCount != 3)
+    if (_iRetCount > 3)
     {
-        Scierror(78, _("%s: Wrong number of output argument(s): %d to %d expected.\n"), "bezout", 2, 3);
+        Scierror(78, _("%s: Wrong number of output argument(s): %d to %d expected.\n"), "bezout", 1, 3);
         return types::Function::Error;
+        // _iRetCount==3 is undocumented. May be it is used in an internal way
     }
 
     // get input arguments
@@ -115,23 +116,27 @@ types::Function::ReturnValue sci_bezout(types::typed_list &in, int _iRetCount, t
     pPolyGCD->set(0, pSP);
     delete pSP;
 
-    types::Polynom* pPolyU = new types::Polynom(wstrName, 2, 2);
-    for (int i = 0; i < 4; i++)
+    // return result
+    out.push_back(pPolyGCD);
+
+    if (_iRetCount > 1)
     {
-        int ii     = i + 1;
-        int iRankU = ipb[ii + 1] - ipb[ii];
-        double* pdblU = NULL;
-        types::SinglePoly* pSPU = new types::SinglePoly(&pdblU, iRankU - 1);
-        memcpy(pdblU, pdblOut + ipb[ii] - 1, iRankU * sizeof(double));
-        pPolyU->set(i, pSPU);
-        delete pSPU;
+        types::Polynom* pPolyU = new types::Polynom(wstrName, 2, 2);
+        for (int i = 0; i < 4; i++)
+        {
+            int ii     = i + 1;
+            int iRankU = ipb[ii + 1] - ipb[ii];
+            double* pdblU = NULL;
+            types::SinglePoly* pSPU = new types::SinglePoly(&pdblU, iRankU - 1);
+            memcpy(pdblU, pdblOut + ipb[ii] - 1, iRankU * sizeof(double));
+            pPolyU->set(i, pSPU);
+            delete pSPU;
+        }
+        out.push_back(pPolyU);
     }
 
     delete[] pdblOut;
 
-    // return result
-    out.push_back(pPolyGCD);
-    out.push_back(pPolyU);
 
     if (_iRetCount == 3)
     {
@@ -141,4 +146,3 @@ types::Function::ReturnValue sci_bezout(types::typed_list &in, int _iRetCount, t
     return types::Function::OK;
 }
 /*--------------------------------------------------------------------------*/
-
index 9021088..d31b266 100644 (file)
@@ -562,6 +562,17 @@ p1=1;p2=1;
 [p,U]=bezout(p1,p2+0);if norm(coeff([p1 p2]*U-[p 0]))>10*%eps  then pause,end
 [p,U]=bezout(p1+0,p2+0);if norm(coeff([p1 p2]*U-[p 0]))>10*%eps  then pause,end
 
+//bezout single output
+p1=1;p2=1;
+[p, U] = bezout(p1,p2);
+assert_checkequal(p, bezout(p1,p2));
+[p, U] = bezout(p1+0,p2);
+assert_checkequal(p, bezout(p1+0,p2));
+[p, U] = bezout(p1,p2+0);
+assert_checkequal(p, bezout(p1,p2+0));
+[p, U] = bezout(p1+0,p2+0);
+assert_checkequal(p, bezout(p1+0,p2+0));
+
 
 //sfact
 p=(%s-1/2)*(2-%s);