cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Translate the entire conversation x

Prime - local recursive function definition

StuartBruff
23-Emerald IV

Prime - local recursive function definition

I've been trying to port a worksheet to Prime 1.0, but have got stuck because, whilst recursion is supported, local recursive function definition is giving me a problem. How does one define local function f to be recursive in the attached worksheet? Does it work in Prime 2.0?

Thanks,

Stuart

14 REPLIES 14

I think it is an error in Mathcad Prime 1.0 and 2.0 - see the picture

LocFuncRecursPrimeError.png

Спасибо, Валерий

In this instance (a worksheet I intend to post on filling matrices with implied polynomial data) I could easily rewrite the algorithm to avoid recursion, but there are many instances where this cannot be reasonably done.

Stuart

StuartBruff wrote:

I've been trying to port a worksheet to Prime 1.0, but have got stuck because, whilst recursion is supported, local recursive function definition is giving me a problem.   How does one define local function f to be recursive in the attached worksheet?  Does it work in Prime 2.0?

I've just been going through the process of updating my utility functions to try and make them work in both M15 and Prime 3.1.  Whilst converting a number of my worksheets I spent a good few minute painfully editing some functions to get them to work.   I'd forgotten about this particular problem, which turned out to be the source of my particular problems this time as well.   Rewriting these functions will be a pain, plus they lose the natural elegance of the recursive definition. 

I hope this 3 year old bug is in the pipeline to be fixed in Prime 4.0, along with restoration of currying (partial function application), the ability to pass a range definition as an argument to a function (eg, f(2..5)), re-definable global definitions and Math Styles (or equivalent) ... the lack of these capabilities is proving somewhat irritating.

It would be helpful if the Prime Converter:

converted an equation as best it could rather than, or in addition to, replacing it with an image of a non-convertible region.

extended a variable name with a Math Style name  (eg, func_MSU5 for function func defined in Math Style User 5) rather than convert to Variable ... this requires more attention to detail and effort than I'd like to manually separate converted functions with the same lexical name but differing Math Styles.

Stuart

Unfortunately, Prime still seems to lack the ability to define a local recursive function.

 

As I'm trying to write a few brief worksheets / articles on functional programming in Mathcad, this is adding to the problem of having to work around the lack of an empty array (not to mention having currying back would make life a lot easier!).

 

Are there any plans to fix this problem in, say, the next release of Prime ... 

 

Stuart

This bug remains unfixed in Mathcad Prime 11.  That's eleven versions of Mathcad Prime where a long-standing bug remains unaddressed.

 

Is this bug scheduled for review?   

 

Stuart

 

 

Werner_E
25-Diamond I
(To:StuartBruff)

That's really disappointing! I consider it a severe bug  and significant limitation.

Was the bug reported 'officially'?
I can't do so as a valid SCN would be necessary. Even if I had it, I'm not sure I'd be willing to jump through all the hoops and answer all the questions. It seems as if artificial barriers are being erected to deter people from seeking support.

As has often been criticized in the past, PTC does not exactly give the impression that they are particularly interested in bug reports and improving their software.

On the other hand, I just stumbled across an older thread of mine, and here @olivierlp  took notice and  apparently reported the bugs to the product team. I  just gave it a try and both bugs  have already been fixed in Prime 11 -> Solved: BUGS in Prime - PTC Community
Also @DJNewman  from PTC sales was kind enough act on bugs reported here in forum threads.

It is fortunate if a friendly person at PTC reads the forum posts here and then takes the time to forward them to the relevant department within the company for processing.
PTC would be well-advised to consider offering a low-threshold option for reporting software errors, independent of an active service contract.

 

StuartBruff
23-Emerald IV
(To:Werner_E)

Hi Werner.

 


@Werner_E wrote:

That's really disappointing! I consider it a severe bug  and significant limitation.

Was the bug reported 'officially'?


Yes, PTC are aware.  I can't find my first report - but then again, it wouldn't do me much good, as I've forgotten how to read cuneiform (I've certainly got a Prime 3.1 worksheet featuring the bug from Aug 2015).

 

However, I do know that it was picked up on by PTC in Jun 20 (during a Coffee Morning) and in Sep 21 (Mathcad Webinar), as I was asked follow-up questions about the bug.

 


@Werner_E wrote:

That's really disappointing! I consider it a severe bug  and significant limitation.

Was the bug reported 'officially'?
As has often been criticized in the past, PTC does not exactly give the impression that they are particularly interested in bug reports and improving their software.

On the other hand, I just stumbled across an older thread of mine, and here @olivierlp  took notice and  apparently reported the bugs to the product team. I  just gave it a try and both bugs  have already been fixed in Prime 11 -> Solved: BUGS in Prime - PTC Community
Also @DJNewman  from PTC sales was kind enough act on bugs reported here in forum threads.

It is fortunate if a friendly person at PTC reads the forum posts here and then takes the time to forward them to the relevant department within the company for processing.
PTC would be well-advised to consider offering a low-threshold option for reporting software errors, independent of an active service contract.

 


Agreed.  I noticed that @olivierlp responded positively to your recent thread, and Dave has been more than helpful on several occasions.  I can but hope that this (local recursion) issue is given a little more recognition and priority.

 

