<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - comments on Post, The mysterious `if`</title>
    <link>http://www.mapleprimes.com/posts/140690-The-Mysterious-if</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Wed, 10 Jun 2026 23:48:58 GMT</lastBuildDate>
    <pubDate>Wed, 10 Jun 2026 23:48:58 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest comments added to the Post, The mysterious `if`</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - comments on Post, The mysterious `if`</title>
      <link>http://www.mapleprimes.com/posts/140690-The-Mysterious-if</link>
    </image>
    <item>
      <title>Operator form</title>
      <link>http://www.mapleprimes.com/posts/140690-The-Mysterious-if?ref=Feed:MaplePrimes:The mysterious `if`:Comments#comment140692</link>
      <itunes:summary>&lt;p&gt;It's the so-called operator form, documented under &lt;a href='http://www.maplesoft.com/support/help/search.aspx?term=if' target='_new'&gt;?if&lt;/a&gt;. There is one (trivial) example, so there could be more, agreed.&lt;/p&gt;</itunes:summary>
      <description>The latest comments added to the Post, The mysterious `if`</description>
      <guid>140692</guid>
      <pubDate>Thu, 22 Nov 2012 14:08:08 Z</pubDate>
      <itunes:author>Thomas Richard</itunes:author>
      <author>Thomas Richard</author>
    </item>
    <item>
      <title>?if</title>
      <link>http://www.mapleprimes.com/posts/140690-The-Mysterious-if?ref=Feed:MaplePrimes:The mysterious `if`:Comments#comment140694</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/posts/140690-The-Mysterious-if#comment140692"&gt;@Thomas Richard&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks, I hadn't seen that. I had searched for `if` but I seem to have missed it somehow, strange.&lt;/p&gt;
&lt;p&gt;&lt;br&gt;http://www.maplesoft.com/support/help/search.aspx?term=%60if%60&amp;amp;pr=All&amp;amp;sa.x=0&amp;amp;sa.y=0&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</itunes:summary>
      <description>The latest comments added to the Post, The mysterious `if`</description>
      <guid>140694</guid>
      <pubDate>Thu, 22 Nov 2012 15:07:15 Z</pubDate>
      <itunes:author>PatrickT</itunes:author>
      <author>PatrickT</author>
    </item>
    <item>
      <title>don't forget about select, remove, and selectremove</title>
      <link>http://www.mapleprimes.com/posts/140690-The-Mysterious-if?ref=Feed:MaplePrimes:The mysterious `if`:Comments#comment140768</link>
      <itunes:summary>&lt;p&gt;I have to admit that I had not thought about using `if` in this way, but I'll have to add it to my list of tricks.&lt;/p&gt;
&lt;p&gt;I also want to point out that some of these examples are very easily (and logically) implemented using the select command. For example:&lt;/p&gt;
&lt;pre&gt;nops( select( a-&amp;gt;a&amp;lt;0, L ) );&lt;br&gt;                               27&lt;br&gt;nops( select( is, L, negative ) );&lt;br&gt;                               27&lt;/pre&gt;
&lt;pre&gt;&lt;br&gt;select( isprime, [$1..n] );&lt;br&gt;    [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]&lt;/pre&gt;
&lt;p&gt;I don't see immediate ways to implement the test involving consecutive elements or rows of a matrix using select. I'm sure others might see a way to do these using select.&lt;/p&gt;
&lt;p&gt;I do wonder how these different approaches compare in terms of efficiency. As much as I'd like to do some of these tests, my day is done and I need some rest.&lt;/p&gt;
&lt;!--break--&gt;
&lt;p&gt;Doug&lt;/p&gt;
&lt;pre&gt;---------------------------------------------------------------------
Douglas B. Meade  &amp;lt;&amp;gt;&amp;lt;
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu&lt;/pre&gt;</itunes:summary>
      <description>The latest comments added to the Post, The mysterious `if`</description>
      <guid>140768</guid>
      <pubDate>Sat, 24 Nov 2012 10:45:34 Z</pubDate>
      <itunes:author>Doug Meade</itunes:author>
      <author>Doug Meade</author>
    </item>
    <item>
      <title>a place for information</title>
      <link>http://www.mapleprimes.com/posts/140690-The-Mysterious-if?ref=Feed:MaplePrimes:The mysterious `if`:Comments#comment140770</link>
      <itunes:summary>&lt;p&gt;Yes, this operator or functional form of &lt;strong&gt;if&lt;/strong&gt; is powerful and actually used systematically by some developers. So, a place for finding additional examples of its usage is the library code itself. Sadly not a good place in the sense that this code is not documented for the users (which I consider bad).&lt;/p&gt;
