<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Mathcad Express Challenge - faster recursive chr2str function in Mathcad</title>
    <link>https://www.ptcusercommunity.com/t5/Mathcad/Mathcad-Express-Challenge-faster-recursive-chr2str-function/m-p/1037765#M219083</link>
    <description>&lt;P&gt;My string library defines three different representations of a string, two of which should already be familar: the string and the vector of character codes. The third type is the vector of characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the following, "str" indicates a string, "vec" indicates a vector of character codes, and "chr" represents a vector of characters. For example, chr2str indicates a conversion from a string to a vector of characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="book antiqua,palatino" color="#0000FF"&gt;&lt;EM&gt;chr2str&lt;/EM&gt;&lt;/FONT&gt; itself is relatively quick, even for long strings. &lt;FONT face="book antiqua,palatino" color="#0000FF"&gt;&lt;EM&gt;chr2str0&lt;/EM&gt;&lt;/FONT&gt; has the limitation of hitting Mathcad's recursion depth limit. &lt;FONT face="book antiqua,palatino" color="#0000FF"&gt;&lt;EM&gt;chr2str2&lt;/EM&gt;&lt;/FONT&gt;'s use of folding over &lt;STRONG&gt;&lt;FONT face="book antiqua,palatino" color="#339966"&gt;concat&lt;/FONT&gt;&lt;/STRONG&gt;, however, is proving somewhat slow once the string length increases to above about 20,000.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The challenge is to define a faster recursive variant of &lt;FONT face="book antiqua,palatino" color="#0000FF"&gt;&lt;EM&gt;chr2str&lt;/EM&gt;&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2025 10 08 D.png" style="width: 999px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/129543i1731D6D6FA847459/image-size/large?v=v2&amp;amp;px=999" role="button" title="2025 10 08 D.png" alt="2025 10 08 D.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where the dependencies are as shown below (&lt;EM&gt;except the timer functions, which are in an Area at the top of the attached Mathcad Express 11 worksheet&lt;/EM&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2025 10 08 C.png" style="width: 999px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/129544iC38795EBDD7F2369/image-size/large?v=v2&amp;amp;px=999" role="button" title="2025 10 08 C.png" alt="2025 10 08 C.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Stuart&lt;/P&gt;</description>
    <pubDate>Wed, 08 Oct 2025 22:06:21 GMT</pubDate>
    <dc:creator>StuartBruff</dc:creator>
    <dc:date>2025-10-08T22:06:21Z</dc:date>
    <item>
      <title>Mathcad Express Challenge - faster recursive chr2str function</title>
      <link>https://www.ptcusercommunity.com/t5/Mathcad/Mathcad-Express-Challenge-faster-recursive-chr2str-function/m-p/1037765#M219083</link>
      <description>&lt;P&gt;My string library defines three different representations of a string, two of which should already be familar: the string and the vector of character codes. The third type is the vector of characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the following, "str" indicates a string, "vec" indicates a vector of character codes, and "chr" represents a vector of characters. For example, chr2str indicates a conversion from a string to a vector of characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="book antiqua,palatino" color="#0000FF"&gt;&lt;EM&gt;chr2str&lt;/EM&gt;&lt;/FONT&gt; itself is relatively quick, even for long strings. &lt;FONT face="book antiqua,palatino" color="#0000FF"&gt;&lt;EM&gt;chr2str0&lt;/EM&gt;&lt;/FONT&gt; has the limitation of hitting Mathcad's recursion depth limit. &lt;FONT face="book antiqua,palatino" color="#0000FF"&gt;&lt;EM&gt;chr2str2&lt;/EM&gt;&lt;/FONT&gt;'s use of folding over &lt;STRONG&gt;&lt;FONT face="book antiqua,palatino" color="#339966"&gt;concat&lt;/FONT&gt;&lt;/STRONG&gt;, however, is proving somewhat slow once the string length increases to above about 20,000.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The challenge is to define a faster recursive variant of &lt;FONT face="book antiqua,palatino" color="#0000FF"&gt;&lt;EM&gt;chr2str&lt;/EM&gt;&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2025 10 08 D.png" style="width: 999px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/129543i1731D6D6FA847459/image-size/large?v=v2&amp;amp;px=999" role="button" title="2025 10 08 D.png" alt="2025 10 08 D.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where the dependencies are as shown below (&lt;EM&gt;except the timer functions, which are in an Area at the top of the attached Mathcad Express 11 worksheet&lt;/EM&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2025 10 08 C.png" style="width: 999px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/129544iC38795EBDD7F2369/image-size/large?v=v2&amp;amp;px=999" role="button" title="2025 10 08 C.png" alt="2025 10 08 C.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Stuart&lt;/P&gt;</description>
      <pubDate>Wed, 08 Oct 2025 22:06:21 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Mathcad/Mathcad-Express-Challenge-faster-recursive-chr2str-function/m-p/1037765#M219083</guid>
      <dc:creator>StuartBruff</dc:creator>
      <dc:date>2025-10-08T22:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: Mathcad Express Challenge - faster recursive chr2str function</title>
      <link>https://www.ptcusercommunity.com/t5/Mathcad/Mathcad-Express-Challenge-faster-recursive-chr2str-function/m-p/1037881#M219094</link>
      <description>&lt;P&gt;Why are you unhappy with your chr2str function? Its fast and does not suffer from the silly recursion limit.&lt;/P&gt;
&lt;P&gt;You may speed up chr2str2 a little bit by replacing the call to&amp;nbsp;chr2str2 by the fold command directly.&amp;nbsp; But speed in no way comes near that of chr2str.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Werner_E_3-1760023561183.png" style="width: 611px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/129569i6CA39D76B2464E36/image-dimensions/611x116?v=v2" width="611" height="116" role="button" title="Werner_E_3-1760023561183.png" alt="Werner_E_3-1760023561183.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Furthermore chr2str0 and chr2str2 not only are slower, they suffer from another drawback as well:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Werner_E_1-1760023136744.png" style="width: 630px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/129565iBB116E76A9C44891/image-dimensions/630x181?v=v2" width="630" height="181" role="button" title="Werner_E_1-1760023136744.png" alt="Werner_E_1-1760023136744.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Oct 2025 15:26:15 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Mathcad/Mathcad-Express-Challenge-faster-recursive-chr2str-function/m-p/1037881#M219094</guid>
      <dc:creator>Werner_E</dc:creator>
      <dc:date>2025-10-09T15:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: Mathcad Express Challenge - faster recursive chr2str function</title>
      <link>https://www.ptcusercommunity.com/t5/Mathcad/Mathcad-Express-Challenge-faster-recursive-chr2str-function/m-p/1037937#M219095</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://www.ptcusercommunity.com/t5/user/viewprofilepage/user-id/66934"&gt;@Werner_E&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Why are you unhappy with your chr2str function? Its fast and does not suffer from the silly recursion limit.&lt;/P&gt;
&lt;P&gt;You may speed up chr2str2 a little bit by replacing the call to&amp;nbsp;chr2str2 by the fold command directly.&amp;nbsp; But speed in no way comes near that of chr2str.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Werner_E_3-1760023561183.png" style="width: 611px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/129569i6CA39D76B2464E36/image-dimensions/611x116?v=v2" width="611" height="116" role="button" title="Werner_E_3-1760023561183.png" alt="Werner_E_3-1760023561183.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Furthermore chr2str0 and chr2str2 not only are slower, they suffer from another drawback as well:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Werner_E_1-1760023136744.png" style="width: 630px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/129565iBB116E76A9C44891/image-dimensions/630x181?v=v2" width="630" height="181" role="button" title="Werner_E_1-1760023136744.png" alt="Werner_E_1-1760023136744.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm not unhappy with chr2str, it's the performance of chr2str2 that leaves me feeling unfulfilled.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And that slowness is why the specific challenge.&amp;nbsp; Is there a way of improving the performance of the recursive algorithm?&amp;nbsp; Might the underlying reason for any improvement be more generally applicable?&amp;nbsp; Even a small improvement might take a function's performance from annoying to bearable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It can also be surprising just what a difference an apparently small change can make to a function's performance.&amp;nbsp; &amp;nbsp;For example, the marked increase in speed by using update1 rather than stack in my vec function (&lt;EM&gt;as mentioned in &lt;A href="https://community.ptc.com/t5/Mathcad/Mathcad-Express-speeding-up-vec/m-p/1036853" target="_blank" rel="noopener"&gt;another thread&lt;/A&gt;&amp;nbsp;and as shown below&lt;/EM&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even some of the matrix summation functions surprised me with how quick they were - look at matsum.sigrow and matsum.onesmat below, especially the latter when compared to the other Sigma operator (&lt;FONT face="symbol" size="4"&gt;S&lt;/FONT&gt;) variants.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Summation Function Timings&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2025 10 09 C.png" style="width: 800px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/129580i2A199F71EDF25EDA/image-size/large?v=v2&amp;amp;px=999" role="button" title="2025 10 09 C.png" alt="2025 10 09 C.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Summation Function Definitions&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2025 10 09 D.png" style="width: 999px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/129581iB07D6100D0DBFCA7/image-size/large?v=v2&amp;amp;px=999" role="button" title="2025 10 09 D.png" alt="2025 10 09 D.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Auxiliary Function Definitions&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2025 10 09 E.png" style="width: 584px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/129582iAB6402161D5D07A0/image-size/large?v=v2&amp;amp;px=999" role="button" title="2025 10 09 E.png" alt="2025 10 09 E.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Stuart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Mathcad Prime (Express) 11 worksheet attached.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Oct 2025 22:08:14 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Mathcad/Mathcad-Express-Challenge-faster-recursive-chr2str-function/m-p/1037937#M219095</guid>
      <dc:creator>StuartBruff</dc:creator>
      <dc:date>2025-10-09T22:08:14Z</dc:date>
    </item>
  </channel>
</rss>