Stuart

 

Hi, Werner ( @Werner_E ) 

 

Whilst looking for something else, I found an email confirming that PTC are aware of the bug.

 

Stuart is right in his observation. You can let him know that we have investigated and concluded that he is correct: You cannot define functionrecursively in programming in Prime. Mathcad 15, however, does allow it. This is being documented as a bug in Prime since it works in Mathcad 15, but we do need to investigate further with R&D to determine if there was a reason they intentionally removed this functionality. The workaround in Prime is to define the function to be used recursively outside the main program. We appreciate Stuart bringing this to our attention!

That was in Nov 2021.

 

Stuart

Werner_E
25-Diamond I
(To:StuartBruff)

That wasn't even four years ago, so it's a bit of a waiting game. 😄

StuartBruff
23-Emerald IV
(To:Werner_E)

"They also serve who stand and wait" might be true for many things, Werner, but I am dismally failing to understand how I serve the cause of Mathcad by waiting. 😞

 

Have you played with the new (PM11) vec function?

 

Stuart

Werner_E
25-Diamond I
(To:StuartBruff)


Have you played with the new (PM11) vec function?


Not excessively so. However, it is beneficial that it can be used both to generate vectors and to convert ranges into vectors.
Nevertheless, I primarily use Prime to respond to questions here in the forum; for personal projects, I still prefer Mathcad.

StuartBruff
23-Emerald IV
(To:Werner_E)

Yes, it is beneficial in some respects.  It's certainly quicker than all the other range-to-vector conversion methods proposed over the years, and the optional arguments are useful too.  I've also used the new vec function to speed up and simplify a few of my standard library sequence generation functions.

 

However, .... (there just had to be a 'however')

 

PTC published Mathcad Support Article CS416474 to address the change in Mathcad Prime 10 regarding how concurrent evaluation of range variable definitions was handled.  In CS416474, PTC introduced the function Range2Vec as a suggested workaround for the change in Prime 10 behaviour. 

 

This is where vec is potentially a bug as Range2Vec converts a flat matrix into a vector (in accordance with standard mathematical use).  vec , however, only converts a range into a vector or acts as an identity for a vector.  It does not convert even flat matrices into vectors, let alone nested ones.  Again, whilst I see benefits to Prime's vec , I am disappointed that PTC took no apparent notice of the definitions of vec that have been in use for at least the last twenty years.

 

(In the screen shots below, M is a flat matrix and N is a nested array (one element is a matrix)).

 

2025 09 11 A.png

 

2025 09 11 B.png

 

Stuart 

Werner_E
25-Diamond I
(To:StuartBruff)

I wondered what a 'flat matrix' would be unless I saw your examples - I would call it a row vector.

Yes, the behaviour of range2vec compared to vec is different in that case and maybe range2vec could be said to be a bit more versatile. Given the name "vec" this new function could turn 'everything' into a vector but in fact its limited to ranges and column vectors (which remain unchanged and are not treated recursively).

Guess that 'vec' was just a quick hack because of complaints and irritations as of the sudden removal in P10 of the undocumented range to vector trick using the inline evaluation without providing a decent substitution. As this replacement was only submitted in P11, you might have thought it could have been a bigger throw.

StuartBruff
23-Emerald IV
(To:Werner_E)

Sorry about that.  I sometimes forget whether I'm supposed to be speaking maths, programming language, or Mathcad.

 

A matrix, mathematically, is an m x n array of numbers.  In Mathcad, vectors and matrices are data structures that can contain numbers, expressions, strings, nested matrices, and units.

 

So when I said "flat matrix", I was thinking "Mathcad" and referring to an m x n array of non-array data types; that is, an unnested array.  I suppose I should have said "flat array".

 

_________________

 

Even a quick hack should require a lot of procedure to get through (eg, specification writing, specification review, design, coding, testing, review, ...).  PTC must have put some thought into it, because the optional arguments are quite a neat and very Mathcad idea.   

 

Going the extra micromile to realise a fully flattening vec can't have demanded that much more effort; the plethora of vec implementations shows that it can't be that hard to implement.  For want of a nail, and all that (Diz sagent uns die wîsen, ein nagel behalt ein îsen, ein îsen ein ros, ein ros ein man, ein man ein burc, der strîten kan - it's not often one gets to use Mittelhochdeutsch in a Mathcad Community post!).

,

A(nother) long-standing annoyance of mine is the poor support for strings, including the inability to specify character sequences as ranges, eg. "a".."e" or "0".."9".  Over the millenia, I've implemented various ad hoc (wow, Latin now! Отличный!) functions to fulfil this need, some of which use a vec variant. 

 

MP11's vec has a further limitation in that it vectorizing (in the Mathcad sense) over vec over a vector just returns the original vector, whereas most vec implementations return a vector whose elements are the elements of the original vector converted into 1-arrays.   Again, Range2Vec supports this latter behaviour.

 

Here's a demonstration of what I mean ...

 

2025 09 11 C.png

 

Such a shame, as it's good that vec is there, I like the optional argument form, and I'm very pleased to see IsRange.

 

Stuart

 

Announcements

Top Tags