On Thursday 19 Jan 2012 08:08:47 Ralf Hemmecke wrote:
> Hi Martin,
>
> can you give some explanation for this complicated setup?
>
> https://github.com/hemmecke/fricas/blob/martin-baker/src/algebra/graph.spad
> .pamphlet#L543
>
> You seem to want to store the loop with the smallest index first.
> Obviously, this wish cannot have any mathematically relevant meaning,
> since if I give you the list

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.

So I took an arbitrary decision to store the loop with the smallest
index first, can you think of a more canonical form?

So in the following [5,6,2,8] is = to [2,8,5,6] (they are both stored
as [2,8,5,6]) but different to [5,2,6,8] (which is stored as
[2,6,8,5])

(9) -> l1 := loop([5::NNI,6::NNI,2::NNI,8::NNI])
   (9)  "[->2->8->5->6]"

                                                           Type: Loop
(10) -> l2 := loop([2::NNI,8::NNI,5::NNI,6::NNI])
   (10)  "[->2->8->5->6]"

                                                           Type: Loop
(11) -> l3 := loop([5::NNI,2::NNI,6::NNI,8::NNI])
   (11)  "[->2->6->8->5]"

                                                           Type: Loop
(12) -> (l1 = l2)::Boolean
   (12)  true

                                                        Type: Boolean
(13) -> (l1 = l3)::Boolean
   (13)  false
                                                        Type: Boolean

> then after the for loop
>
>        minValue:NNI := 10000::NNI
>        minIndex:NNI := 0::NNI
>        for i in 1..#li repeat
>          if (li.i)<minValue then
>            minValue := li.i
>            minIndex := i
>
> we will still have minIndex=0 and thus return the array with the entries
> in the above order.

I'll look into that.

> I also don't like the "pretend" in these lines:

nor do I.

>      entries(lp:%):List NNI ==
>        entries(lp pretend PrimitiveArray(NNI))$PrimitiveArray(NNI)
>
> "pretend" should almost nowhere be visible in SPAD code. For this
> particular case maybe you want to look at
>
> http://groups.google.com/group/fricas-devel/browse_thread/thread/a547ad5e27
> 65e3e7
>
> I.e. replace "Rep :=" by "Rep ==" and define "rep" and "per" as functions
>
> rep(x: %): Rep == x pretend Rep
> per(x: Rep): % == x pretend %
>
> inside the domain or as macros at top level
>
> rep x ==> (x@%) pretend Rep
> per x ==> (x@Rep) pretend %
>
> (This would be the only places where I'd accept "pretend".)
>
> ((NB: Bill, since I basically neither want to see "Lisp" nor "pretend"
> in a spad file (since they are inherently type unsafe). That is my
> reason for why I want ")include". In fact, I'd also like to specify
> which things are in scope while compilation happens. Just like in Aldor
> compiling a .spad file should start with empty knowledge. Imports should
> be explicit.))
>
> For the "macro" variant, you must merge your branch with trunk since
> parametrized macros have only be added some days ago.
>
> After that your code will look like
>
>      entries(lp:%):List NNI == entries rep lp
>
> which I find tremendously more readable. And the rep makes it clear that
> you rely on functionality of the domain that you have chosen as a
> representation. The SPAD compiler is able to figure out that it has to
> call entries$Rep, but you should not use "Rep:=" for this to work.
>
> Always writing "PrimitiveArray(NNI)" in such places makes it hard to
> easily change the representation and IMHO hides the intend of the code.

Ok, looks like a good improvement, thanks I'll look at this.

Martin

-- 
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.

Reply via email to