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

I'm dithering - which seq should I use?

StuartBruff
23-Emerald III

I'm dithering - which seq should I use?

I'm rewriting a number of functions whilst sorting out my toolbox of utility functions and I've hit a slight quandry with regard to one of the most regularly used ones, seq.

seq(n) was originally written to generate simple integer sequences, primarily for use as vector indices and as test data. Consequently, I thought about its input argument, n, in terms of the number of elements and mentally regarded it as an integer with no thought for other interpretations (apart from arrays and range definitions, which seq passed to my other primary tool, vec).

However, I have several variants of seq (often with additional arguments) that allow me to generate more complex sequences, including string sequences. The downside is that it necessitates a change in world view to looking at n as the upper limit of a sequence (and implied lower limit for negative numbers). This will involve a further rewrite of several functions to accomodate the effect this has upon zero-based indices (positive n will now give a vector of n+1 elements). I also get a different response for 0 and negative numbers, which previously generated errors (on the not entirely unreasonable basis that you shouldn't have a vector with zero or a negative amount elements) but now return valid sequences (if, in the case of 0, you can call a one-element array a sequence).

My goal in tool generation is to keep the tools small and simple with as few arguments as possible, and preferably with short meaningful names.

The question is does this new form of seq look worth trouble? It's larger than I like tools to be (but I do have some larger ones), is fairly complex in its treatment of its argument and, although I'm happyish with most of the interpretations, they may not be so for others or there may be better ones.

All comments gratefully received.

Thank you.

Stuart

7 REPLIES 7
RichardJ
19-Tanzanite
(To:StuartBruff)

To be honest, I have never found a use for seq. I prefer to use vec, or one of the many variations thereof. vec(0..4) may require a very small amount of additional typing, but it's much clearer what is being asked for than seq(4) (especially to someone that's not familiar with Mathcad). I might find a use for a more flexible seq function though.

LouP
12-Amethyst
(To:StuartBruff)

I have created similar functions for my own libraries, but found limited use for extremely generic versions. The simple versions cover 99+% of the need, so I have come to keep the def's on the simple side. Also, with my fading, old memory, it's easier to remember what simple functions do. One of my main decisions in creating a function is its name; how to trade off my laziness vs. utility - i.e, really short, cryptic names vs. longer, descriptive names (LSMFT vs. Least_Squares_Modifed_Fourier_Transform).

In the end, however many comments you may get (worth what you pay for them), if you're the user, then go for what makes best sense for you.

Lou

P.S. I remember someone from the old collab with a similar name. Your grandfather perhaps? He may remember that LSMFT was an acronym used in an old cigarette marketing campaign.

StuartBruff
23-Emerald III
(To:LouP)

Lou Poulo wrote:

I have created similar functions for my own libraries, but found limited use for extremely generic versions. The simple versions cover 99+% of the need, so I have come to keep the def's on the simple side. Also, with my fading, old memory, it's easier to remember what simple functions do. One of my main decisions in creating a function is its name; how to trade off my laziness vs. utility - i.e, really short, cryptic names vs. longer, descriptive names (LSMFT vs. Least_Squares_Modifed_Fourier_Transform).

In the end, however many comments you may get (worth what you pay for them), if you're the user, then go for what makes best sense for you.

Hey, ho. <sigh> That's at the core of my quandry. I like simple routines and there is a benefit to having tools do one job very well; I'm quite fond of my vec function because it's short, recursive and turns just about anything into a vector. I also keep a copy of Tom Gutman's ravel around, but I haven't had the need to use it for quite some time ... years, in fact, gosh tempus really does fugit; I have another function, flatten, that I use when I want to control the how deep I go with the conversion on a nested array.

seq(n) started out with a simple need - as a shorthand for vec(0..n-1) to generate a sequence of n successive integers and let me convert scalars into vectors as well; it also has, in my mind, a more mnemonic name for its purpose.