&lt;p&gt;Just three examples of many that you could find searching the library:&lt;/p&gt;
&lt;pre&gt;showstat(`Record/fixmyself`,6);
`Record/fixmyself` := proc(r::record)
local TEMPLATE, B, E, V, iform, NoInit, one, mdi;
       ...
   6   V := map(s -&amp;gt; `if`(s::last_name_eval,eval(s,2),s),V);
       ...
end proc


eval(`convert/Airy/from`[Sum]);
f -&amp;gt; `convert/to_special_function/TO_FROM`[Airy](
    `if`(nargs = 0, "query"(Sum), f), [BesselK, BesselJ])


showstat(`odeadv/WeierstrassPPrime`,16);
`odeadv/WeierstrassPPrime` := proc(f, y, x, diff_ord, INFO, c)
local ode, case, j, tmp;
       ...
  16           ode := `if`(ode::('`+`'),map('`@`(normal,`/`)',ode,c[1]),ode/c[1]);
       ...
end proc
&lt;/pre&gt;</itunes:summary>
      <description>The latest comments added to the Post, The mysterious `if`</description>
      <guid>140770</guid>
      <pubDate>Sat, 24 Nov 2012 12:01:42 Z</pubDate>
      <itunes:author>Alejandro Jakubi</itunes:author>
      <author>Alejandro Jakubi</author>
    </item>
    <item>
      <title>performance</title>
      <link>http://www.mapleprimes.com/posts/140690-The-Mysterious-if?ref=Feed:MaplePrimes:The mysterious `if`:Comments#comment140771</link>
      <itunes:summary>&lt;p&gt;Using `if` as condition inside the `seq` constructor (especially with NULL as the fallback value) is a must-know technique, I agree.&lt;/p&gt;
