* Bug 16244 fixed: perms() checkmemory & 'unique' 26/21126/7
Samuel GOUGEON [Sun, 10 Nov 2019 21:58:08 +0000 (22:58 +0100)]
  http://bugzilla.scilab.org/16244

  PDF page: http://bugzilla.scilab.org/attachment.cgi?id=5024

  See also: https://codereview.scilab.org/21124

  Supporting "unique" for complex numbers is prevented, until
  the required https://codereview.scilab.org/20723 is merged.

  Extension of factorial() at https://codereview.scilab.org/19940
  would increase perms() robustness.

  m2sci: no reason to keep perms() in the "Not yet converted" list
         (even without this patch). All Matlab perms() syntaxes exist
         as is in Scilab. m2sci_perms() had no unit test.

Change-Id: I52bdc025ba530a63a1369650c1f5d133bc619f9e

12 files changed:
scilab/CHANGES.md
scilab/modules/core/tests/nonreg_tests/bug_8086.tst
scilab/modules/elementary_functions/help/en_US/setoperations/perms.xml
scilab/modules/elementary_functions/help/fr_FR/setoperations/perms.xml
scilab/modules/elementary_functions/help/ja_JP/setoperations/perms.xml [deleted file]
scilab/modules/elementary_functions/help/pt_BR/setoperations/perms.xml [deleted file]
scilab/modules/elementary_functions/help/ru_RU/setoperations/perms.xml [deleted file]
scilab/modules/elementary_functions/macros/perms.sci
scilab/modules/elementary_functions/tests/unit_tests/perms.tst [new file with mode: 0644]
scilab/modules/m2sci/help/en_US/m2sci_equivalents/p/perms.xml [deleted file]
scilab/modules/m2sci/macros/kernel/not_yet_converted.sci
scilab/modules/m2sci/macros/sci_files/sci_perms.sci [deleted file]

index 9141e84..1ac9863 100644 (file)
@@ -185,6 +185,8 @@ Feature changes and additions
   - The content of implicitlist objects, and information for Scilab functions and libraries of functions are now displayed.
 * `nchoosek` is introduced, to compute the binomial coefficients.
 * The left .\. and right ./. Kronecker divisions are now implemented, for arrays of decimal or complex numbers.
+* `perms` can now build and return only unique permutations, without duplicates.
+
 
 Help pages:
 -----------
