Adept Scientific - English
The world's best software for research, science and engineering.
flag arrow
clearclear
 

 Adept Store | register Join My Adept | Flags  
Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055  
UKusdedksvnofi
Home
Products
Training
Consultancy
 Buy Online
Downloads
Education
Support
My Adept
International |  About Us |  Contact Us |  Press Room |  Jobs


The Next Steps

• Ask us a question
• Maple Product Tour
• Buy Maple Now
• View Maple Pricing
• Find out about Online Training
• Download a Brochure
• Request a Brochure
• Download a Demo
• Request a Demo
• Meet Our Team
• Read our RSS Feeds

Learn More

Maple Home
Maple 11 Professional
Maple 11 Academic
Maple 11 Student Use
Recorded Online Seminars
FREE Training Resources


MapleNet
Maple T.A.
MapleConnect
BlockImporter for Simulink
BlockBuilder for Simulink
Maple Toolboxes
Maple Rave Reviews
Maple Study Guides
Books about Maple
System Requirements

View Maple 10 in Action
Product Comparison Chart

Latest Information

New Features: Professional
New Features: Academic
The Maple Reporter
The Maple Reporter Online
Numerical Algorithms Group
(NAG)


Service & Support

Maple 10 Training Videos
MaplePrimes, blogs, forums
Elite Maintenance Program
Application Centre
Powertools
Maple User Group (MUG)
Join the Maple User Group
(MUG)

Search the Knowledge Base
Technical Support request

List Archives >  Maple User Group List Archive >  Archive by date >  This Month By Date >  This Month By Topic

[MUG] Re: sorting alphanumeric lists

Search email archive for  

[MUG] Re: sorting alphanumeric lists
Author: Maple User Group    Posted: Fri, 22 Nov 2002 16:39:38 -0500

>> From: Maple User Group "maple_gr"

-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Wed, 20 Nov 2002 13:46:30 -0800 (PST)
From: Michael Monagan "mmonagan"
To: maple-list "maple-list"
Subject: sorting alphanumeric lists

>I have a problen in sorting object. Maple provides two buildin functions
>sort and lexorder, which are pretty fast. I need to compare two lists, to
>compute the number of transpositions of a permutation (which are needed
>for keelping track of some q-factors in q-deformed symmetric groups).
=======

You need to use Maple trick number 2.
Use the antisymmetric indexing function for a table as follows.


> L := [1,3,2,4];
L := [1, 3, 2, 4]

> T := table(antisymmetric);
T := table(antisymmetric, [])

> T[op(L)];
-T[1, 2, 3, 4]

> L := [1,3,4,2];
L := [1, 3, 4, 2]

> T[op(L)];
T[1, 2, 3, 4]

The result is of type indexed <==> L is an even permutation,
i.e. and even number of transpositions are required.

Michael Monagan
----------------------------------------------------------------

Dr. Michael Monagan,
Department of Mathematics, Tel: (604) 291-4279
Simon Fraser University, Fax: (604) 291-4947
Burnaby, BC, CANADA V5A 1S6 e-mail: "monagan"


-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Tue, 19 Nov 2002 16:26:14 -0800 (PST)
From: Robert Israel "israel"
To: maple-list "maple-list"
Subject: sorting alphanumeric lists

I'm somewhat puzzled, and would like to see a concrete example where
lexorder gives a wrong answer on integers turned into names. Are you
sure the problem isn't simply that lexicographic order is different
from numerical order? For example, `10` comes before `9` in lexicographic
order.

Robert Israel "israel"
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia
Vancouver, BC, Canada V6T 1Z2



-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

From: Joe Riel "joer"
To: "maple-list"
Date: Wed, 20 Nov 2002 11:53:02 -0800
Subject: sorting alphanumeric lists

Maple does have a random permutation generator, combinat[randperm].
It uses the shuffling algorithm of Fisher and Yates discussed
in Knuth [1]. As mentioned there, this method will generate at most
p distinct permutations, where p is the modulus of the linear
congruential generator. For Maple (R8), p = 999999999989.
So, for permutations with more than 13 elements, some permutations
will never arise.

The method that Bertfried uses [to generated a random permutation]
appears to be O(n*log(n)), though for large n I suspect that this
goes to O(n^2) because list building in Maple is O(l), where l
is the length of the list. Combinat[randperm] is O(n).

The perm_num_of_tr function appear to have a few errors.
First, the comparison is being
done between items on the same list (only the lenght of lst1 is used).
Did you mean

perm_num_of_tr:=proc(lst1,lst2)
local i,j;
nops(select(evalb,[seq(seq((lst2[j]>lst1[j]),
j=i+1..nops(lst2)),
i=1..nops(lst1))]))
end proc

Also, the commented out line (not shown above) is definitely wrong;
lexorder(""||lst2[j],""||lst2[i]) should work (aside from the previous
comment). Finally, the algorithm above is definitely flawed.
Swapping the two arguments gives different results.

Do you really need to know the number of transpositions between permutations?
Or is it just the relative parity that interests you?
If the latter, there are fast ways of getting that.


Joe Riel



[1] Donald E. Knuth, "The Art of Computer Programming,"
Vol 2. Seminumerical Algorithms, Third Edition, Addison Wesley.

[View Complete Thread]



Previous by date: [MUG] animation problems, Bertfried Fauser
Next by date: [MUG] problems with subs(),  Charles James Leonardo Quarra Cappiello
Previous thread: [MUG] ODE with singularity, Jens-Uwe Herrmann
Next thread: [MUG] problems with subs(),  Charles James Leonardo Quarra Cappiello



Ready to buy?

Maple - single user licence
Add to shopping basket
$ 1,895.00
Upgrade to Maple 12 from v11
Add to shopping basket
$ 995.00
Upgrade to Maple 12 from v10 & below
Add to shopping basket
$ 1,395.00

Featured Downloads

What's New in Maple 11 for Professionals
Maple White Paper: Technical Knowledge - An Asset You Can Afford to Lose?
Maple in Electronics Application Pack
Maple in Robotics & Aerospace Application Pack
Maple in Finance Application Pack

Product Reviews

"Without the Maple software, we would have to spend weeks generating the equations of motion for every experiment. Then the chances that we did it right would basically be near zero. There would always be a mistake somewhere. It is very difficult to set up a dynamic motion model by hand."
- Jean-Claude PiedBeouf, Ph.D Manager of Robotics, Canadian Space Agency

"Its very good - highly accurate and easy to use. The speed of Maple allows me to change equations and quickly reintegrate them into the application, so more possibilities can be explored to achieve the precise effect desired."
Shawn Neely, Senior R & D Director for PDI/Dreamworks
adept

Top of the Page

Our Privacy and Terms and Conditions Statement
All Trademarks Recognised. Copyright © 2007, Adept Scientific plc.
Site designed and maintained by Adeptise

Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055