&lt;p&gt;And it's easy enough to compare performance of a few appoaches. Sometimes the charge can be levied at Maple (quite fairly) that it is more difficult to use because there are lots of ways to do a given task and the most efficient way is often not the most obvious. But I believe that in this case some of the performance differences can be ascribed to particular qualities of the approaches.&lt;/p&gt;
&lt;p&gt;The 6 ways below are all repeated over again, at the end, so as to show that the timings aren't due to the order in which they are tried in the very same session.&lt;/p&gt;
&lt;p&gt;Method C) is one of the three fast ways (almost identically quick -- the difference between them seems to vary less that does the difference they show individually when tried repeatedly in several new sessions). And method C) is the only one of the 6 shown which does not involving creating a new list as a temporary (collectible garbage) object.&lt;/p&gt;
&lt;p&gt;The worst performer is F), which uses `is`, and that's no surprise. The `is` command is like an umbrella covering many approaches. Using it to accomplish what could be done with just some `evalb` arithmetic comparison is overkill. It's a bit like using `simplify` when you know that `nomal` covers the given expression type.&lt;/p&gt;
&lt;p&gt;The difference between B) and D) is conceptually quite like the difference between A) and E), The D) and E) approaches both use some custom "user-defined" operator, wrapped around a builtin arithmetic comparison, which gets called for each entry test. That costs quite a bit more than does testing with just the builtin entry-wise comparison. The moral here is that it you're going to use `select` then always spend a moment wondering whether there is a (possibly creative) way to get the predicate (1st argumnet) to be a fast builtin. The user-defined operators like x-&amp;gt;.... are still relatively slower interpreted code, no matter how short and simple they are.&lt;/p&gt;
&lt;p&gt;And the difference between A) and B) is something similar to the difference between D) and E). If Maple didn't have the `select` command then we might code as in A) to get the functionality. Note that it becomes a bigger issue when compounded by the problem of wrapping with a user-defined operator.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;form name="worksheet_form"&gt;
&lt;table style="width: 576px;" align="center"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;restart; &lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;n := 10^7:&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;#f:=RandomTools:-Generate(integer(range=-100..100),makeproc=true):&lt;br&gt; &lt;/span&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;#L := RandomTools:-Generate(list(integer(range=-100..100),n)):&lt;br&gt; &lt;/span&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;#L := [seq(f(),i=1..n)]:&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;V := LinearAlgebra:-RandomVector(n,generator=-100..100):&lt;br&gt; &lt;/span&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;L :=convert(V,list):&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;# A) builtin seq, builtin `if` called for each call to `&amp;lt;`&lt;br&gt; &lt;/span&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;CodeTools:-Usage( &amp;nbsp;&amp;nbsp;nops([seq(`if`(u&amp;lt;0,1,NULL), u in L)]) &amp;nbsp;&amp;nbsp;);&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #0000ff; font-size: 100%; font-family: Courier New,monospace; font-weight: normal; font-style: normal;"&gt;memory used=343.13MiB, alloc change=308.30MiB, cpu time=5.07s, real time=5.10s&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="center"&gt;&lt;img style="vertical-align: -6;" src="/view.aspx?sf=140771/448686/c7b07d4d688f66bf0d2dd1ce45b894e9.gif" alt="4974312" width="58" height="23"&gt;&lt;/p&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;# B) builtin `select`, and builtin predicate `&amp;lt;`&lt;br&gt; &lt;/span&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;CodeTools:-Usage( &amp;nbsp;&amp;nbsp;nops(select( `&amp;lt;`, L, 0)) &amp;nbsp;&amp;nbsp;);&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #0000ff; font-size: 100%; font-family: Courier New,monospace; font-weight: normal; font-style: normal;"&gt;memory used=0.78GiB, alloc change=237.95MiB, cpu time=4.77s, real time=4.78s&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="center"&gt;&lt;img style="vertical-align: -6;" src="/view.aspx?sf=140771/448686/b256a29b7602c7ac53303fd0314a5d47.gif" alt="4974312" width="58" height="23"&gt;&lt;/p&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;# C) builtin `add`, builtin `if called for each call to `&amp;lt;`&lt;br&gt; &lt;/span&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;CodeTools:-Usage( &amp;nbsp;&amp;nbsp;add(`if`(L[i] &amp;lt; 0, 1, 0) , i = 1 .. n ) &amp;nbsp;&amp;nbsp;);&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #0000ff; font-size: 100%; font-family: Courier New,monospace; font-weight: normal; font-style: normal;"&gt;memory used=248.88MiB, alloc change=0 bytes, cpu time=4.82s, real time=4.83s&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="center"&gt;&lt;img style="vertical-align: -6;" src="/view.aspx?sf=140771/448686/95f21b1689c74c0e9e5ce87f4bd518e5.gif" alt="4974312" width="58" height="23"&gt;&lt;/p&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;# D) builtin select, user-defined operator called for each call to `&amp;lt;`&lt;br&gt; &lt;/span&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;CodeTools:-Usage( &amp;nbsp;&amp;nbsp;nops(select( a-&amp;gt;a&amp;lt;0, L)) &amp;nbsp;&amp;nbsp;);&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #0000ff; font-size: 100%; font-family: Courier New,monospace; font-weight: normal; font-style: normal;"&gt;memory used=0.71GiB, alloc change=0 bytes, cpu time=7.10s, real time=7.09s&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="center"&gt;&lt;img style="vertical-align: -6;" src="/view.aspx?sf=140771/448686/6248d9eb9aab90002358512a8d955e91.gif" alt="4974312" width="58" height="23"&gt;&lt;/p&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;# E) builtin `map`, user-defined operator called for each call to `&amp;lt;`&lt;br&gt; &lt;/span&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;CodeTools:-Usage( &amp;nbsp;&amp;nbsp;nops(map( (u-&amp;gt;`if`(u&amp;lt;0,1,NULL)), L)) &amp;nbsp;&amp;nbsp;);&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #0000ff; font-size: 100%; font-family: Courier New,monospace; font-weight: normal; font-style: normal;"&gt;memory used=0.71GiB, alloc change=0 bytes, cpu time=9.42s, real time=9.43s&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="center"&gt;&lt;img style="vertical-align: -6;" src="/view.aspx?sf=140771/448686/03bf4b02e6277678f03c6aa24431d8de.gif" alt="4974312" width="58" height="23"&gt;&lt;/p&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;# F) builtin `select`, interpreted Library routine `is`&lt;br&gt; &lt;/span&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;CodeTools:-Usage( &amp;nbsp;&amp;nbsp;nops(select( is, L, negative)) &amp;nbsp;&amp;nbsp;);&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #0000ff; font-size: 100%; font-family: Courier New,monospace; font-weight: normal; font-style: normal;"&gt;memory used=0.71GiB, alloc change=64.00MiB, cpu time=10.45s, real time=10.45s&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="center"&gt;&lt;img style="vertical-align: -6;" src="/view.aspx?sf=140771/448686/4eb4faa62e98e827f9c5bb34424df6bf.gif" alt="4974312" width="58" height="23"&gt;&lt;/p&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;#&lt;br&gt; &lt;/span&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;#&lt;br&gt; &lt;/span&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;#&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;CodeTools:-Usage( &amp;nbsp;&amp;nbsp;nops([seq(`if`(u&amp;lt;0,1,NULL), u in L)]) &amp;nbsp;&amp;nbsp;);&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #0000ff; font-size: 100%; font-family: Courier New,monospace; font-weight: normal; font-style: normal;"&gt;memory used=343.13MiB, alloc change=0 bytes, cpu time=4.51s, real time=4.52s&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="center"&gt;&lt;img style="vertical-align: -6;" src="/view.aspx?sf=140771/448686/f9539010347e0b55f6a3ca9d19b42341.gif" alt="4974312" width="58" height="23"&gt;&lt;/p&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;CodeTools:-Usage( &amp;nbsp;&amp;nbsp;nops(select( `&amp;lt;`, L, 0)) &amp;nbsp;&amp;nbsp;);&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #0000ff; font-size: 100%; font-family: Courier New,monospace; font-weight: normal; font-style: normal;"&gt;memory used=0.78GiB, alloc change=0 bytes, cpu time=4.66s, real time=4.67s&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="center"&gt;&lt;img style="vertical-align: -6;" src="/view.aspx?sf=140771/448686/9a43829e43b7c5acd9ce643bba1e70f4.gif" alt="4974312" width="58" height="23"&gt;&lt;/p&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;CodeTools:-Usage( &amp;nbsp;&amp;nbsp;add(`if`(L[i] &amp;lt; 0, 1, 0) , i = 1 .. n ) &amp;nbsp;&amp;nbsp;);&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #0000ff; font-size: 100%; font-family: Courier New,monospace; font-weight: normal; font-style: normal;"&gt;memory used=248.88MiB, alloc change=0 bytes, cpu time=4.79s, real time=4.78s&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="center"&gt;&lt;img style="vertical-align: -6;" src="/view.aspx?sf=140771/448686/40696086a65e7779204f0e5582dddbe9.gif" alt="4974312" width="58" height="23"&gt;&lt;/p&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;CodeTools:-Usage( &amp;nbsp;&amp;nbsp;nops(select( a-&amp;gt;a&amp;lt;0, L)) &amp;nbsp;&amp;nbsp;);&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #0000ff; font-size: 100%; font-family: Courier New,monospace; font-weight: normal; font-style: normal;"&gt;memory used=0.71GiB, alloc change=0 bytes, cpu time=7.07s, real time=7.09s&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="center"&gt;&lt;img style="vertical-align: -6;" src="/view.aspx?sf=140771/448686/689acc44d29bde16d9c5b96a43dd011a.gif" alt="4974312" width="58" height="23"&gt;&lt;/p&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;CodeTools:-Usage( &amp;nbsp;&amp;nbsp;nops(map( (u-&amp;gt;`if`(u&amp;lt;0,1,NULL)), L)) &amp;nbsp;&amp;nbsp;);&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #0000ff; font-size: 100%; font-family: Courier New,monospace; font-weight: normal; font-style: normal;"&gt;memory used=0.71GiB, alloc change=0 bytes, cpu time=9.34s, real time=9.35s&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="center"&gt;&lt;img style="vertical-align: -6;" src="/view.aspx?sf=140771/448686/8a4f630e1caebde91a96ed834016753c.gif" alt="4974312" width="58" height="23"&gt;&lt;/p&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;CodeTools:-Usage( &amp;nbsp;&amp;nbsp;nops(select( is, L, negative)) &amp;nbsp;&amp;nbsp;);&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #0000ff; font-size: 100%; font-family: Courier New,monospace; font-weight: normal; font-style: normal;"&gt;memory used=0.71GiB, alloc change=0 bytes, cpu time=10.39s, real time=10.38s&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="center"&gt;&lt;img style="vertical-align: -6;" src="/view.aspx?sf=140771/448686/8f7543c939ca01f75765be2e4e345f81.gif" alt="4974312" width="58" height="23"&gt;&lt;/p&gt;
&lt;table style="margin-left: 0px; margin-right: 0px;"&gt;
&lt;tbody&gt;
&lt;tr valign="baseline"&gt;
&lt;td&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt; &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p style="margin: 0 0 0 0; padding-top: 0px; padding-bottom: 0px;" align="left"&gt;&lt;span style="color: #ff0000; font-size: 100%; font-family: Courier New,monospace; font-weight: bold; font-style: normal;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;input type="hidden" name="sequence" value="1"&gt; &lt;input type="hidden" name="cmd" value="none"&gt;&lt;/form&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="/view.aspx?sf=140771/448686/listselectorcomp1.mw"&gt;Download listselectorcomp1.mw&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Maybe I can mention one more. It's similar in spirit to the `is` approach, using `type`. It's much quicker here than is its cousin `is`.&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;CodeTools:-Usage(   nops(select( type, L, negative))   );&lt;br&gt;memory used=114.25MiB, alloc change=0 bytes, cpu time=624.00ms, real time=618.00ms&lt;br&gt;                            4974312&lt;/pre&gt;
&lt;p&gt;acer&lt;/p&gt;</itunes:summary>
      <description>The latest comments added to the Post, The mysterious `if`</description>
      <guid>140771</guid>
      <pubDate>Sat, 24 Nov 2012 12:30:28 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
    <item>
      <title>uniform random integer list generation</title>
      <link>http://www.mapleprimes.com/posts/140690-The-Mysterious-if?ref=Feed:MaplePrimes:The mysterious `if`:Comments#comment140772</link>
      <itunes:summary>&lt;p&gt;I forgot to mention, above, that you could compare the relative performance between either of,&lt;/p&gt;
&lt;pre&gt;n := 10^5: # or higher

L := RandomTools:-Generate(list(integer(range=-100..100),n)):

f:=RandomTools:-Generate(integer(range=-100..100),makeproc=true):
L := [seq(f(),i=1..n)]:

&lt;/pre&gt;
&lt;p&gt;and,&lt;/p&gt;
&lt;pre&gt;n := 10^5: # or higher

V := LinearAlgebra:-RandomVector(n,generator=-100..100):
L := convert(V,list):&lt;/pre&gt;</itunes:summary>
      <description>The latest comments added to the Post, The mysterious `if`</description>
      <guid>140772</guid>
      <pubDate>Sat, 24 Nov 2012 12:43:04 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
  </channel>
</rss>