Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
Once upon a time, when a whiteboard was bitten by a radioactive spider and mutated into Mathcad, I wrote several sequence generation functions.
One of these functions was integers(a,b), which, given integers a and b, generated a list of consecutive integers between a and b, inclusive.
Whilst updating my library of such functions to Mathcad Prime 11, I was emboldened by the idea of handling real a and b. Now, I could have gone the restrictive route and treated non-integer arguments as errors, but I decided to go with the flow and see if I could give some meaning to real inputs.
All went swimmingly in my imagination - just restrict the output of the function to those integers lying between a and b. Until I thought about it for a few moments and realised that wouldn't work for certain cases - see the bottom of the screenshot below.
Any ideas for how integers should handle such cases to give "meaningful" results? Or am I on a fool's errand?
(The algorithm doesn't matter, merely the behaviour)
Oh, and, yes, integers covers the Gaussian integers. The image below shows the performance change from using a Bresenham algorithm (integers) to using vec (integers2) to generate a sequence.
Stuart
And talking of flying ideas about, it's a wonderfully breezy day where I live. The wind is about 18 knots, gusting to 30 knots (that's about Beaufort 5 and 6, respectively). There is a yacht sailing just off the shore of the island a few miles away from me, the corvids are enjoying themselves, and gliders are having fun taking advantage of the lift (ridge and wave, I'd imagine) a bit further north in the Scottish Highlands. And here am I cogitating numerical niceties on land. Sigh.
I would suggest that you get PTC to finally implement empty array and then return it this case there is no integer within the given limits. May take some time as they first will implement multidimensional arrays 😈
In the meantime, the function maybe could return NaN or [NaN].
@Werner_E wrote:
I would suggest that you get PTC to finally implement empty array and then ...
Ha Ha Ha Ha Ha Ha Ha ....
@Werner_E wrote:
I would suggest that you get PTC to finally implement empty array and then return it this case there is no integer within the given limits. May take some time as they first will implement multidimensional arrays 😈
In the meantime, the function maybe could return NaN or [NaN].
I am struggling to think of another programming language that doesn't have the empty array. Even FriCAS has the empty list - from the FriCAS Book, Section 9.51.2 Accessing List Elements:
Alternatively, equality with explicit empty list [] can be tested.
(rest([1]) = [])@Boolean
true Boolean
There is even an empty? predicate.
@Werner_E wrote:
May take some time as they first will implement multidimensional arrays 😈
Look, I'm an optimist by nature, but even my optimism has its limits. World peace? Yes, I can see that happening. MDAs in Mathcad? Not a chance.
I'm thoroughly convinced that PTC has a special team devoted to ensuring that nothing I want ever gets into the Mathcad requirements set. And if it does, it will have quirks that somehow manage to not quite do what I'd like (see my recent comments on vec)
@Werner_E wrote:
In the meantime, the function maybe could return NaN or [NaN].
Yes, that's the conclusion I'd regretfully decided was the most sensible option. I use 0 (zero) as the empty array substitute because it's easier to test for (and was what I used before the introduction of NaN, so I'd have to rewrite quite a few library functions to achieve consistency).
Stuart