Hi
Is there an existing data structure that allow to represent interval with either open or closed ends like [1 ; 10[. Thanks -- Cédrick _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On 24.11.2008, at 15:03, Cédrick Béler wrote: > Hi > > Is there an existing data structure that allow to represent interval > with either open or closed ends like [1 ; 10[. Class Interval is closed: 1 to: 10 I don't think there is an open interval class. - Bert - _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by cedreek
Hello
Squeak has Interval that represents interval with closed ends. See the samples below: (Interval from: 1 to: 10) includes: 2 --> true (Interval from: 1 to: 10) includes: 10 --> true
(Interval from: 1 to: 10) includes: 11 --> false 2008/11/24 Cédrick Béler <[hidden email]> Hi -- ------------------------------------------ Marcelo Pereira Barbosa São Paulo, Brasil _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
You can always make subclass of Interval for example OpenedInterval , add two variables: left and right.Make new methods:
OpenedInterval>>from: aNumber to: aNumber left: aBoolean OpenedInterval>>from: aNumber to: aNumber right: aBoolean OpenedInterval>>from: aNumber to: aNumber left: aBoolean right: aBoolean they should create standard Interval and write aBoolean to variables left and right; lets say that true for opened form left/right and false for closed. Then add methods OpenedInterval>>includes: aNumber that checks if aNumber is one of borders and founds if left or right is opened/closed. If aNumber is border which should be closed, then uses super include, else answer false. Easy, aint it? You can add accessors and setters for left and right, so that you can open/close intervals without making new one, and check state of variables. You know, you gave me some ideas, that I would be pleased to work out :P I will make this class up and make it public ;) -- Pozdrawiam: Filip GG: 2486889 mail: [hidden email] _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
>>>>> "Filip" == Filip Malczak <[hidden email]> writes:
Filip> You can always make subclass of Interval for example OpenedInterval , add Filip> two variables: left and right.Make new methods: OpenedInterval> from: aNumber to: aNumber left: aBoolean OpenedInterval> from: aNumber to: aNumber right: aBoolean OpenedInterval> from: aNumber to: aNumber left: aBoolean right: aBoolean You're exposing implementation there. I suggest: beOpenLeft beClosedLeft isOpenLeft isClosedLeft and the corresponding "right" methods, rather than an explicit boolean. More flexibility later. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[hidden email]> <URL:http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On 24.11.2008, at 17:46, Randal L. Schwartz wrote: >>>>>> "Filip" == Filip Malczak <[hidden email]> writes: > > Filip> You can always make subclass of Interval for example > OpenedInterval , add > Filip> two variables: left and right.Make new methods: > OpenedInterval> from: aNumber to: aNumber left: aBoolean > OpenedInterval> from: aNumber to: aNumber right: aBoolean > OpenedInterval> from: aNumber to: aNumber left: aBoolean right: > aBoolean > > You're exposing implementation there. How so? - Bert - _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
>>>>> "Bert" == Bert Freudenberg <[hidden email]> writes:
Bert> On 24.11.2008, at 17:46, Randal L. Schwartz wrote: >>>>>>> "Filip" == Filip Malczak <[hidden email]> writes: >> Filip> You can always make subclass of Interval for example OpenedInterval >> , add Filip> two variables: left and right.Make new methods: OpenedInterval> from: aNumber to: aNumber left: aBoolean OpenedInterval> from: aNumber to: aNumber right: aBoolean OpenedInterval> from: aNumber to: aNumber left: aBoolean right: aBoolean >> >> You're exposing implementation there. Bert> How so? You're requiring the user to do their own encoding of "open = true, closed = false", when that's really no business of the user. And what if you decide later to encode the four combinations as a single pluggable block or symbol? -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[hidden email]> <URL:http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Bert Freudenberg
Thanks all for these answers... I should have precised I knew about
Interval ;) But you answered all and more. I wanted to be sure they were no existing implementation of it. I was also imaginating an implementation of a special kind of interval (closed + open ends). I have some questions: - does Interval is a good starting point to me it looks like a closed interval but is not because there's a step between the values which is one by default, so : (0.0 to: 1.0) includes: 0.5 "false" I'd like (0 to: 1) beRightOpen includes: 0.4356456 -> true... (0 to: 1) beRightOpen includes: 1 "false" and I'd also like (this is the original motivation): (0 to: 1) by 0.25 equivalent to: # ( [0 0,25[ [0 0,5[ [0 0,75[ [0 1] ) Would you use Interval or create another class (distinct, super, sub...) ? Thanks for all, Cédrick ps: as an extra question, I wonder what has to be done (if possible) to change the scanner so that: [1 2] creates an interval... it shouldn't be recognized as a block because there's only number inside... maybe it would be difficult to read though _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Randal L. Schwartz
On 24.11.2008, at 18:36, Randal L. Schwartz wrote: >>>>>> "Bert" == Bert Freudenberg <[hidden email]> writes: > > Bert> On 24.11.2008, at 17:46, Randal L. Schwartz wrote: > >>>>>>>> "Filip" == Filip Malczak <[hidden email]> writes: >>> > Filip> You can always make subclass of Interval for example > OpenedInterval >>> , add > Filip> two variables: left and right.Make new methods: > OpenedInterval> from: aNumber to: aNumber left: aBoolean > OpenedInterval> from: aNumber to: aNumber right: aBoolean > OpenedInterval> from: aNumber to: aNumber left: aBoolean right: > aBoolean >>> >>> You're exposing implementation there. > > Bert> How so? > > You're requiring the user to do their own encoding of "open = true, > closed = > false", when that's really no business of the user. It might be a bad interface, but it does not expose the implementation. > And what if you decide later to encode the four combinations as a > single pluggable block or symbol? Then you change the method that takes the booleans to create a block or symbol. - Bert - _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by cedreek
>
> (0 to: 1) by: 0.25 equivalent to: # ( [0 0,25[ [0 0,5[ [0 > 0,75[ [0 1] ) > Of course, I meant: (0 to: 1) by 0.25 "--> #( [0 0,25[ [0,25 0,5[ [0,5 0,75[ [0,75 1] ) " " an array of interval, ie. a discretized interval" (0 to: 1) leftOpen by: 0.25 "--> #( ]0 0,25[ [0,25 0,5[ [0,5 0,75[ [0,75 1] ) " ((0 to: 1) by 0.25) beClosedAtFirstEnd "--> #( [0 0,25] ]0,25 0,5] ]0,5 0,75] ]0,75 1] ) " beClosedAtFirstEnd is not nice but you see what I meant ;) ) Cédrick _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Hmm... When you were talking I wasnt aware of discussion and made up some basis for this subclass. I send it with this mail.
Now Im gonna work on Intervals arithmetics to each other, for example: OpenedInterval from: 1 to: 5 right: true sumWith Interval from: 5 to: 8 should give Interval (or OpenedInterval) from: 1 to: 8 (both borders closed, so no difference). After finishing this Im gonna try to make make some Interval converting, beginning from asOpenedInterval (what should give OpenedInterval with left and right false). -- Pozdrawiam: Filip GG: 2486889 mail: [hidden email] _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners OpenedInterval.st (6K) Download Attachment |
2008/11/24 Filip Malczak <[hidden email]>:
> Hmm... When you were talking I wasnt aware of discussion and made up some > basis for this subclass. I send it with this mail. Thanks Filip. I'll have a look into it :) > > Now Im gonna work on Intervals arithmetics to each other, for example: > OpenedInterval from: 1 to: 5 right: true sumWith Interval from: 5 to: 8 > should give > Interval (or OpenedInterval) from: 1 to: 8 (both borders closed, so no > difference). > Yes this is the kind of operation we can provide (union/intersection). The more I think to it, the more I find Interval might not be the good candidate to subclass. I find Interval correspond to an ordered collection where each element (numbers) difference with its successor is the step. So Interval is a collection of discrete values. I think Interval open/closed (the one I'd like to have) is a "collection" for continues values (infinite element?)... So maybe it's ok for an implementation to subclass Interval but I don't think it's correct. Interval -> "I represent a finite arithmetic progression." What about infinite arithmetic progression ? ;) Can a collection contain an infinite number of elements... ? [0 1[ could represent the collection of **all number** between 0 and 1 excluded. Thanks > After finishing this Im gonna try to make make some Interval converting, > beginning from asOpenedInterval (what should give OpenedInterval with left > and right false). > > -- > Pozdrawiam: > Filip > GG: 2486889 > mail: [hidden email] > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > -- Cédrick _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
2008/11/24 Cédrick Béler <[hidden email]>
What do you need it for? As you can see in methods for Interval - there are two tests for include : rangeIncludes and valueIncludes (includes is both of them connected). First checks if a number is beetween borders and second if its enumerated (with stepping). In deed it contains both: finite and infinite progressions, but just in special cases. The question (already asked) is: what do you need it for? -- Pozdrawiam: Filip GG: 2486889 mail: [hidden email] _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
>
> What do you need it for? As you can see in methods for Interval - there are > two tests for include : rangeIncludes and valueIncludes (includes is both of > them connected). > First checks if a number is beetween borders and second if its enumerated > (with stepping). In deed it contains both: finite and infinite progressions, > but just in special cases. > The question (already asked) is: what do you need it for? > -- work on intervals... continu or symbolic do union/intersection on them... use association between an interval (continu right open) and a weight (kind of probability distribution). I'd also like to transform one into another (1) in (2): (1) [0 0,25[ -> 0.3 [0,25 0,5[ -> 0.1 [0,5 0,75[ -> 0 [0,75 1] -> 0.6 (2) [0 0,75[ -> 0,4 [0,75 1] -> 0.6 At first try I used an array... and did manually the conversion but I'd like now a more object oriented way... So I looked closer at Interval and now I wonder how to represent bounded continu values :) I can use an Interval as you did though... -- Cédrick _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Randal L. Schwartz
On Tue, Nov 25, 2008 at 5:46 AM, Randal L. Schwartz <[hidden email]> wrote: >>>>> "Filip" == Filip Malczak <[hidden email]> writes: Or how about a := 1 to: ∞. If you add the Unicode symbol for infinity as a global variable, it seems to work okay. You just need to choose a font which has that symbol. Alternatively, you could be boring and use a name like "Infinity". Now, the implementation would be most interesting :-). You could go a bit further and make infinity a valid number to use in code. Gulik. -- http://people.squeakfoundation.org/person/mikevdg http://gulik.pbwiki.com/ _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
2008/11/25 Michael van der Gulik <[hidden email]>
Actually, this works fine in the image already: (1 to: Float infinity) includes: 1000 ---> true. I didn't really expect it to work. Smalltalk is good like that :-). Gulik. -- http://people.squeakfoundation.org/person/mikevdg http://gulik.pbwiki.com/ _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Randal L. Schwartz
Randal L. Schwartz a écrit :
>>>>>> "Filip" == Filip Malczak <[hidden email]> writes: > > Filip> You can always make subclass of Interval for example OpenedInterval , add > Filip> two variables: left and right.Make new methods: > OpenedInterval> from: aNumber to: aNumber left: aBoolean > OpenedInterval> from: aNumber to: aNumber right: aBoolean > OpenedInterval> from: aNumber to: aNumber left: aBoolean right: aBoolean > > You're exposing implementation there. I suggest: > > beOpenLeft > beClosedLeft > isOpenLeft > isClosedLeft > > and the corresponding "right" methods, rather than an explicit boolean. > More flexibility later. > > Gulik: > Actually, this works fine in the image already: > > (1 to: Float infinity) includes: 1000 ---> true. > > I didn't really expect it to work. Smalltalk is good like that :-). > > Gulik. Very nice that it works indeed. It was less obvious for this one: (1 to: Float infinity) includes: (10 raisedTo: 400). Luckily, it does also work because of tricky IEEE policy: (Float infinity = Float infinity). Above equality is far from obvious knowing: (Float infinity - Float infinity) isNan... Don't know what they had in mind when comparing Infinities... Anyway the Interval you proposed only has the cardinal of N. Very small compared to the Cardinal of R required for [ 0 , 1 ]. Nicolas _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |