1. Integer() operation on a sequence?
- Posted by Michael Raley <thinkways at yahoo.com> Jun 04, 2004
- 486 views
not too suprisingly I cannot do this s = integer({0.12321,0.44343,1,1,0.555}) - s becomes {0,0,1,1,0} So howabout? s = integers({sequence}) Secondly; a sequence summation operator i= ~sigma ({sequence s from above}) i = 2 --"ask about our layaway plan". --
2. Re: Integer() operation on a sequence?
- Posted by cklester <cklester at yahoo.com> Jun 04, 2004
- 456 views
Michael Raley wrote: > > > not too suprisingly I cannot do this > > s = integer({0.12321,0.44343,1,1,0.555}) > - s becomes {0,0,1,1,0} > > So howabout? > s = integers({sequence}) Does s = floor( {sequence} ) do what you want?
3. Re: Integer() operation on a sequence?
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Jun 05, 2004
- 442 views
On Fri, 04 Jun 2004 13:02:59 -0700, irv mullins <guest at RapidEuphoria.com> wrote: >posted by: irv mullins <irvm at ellijay.com> >Andy Serpa wrote: >> cklester wrote: >> > Michael Raley wrote: >> > > not too suprisingly I cannot do this >> > > >> > > s = integer({0.12321,0.44343,1,1,0.555}) >> > > - s becomes {0,0,1,1,0} >> > > >> > > So howabout? >> > > s = integers({sequence}) >> > >> > Does >> > >> > s = floor( {sequence} ) >> > >> > do what you want? >> >> I think what he wants is: >> >> function integers(sequence s) >> return floor(s) = s >> end function >> > >constant s = {0.12321,0.44343,1,1,0.555} > > ? floor(s) > ? floor(s) = s > > >{0,0,1,1,0} >{0,0,1,1,0} > > >Press Enter... > >Looks like you're both right (unless one of the integers > 1, in which >case at least one of you is wrong :) > >Irv Note that: constant s={0.1,1,2,{3,4.5,6}} ?s=floor(s) will display {0,1,1,{1,0,1}}, instead of {0,1,1,0}. Regards, Pete
4. Re: Integer() operation on a sequence?
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 06, 2004
- 474 views
Michael Raley wrote: > > > not too suprisingly I cannot do this > > s = integer({0.12321,0.44343,1,1,0.555}) > - s becomes {0,0,1,1,0} What were you expecting to achieve? ** Did you wish to convert each of the elements into an integer? seq s s = floor({0.12321,0.44343,1,1,0.555}) ** Did wish to see if each element was an integer? seq s s = integer({0.12321,0.44343,1,1,0.555}) ** Did you wish to see if the entire paramter was an integer? integer s if integer({0.12321,0.44343,1,1,0.555}) then s = 1 else s = 0 end if ** Did you wish to convert the entire parameter into a single integer? sequence s s = value({0.12321,0.44343,1,1,0.555}) > So howabout? > s = integers({sequence}) What is supposed to return? The number of integers in the sequence? s = integer (x) y = 0 for i = 1 to length(x) y += x[i] end for > Secondly; a sequence summation operator > i= ~sigma ({sequence s from above}) > i = 2 Euphoria does allow a fair degree of flexibility. How about this version of sigma for you... function i_qual(object x) if integer(x) then return 1 else return 0 end if end function function a_qual(object x) if atom(x) then return 1 else return 0 end if end function function p_qual(object x) if atom(x) and x > 0 then return 1 else return 0 end if end function function n_qual(object x) if atom(x) and x < 0 then return 1 else return 0 end if end function constant OnlyIntegers = routine_id("i_qual"), OnlyAtoms = routine_id("a_qual"), OnlyPos = routine_id("p_qual"), OnlyNeg = routine_id("n_qual") function sigma(sequence x, object qual) object y integer t if atom(qual) then qual ={qual} end if y = 0 for i = 1 to length(x) do t = 0 for j = 1 to length(qual) do t += call_func(qual[j],{x[i]}) end for if t = length(qual) then y += x[i] end if end for return y end function sequence s s = {0.12321,-0.44343,1,-2,0.555} ? sigma(s, OnlyIntegers) ? sigma(s, OnlyAtoms) ? sigma(s, {OnlyIntegers,OnlyPos}) ? sigma(s, {OnlyAtoms,OnlyNeg}) ? sigma(s, {OnlyAtoms,OnlyPos}) ? sigma(s, {OnlyIntegers,OnlyNeg}) What I'm trying to say is that you could try out writing your own function first and if that is not ever going to be fast enough for your needs, then you could lobby RDS for a new built-in routine. -- Derek Parnell Melbourne, Australia
5. Re: Integer() operation on a sequence?
- Posted by "Elliott S. de Andrade" <quantum_analyst at hotmail.com> Jun 06, 2004
- 457 views
>From: Derek Parnell <guest at RapidEuphoria.com> >Reply-To: EUforum at topica.com >To: EUforum at topica.com >Subject: Re: Integer() operation on a sequence? >Date: Sat, 05 Jun 2004 18:02:04 -0700 > >Michael Raley wrote: > > not too suprisingly I cannot do this > > > > s = integer({0.12321,0.44343,1,1,0.555}) > > - s becomes {0,0,1,1,0} > That is not what integer() is for. Obviously, you cannot do that. >What were you expecting to achieve? > >** Did you wish to convert each of the elements into an integer? > seq s s = floor({0.12321,0.44343,1,1,0.555}) > >** Did wish to see if each element was an integer? > seq s s = integer({0.12321,0.44343,1,1,0.555}) > You'd need a for-loop for that one, Derek. You'll get a type-check error because integer() will return 0. >** Did you wish to see if the entire paramter was an integer? > integer s if integer({0.12321,0.44343,1,1,0.555}) then > s = 1 else s = 0 end if > >** Did you wish to convert the entire parameter into a single integer? > sequence s s = value({0.12321,0.44343,1,1,0.555}) > Uh... What? > > > > So howabout? > > s = integers({sequence}) > >What is supposed to return? The number of integers in the sequence? > > s = integer (x) > y = 0 > for i = 1 to length(x) > y += x[i] > end for > That would give you the sum of the values in the sequence. I'm not sure what s if for either. You mean:
y = 0 for i = 1 to length(x) do y += integer(x[i]) end for
> > Secondly; a sequence summation operator > > i= ~sigma ({sequence s from above}) > > i = 2 > Don't use the tilde! I wanted that for ignoring return values of functions. That's a whole other topic which could be discussed in another thread. As Derek said, though, you don't need a new operator for such a thing. > [stuff written that I didn't comment on] > ~[ WingZone ]~ http://wingzone.tripod.com/
6. Re: Integer() operation on a sequence?
- Posted by Michael Raley <thinkways at yahoo.com> Jun 07, 2004
- 474 views
Derek Parnell wrote: > > Michael Raley wrote: > > > > > > not too suprisingly I cannot do this > What were you expecting to achieve? As I stated in the example with integer, to apply the test to a slice of elements and return a sequence of True/False values. i.e (1,0,0,1,1,0) > > What I'm trying to say is that you could try out writing your own function > first and if that is not ever going to be fast enough for your needs, > then you could lobby RDS for a new built-in routine. > Yes I could, but I think the functionality has as much broader merit as current native functions and should at least be mentioned.
7. Re: Integer() operation on a sequence?
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 07, 2004
- 449 views
Michael Raley wrote: > > > Derek Parnell wrote: > > > > Michael Raley wrote: > > > > > > > > > not too suprisingly I cannot do this > > What were you expecting to achieve? > As I stated in the example with integer, > to apply the test to a slice of elements > and return a sequence of True/False values. > i.e (1,0,0,1,1,0) Sorry. I totally misunderstood your question. > > What I'm trying to say is that you could try out writing your own function > > first and if that is not ever going to be fast enough for your needs, > > then you could lobby RDS for a new built-in routine. > > > Yes I could, but I think the functionality has as much broader merit as > current native functions and should at least be mentioned. Hmmm...I'll take your word for that, as I've never needed this or similar functionalty yet. It strikes me as not necessary as what are you going to do with the resultant sequence? My guess is that you will examine each result element and do something appropriate. In which case what is different between ... s = integers({2.3, 0, 5, 3.22, -4}) for i = 1 to length(s) do -- Derek Parnell Melbourne, Australia
8. Re: Integer() operation on a sequence?
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 07, 2004
- 465 views
Michael Raley wrote: > > > Derek Parnell wrote: > > > > Michael Raley wrote: > > > > > > > > > not too suprisingly I cannot do this > > What were you expecting to achieve? > As I stated in the example with integer, > to apply the test to a slice of elements > and return a sequence of True/False values. > i.e (1,0,0,1,1,0) > > > > What I'm trying to say is that you could try out writing your own function > > first and if that is not ever going to be fast enough for your needs, > > then you could lobby RDS for a new built-in routine. > > > Yes I could, but I think the functionality has as much broader merit as > current native functions and should at least be mentioned. My previous reply was incomplete because I pressed the TAB key followed by the ENTER key, thus causing focus to move the the 'Send Now' button and sending it. Robert/Junko: Maybe this is a minor GUI issue you can tweak. Anyhow, back to the thread... What is the difference between ... s = integers({2.4, 1, 0, 3.22, -5}) for i = 1 to length(s) do if s[i] then ... end if end for and s = {2.4, 1, 0, 3.22, -5} for i = 1 to length(s) do if integer(s[i]) then ... end if end for -- Derek Parnell Melbourne, Australia
9. Re: Integer() operation on a sequence?
- Posted by Michael Raley <thinkways at yahoo.com> Jun 07, 2004
- 452 views
> > Hmmm...I'll take your word for that, as I've never needed this > or similar functionalty yet. It strikes me as not necessary as > what are you going to do with the resultant sequence? My guess is > that you will examine each result element and do something appropriate. > In which case what is different between ... > > s = integers({2.3, 0, 5, 3.22, -4}) > for i = 1 to length(s) do > > -- > Derek Parnell > Melbourne, Australia > actually I'm imagining using it to find patterns in data; vertical_length = 3000 reallybigsequence = {0,1,2,3,4,5,6,7,1,4,3,4,5,7,1,4,0,...and so on pattern = {1,1,repeat(0,vertical_length/2),1,1,0} for i = 1 to 7 m = find(pattern,integers(i/reallybigsequence)) if m then blah blah blah end for