However, I also keep hitting the need for more complex sequences and, this must the Scot in me coming out, I hate to waste the opportunities that other values of n might present in meeting these needs. Overloading argument interpretations is somewhat prevalent in other applications, such as Mathematica, and in Mathcad is the most effective way of getting round the lack of optional arguments. So, carrying on this grand tradition, with usage, the name 'seq' began to become more suggestive of the sequence 0..n or -n..n or "a".."g" and that's how it evolved. Simultaneously, the auxiliary function idx, which took a vector argument and generated its corresponding index vector, evolved to deal with 2-dimensional arrays and also now generates 0..n-1 for a scalar input, so it kind of takes over the original ecological niche that seq was designed to fill.

I'm leaning towards the new definitions, but ....

I suppose the real worry nagging at the back of my mind is the infamous 'requirement creep' syndrome that tries to make an all-singing, all-dancing, all-weather weapons platform out of what was originally a daylight, VFR trainer.

P.S. I remember someone from the old collab with a similar name. Your grandfather perhaps?

Not unless I invent a time machine and play around with a few paradoxes.

I think it was probably me, especially if you remember the dog-fights over the skies of Drummondville against the Giraud Mk I.

P.S. .. He may remember that LSMFT was an acronym used in an old cigarette marketing campaign.

Being Brits, I'm not sure either of my grandfathers would have been au fait with Lucky Strikes ... Woodbines or Players is more like it.

Stuart

LouP
12-Amethyst
(To:StuartBruff)

I remember the Mk I; kept things from getting dull.

As far as how generic to write routines, I tend to keep the initial versions relatively simple, and expand when a need arises. Once I need to make revisions, I tend to add a bit more generality at that time than I actually need, trying to head off future revisions. As you might guess, this is not always successful.

My advice on this topic: worry less and enjoy drinking more (and not tea).

The attached was always one of my favorites (available in many versions) on the topic of mission creep.

Lou

the swing.jpg

StuartBruff
23-Emerald III
(To:LouP)

Lou Poulo wrote:

I remember the Mk I; kept things from getting dull.[/quote]

It did indeed!

As far as how generic to write routines, I tend to keep the initial versions relatively simple, and expand when a need arises. Once I need to make revisions, I tend to add a bit more generality at that time than I actually need, trying to head off future revisions. As you might guess, this is not always successful.

Sigh. I have decided that the three phrases that rattle round my head that I really need to ignore are: "Ooh! That looks interesting", "Hey, if I combine this with that" and "Hmm, What If ....". Good job I wasn't born a redneck or several Southern States would probably only be recognized by the shape of their craters. Jehosaphat! What am I a thinkin' ... several Northern States would only be recognized ...

The attached was always one of my favorites (available in many versions) on the topic of mission creep.

the swing.jpg

One of my favourites too. Only the 'billing' one can stand in for requirements creep as well, and we need a final one showing just a tyre (fitted "for but not with" rope) and a 100 year delay having outsourced production of oak trees to the cheapest bidder (who are trying to expand their acorn feed division).

My advice on this topic: worry less and enjoy drinking more (and not tea).

Not .... Drink .... Tea????

http://i.istockimg.com/file_thumbview_approve/8438152/2/stock-illustration-8438152-monocle-shock.jpg

I think one is taking one's Colonialist tendencies a lttle too far, Sir! Not paying tax on the stuff is one thing, but ...

RichardJ
19-Tanzanite
(To:StuartBruff)

I think Mathcad should just have one function. All possible needs can then be accommodated by a list of arguments. The number of arguments would of course have to be variable, which des bring up the question of what the function should return with no arguments at all. I suggest 42.

StuartBruff
23-Emerald III
(To:RichardJ)

Richard Jackson wrote:

I think Mathcad should just have one function. All possible needs can then be accommodated by a list of arguments. The number of arguments would of course have to be variable, which des bring up the question of what the function should return with no arguments at all. I suggest 42.

Ah, that would explain it. I did try to write such a function and, as you suggest, it did start to tend towards 42. There were 2 problems I couldn't resolve though. As my approximations got better, there was this damned squeaking noise that got louder and louder - sounded for all the world just like a cat-full of excited mice! But the major problem, and I can't see any way round it until Mathcad hits its Prime, was that it suddenly started returning NaN·e as a solution and throwing up indecipherable error messages. Man, did that SUC.

Anyway, must go - there are starting some roadworks outside my house and I need to get onto the council about it.

Stuart

Announcements

Top Tags