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

SOLVED
Newbie

## Csort, is it true?

Hello!

Sorry for my english

I just found this "problem"

I think that first "mas" was sorted by first column. But "Mathcad 14" doesn't think so... And we get "mas1"... But again "Mathcad" doesn't think that "mas1" is sorted... and so on...

This little thing brought me a lot of problems...

Can you tell me, is it error of "Mathcad 14"? Or it works as it should? And what should I do?..

Thank!

Sergey

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions

## Re: Csort, is it true?

This seems to be a bug.

Mike

25 REPLIES 25

## Re: Csort, is it true?

This seems to be a bug.

Mike

## Re: Csort, is it true?

Thank, Mike! Happy new year!
I think that it is bug too... I try this function on Mathcad 14 M011, M035, Mathcad 15 - all works the same way...

But what should I do?...

## Re: Csort, is it true?

It is not a bug. When you sort by column 0 there are multiple solutions that are equally valid. The starting point is one valid solution, and the ending point is another. This may be considered undesirable behavior, but it's not a bug.

Tom wrote a Csort function that allows you to sort by multiple columns (csort does not preserve the order of previous sorts), but that also does not attempt to preserve the order of columns that are not specified for the sorting. So I modified it (in my opinion, the new version is an improvement over Tom's version, but then I wrote the modification, so I am biased ).

Edit: 11:50 AM Dec 31. I just uploaded a new file with a minor modificaton to the new function.

## Re: Csort, is it true?

rsort behaves exactly the same as csort, except on the rows rather than the columns.

## Re: Csort, is it true?

 It is not a bug. When you sort by column 0 there are multiple solutions that are equally valid. The starting point is one valid solution, and the ending point is another. This may be considered undesirable behavior, but it's not a bug.

Oh right, my mistake. Nice function by the way.

Maybe this should be added to the Prime request.

Mike

## Re: Csort, is it true?

A word of caution. The routine by Tom, as well as the improvement by Richard, fail if the matrix is large enough and you want to sort successively by enough columns. Demonstration:

Phew, it does.

But When I increase lc to 4 (add an extra column to the matrix):

The maximum difference is 8, not 0.

Row 8130 should follow, not precede rows 8131 and 8132.

QED

Luc

## Re: Csort, is it true?

Of course there's a solution. If you are willing to take a little more processing time you can get:

With 10 million matrix elements, no problem sorting on 10 columns.

The routine is recursive:

Success!
Luc

## Re: Csort, is it true?

Thanks to all! Happy new year!

Okey, this may be considered as undesirable behavior (but it brought me many problems...(((( But in my opinion, it is not correctly.... Because csort will be do transforming of the same matrix many times. Yes, there are multiple solutions. But I think that there is only one highest priority solution, when you meet values in sorted matrix in the same order as in unsorted matrix, don't you think so?
I hope that developers will change this function and fix this "undesirable behavior". (this is not normal logic, when the function receives the correct answer, and gives back another correct answer)
Hope to see the response of developers.

Sergey

## Re: Csort, is it true?

 Yes, there are multiple solutions. But I think that there is only one highest priority solution, when you meet values in sorted matrix in the same order as in unsorted matrix, don't you think so?

In an ideal world, yes. But that's not the way the algorithm used for csort works. The input vector could be checked to see if it is already sorted, but csort does not do that, presumably because of the extra overhead required. A small wrapper program could easily be written in Mathcad to do that though.

 Hope to see the response of developers.

The developers never comment on these forums. As far as I know, they don't even read them.

## Re: Csort, is it true?

It seems that in the program of c(r)sort function we have not more operator but more or equal operator.

## Re: Csort, is it true?

I think so too (don't know enough algorithms, it seems like "bubble sort"...)

## Re: Csort, is it true?

 I think so too (don't know enough algorithms, it seems like "bubble sort"...)

Bubble sort is a terrible algorithm. The csort function uses the heapsort algorithm (it says so in the help). You can read about it in chapter 8 here:

http://www.nrbook.com/a/bookcpdf.php

Note that the help also says: "The heapsort procedure is not a stable sort, meaning that if you sort values with repeated elements, they appear in an arbitrary order.".

## Re: Csort, is it true?

On another note - I was a little surprised to see that Mathcad can sort via text.

Mike

## Re: Csort, is it true?

I expect a lot of people would have complained if it couldn't!

## Re: Csort, is it true?

Has that always been the case with Mathcad?

I take it Mathcad treats the letters as numbers?

Mike

## Re: Csort, is it true?

As far as I can recall it has always worked with strings. The sort is alphabetic, so "a10" comes before "a2".

## Re: Csort, is it true?

In my opinion it will be good if developers will add alternate functions (alt_csort and alt_rsort). And those functions will work as I want! 😃 (yes, they will work slowly... but they will work!) Some tasks can't be solved with csort and rsort as they are today...

How do you think? Can we tell about this to developers? How can I do this? 😃

## Re: Csort, is it true?

The usual way is to write your message using invisible ink on black paper and seal it in a lead bottle floating it down your local river so that they can pick it up on the sea shores off Cambridge Mass. after it has gone around the Atlantic a few times

Well I think that has been the most effective method so far <big wink>

Philip

## Re: Csort, is it true?

Bearing in mind, of course, that nothing gets implemented until it has been suggested by at least ten people, ten times each, over a period of at least ten years, we should all get out our black paper and invisible ink and start writing!

## Re: Invisible variable/function/operator name

 The usual way is to write your message using invisible ink...

I know 7 examples when the invisible variable/function/operator name is useful.

Do you know more?

Mathcad allow us to change the multiplication sign. A user may select the one from the following:

2×а 2·а 2 х a 2 а 2а

The multiplication sign is invisible in last two examples that conform to the tradition existing in mathematics do not place a sing between efficients, if the first is a constant and the second is a variable.

Comment

However, blank space between the two values may mean as addition, as multiplication. For example, 2 hours 30 minutes, 1 kilometer 200 metes etc. Here the invisible addition sign stands between the same quantities (time and length), and multiplication sign — between the constants and the units. Fig. 1 shows how to solve it in Mathcad.

#### Example 2. Zero dimension quantity

Sometimes Mathcad is too pedantic in dimensional quantities. For example, one says that some equipment is situated at a height of twenty meters and another at zero and not specifies the units of that zero (meters, centimeters, feet, or inches etc). Nevertheless, Mathcad always displays the units of the dimensional values even when it is not necessary. In that case, we can hide an excess unit converting it to invisible (Fig. 2).

#### Example 3. The Roman arithmetic

Mathcad works with decimal, binary, hexadecimal, octal numbers. However, we may need to make Mathcad work with forms more exotic, for example, with Roman numbers. For that, we insert the function with the invisible name that returns a Roman number if its argument is an Arabic and conversely the Arabic number if the argument is Roman (Fig. 3).

Example 4. The sparse matrix

Mathcad has powerful instruments to work with vectors and matrixes (arrays). There is one limitation: these arrays should be completely filled. In practice we sometimes deal with nonrectangular matrixes, for example, with triangular. The matrixes may have more complicated form. Fig. 4 shows how to imitate working with sparse matrix.

## Re: Invisible variable/function/operator name

Example 5. Invisible matker on the plot:

Example 6. Duoble answer with two units:

Example 7. Endless loop:

## Re: Csort, is it true?

 Some tasks can't be solved with csort and rsort as they are today..

That is true. So unless you have a great deal of patience and are prepared to wait until the alternative functions are implemented (or the heat death of the universe occurs, which may be sooner), use the functions I posted

## Re: Csort, is it true?

 As far as I can recall it has always worked with strings. The sort is alphabetic, so "a10" comes before "a2".

Now that has no logic at all.

Mike

## Re: Csort, is it true?

 I expect a lot of people would have complained if it couldn't!

Complained!!!!!!!!

WE DON'T COMPLANE ON HERE DO WE ??????

Mike

Announcements