<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - answers and comments on Question, Incapable de programmer dans maple ( Probleme de maths)</title>
    <link>http://www.mapleprimes.com/questions/99353-Incapable-De-Programmer-Dans-Maple--Probleme-De-Maths</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Fri, 12 Jun 2026 03:43:25 GMT</lastBuildDate>
    <pubDate>Fri, 12 Jun 2026 03:43:25 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest answers and comments added to the Question, Incapable de programmer dans maple ( Probleme de maths)</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - answers and comments on Question, Incapable de programmer dans maple ( Probleme de maths)</title>
      <link>http://www.mapleprimes.com/questions/99353-Incapable-De-Programmer-Dans-Maple--Probleme-De-Maths</link>
    </image>
    <item>
      <title>idea</title>
      <link>http://www.mapleprimes.com/questions/99353-Incapable-De-Programmer-Dans-Maple--Probleme-De-Maths?ref=Feed:MaplePrimes:Incapable de programmer dans maple ( Probleme de maths):Comments#answer99354</link>
      <itunes:summary>&lt;p&gt;Perhaps your recursive binary search routine could pass 4 arguments instead of 3 arguments, and always pass along the full L. (I realize that this might not be the original assignment, but I'll lay out the idea anyway, for efficiency's sake.)&lt;/p&gt;
&lt;pre&gt;ZeFouilleDicho( L, x, G, D)&lt;/pre&gt;
&lt;p&gt;Here, the G is the left end position of the subrange of L on which one wishes to search. And D is the right end position.&lt;/p&gt;
&lt;p&gt;One starts it off with an initial call like ZeFouilleDicho( L, 4, 1, nops(L)) since nops(L) is the last position of the previously sorted list L.&lt;/p&gt;
&lt;p&gt;The routine determines which half of L, ie. the subrange L[G..D], one need to recurse into. Of course L[G..D] is never formed or passed along. Only the full list L is ever re-passed. That's the efficiency point. (One could also get rid of the recursion altogether, and do a binary search. But I'll retain the recursive nature, in the spirit of the assigned task.)&lt;/p&gt;
&lt;p&gt;Note that you might consider using square brackets like L:=[1, 2, 4, 5, 6, 9, 11, 16] to make L a Maple list rather than squiggly brackets {} which are for creating Maple sets. That's because you might want to extend the code to handle exact symbolic constants like sqrt(2) or a mix of floats and exact integers. Compare,&lt;/p&gt;
&lt;pre&gt;&amp;gt; L:={1.2, 3, 4.6, 5, 7}; 
                      {3, 5, 7, 1.2, 4.6}
&amp;gt; L[1..3]; # oops, L isn't sorted as one might mistakenly expect
                           {3, 5, 7}

&amp;gt; L:=[1.2, 3, 4.6, 5, 7]; 
                      [1.2, 3, 4.6, 5, 7]
&amp;gt; L[1..3];
                         [1.2, 3, 4.6]
&lt;/pre&gt;
&lt;p&gt;This recursive algorithm in which L is only ever passed in full is interesting because it avoids creating the sublists like L[G..D] explicitly. It passes along the extra 2 (G &amp;amp; D) pieces of positional information which denote that subrange. By avoiding creating each sublist explicitly, its avoid creating a whole bunch of sub-lists as collectible garbage. (This is the situation described in the 3rd paragraph &lt;a href="http://www.mapleprimes.com/posts/98790-Subvectors-As-Arguments"&gt;here&lt;/a&gt;, where you yourself own and author `f`.)&lt;/p&gt;
&lt;p&gt;Here's one possible implementation (of my suggestion, and technically not of what's asked above):&lt;/p&gt;
&lt;pre&gt;bs := proc(L,x,g,d)
  local mp;
  if d=g then d;
  elif x=L[g] then g;
  elif x=L[d] then d;
  elif x&amp;lt;L[g] or x&amp;gt;L[d] then
    error "x not in L";
  else
    mp := trunc((d+g)/2);
    if g=mp then g,d;
    elif x=L[mp] then mp;
    elif x&amp;gt;L[mp] then
      if d=mp+1 then mp,d;
      else
        procname(L,x,mp,d);
      end if;
    else
      if g=mp+1 then d,mp;
      else
        procname(L,x,g,mp);
      end if;
    end if;
  end if;
end proc:

L:=[3,4,5,6,7,9,10,11,12]:
bs(L,9,1,nops(L));
                               6
bs(L,5.5,1,nops(L));
                              3, 4
bs(L,3,1,nops(L));
                               1
bs(L,12,1,nops(L));
                               9

N := 10^7:
L := [seq(i,i=10^3..N)]:
st,ba,bu := time(),kernelopts(bytesalloc),kernelopts(bytesused):
bs(L,L[43*N/100],1,nops(L));
time()-st, kernelopts(bytesalloc)-ba ,kernelopts(bytesused)-bu;

                            4300000
                         0.172, 0, 7804
