Skip to main content
23-Emerald V
November 10, 2025
Question

Yet another "unique" function and the NaN (Not a "Not a Nusiance")

  • November 10, 2025
  • 2 replies
  • 533 views

I was playing around with sorting and decided (yet again) that I was frustrated by some of the restrictions.  One thing led to another, and before I knew it, I was hip deep in ways to "improve" the lookup functions. 

 

While contemplating Mathcad Zen Principles 3, 6, 7, 16, and 17, I wondered whether "unique" would be a worthwhile addition to the match/lookup modifiers.  

 

Then my mind went blank when faced with how to handle NaNs.  In principle,  IEEE 754 NaNs are distinct.  And they would be if a standard Mathcad user had any way to distinguish between them, but they're harder to tell apart than Zathras and Zathras.  To the Mathcadder in the street, they might as well be indistinguishable, for all the good their distinctiveness does.

 

So, I've written two versions of unique to cater for both cases.   The question is which one would a user expect to be the default (and hence all lowercase) version?

 

I've checked in a few other languages.  Matlab seems to be an outlier in treating NaNs as distinct.  Python (numpy), Julia, and (surprisingly) Mathematica appear to treat NaNs as indistinguishable from each other (for uniqueness testing); even XCas does so: set( [1,2,4,5,NaN, 6,2,NaN,5,1,4,2,5]) == 1,2,4,5,NaN,6 

.

2025 11 10 B.png

 

In the meantime, could a kind soul please check whether the attached Mathcad Express 10.0 worksheet works in Mathcad Prime?

 

I'd expect the results to look something like this:

 

2025 11 10 A.png

 

Thank you,

 

Stuart

 

https://www.validlab.com/goldberg/paper.pdf

 

https://community.ptc.com/t5/Mathcad/MEP-00-The-Zen-of-Mathcad/m-p/1040983#M219315

 

3. Be like Zathras-- cover all possibilities. Zathras does not want other people being confoosed.
6. Explicit is better than implicit.
7. Unless implicit is better.
16. Functions should work over any data type.
17. Except where there is no meaning.

2 replies

23-Emerald V
November 10, 2025

And a follow-up question?

 

What does the Mathcad Prime function trim do if it has replicated indices?  Does it only delete the one instance of index k in vector v?  Or does it, say, delete vk  at the "new" index k after deleting the first vk

 

β€’trim(v, vindex)β€”Trims out the entries (rows) specified by vindex.

 

Stuart

23-Emerald IV
November 10, 2025

The function trim() operates as follows:

LucMeekes_0-1762814381813.png

So it doesn't throw out the 3 AND the 4, only the 3.

See attached. Also observe what happens when you change ORIGIN (before all function definitions of course).

 

Success!
Luc

 

25-Diamond I
November 10, 2025

The same goes for the built-in "trim" function

Werner_E_0-1762817392294.png

Is the repeated use of an index also known as "secure erase", just like the repeated overwriting when you're wiping hard drive data?

If the index is used once, the row is gone. If you repeat the index, the row is goner ? πŸ˜‰

25-Diamond I
November 10, 2025

When you define "match" and "Match" you have to decide whether the formal argument name should be "x" or "z" πŸ™‚

And function "_eq" is not defined, only "eq" and of course "_eqNaN".

Later in your sheet you use both "eq" and "_eq".

 

BTW, I sometimes found it annoying that Prime treats NaN with units differently from "normal" unit-less NaN's which made it necessary in some programs to add units to NaN's. Nonetheless the "IsNaN" functions seems to not care about the units.

That's definitely a difference in behaviour compared to Mathcad.

Prime 11.0.0.0:

Werner_E_0-1762811990220.png

Mathcad 15:

Werner_E_1-1762812000158.png

 

 

23-Emerald V
November 10, 2025

Thanks, Werner.  That's why it's always good for me to check things.

 

'z' is used as the formal argument in the match/lookup Help, so I'd go with that.

 

Copy & Paste error for _eq and eq.  I use the name _eq specifically for my match implementation, and eq for a named equivalent of the = operator, but I copied the wrong definition below _eq.

 

Stuart