<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - comments on Post, When pattern matching is useful</title>
    <link>http://www.mapleprimes.com/posts/39631-When-Pattern-Matching-Is-Useful</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 02:13:31 GMT</lastBuildDate>
    <pubDate>Wed, 10 Jun 2026 02:13:31 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest comments added to the Post, When pattern matching is useful</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - comments on Post, When pattern matching is useful</title>
      <link>http://www.mapleprimes.com/posts/39631-When-Pattern-Matching-Is-Useful</link>
    </image>
    <item>
      <title>one way</title>
      <link>http://www.mapleprimes.com/posts/39631-When-Pattern-Matching-Is-Useful?ref=Feed:MaplePrimes:When pattern matching is useful:Comments#comment72418</link>
      <itunes:summary>&lt;p&gt;This fails because pattern matching won't 'split' a base type (not sure the correct terminology).&amp;nbsp; You could get it to work by using x::imaginary(fraction) in the pattern match and then removing the imaginary unit and scaling by five, however, what you would really like is to be able to provide an additional test to ensure that x has a denominator of 5.&amp;nbsp; That can be done, if crudely, with&lt;/p&gt;
&lt;pre&gt;
seq(applyrule(exp(x::And(imaginary(fraction),`satisfies`(x -&amp;gt; denom(x/I)=5))*Pi)=alpha^(x/I*5)
              ,exp(i/5*I*Pi)),i=1..4);&amp;nbsp;  
&lt;/pre&gt;
&lt;pre&gt;
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alpha, alpha , alpha , alpha


&lt;/pre&gt;</itunes:summary>
      <description>The latest comments added to the Post, When pattern matching is useful</description>
      <guid>72418</guid>
      <pubDate>Mon, 07 Apr 2008 10:31:54 Z</pubDate>
      <itunes:author>Joe
 Riel
</itunes:author>
      <author>Joe
 Riel
</author>
    </item>
    <item>
      <title>less type-system gymnastics</title>
      <link>http://www.mapleprimes.com/posts/39631-When-Pattern-Matching-Is-Useful?ref=Feed:MaplePrimes:When pattern matching is useful:Comments#comment72413</link>
      <itunes:summary>&lt;p&gt;One of the under-appreciated aspects of patmatch are its capabilities of doing conditional matching, and thus conditional rewriting with applyrule.&amp;nbsp; So taking Joe's basic idea, one can encode this as&lt;/p&gt;
&lt;pre&gt;
seq(applyrule(conditional(exp((n::imaginary(fraction))*Pi), _type(5*n/I,integer))=alpha^(5/I*n),exp(i/5*I*Pi)),i=1..4);&lt;/pre&gt;
&lt;p&gt;which also works.&amp;nbsp; But one can still see that Maple's internal representation for objects peeks through [there are fewer than 25(?) people in the world who would have been able to figure out the need for imaginary(fraction) here].&amp;nbsp; And note the use of the underscore in _type!&amp;nbsp; &lt;code&gt;match&lt;/code&gt; suffers less from this particular disease, but there is no convenient wrapper like &lt;code&gt;applyrule&lt;/code&gt; that goes along with it.  Of course, &lt;code&gt;match&lt;/code&gt; heavily relies on &lt;code&gt;solve&lt;/code&gt;, so your mileage may vary.&lt;/p&gt;</itunes:summary>
      <description>The latest comments added to the Post, When pattern matching is useful</description>
      <guid>72413</guid>
      <pubDate>Mon, 07 Apr 2008 17:56:12 Z</pubDate>
      <itunes:author>JacquesC</itunes:author>
      <author>JacquesC</author>
    </item>
    <item>
      <title>_denom</title>
      <link>http://www.mapleprimes.com/posts/39631-When-Pattern-Matching-Is-Useful?ref=Feed:MaplePrimes:When pattern matching is useful:Comments#comment83784</link>
      <itunes:summary>&lt;p&gt;Thanks for demonstrating the use of conditional; I recall reading of its existence but haven't ever used it. Actually, I'm not sure I've ever used applyrule before, so this should increase my awareness.&amp;nbsp; Because we've restricted n, one can safely use denom here to make the code a bit more friendly&lt;/p&gt;
&lt;pre&gt;
seq(applyrule(conditional(exp((n::imaginary(fraction))*Pi), _denom(n)=5)=alpha^(5/I*n),exp(i/5*I*Pi)),i=1..4);
&lt;/pre&gt;
&lt;p&gt;Note that the test for equality works fine despite the caveat in the applyrule help page:&lt;/p&gt;
&lt;p style="margin-left: 40px;"&gt;... the condition has to be unevaluated or in inert form: use an `_` in front of every name, for example, _type(a,.freeof(x)) and it is not possible to use `=` or `&amp;lt;&amp;gt;`.&lt;/p&gt;
&lt;p&gt;If that didn't work, one can do either _Testzero(_denom(n)-5) or _type(_denom(n),5).&lt;/p&gt;</itunes:summary>
      <description>The latest comments added to the Post, When pattern matching is useful</description>
      <guid>83784</guid>
      <pubDate>Mon, 07 Apr 2008 18:57:44 Z</pubDate>
      <itunes:author>Joe
 Riel
</itunes:author>
      <author>Joe
 Riel
</author>
    </item>
    <item>
      <title>Tricks</title>
      <link>http://www.mapleprimes.com/posts/39631-When-Pattern-Matching-Is-Useful?ref=Feed:MaplePrimes:When pattern matching is useful:Comments#comment72409</link>
      <itunes:summary>&lt;p&gt;I may like such tricks as a &amp;quot;sport&amp;quot;, but I dislike to be distracted when doing mathematics and I am forced to use them for no good reason. Nothing more than&amp;nbsp; a &amp;quot;normal&amp;quot; syntax, like that I have&amp;nbsp; used, should be required to produce the expected result.&amp;nbsp; I do not&amp;nbsp; think&amp;nbsp; that using here something like&amp;nbsp; &amp;quot;n::imaginary(fraction)&amp;quot;&amp;nbsp; qualifies as&amp;nbsp; &amp;quot;normal&amp;quot;&amp;nbsp; for anybody.&lt;/p&gt;
&lt;p&gt;The example above is only one out of many.&amp;nbsp; Just changing the  example a little bit:&lt;/p&gt;
&lt;pre&gt;
seq(applyrule(exp(n::integer/5*q::name*Pi)=alpha^n,exp(i/5*q*Pi)),i=1..4);
&lt;/pre&gt;
&lt;p&gt;requires thinking the trick again. So, my point here is not how to do this particular example, but&amp;nbsp; to exemplify a &amp;quot;generic&amp;quot; problem.&lt;/p&gt;
&lt;p&gt;If this level of &amp;quot;sophistication&amp;quot; and &amp;quot;fine-tuning&amp;quot; is required to make 'applyrule' work for such a simple example, it shows to me that the pattern-matching system still needs much more development&amp;nbsp; to become useful for the ordinary user.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</itunes:summary>
      <description>The latest comments added to the Post, When pattern matching is useful</description>
      <guid>72409</guid>
      <pubDate>Mon, 07 Apr 2008 21:58:44 Z</pubDate>
      <itunes:author>jakubi</itunes:author>
      <author>jakubi</author>
    </item>
    <item>
      <title>reality</title>
      <link>http://www.mapleprimes.com/posts/39631-When-Pattern-Matching-Is-Useful?ref=Feed:MaplePrimes:When pattern matching is useful:Comments#comment83782</link>
      <itunes:summary>&lt;p&gt;Yes, but the reality is that n::integer/5 is never going to match anything.&amp;nbsp; It is analogous to using `n::integer + 3' and hoping that it will match some integer.&amp;nbsp; It won't.&amp;nbsp; Maple's matchers don't (as a rule) do more than match syntax.&amp;nbsp; I think we can see that this is the case for integer addition or multiplication.&amp;nbsp; For division it is not so apparent since we (the user) can see the desired target in the denominator.&amp;nbsp; However, Maple integer fractions are of type atomic so ...&lt;/p&gt;
&lt;p&gt;That doesn't preclude one from creating a more sophisticated matcher that would translate, say, n::integer/5 into a conditional match that does what you want, but I suspect that a general approach would be difficult.&lt;/p&gt;
&lt;p&gt;In your example, suppose that exp(q*Pi) appeared.&amp;nbsp; Mathematically, n=5 matches that, but I suspect you would not want it to match.&amp;nbsp;&amp;nbsp; How would your hypothetical matcher deal with that?&lt;/p&gt;</itunes:summary>
      <description>The latest comments added to the Post, When pattern matching is useful</description>
      <guid>83782</guid>
      <pubDate>Mon, 07 Apr 2008 22:27:27 Z</pubDate>
      <itunes:author>Joe
 Riel
</itunes:author>
      <author>Joe
 Riel
</author>
    </item>
    <item>
      <title>I completely agree</title>
      <link>http://www.mapleprimes.com/posts/39631-When-Pattern-Matching-Is-Useful?ref=Feed:MaplePrimes:When pattern matching is useful:Comments#comment83781</link>
      <itunes:summary>&lt;p&gt;We are witnessing a fundamental shift in software these days.&amp;nbsp; In the 80s, it was expected that internal concerns of the developers were going to be visible in the interface (API or GUI) of a piece of software, and that &amp;quot;users&amp;quot; were sophisticated people who could deal with that.&amp;nbsp; But 20 years later, things have now changed drastically: users see software as tools to get a job done, and expect the software to intrude into their thinking as little as possible.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;This is not to say that this is easy to do.&amp;nbsp; But take a look at Google maps, for example, and you will see a beautiful such example.&amp;nbsp; There are many others, of course.&amp;nbsp; &lt;/p&gt;</itunes:summary>
      <description>The latest comments added to the Post, When pattern matching is useful</description>
      <guid>83781</guid>
      <pubDate>Mon, 07 Apr 2008 22:31:35 Z</pubDate>
      <itunes:author>JacquesC</itunes:author>
      <author>JacquesC</author>
    </item>
  </channel>
</rss>