&lt;/pre&gt;
&lt;p&gt;Note that bytesused goes up very little, indicating that little garbage collection is needed and done. (Which helps keep the timing down.) Of course a Compiled routine could be faster, but that's a whole other game. The performance of 'bs` is not too bad, compared to ListTools:-Search which uses the very fast kernel builtin `member` routine. (It likely could be made better, if the recursion mandate were dropped.)&lt;/p&gt;
&lt;pre&gt;st,ba,bu := time(),kernelopts(bytesalloc),kernelopts(bytesused):
ListTools:-Search(L[43*N/100],L);
time()-st, kernelopts(bytesalloc)-ba ,kernelopts(bytesused)-bu;
                            4300000
                         0.093, 0, 1880
&lt;/pre&gt;
&lt;p&gt;acer&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;Perhaps your recursive binary search routine could pass 4 arguments instead of 3 arguments, and always pass along the full L. (I realize that this might not be the original assignment, but I'll lay out the idea anyway, for efficiency's sake.)&lt;/p&gt;
&lt;pre&gt;ZeFouilleDicho( L, x, G, D)&lt;/pre&gt;
&lt;p&gt;Here, the G is the left end position of the subrange of L on which one wishes to search. And D is the right end position.&lt;/p&gt;
&lt;p&gt;One starts it off with an initial call like ZeFouilleDicho( L, 4, 1, nops(L)) since nops(L) is the last position of the previously sorted list L.&lt;/p&gt;
&lt;p&gt;The routine determines which half of L, ie. the subrange L[G..D], one need to recurse into. Of course L[G..D] is never formed or passed along. Only the full list L is ever re-passed. That's the efficiency point. (One could also get rid of the recursion altogether, and do a binary search. But I'll retain the recursive nature, in the spirit of the assigned task.)&lt;/p&gt;
&lt;p&gt;Note that you might consider using square brackets like L:=[1, 2, 4, 5, 6, 9, 11, 16] to make L a Maple list rather than squiggly brackets {} which are for creating Maple sets. That's because you might want to extend the code to handle exact symbolic constants like sqrt(2) or a mix of floats and exact integers. Compare,&lt;/p&gt;
&lt;pre&gt;&amp;gt; L:={1.2, 3, 4.6, 5, 7}; 
                      {3, 5, 7, 1.2, 4.6}
&amp;gt; L[1..3]; # oops, L isn't sorted as one might mistakenly expect
                           {3, 5, 7}

&amp;gt; L:=[1.2, 3, 4.6, 5, 7]; 
                      [1.2, 3, 4.6, 5, 7]
&amp;gt; L[1..3];
                         [1.2, 3, 4.6]
&lt;/pre&gt;
&lt;p&gt;This recursive algorithm in which L is only ever passed in full is interesting because it avoids creating the sublists like L[G..D] explicitly. It passes along the extra 2 (G &amp;amp; D) pieces of positional information which denote that subrange. By avoiding creating each sublist explicitly, its avoid creating a whole bunch of sub-lists as collectible garbage. (This is the situation described in the 3rd paragraph &lt;a href="http://www.mapleprimes.com/posts/98790-Subvectors-As-Arguments"&gt;here&lt;/a&gt;, where you yourself own and author `f`.)&lt;/p&gt;
&lt;p&gt;Here's one possible implementation (of my suggestion, and technically not of what's asked above):&lt;/p&gt;
&lt;pre&gt;bs := proc(L,x,g,d)
  local mp;
  if d=g then d;
  elif x=L[g] then g;
  elif x=L[d] then d;
  elif x&amp;lt;L[g] or x&amp;gt;L[d] then
    error "x not in L";
  else
    mp := trunc((d+g)/2);
    if g=mp then g,d;
    elif x=L[mp] then mp;
    elif x&amp;gt;L[mp] then
      if d=mp+1 then mp,d;
      else
        procname(L,x,mp,d);
      end if;
    else
      if g=mp+1 then d,mp;
      else
        procname(L,x,g,mp);
      end if;
    end if;
  end if;
end proc:

L:=[3,4,5,6,7,9,10,11,12]:
bs(L,9,1,nops(L));
                               6
bs(L,5.5,1,nops(L));
                              3, 4
bs(L,3,1,nops(L));
                               1
bs(L,12,1,nops(L));
                               9

N := 10^7:
L := [seq(i,i=10^3..N)]:
st,ba,bu := time(),kernelopts(bytesalloc),kernelopts(bytesused):
bs(L,L[43*N/100],1,nops(L));
time()-st, kernelopts(bytesalloc)-ba ,kernelopts(bytesused)-bu;

                            4300000
                         0.172, 0, 7804
&lt;/pre&gt;
&lt;p&gt;Note that bytesused goes up very little, indicating that little garbage collection is needed and done. (Which helps keep the timing down.) Of course a Compiled routine could be faster, but that's a whole other game. The performance of 'bs` is not too bad, compared to ListTools:-Search which uses the very fast kernel builtin `member` routine. (It likely could be made better, if the recursion mandate were dropped.)&lt;/p&gt;
&lt;pre&gt;st,ba,bu := time(),kernelopts(bytesalloc),kernelopts(bytesused):
ListTools:-Search(L[43*N/100],L);
time()-st, kernelopts(bytesalloc)-ba ,kernelopts(bytesused)-bu;
                            4300000
                         0.093, 0, 1880
&lt;/pre&gt;
&lt;p&gt;acer&lt;/p&gt;</description>
      <guid>99354</guid>
      <pubDate>Tue, 23 Nov 2010 21:57:11 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
  </channel>
</rss>