Re: Dimension of sequences

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hello Igor!

[snipped]
> 
> Good, the question about the dimensionality of sequences themselves
> seems to be answered, it is just 2, and these two dimensions can be
> considered as maximum length, Length, and maximum depth, Depth.
> 
> But Length of Euphoria sequence is limited by the current Euphoria
> integer.
> For Depth, seems to be same limit, machine memory at least.
> 
> [snip] 
>  
> > I appreciated very much your view about this.
> > I still have another approach about the "dimension of sequences", but before
> > I post it, I want to implement it in Euphoria.
> > The line of reasoning is: a NRS is a set of RS where each one has a known
> > integer
> > dimension. Then, the dimension of a NRS is a sequence formed by that
> > dimensions.
> 
> OK, interesting, the specific structure of a sequence is involved.
> Let's wait.
> 
> Good Luck!
> 
> Regards,
> Igor Kachan
> kinz at peterlink.ru

Here is my current implementation of "dimension of sequences" involving its
structure:
function Dimension(object o)
integer ini
object base
sequence s

   if atom(o) then return 0 end if
   if length(o)=0 then return 1 end if
   if length(o)=1 then return 1+Dimension(o[1]) end if   
   s = {}
   ini = 1
   o = o = o
   base = o[1]
   for i = 2 to length(o) do
      if not equal(base, o[i]) then
         if i > ini+1 then 
            s = append(s,1+Dimension(base))
         else
            s = append(s,Dimension(base))
         end if
         base = o[i]
         ini = i
      end if
   end for
   if ini = 1          then return 1+Dimension(o[1]) end if
   if ini = length(o)  then return append(s,Dimension(o[ini])) end if
   return append(s,1+Dimension(o[ini]))
end function

procedure ShowDimension(object o)
puts(1,"Dimension of ")
print(1, o)
puts(1," = ")
print(1,Dimension(o))
puts(1,"\n")
end procedure

object obj
-- Create an object formed by rectangular sequences with incremental dimension
obj = {1}
for i = 2 to 4 do
   obj = append(obj, repeat(obj[i-1],1))
end for

for i=1 to length(obj) do
   ShowDimension(obj[i])
end for

ShowDimension(1)
ShowDimension({})
ShowDimension({2})
ShowDimension({3,4})
ShowDimension({5,{6}})
ShowDimension({7,{8},9})
ShowDimension({10,{11},{12}})
ShowDimension({13,{14,15}})
ShowDimension({{16,17},{18,19}})
ShowDimension({{20,21},{22}})
ShowDimension({23,{24,{{25,26},{27,28}}}})
ShowDimension({1,{1},{1,1},{1,1,1},{1,1},{1},1})
ShowDimension({1,{1},{1},{1,1},{1,1},{{1,1},{1,1},{1,1}}})
ShowDimension({obj[1],obj[2],obj[3],obj[4]})
ShowDimension({obj[4],obj[3],obj[2],obj[1]})
ShowDimension({obj[1],{obj[2],{obj[3],{obj[4]}}},obj[1]})

for i = 1 to length(obj) do
   for j = 1 to length(obj) do
      for k = 1 to length(obj) do
         ShowDimension({obj[i], obj[j], obj[k]})
      end for
   end for
end for


Thanks to everyone who has contributed to this topic!
Regards,
  Fernando

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu