<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - answers and comments on Question, help migrating old maple code with "stats" commands</title>
    <link>http://www.mapleprimes.com/questions/94576-Help-Migrating-Old-Maple-Code-With-stats</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Sat, 13 Jun 2026 01:59:22 GMT</lastBuildDate>
    <pubDate>Sat, 13 Jun 2026 01:59:22 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest answers and comments added to the Question, help migrating old maple code with "stats" commands</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - answers and comments on Question, help migrating old maple code with "stats" commands</title>
      <link>http://www.mapleprimes.com/questions/94576-Help-Migrating-Old-Maple-Code-With-stats</link>
    </image>
    <item>
      <title>empirical</title>
      <link>http://www.mapleprimes.com/questions/94576-Help-Migrating-Old-Maple-Code-With-stats?ref=Feed:MaplePrimes:help migrating old maple code with "stats" commands:Comments#answer94578</link>
      <itunes:summary>&lt;p&gt;If L is a list of n elements with all L[j] &amp;gt;= 0 and sum(L[j], j=1..n) = 1, empirical[L] is a discrete distribution with &lt;br&gt;Probability(X = j) = L[j] for j in [1,2,...,n], 0 otherwise.&amp;nbsp; The equivalent in Statistics is ProbabilityTable (not Empirical).&amp;nbsp; What this Maple code is doing is simulating a Markov chain with transition matrix P and states labelled S,C,R.&amp;nbsp; I might implement it in a more modern Maple (and in a somewhat more efficient way) like this:&lt;/p&gt;
&lt;pre&gt;&lt;br&gt;with(Statistics):&lt;br&gt;P1:= [[.6,.3,.1],[.4,.5,.1],[.3,.4,.3]]:&lt;br&gt;X:= [seq(Sample(ProbabilityTable(P1[i]),51),i=1..3)]:&lt;br&gt;R:= Array(1..51):&lt;br&gt;R[1]:= 1:&lt;br&gt;for j from 2 to 51 do R[j]:= X[R[j-1]][j] end do: &lt;br&gt;S:= cat(op(convert(subs(1="S",2="C",3="R",R),list)));&lt;br&gt;&lt;br&gt;&lt;/pre&gt;</itunes:summary>
      <description>&lt;p&gt;If L is a list of n elements with all L[j] &amp;gt;= 0 and sum(L[j], j=1..n) = 1, empirical[L] is a discrete distribution with &lt;br&gt;Probability(X = j) = L[j] for j in [1,2,...,n], 0 otherwise.&amp;nbsp; The equivalent in Statistics is ProbabilityTable (not Empirical).&amp;nbsp; What this Maple code is doing is simulating a Markov chain with transition matrix P and states labelled S,C,R.&amp;nbsp; I might implement it in a more modern Maple (and in a somewhat more efficient way) like this:&lt;/p&gt;
&lt;pre&gt;&lt;br&gt;with(Statistics):&lt;br&gt;P1:= [[.6,.3,.1],[.4,.5,.1],[.3,.4,.3]]:&lt;br&gt;X:= [seq(Sample(ProbabilityTable(P1[i]),51),i=1..3)]:&lt;br&gt;R:= Array(1..51):&lt;br&gt;R[1]:= 1:&lt;br&gt;for j from 2 to 51 do R[j]:= X[R[j-1]][j] end do: &lt;br&gt;S:= cat(op(convert(subs(1="S",2="C",3="R",R),list)));&lt;br&gt;&lt;br&gt;&lt;/pre&gt;</description>
      <guid>94578</guid>
      <pubDate>Tue, 29 Jun 2010 07:11:11 Z</pubDate>
      <itunes:author>Robert Israel</itunes:author>
      <author>Robert Israel</author>
    </item>
    <item>
      <title>Thanks!</title>
      <link>http://www.mapleprimes.com/questions/94576-Help-Migrating-Old-Maple-Code-With-stats?ref=Feed:MaplePrimes:help migrating old maple code with "stats" commands:Comments#comment94583</link>
      <itunes:summary>&lt;p&gt;Thanks Robert,&lt;/p&gt;
&lt;p&gt;That's exactly what I needed to know.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It's for the undergrads though; so I may put the for loop back in (although your version is definitely more&amp;nbsp;efficient).&amp;nbsp;&amp;nbsp;In this case exposition is more important than speed.&lt;/p&gt;
&lt;p&gt;Thanks again,&lt;/p&gt;
&lt;p&gt;Paul&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;Thanks Robert,&lt;/p&gt;
&lt;p&gt;That's exactly what I needed to know.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It's for the undergrads though; so I may put the for loop back in (although your version is definitely more&amp;nbsp;efficient).&amp;nbsp;&amp;nbsp;In this case exposition is more important than speed.&lt;/p&gt;
&lt;p&gt;Thanks again,&lt;/p&gt;
&lt;p&gt;Paul&lt;/p&gt;</description>
      <guid>94583</guid>
      <pubDate>Tue, 29 Jun 2010 15:59:52 Z</pubDate>
      <itunes:author>pvrbik</itunes:author>
      <author>pvrbik</author>
    </item>
    <item>
      <title>exposition</title>
      <link>http://www.mapleprimes.com/questions/94576-Help-Migrating-Old-Maple-Code-With-stats?ref=Feed:MaplePrimes:help migrating old maple code with "stats" commands:Comments#comment94595</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/94576-Help-Migrating-Old-Maple-Code-With-stats-Commands#comment94583"&gt;@pvrbik&lt;/a&gt; : I agree, exposition is important, but one aspect of good Maple exposition is to avoid "anti-patterns" such as building up a string one character at a time.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/94576-Help-Migrating-Old-Maple-Code-With-stats-Commands#comment94583"&gt;@pvrbik&lt;/a&gt; : I agree, exposition is important, but one aspect of good Maple exposition is to avoid "anti-patterns" such as building up a string one character at a time.&lt;/p&gt;</description>
      <guid>94595</guid>
      <pubDate>Tue, 29 Jun 2010 22:18:16 Z</pubDate>
      <itunes:author>Robert Israel</itunes:author>
      <author>Robert Israel</author>
    </item>
    <item>
      <title>@Robert Israel&amp;nbsp;
Completely agree. However,</title>
      <link>http://www.mapleprimes.com/questions/94576-Help-Migrating-Old-Maple-Code-With-stats?ref=Feed:MaplePrimes:help migrating old maple code with "stats" commands:Comments#comment94599</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/94576-Help-Migrating-Old-Maple-Code-With-stats-Commands#comment94595"&gt;@Robert Israel&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Completely agree. However, this is a stochastic process course (for non-programmers and non-mathematicians) and most of the students will only be able to use maple as a "symbolic calculator". We're trying to be very verbose with our code so they know exactly what happens. Although I think functional (or semi-functional in the case of maple) is more elegant; it is notoriously difficult to decipher.&lt;/p&gt;
