The aim is to consider two loops equal if they go through the same
nodes in the same order, regardless of where we happen to start in the
sequence.
Good. Put that into the documentation!
So I took an arbitrary decision to store the loop with the smallest
index first, can you think of a more canonical form?
No, the idea is OK.
I was only complaining about the implementation. In particular about
"minValue:NNI := 10000::NNI". The 10000 here is a value that seems to
come from nowhere.
I guess, loop([]), i.e. with an empty list makes no sense. Or does it?
So you probably put a word into the documentation about it and handle
the empty list separately at the beginning.
After that you know that your list is non-empty.
What about starting your code like that?
loop(li:List NNI):% ==
empty? li => error "cannot form empty loop"
-- first find the index of the minimum entry
minValue:NNI := first i
minIndex:NNI := 1$NNI
for i in 1..#li for v in li repeat
if v < minValue then
minValue := v
minIndex := i
...
Or even do this.
-- construct loop with list of indexes
-- smallest index at the beginning
loop(li:List NNI):% ==
empty? li => error "cannot form empty loop"
-- first find the index of the minimum entry
minValue:NNI := first i
minIndex:NNI := 1$NNI
lx := []$List(NNI)
l1 := li -- initialize part that comes first
l2 := lx -- initialize part that comes after l1
while not empty? li repeat
if first li < minValue then
l1 := li
l2 := lx
lx := cons(first li, lx)
li := rest li
construct(concat(l1, reverse! l2))
Ralf
--
You received this message because you are subscribed to the Google Groups "FriCAS -
computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/fricas-devel?hl=en.