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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Translate the entire conversation x

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

StuartBruff
23-Emerald V

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

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.

6 REPLIES 6

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

LucMeekes
23-Emerald IV
(To:StuartBruff)

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

 

Werner_E
25-Diamond I
(To:LucMeekes)

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 ? 😉

LucMeekes
23-Emerald IV
(To:Werner_E)

That's why my trim() function was built the way it was. It is supposed to implement the functionality of the trim() function in full Prime.

After posting I realised that my trim() has a built-in unique() functionality (to make sure that the same index isn't used twice). It is:

LucMeekes_0-1762885417034.png

(the operating function in the fold is called 'set_fold' because it makes a vector into a mathematical set, one in which each element value occurs only once)
So with that I can build:

LucMeekes_1-1762885662850.png

with as results on M, N and N2:

LucMeekes_2-1762885693516.png

LucMeekes_3-1762885704414.png

LucMeekes_4-1762885711398.png

 

"If the index is used once, the row is gone. If you repeat the index, the row is goner ? "

If you carelessly repeat the index, the corresponding position in the vector and an adjacent one could be deleted.

But it's an interesting idea to have an Array that remembers the values of each of its members, especially if it also administrates what action, executed by which function, made an element value change, and when it happened...Secure array management!

 

Success!
Luc

 

 

Werner_E
25-Diamond I
(To:StuartBruff)

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

 

 

StuartBruff
23-Emerald V
(To:Werner_E)

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 

Announcements

Top Tags