&lt;p&gt;I did something like this instead:&lt;/p&gt;
&lt;pre&gt;interface(quiet=true):&lt;br&gt;with(Statistics):&lt;br&gt;states := [ "S", "C", "R" ]:&lt;/pre&gt;
&lt;pre&gt;#The probability distributions from transitioning OUT of a state&lt;/pre&gt;
&lt;pre&gt;dist["S"] := ProbabilityTable([0.6, 0.3, 0.1]):&lt;/pre&gt;
&lt;pre&gt;dist["C"] := ProbabilityTable([0.4, 0.5, 0.1]):&lt;/pre&gt;
&lt;pre&gt;dist["R"] := ProbabilityTable([0.3, 0.4, 0.3]):&lt;/pre&gt;
&lt;pre&gt;TransitionFrom := state -&amp;gt; states[ Sample( dist[state], 1)[1] ];&lt;br&gt;&lt;br&gt;&lt;/pre&gt;
&lt;pre&gt;#starting from the 'sunny' state is arbritrary&lt;/pre&gt;
&lt;pre&gt;TodaysWeather := "S";&lt;/pre&gt;
&lt;pre&gt;WeatherHistory := NULL;&lt;/pre&gt;
&lt;pre&gt;for i from 1 to 50 do&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;    NextWeather := TransitionFrom( TodaysWeather );&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;    WeatherHistory := WeatherHistory, NextWeather;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;   &amp;nbsp;TodaysWeather := NextWeather;&lt;/pre&gt;
&lt;pre&gt;end do:&lt;br&gt;&lt;br&gt;&lt;/pre&gt;
&lt;pre&gt;cat(WeatherHistory);&lt;br&gt;&lt;br&gt;&lt;/pre&gt;
&lt;p&gt;As a side note. I'm having a lot of difficulty posting code into these windows. It doesn't format properly, and everything seems to want to double space. Advise?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/94576-Help-Migrating-Old-Maple-Code-With-stats-Commands#comment94595"&gt;@Robert Israel&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Completely agree. However, this is a stochastic process course (for non-programmers and non-mathematicians) and most of the students will only be able to use maple as a "symbolic calculator". We're trying to be very verbose with our code so they know exactly what happens. Although I think functional (or semi-functional in the case of maple) is more elegant; it is notoriously difficult to decipher.&lt;/p&gt;
&lt;p&gt;I did something like this instead:&lt;/p&gt;
&lt;pre&gt;interface(quiet=true):&lt;br&gt;with(Statistics):&lt;br&gt;states := [ "S", "C", "R" ]:&lt;/pre&gt;
&lt;pre&gt;#The probability distributions from transitioning OUT of a state&lt;/pre&gt;
&lt;pre&gt;dist["S"] := ProbabilityTable([0.6, 0.3, 0.1]):&lt;/pre&gt;
&lt;pre&gt;dist["C"] := ProbabilityTable([0.4, 0.5, 0.1]):&lt;/pre&gt;
&lt;pre&gt;dist["R"] := ProbabilityTable([0.3, 0.4, 0.3]):&lt;/pre&gt;
&lt;pre&gt;TransitionFrom := state -&amp;gt; states[ Sample( dist[state], 1)[1] ];&lt;br&gt;&lt;br&gt;&lt;/pre&gt;
&lt;pre&gt;#starting from the 'sunny' state is arbritrary&lt;/pre&gt;
&lt;pre&gt;TodaysWeather := "S";&lt;/pre&gt;
&lt;pre&gt;WeatherHistory := NULL;&lt;/pre&gt;
&lt;pre&gt;for i from 1 to 50 do&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;    NextWeather := TransitionFrom( TodaysWeather );&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;    WeatherHistory := WeatherHistory, NextWeather;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;   &amp;nbsp;TodaysWeather := NextWeather;&lt;/pre&gt;
&lt;pre&gt;end do:&lt;br&gt;&lt;br&gt;&lt;/pre&gt;
&lt;pre&gt;cat(WeatherHistory);&lt;br&gt;&lt;br&gt;&lt;/pre&gt;
&lt;p&gt;As a side note. I'm having a lot of difficulty posting code into these windows. It doesn't format properly, and everything seems to want to double space. Advise?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
      <guid>94599</guid>
      <pubDate>Tue, 29 Jun 2010 23:16:59 Z</pubDate>
      <itunes:author>pvrbik</itunes:author>
      <author>pvrbik</author>
    </item>
    <item>
      <title>@pvrbik There is noting particularly more</title>
      <link>http://www.mapleprimes.com/questions/94576-Help-Migrating-Old-Maple-Code-With-stats?ref=Feed:MaplePrimes:help migrating old maple code with "stats" commands:Comments#comment94636</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/94576-Help-Migrating-Old-Maple-Code-With-stats-Commands#comment94599"&gt;@pvrbik&lt;/a&gt; There is noting particularly more intuitive about using an exprseq or list instead of an Array or Table.&lt;/p&gt;
&lt;pre&gt;WeatherHistory := Array(1..50); # or table();

for i from 1 to 50 do    
    NextWeather := TransitionFrom( TodaysWeather );    
    WeatherHistory[i] := NextWeather;   
    TodaysWeather := NextWeather;
end do:

cat(entries(WeatherHistory, 'nolist'));
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is, arguably, even easier to read and has the bonus of not teaching students very bad habits in Maple.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/94576-Help-Migrating-Old-Maple-Code-With-stats-Commands#comment94599"&gt;@pvrbik&lt;/a&gt; There is noting particularly more intuitive about using an exprseq or list instead of an Array or Table.&lt;/p&gt;
&lt;pre&gt;WeatherHistory := Array(1..50); # or table();

for i from 1 to 50 do    
    NextWeather := TransitionFrom( TodaysWeather );    
    WeatherHistory[i] := NextWeather;   
    TodaysWeather := NextWeather;
end do:

cat(entries(WeatherHistory, 'nolist'));
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is, arguably, even easier to read and has the bonus of not teaching students very bad habits in Maple.&lt;/p&gt;</description>
      <guid>94636</guid>
      <pubDate>Wed, 30 Jun 2010 20:03:44 Z</pubDate>
      <itunes:author>John May</itunes:author>
      <author>John May</author>
    </item>
    <item>
      <title>@John May&amp;nbsp;
&amp;nbsp;
I'm inclined to</title>
      <link>http://www.mapleprimes.com/questions/94576-Help-Migrating-Old-Maple-Code-With-stats?ref=Feed:MaplePrimes:help migrating old maple code with "stats" commands:Comments#comment94638</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/94576-Help-Migrating-Old-Maple-Code-With-stats-Commands#comment94636"&gt;@John May&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I'm inclined to agree with you John.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/94576-Help-Migrating-Old-Maple-Code-With-stats-Commands#comment94636"&gt;@John May&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I'm inclined to agree with you John.&lt;/p&gt;</description>
      <guid>94638</guid>
      <pubDate>Wed, 30 Jun 2010 20:55:26 Z</pubDate>
      <itunes:author>pvrbik</itunes:author>
      <author>pvrbik</author>
    </item>
  </channel>
</rss>