@@ -454,6 +456,7 @@ Bug Fixes
 * [#16232](https://bugzilla.scilab.org/16232): `colorbar` did not support `$` in `colminmax`, standing for the number of colors in the current color map.
 * [#16234](https://bugzilla.scilab.org/16234): Airy functions were not available.
 * [#16242](https://bugzilla.scilab.org/16242): `loadmatfile` could not read Octave native text data files.
+* [#16244](http://bugzilla.scilab.org/show_bug.cgi?id=16244): `perms` could freeze the whole computer. It could not ignore duplicate permutations.
 * [#16245](https://bugzilla.scilab.org/16245): `gsort` could not sort booleans.
 * [#16246](https://bugzilla.scilab.org/16246): `isvector` was broken for sparse matrices.
 * [#16257](https://bugzilla.scilab.org/16257): `blockdiag` implemented to replace `sysdiag`, improved and extended to strings.
@@ -477,3 +480,4 @@ Bug Fixes
 * [#16321](https://bugzilla.scilab.org/16321): There were typo errors in the documentation.
 * [#16323](https://bugzilla.scilab.org/16323): `conj(sparse(x))` was complex when x is real.
 * [#16325](https://bugzilla.scilab.org/16325): `mgetl` could not read single line data which is greater than ~260,000 characters.
+
index 4c5864e..ab6b181 100644 (file)
@@ -52,7 +52,6 @@ macros_error_type_1 = ["isscalar"; ..
 "ndims"; ..
 "nextpow2"; ..
 "oct2dec"; ..
-"perms"; ..
 "pertrans"; ..
 "primes"; ..
 "sec"; ..
index 8e27dbe..158dd1c 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) 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.
  * 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="perms" xml:lang="en">
+<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="perms" xml:lang="en">
     <refnamediv>
         <refname>perms</refname>
-        <refpurpose>Set of all permutations of given components</refpurpose>
+        <refpurpose>Set of permutations of given components</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Syntax</title>
-        <synopsis>y=perms(x)</synopsis>
+        <synopsis>
+            y = perms(x)
+            y = perms(x, "unique")
+        </synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>Arguments</title>
             <varlistentry>
                 <term>x</term>
                 <listitem>
-                    <para>scalar or vector</para>
+                    <para>
+                        Row or column vector of any data type for which the size(), ==, and []
+                        operators are defined, including cells.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>"unique"</term>
+                <listitem>
+                    <para>
+                        Optional text flag, to compute and return the whole set of
+                        unique permutations, <emphasis>without any duplicate</emphasis> row.
+                        This option can be used only if <varname>x</varname> is sortable.
+                        That applies to boolean, integer, real number, and text data types.
+                    </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
                 <term>y</term>
                 <listitem>
-                    <para>matrix</para>
+                    <para>
+                        Array of the type of x, with n=size(x,"*") columns.
+                        Each row provides a permutation. Without using the "unique" option,
+                        <varname>y</varname> returns n! rows. Otherwise, the number
+                        size(y,1)≤ n! of rows depends on the multiplicities of unique values of x.
+                    </para>
                 </listitem>
             </varlistentry>
         </variablelist>
     <refsection>
         <title>Description</title>
         <para>
-            Given a vector <literal>x</literal> of length <literal>n</literal>,
-            <literal>perms</literal> returns all the permutations of the
-            <literal>n</literal> components of <literal>x</literal> (i.e
-            <literal>n!</literal> permutations). The size of <literal>y</literal>
-            is <literal> n!-by-n.</literal>
+            Given a vector <varname>x</varname> of length <literal>n</literal>,
+            <literal>perms(..)</literal> computes the expected number of permutations,
+            and checks if there is enough available memory to compute and store them as the result.
+        </para>
+        <para>
+            If there is not enough memory, nothing else is done and an error is generated.
+        </para>
+        <para>
+            Otherwise, the permutations are computed and returned.
+        </para>
+        <note>
+            When "unique" is used,
+            <itemizedlist>
+                <listitem>
+                    if no duplicate is detected in <varname>x</varname>, the computations are done
+                    as without "unique", that is faster.
+                </listitem>
+                <listitem>
+                    <varname>x</varname> is first sorted in ascending direction, and
+                    <varname>y</varname> is built in ascending lexicographic order.
+                </listitem>
+            </itemizedlist>
+            Otherwise : The initial order of <varname>x</varname> components is kept, and the order
+            of permutations in <varname>y</varname> takes it into account. Thus, if necessary,
+            <varname>x</varname> can be sorted according to the order <emphasis>chosen by the user,
+            before</emphasis> calling <literal>perms()</literal>.
+        </note>
+        <warning>
+            As a reminder, here is the weight <varname>n*n!*8</varname> of <varname>y</varname>
+            in bytes, vs the length <literal>n</literal> of <varname>x</varname>,
+            if <varname>x</varname> are decimal numbers and "unique" is not used:
+        </warning>
+        <para>
+            <table border="1">
+                <tr align="center">
+                    <th>n</th>
+                    <td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td>
+                    <td>9</td><td>10</td><td>11</td><td>12</td><td>13</td>
+                </tr>
+                <tr>
+                    <th>y [bytes]</th>
+                    <td>32</td><td>144</td><td>768</td><td>4800</td><td>34560</td><td>288240</td>
+                    <td>2.58×10<superscript>6</superscript></td>
+                    <td>26.1×10<superscript>6</superscript></td>
+                    <td>290×10<superscript>6</superscript></td>
+                    <td>3.51×10<superscript>9</superscript></td>
+                    <td>46.0×10<superscript>9</superscript></td>
+                    <td>648×10<superscript>9</superscript></td>
+                </tr>
+            </table>
         </para>
     </refsection>
     <refsection>
         <title>Examples</title>
         <programlisting role="example"><![CDATA[
-x=[4, 7, 10]
-y=perms(x)
-x=[1, 5, 2, 5]
-y=perms(x)
+x = [4, 7, 10];
+y = perms(x)
+
+x = ["a" "b" "c" "d"];
+y = perms(x)'
+
+c = {"bonjour", %pi, %t};
+perms(c)
+ ]]></programlisting>
+    <screen><![CDATA[
+--> x = [4, 7, 10];
+--> y = perms(x)
+ y  =
+   10.   7.    4.
+   10.   4.    7.
+   7.    10.   4.
+   7.    4.    10.
+   4.    10.   7.
+   4.    7.    10.
+
+--> x = ["a" "b" "c" "d"];
+--> perms(x)'
+ ans  =
+!d  d  d  d  d  d  c  c  c  c  c  c  b  b  b  b  b  b  a  a  a  a  a  a  !
+!c  c  b  b  a  a  d  d  b  b  a  a  d  d  c  c  a  a  d  d  c  c  b  b  !
+!b  a  c  a  c  b  b  a  d  a  d  b  c  a  d  a  d  c  c  b  d  b  d  c  !
+!a  b  a  c  b  c  a  b  a  d  b  d  a  c  a  d  c  d  b  c  b  d  c  d  !
+
+--> c = {"bonjour", %pi, %t};
+--> perms(c)
+ ans  =
+  [1x1 boolean ]  [1x1 constant]  [1x1 string  ]
+  [1x1 boolean ]  [1x1 string  ]  [1x1 constant]
+  [1x1 constant]  [1x1 boolean ]  [1x1 string  ]
+  [1x1 constant]  [1x1 string  ]  [1x1 boolean ]
+  [1x1 string  ]  [1x1 boolean ]  [1x1 constant]
+  [1x1 string  ]  [1x1 constant]  [1x1 boolean ]
+]]></screen>
+    <para>
+        With duplicate elements:
+    </para>
+    <programlisting role="example"><![CDATA[
+perms([1 0 0])
+perms([1 0 0], "unique")
+perms([0 1 2 0], "unique")'
+p = perms([0 0 0 0 1 1 1 2 2 3], "unique");
+size(p)
  ]]></programlisting>
+    <screen><![CDATA[
+--> perms([1 0 0])
+ ans  =
+   0.   0.   1.
+   0.   1.   0.
+   0.   0.   1.
+   0.   1.   0.
+   1.   0.   0.
+   1.   0.   0.
+
+--> perms([1 0 0], "unique")
+ ans  =
+   0.   0.   1.
+   0.   1.   0.
+   1.   0.   0.
+
+--> perms([0 1 2 0], "unique")'
+ ans  =
+   0.   0.   0.   0.   0.   0.   1.   1.   1.   2.   2.   2.
+   0.   0.   1.   1.   2.   2.   0.   0.   2.   0.   0.   1.
+   1.   2.   0.   2.   0.   1.   0.   2.   0.   0.   1.   0.
+   2.   1.   2.   0.   1.   0.   2.   0.   0.   1.   0.   0.
+
+--> p = perms([0 0 0 0 1 1 1 2 2 3], "unique");
+--> size(p)
+ ans  =
+   12600.   10.  // instead of 10! = 3628800 rows
+]]></screen>
+    </refsection>
+    <refsection role="see also">
+        <title>See Also</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="grand">grand(x,'prm')</link>
+            </member>
+            <member>
+                <link linkend="factorial">factorial</link>
+            </member>
+            <member>
+                <link linkend="unique">unique</link>
+            </member>
+            <member>
+                <link linkend="gsort">gsort</link>
+            </member>
+            <member>
+                <link linkend="try">try</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    "unique" option introduced.
+                </revdescription>
+            </revision>
+        </revhistory>
     </refsection>
 </refentry>
index 7b9cd20..a878f12 100644 (file)
@@ -1,28 +1,65 @@
 <?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: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="perms" xml:lang="fr">
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2008 - INRIA
+ * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 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.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * 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="perms" xml:lang="fr">
     <refnamediv>
         <refname>perms</refname>
-        <refpurpose>
-                       Ensemble des permutations des éléments donnés
-        </refpurpose>
+        <refpurpose>Ensemble des permutations des éléments donnés</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Séquence d'appel</title>
-        <synopsis>y=perms(x)</synopsis>
+        <synopsis>
+            y = perms(x)
+            y = perms(x, "unique")
+        </synopsis>
     </refsynopsisdiv>
     <refsection>
-        <title>Paramètres</title>
+        <title>Arguments</title>
         <variablelist>
             <varlistentry>
                 <term>x</term>
                 <listitem>
-                    <para>vecteur ou matrice</para>
+                    <para>
+                        Vecteur ligne ou colonne de tout type de données pour lesquelles les
+                        opérateurs size(), ==, et [] sont définis, incluant le type cell.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>"unique"</term>
+                <listitem>
+                    <para>
+                        indicateur texte optionnel, pour calculer et produire uniquement les
+                        permutations uniques, sans aucun doublon.
+                        Cette option est utilisable uniquement si <varname>x</varname> est ordonnable :
+                        booléen, entier, réel, ou texte.
+                    </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
                 <term>y</term>
                 <listitem>
-                    <para>matrice</para>
+                    <para>
+                        Tableau du type de x, avec n=size(x,"*") colonnes.
+                        Chaque ligne contient une permutation. Sans utiliser l'option "unique",
+                        <varname>y</varname> comprend n! lignes. Sinon, le nombre de lignes
+                        size(y,1) ≤ n! dépend de la multiplicité des valeurs dédoublonnées de x.
+                    </para>
                 </listitem>
             </varlistentry>
         </variablelist>
     <refsection>
         <title>Description</title>
         <para>
-            Etant donné un vecteur <literal>x</literal> de longueur
-            <literal>n</literal>, la fonction <literal>perms</literal> retourne toutes
-            les permutations des <literal>n</literal> elements du vecteur
-            <literal>x</literal>, soit <literal>n!</literal> permutations. La matrice
-            <literal>y</literal> est de taille <literal>n!-par-n</literal>.
+            Etant donné un vecteur <literal>x</literal> de <literal>n</literal> éléments,
+            <literal>perms(..)</literal> calcule le nombre attendu de permutations attendues,
+            et vérifie qu'il y a suffisamment de mémoire vive disponible pour les calculer et les
+            stocker en résultat.
+        </para>
+        <para>
+            S'il n'y a pas suffisamment de mémoire vive, aucun calcul effectif n'est effectué,
+            et une erreur est générée.
+        </para>
+        <para>
+            Sinon, les permutations sont calculées et retournées en résultat.
+        </para>
+        <note>
+            Lorsque "unique" est utilisé,
+            <itemizedlist>
+                <listitem>
+                    si aucun doublon n'est détecté dans <varname>x</varname>,
+                    l'algorithme sans "unique" est automatiquement utilisé pour effectuer
+                    les calculs plus rapidement.
+                </listitem>
+                <listitem>
+                    <varname>x</varname> est préalablement trié en ordre croissant, et
+                    <varname>y</varname> est construite en ordre lexicographique croissant.
+                </listitem>
+            </itemizedlist>
+            Sinon : l'ordre initial des éléments de <varname>x</varname> est conservé, et l'ordre
+            des permutations dans <varname>y</varname> en tient compte. Ainsi <varname>x</varname>
+            pourra si besoin être trié selon l'ordre <emphasis>choisi par l'utilisateur,
+            avant</emphasis> d'appeler <literal>perms()</literal>.
+        </note>
+        <warning>
+            Pour mémoire, le poids <varname>n*n!*8</varname> de <varname>y</varname> en octets
+            est listé ci-dessous en fonction du nombre <literal>n</literal> d'éléments de
+            <varname>x</varname>, pour <varname>x</varname> nombres décimaux, et sans
+            l'option "unique" :
+        </warning>
+        <para>
+            <table border="1">
+                <tr align="center">
+                    <th>n</th>
+                    <td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td>
+                    <td>9</td><td>10</td><td>11</td><td>12</td><td>13</td>
+                </tr>
+                <tr>
+                    <th>y [octets]</th>
+                    <td>32</td><td>144</td><td>768</td><td>4800</td><td>34560</td><td>288240</td>
+                    <td>2.58×10<superscript>6</superscript></td>
+                    <td>26.1×10<superscript>6</superscript></td>
+                    <td>290×10<superscript>6</superscript></td>
+                    <td>3.51×10<superscript>9</superscript></td>
+                    <td>46.0×10<superscript>9</superscript></td>
+                    <td>648×10<superscript>9</superscript></td>
+                </tr>
+            </table>
         </para>
     </refsection>
     <refsection>
         <title>Exemples</title>
         <programlisting role="example"><![CDATA[
-x=[4, 7, 10]
-y=perms(x)
-x=[1, 5, 2, 5]
-y=perms(x)
+x = [4, 7, 10];
+y = perms(x)
+
+x = ["a" "b" "c" "d"];
+y = perms(x)'
+
+c = {"bonjour", %pi, %t};
+perms(c)
+ ]]></programlisting>
+    <screen><![CDATA[
+--> x = [4, 7, 10];
+--> y = perms(x)
+ y  =
+   10.   7.    4.
+   10.   4.    7.
+   7.    10.   4.
+   7.    4.    10.
+   4.    10.   7.
+   4.    7.    10.
+
+--> x = ["a" "b" "c" "d"];
+--> perms(x)'
+ ans  =
+!d  d  d  d  d  d  c  c  c  c  c  c  b  b  b  b  b  b  a  a  a  a  a  a  !
+!c  c  b  b  a  a  d  d  b  b  a  a  d  d  c  c  a  a  d  d  c  c  b  b  !
+!b  a  c  a  c  b  b  a  d  a  d  b  c  a  d  a  d  c  c  b  d  b  d  c  !
+!a  b  a  c  b  c  a  b  a  d  b  d  a  c  a  d  c  d  b  c  b  d  c  d  !
+
+--> c = {"bonjour", %pi, %t};
+--> perms(c)
+ ans  =
+  [1x1 boolean ]  [1x1 constant]  [1x1 string  ]
+  [1x1 boolean ]  [1x1 string  ]  [1x1 constant]
+  [1x1 constant]  [1x1 boolean ]  [1x1 string  ]
+  [1x1 constant]  [1x1 string  ]  [1x1 boolean ]
+  [1x1 string  ]  [1x1 boolean ]  [1x1 constant]
+  [1x1 string  ]  [1x1 constant]  [1x1 boolean ]
+]]></screen>
+    <para>
+        Avec des éléments de multiplicité > 1 (doublons ou plus) :
+    </para>
+    <programlisting role="example"><![CDATA[
+perms([1 0 0])
+perms([1 0 0], "unique")
+perms([0 1 2 0], "unique")'
+p = perms([0 0 0 0 1 1 1 2 2 3], "unique");
+size(p)
  ]]></programlisting>
+    <screen><![CDATA[
+--> perms([1 0 0])
+ ans  =
+   0.   0.   1.
+   0.   1.   0.
+   0.   0.   1.
+   0.   1.   0.
+   1.   0.   0.
+   1.   0.   0.
+
+--> perms([1 0 0], "unique")
+ ans  =
+   0.   0.   1.
+   0.   1.   0.
+   1.   0.   0.
+
+--> perms([0 1 2 0], "unique")'
+ ans  =
+   0.   0.   0.   0.   0.   0.   1.   1.   1.   2.   2.   2.
+   0.   0.   1.   1.   2.   2.   0.   0.   2.   0.   0.   1.
+   1.   2.   0.   2.   0.   1.   0.   2.   0.   0.   1.   0.
+   2.   1.   2.   0.   1.   0.   2.   0.   0.   1.   0.   0.
+
+--> p = perms([0 0 0 0 1 1 1 2 2 3], "unique");
+--> size(p)
+ ans  =
+   12600.   10.  // au lieu de 10! = 3628800 lignes
+]]></screen>
+    </refsection>
+    <refsection role="see also">
+        <title>Voir aussi</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="grand">grand(n,'prm',x)</link>
+            </member>
+            <member>
+                <link linkend="factorial">factorial</link>
+            </member>
+            <member>
+                <link linkend="unique">unique</link>
+            </member>
+            <member>
+                <link linkend="gsort">gsort</link>
+            </member>
+            <member>
+                <link linkend="try">try</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection role="history">
+        <title>Historique</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    Option "unique" ajoutée.
+                </revdescription>
+            </revision>
+        </revhistory>
     </refsection>
 </refentry>
diff --git a/scilab/modules/elementary_functions/help/ja_JP/setoperations/perms.xml b/scilab/modules/elementary_functions/help/ja_JP/setoperations/perms.xml
deleted file mode 100644 (file)
index c327d7f..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2008 - INRIA
- *
- * Copyright (C) 2012 - 2016 - Scilab Enterprises
- *
- * 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.
- * This file was originally licensed under the terms of the CeCILL v2.1,
- * and continues to be available under such terms.
- * For more information, see the COPYING file which you should have received
- * 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="perms" xml:lang="ja">
-
-    <refnamediv>
-
-        <refname>perms</refname>
-
-        <refpurpose>ベクトル要素の全順列</refpurpose>
-
-    </refnamediv>
-
-    <refsynopsisdiv>
-
-        <title>呼び出し手順</title>
-
-        <synopsis>y=perms(x)</synopsis>
-
-    </refsynopsisdiv>
-
-    <refsection>
-
-        <title>引数</title>
-
-        <variablelist>
-
-            <varlistentry>
-
-                <term>x</term>
-
-                <listitem>
-
-                    <para>スカラーまたはベクトル</para>
-
-                </listitem>
-
-            </varlistentry>
-
-            <varlistentry>
-
-                <term>y</term>
-
-                <listitem>
-
-                    <para>行列</para>
-
-                </listitem>
-
-            </varlistentry>
-
-        </variablelist>
-
-    </refsection>
-
-    <refsection>
-
-        <title>説明</title>
-
-        <para>
-
-            長さ <literal>n</literal>のベクトル <literal>x</literal> を指定すると,
-
-            <literal>perms</literal> は<literal>x</literal>の
-
-            <literal>n</literal>個の要素の全順列
-
-            (すなわち,<literal>n!</literal>順列)を返します.
-
-            <literal>y</literal>の大きさは <literal> n!-by-n</literal> となります.
-
-        </para>
-
-    </refsection>
-
-    <refsection>
-
-        <title>例</title>
-
-        <programlisting role="example"><![CDATA[
-x=[4, 7, 10]
-y=perms(x)
-x=[1, 5, 2, 5]
-y=perms(x)
- ]]></programlisting>
-
-    </refsection>
-
-</refentry>
-
diff --git a/scilab/modules/elementary_functions/help/pt_BR/setoperations/perms.xml b/scilab/modules/elementary_functions/help/pt_BR/setoperations/perms.xml
deleted file mode 100644 (file)
index f87ab42..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2008 - INRIA
- *
- * Copyright (C) 2012 - 2016 - Scilab Enterprises
- *
- * 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.
- * This file was originally licensed under the terms of the CeCILL v2.1,
- * and continues to be available under such terms.
- * For more information, see the COPYING file which you should have received
- * 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:ns4="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="perms" xml:lang="pt">
-    <refnamediv>
-        <refname>perms</refname>
-        <refpurpose>
-            conjunto de todas as permutações de determinados componentes
-        </refpurpose>
-    </refnamediv>
-    <refsynopsisdiv>
-        <title>Seqüência de Chamamento</title>
-        <synopsis>y=perms(x)</synopsis>
-    </refsynopsisdiv>
-    <refsection>
-        <title>Parâmetros</title>
-        <variablelist>
-            <varlistentry>
-                <term>x</term>
-                <listitem>
-                    <para>um escalar ou um vetor </para>
-                </listitem>
-            </varlistentry>
-            <varlistentry>
-                <term>y</term>
-                <listitem>
-                    <para>um escalar ou uma matriz</para>
-                </listitem>
-            </varlistentry>
-        </variablelist>
-    </refsection>
-    <refsection>
-        <title>Descrição</title>
-        <para>
-            Dado um vetor <literal>x</literal> de comprimento
-            <literal>n</literal>, <literal>perms</literal> retorna todas as
-            permutações dos <literal>n</literal> componentes de <literal>x</literal>
-            (i.e <literal>n!</literal> permutações). O tamanho de <literal>y</literal>
-            é <literal>n!-by-n</literal>
-        </para>
-    </refsection>
-    <refsection>
-        <title>Exemplos</title>
-        <programlisting role="example"><![CDATA[
-x=[4, 7, 10]
-y=perms(x)
-x=[1, 5, 2, 5]
-y=perms(x)
- ]]></programlisting>
-    </refsection>
-</refentry>
diff --git a/scilab/modules/elementary_functions/help/ru_RU/setoperations/perms.xml b/scilab/modules/elementary_functions/help/ru_RU/setoperations/perms.xml
deleted file mode 100644 (file)
index 18d1af9..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2008 - INRIA
- *
- * Copyright (C) 2012 - 2016 - Scilab Enterprises
- *
- * 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.
- * This file was originally licensed under the terms of the CeCILL v2.1,
- * and continues to be available under such terms.
- * For more information, see the COPYING file which you should have received
- * 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="perms" xml:lang="ru">
-    <refnamediv>
-        <refname>perms</refname>
-        <refpurpose>все сочетания компонентов вектора</refpurpose>
-    </refnamediv>
-    <refsynopsisdiv>
-        <title>Синтаксис</title>
-        <synopsis>y=perms(x)</synopsis>
-    </refsynopsisdiv>
-    <refsection>
-        <title>Аргументы</title>
-        <variablelist>
-            <varlistentry>
-                <term>x</term>
-                <listitem>
-                    <para>скаляр или вектор</para>
-                </listitem>
-            </varlistentry>
-            <varlistentry>
-                <term>y</term>
-                <listitem>
-                    <para>матрица</para>
-                </listitem>
-            </varlistentry>
-        </variablelist>
-    </refsection>
-    <refsection>
-        <title>Описание</title>
-        <para>
-            Для заданного вектора <literal>x</literal> длиной <literal>n</literal> функция
-            <literal>perms</literal> возвращает все сочетания <literal>n</literal> компонентов <literal>x</literal> (т. е. <literal>n!</literal> сочетаний). Размер  <literal>y</literal> равен <literal>n!</literal> на <literal>n</literal>.
-        </para>
-    </refsection>
-    <refsection>
-        <title>Примеры</title>
-        <programlisting role="example"><![CDATA[
-x=[4, 7, 10]
-y=perms(x)
-x=[1, 5, 2, 5]
-y=perms(x)
- ]]></programlisting>
-    </refsection>
-</refentry>
index 21b59d3..e763dbb 100644 (file)
@@ -1,8 +1,8 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) INRIA - Farid BELAHCENE
 // Copyright (C) DIGITEO - 2011 - Allan CORNET
-//
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
+// Copyright (C) 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.
 // For more information, see the COPYING file which you should have received
 // along with this program.
 
-function y = perms(x)
+function y = perms(x, unic, self, sortable)
+
+    // self, sortable: internal arguments for recursivity
 
     // PERMS function
-    // Given a vector x (size: 1*n or n*1), this function returns all the permutations of x (i.e n! permutations)
+    // Given an array x of size("*") = n, perms(x) returns the n! possible
+    //  permutations of x components.
     // Inputs :
     //  x : scalars/vectors
     // output :
     // y : matrix
-    // F.Belahcene
 
-    [lhs, rhs] = argn(0);
-    if rhs <> 1 then
-        error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected.\n"),"perms", 1));
+    // Top level instructions
+    // ----------------------
+    if ~isdef("self","l") | type(self)<>4 then
+        rhs = argn(2);
+        if rhs < 1 | rhs > 2 then
+            error(msprintf(gettext("%s: Wrong number of input argument(s): %d or %d expected.\n"),"perms", 1, 2));
+        end
+        xsize = size(x,"*")
+        if xsize < 2 then
+            y = x
+            return
+        end
+        x = x(:).'
+        unic = isdef("unic","l")
+        if unic
+            tx = type(x)
+            sortable = or(tx==[4 8 10]) | (or(tx==[1 5]) && isreal(x))
+            if sortable
+                if tx==4 // gsort() does not yet support booleans
+                    x = gsort(iconvert(x,1),"g","i")==int8(1)
+                else
+                    x = gsort(x,"g","i")
+                end
+                // Let's compute the expected number of permutations
+                    // tags for bounds after sorting
+                if or(tx==[1 5 8])
+                    joker = [x(1)-1, x($)+1]
+                elseif tx==4
+                    joker = ~[x(1) x($)];
+                else // text
+                    joker = [x(1) x($)] + "a";
+                end
+                    // groups of duplicates
+                gl = find([x joker(2)]<>[joker(1) x]);
+                gl = gl(2:$) - gl(1:$-1); // lengths of groups of duplicates
+                nperms = factorial(xsize);
+                if and(gl==1)       // There are only singletons
+                    unic = %f       // => the classical algo is faster
+                    x = x($:-1:1)   // But we match the order when "unique"
+                else
+                    nperms = nperms / prod(factorial(gl));
+                end
+                perms_checkMemory(x, xsize, nperms)
+            else
+                msg = _("perms: The ""unique"" option can be used only for sortable real numbers, booleans or texts.\n")
+                error(msprintf(msg))
+            end
+        elseif xsize > 8  // 8! = 40320  9! = 362880
+            perms_checkMemory(x, xsize, factorial(xsize))
+        end
+
+        if (recursionlimit() - recursionlimit("current")) < xsize
+            oldRecursionlimit = recursionlimit()
+            recursionlimit(recursionlimit("current") + xsize + 1)
+        end
+    else
+        xsize = size(x,"*")
     end
 
-    if size(x,"*")==1 | size(x,"*")==0 then
-        y = x;
-    elseif size(x,1)<>1 & size(x,2)<>1 then
-        error(msprintf(gettext("%s: Wrong size for input argument #%d: Vector expected.\n"),"perms", 1));
+
+    // PROCESSING
+    // ==========
+    if unic & sortable
+        // All DISTINCT permutations
+        // -------------------------
+        if xsize==3
+            y = [x([1 2 3]);
+                 x([1 3 2]);
+                 x([2 1 3]);
+                 x([2 3 1]);
+                 x([3 1 2]);
+                 x([3 2 1])];
+            // y = matrix(x([1 2 3 ; 1 3 2; 2 1 3 ; 2 3 1 ; 3 1 2; 3 2 1]), 6, -1)
+            b = (1:6)<0
+            b([3 4 6]) = x(1)==x(2)
+            b([4 5 6]) = b([4 5 6]) | x(1)==x(3)
+            b([2 5 6]) = b([2 5 6]) | x(2)==x(3)
+            y(b,:) = []
+        elseif xsize <> 2
+            k = [0 find(x(2:$)<>x(1:$-1)) xsize] + 1
+            y = []
+            for i = 1:length(k)-1
+                s = x; s(k(i)) = [];
+                np = 1
+                if xsize==2
+                    p = s
+                elseif xsize==3
+                    if s(1)==s(2)
+                        p = s
+                    else
+                        p = [s ; s([2 1])]
+                        np = 2
+                    end
+                else
+                    p = perms(s, unic, %t, %t)
+                    np = size(p,1)
+                end
+                if type(x)==10
+                    h = x(k(i)) + emptystr(np, 1)
+                else
+                    h = x(k(i)) * ones(np,1)
+                end
+                y = [y ; [h p]]
+            end
+        else // xsize==2 // we have necessarily x(1)==x(2) (otherwise => unic=%f)
+            y = x
+            //else
+            //    y = [x([2 1]) ; x]
+            //end
+        end
     else
-        xsize = size(x, "*");
-        indrec = perms(1:xsize-1);
-        ind = [ones(prod(1:xsize-1),1)*xsize, indrec];
-        for j = xsize-1:-1:1
-            indrec(indrec==j) = j + 1;
-            ind = [ind; [ones(prod(1:xsize-1),1)*j,indrec]];
+        // All permutations
+        // ----------------
+        if xsize==3
+            y = [x([3 2 1])
+                 x([3 1 2]);
+                 x([2 3 1]);
+                 x([2 1 3]);
+                 x([1 3 2]);
+                 x([1 2 3])];
+            // y = matrix(x([1 2 3 ; 1 3 2; 2 1 3 ; 2 3 1 ; 3 1 2; 3 2 1]), 6, -1)
+        elseif xsize <> 2
+            indrec = perms(1:xsize-1);
+            ind = [ones(prod(1:xsize-1),1)*xsize, indrec];
+            for j = xsize-1:-1:1
+                indrec(indrec==j) = j + 1;
+                ind = [ind; [ones(prod(1:xsize-1),1)*j,indrec]];
+            end
+            y = matrix(x(ind), size(ind));
+        else   // xsize == 2
+            y = [x([2 1]) ; x]
         end
-        y = matrix(x(ind), size(ind));
     end
 
+    if isdef("oldRecursionlimit","l") then
+        recursionlimit(oldRecursionlimit)
+    end
 endfunction
+// ----------------------------------------------------------------------------
 
+function perms_checkMemory(x, xsize, nperms)
+    // Checks available RAM. Yields an error if not enough memory
+    // nperms: expected number of permutations
+    // xsize = size(x,"*")
+
+    m = getmemory()*1024 / 3  // free RAM / 3 (for intermediate memory)
+
+    // Required memory for each row = for each permutation
+    select type(x)
+    case 1
+        wr = 8*xsize
+
+    case 4
+        wr = 4*xsize
+
+    case 5  // sparse
+        wr = nnz(x)*12   // 8 bytes for each value, 4 for each address
+
+    case 8  // integers
+        b = inttype(x)
+        if b>10, b = b-10, end
+        wr = b*xsize
+
+    case 10 // text => assessment:
+        wr = sum(length(x)) + xsize // lower bound, for only ascii chars
+
+    else    // polynomials, cells ...
+        [names, wr] = who('local');
+        wr = wr(find(names=="x"))
+    end
+
+    nsr = m / wr     // number of storable rows
+    if nsr < nperms
+        msg = _("perms: Too many permutations (%d). Would run out of memory.\n")
+        error(msprintf(msg, nperms))
+    end
+endfunction
diff --git a/scilab/modules/elementary_functions/tests/unit_tests/perms.tst b/scilab/modules/elementary_functions/tests/unit_tests/perms.tst
new file mode 100644 (file)
index 0000000..d16c219
--- /dev/null
@@ -0,0 +1,101 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+//
+// Copyright (C) 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.
+// This file was originally licensed under the terms of the CeCILL v2.1,
+// and continues to be available under such terms.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+//
+// =============================================================================
+//
+// <-- TEST WITH GRAPHIC -->  // for gda() and gdf()
+// <-- NO CHECK REF -->
+// <-- ENGLISH IMPOSED -->
+
+Ints = list();
+for t = [1 2 4 8 11 12 14 18]
+    Ints($+1) = iconvert([30 40], t);
+end
+
+assert_checkequal(perms([]), []);
+L1 = list([%t %f], Ints(:), [%e %pi], sparse([12 0]), ["abcdé","ABCD"], [1 %i], ..
+          [1+%z,1-%z], [gda(), gdf()], {3, %z});
+for o = L1
+    assert_checkequal(perms(o(1)), o(1));
+end
+for i = 1:length(L1)-1  // [cells] crash
+    o = L1(i)
+    assert_checkequal(perms(o), [o([2 1]); o]);
+end
+
+ref123 = [3,2,1;3,1,2;2,3,1;2,1,3;1,3,2;1,2,3];
+assert_checkequal(perms(1:3), ref123);
+
+for i = 2:7     // 7! = 5040  8! = 40320
+    p = perms(1:i);
+    assert_checkequal(size(p), [factorial(i) i]);
+    np = size(p,1);
+    for j = 1:i
+        assert_checktrue(and(sum(p==j,"r")==np/i));
+        assert_checktrue(and(sum(p==j,"c")==1));
+    end
+end
+// With complex numbers
+ref = [1+%i    %i      1
+       1+%i    1      %i
+        %i     1+%i    1
+        %i     1      1+%i
+        1     1+%i    %i
+        1     %i      1+%i];
+assert_checkequal(perms([1, %i, 1+%i]), ref);
+
+
+// With duplicates
+refDupl = [2,1,1,0,0;2,1,1,0,0;2,1,0,1,0;2,1,0,0,1;2,1,0,1,0;2,1,0,0,1;2,1,1,0,0;2,1,1,0,0;2,1,0,1,0;2,1,0,0,1;2,1,0,1,0;2,1,0,0,1;2,0,1,1,0;2,0,1,0,1;2,0,1,1,0;2,0,1,0,1;2,0,0,1,1;2,0,0,1,1;2,0,1,1,0;2,0,1,0,1;2,0,1,1,0;2,0,1,0,1;2,0,0,1,1;2,0,0,1,1;1,2,1,0,0;1,2,1,0,0;1,2,0,1,0;1,2,0,0,1;1,2,0,1,0;1,2,0,0,1;1,1,2,0,0;1,1,2,0,0;1,1,0,2,0;1,1,0,0,2;1,1,0,2,0;1,1,0,0,2;1,0,2,1,0;1,0,2,0,1;1,0,1,2,0;1,0,1,0,2;1,0,0,2,1;1,0,0,1,2;1,0,2,1,0;1,0,2,0,1;1,0,1,2,0;1,0,1,0,2;1,0,0,2,1;1,0,0,1,2;1,2,1,0,0;1,2,1,0,0;1,2,0,1,0;1,2,0,0,1;1,2,0,1,0;1,2,0,0,1;1,1,2,0,0;1,1,2,0,0;1,1,0,2,0;1,1,0,0,2;1,1,0,2,0;1,1,0,0,2;1,0,2,1,0;1,0,2,0,1;1,0,1,2,0;1,0,1,0,2;1,0,0,2,1;1,0,0,1,2;1,0,2,1,0;1,0,2,0,1;1,0,1,2,0;1,0,1,0,2;1,0,0,2,1;1,0,0,1,2;0,2,1,1,0;0,2,1,0,1;0,2,1,1,0;0,2,1,0,1;0,2,0,1,1;0,2,0,1,1;0,1,2,1,0;0,1,2,0,1;0,1,1,2,0;0,1,1,0,2;0,1,0,2,1;0,1,0,1,2;0,1,2,1,0;0,1,2,0,1;0,1,1,2,0;0,1,1,0,2;0,1,0,2,1;0,1,0,1,2;0,0,2,1,1;0,0,2,1,1;0,0,1,2,1;0,0,1,1,2;0,0,1,2,1;0,0,1,1,2;0,2,1,1,0;0,2,1,0,1;0,2,1,1,0;0,2,1,0,1;0,2,0,1,1;0,2,0,1,1;0,1,2,1,0;0,1,2,0,1;0,1,1,2,0;0,1,1,0,2;0,1,0,2,1;0,1,0,1,2;0,1,2,1,0;0,1,2,0,1;0,1,1,2,0;0,1,1,0,2;0,1,0,2,1;0,1,0,1,2;0,0,2,1,1;0,0,2,1,1;0,0,1,2,1;0,0,1,1,2;0,0,1,2,1;0,0,1,1,2];
+assert_checkequal(perms([0 0 1 1 2]), refDupl);
+
+// =============
+// With "unique"
+// =============
+assert_checkequal(perms([], "unique"), []);
+
+for o = L1
+    assert_checkequal(perms(o(1), "unique"), o(1));
+end
+for i = 1:12    // For complex nums: sorting is possible but not full => unusable
+    o = gsort(L1(i),"g","i");
+    assert_checkequal(perms(o, "unique"), [o ; o([2 1])]);
+end
+
+assert_checkequal(perms(1:3, "unique"), ref123($:-1:1,:));
+
+p = perms([1 2 3 4 zeros(1,9)], "unique");
+assert_checkequal(size(p), [17160 13]);
+
+assert_checkequal(perms([1 zeros(1,14)], "unique"), flipdim(eye(15,15),2));
+
+ref = [0,0,1,1,2;0,0,1,2,1;0,0,2,1,1;0,1,0,1,2;0,1,0,2,1;0,1,1,0,2;0,1,1,2,0;0,1,2,0,1;0,1,2,1,0;0,2,0,1,1;0,2,1,0,1;0,2,1,1,0;1,0,0,1,2;1,0,0,2,1;1,0,1,0,2;1,0,1,2,0;1,0,2,0,1;1,0,2,1,0;1,1,0,0,2;1,1,0,2,0;1,1,2,0,0;1,2,0,0,1;1,2,0,1,0;1,2,1,0,0;2,0,0,1,1;2,0,1,0,1;2,0,1,1,0;2,1,0,0,1;2,1,0,1,0;2,1,1,0,0];
+assert_checkequal(perms([0 0 1 1 2], "unique"), ref);
+
+
+// ==============
+// Error messages
+// ==============
+msg = "perms: Wrong number of input argument(s): 1 or 2 expected.";
+assert_checkerror("perms()", msg);
+assert_checkerror("perms(3,%t,4)", msg);
+
+msg = "perms: The ""unique"" option can be used only for sortable real numbers, booleans or texts.";
+assert_checkerror("perms([%i 1], ""unique"")", msg);
+assert_checkerror("perms([%z 1], ""unique"")", msg);
+assert_checkerror("perms([gdf() gda()], ""unique"")", msg);
+assert_checkerror("perms({1,%z}, ""unique"")", msg);
+
+msg = "perms: Too many permutations (479001600). Would run out of memory.";
+assert_checkerror("perms([1 zeros(1,11)]);", msg);
+msg = "perms: Too many permutations (672672000). Would run out of memory."; // 180 GB required
+assert_checkerror("perms([0 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4], ""unique"");", msg);
diff --git a/scilab/modules/m2sci/help/en_US/m2sci_equivalents/p/perms.xml b/scilab/modules/m2sci/help/en_US/m2sci_equivalents/p/perms.xml
deleted file mode 100644 (file)
index da0e47c..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2009 - DIGITEO - Vincent COUVERT
- *
- * Copyright (C) 2012 - 2016 - Scilab Enterprises
- *
- * 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.
- * This file was originally licensed under the terms of the CeCILL v2.1,
- * and continues to be available under such terms.
- * For more information, see the COPYING file which you should have received
- * 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:id="m2sci_perms">
-    <refnamediv>
-        <refname>perms (Matlab function)</refname>
-        <refpurpose>Array of all permutations of vector components</refpurpose>
-    </refnamediv>
-    <refsection>
-        <title>Matlab/Scilab equivalent</title>
-        <informaltable border="1" width="100%">
-            <tr>
-                <td align="center">
-                    <emphasis role="bold">Matlab</emphasis>
-                </td>
-                <td align="center">
-                    <emphasis role="bold">Scilab</emphasis>
-                </td>
-            </tr>
-            <tr>
-                <td>
-                    <programlisting role="example"><![CDATA[
-perms
-]]></programlisting>
-                </td>
-                <td>
-                    <programlisting role="example"><![CDATA[
-perms
-]]></programlisting>
-                </td>
-            </tr>
-        </informaltable>
-    </refsection>
-</refentry>
index 0c84b1b..b25895e 100644 (file)
@@ -856,7 +856,6 @@ function allnames=not_yet_converted()
     "peaks";
     "penny";
     "perl";
-    "perms";
     "permute";
     "persistent";
     "pie";
diff --git a/scilab/modules/m2sci/macros/sci_files/sci_perms.sci b/scilab/modules/m2sci/macros/sci_files/sci_perms.sci
deleted file mode 100644 (file)
index c67cdc7..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2004-2006 - INRIA - Farid BELAHCENE
-//
-// Copyright (C) 2012 - 2016 - Scilab Enterprises
-//
-// 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.
-// This file was originally licensed under the terms of the CeCILL v2.1,
-// and continues to be available under such terms.
-// For more information, see the COPYING file which you should have received
-// along with this program.
-
-function [tree]=sci_perms(tree)
-    // M2SCI function
-    // Conversion function for Matlab perms()
-    // Input: tree = Matlab funcall tree
-    // Ouput: tree = Scilab equivalent for tree
-
-    A=getrhs(tree)
-    tree.rhs=Rhs_tlist(A)
-
-    if (type(tree.rhs(1).dims(1))==1 & tree.rhs(1).dims(1)==1) & (type(tree.rhs(1).dims(2))==1 & tree.rhs(1).dims(2)<>-1) then
-        tree.lhs(1).dims(1)=prod(1:tree.rhs(1).dims(2))
-        tree.lhs(1).dims(2)=tree.rhs(1).dims(2)
-    elseif (type(tree.rhs(1).dims(2))==1 & tree.rhs(1).dims(2)==1) & (type(tree.rhs(1).dims(1))==1 & tree.rhs(1).dims(1)<>-1) then
-        tree.lhs(1).dims(1)=prod(1:tree.rhs(1).dims(1))
-        tree.lhs(1).dims(2)=tree.rhs(1).dims(1)
-    else
-        tree.lhs(1).dims(1)=-1
-        tree.lhs(1).dims(2)=-1
-    end
-
-    tree.lhs(1).type=tree.rhs(1).type
-
-endfunction