even? odd?

57 views
Skip to first unread message

Hallvard Ystad

unread,
May 11, 2013, 8:11:03 AM5/11/13
to re...@googlegroups.com
What values are supposed to go into the ODD? and EVEN? functions? Here's from R3:

>> source even?
even?: make action! [[
    "Returns TRUE if the number is even."
    number [number! char! date! money! time! pair!]
]]
>> even? 47x47
** Script error: cannot use even? on pair! value
** Where: even?
** Near: even? 47x47

>> source odd?
odd?: make action! [[
    "Returns TRUE if the number is odd."
    number [number! char! date! money! time! pair!]
]]
>> odd? 47x47
** Script error: cannot use odd? on pair! value
** Where: odd?
** Near: odd? 47x47

>>

Thanks,
HY

Carl Read

unread,
May 11, 2013, 8:45:30 AM5/11/13
to re...@googlegroups.com
Pair isn't in R2 and I can't really think why it'd be included in R3. Possibly useful would be checking if the product of multiplying the x and y values is odd or even. But other than that, I can't see what you'd be looking for.

-- Carl Read.


On 11-May-2013 Hallvard Ystad wrote,
>--
>You received this message because you are subscribed to the Google Groups
>"REBOL" group.
>To unsubscribe from this group and stop receiving emails from it, send an
>email to rebol+un...@googlegroups.com.
>To post to this group, send email to re...@googlegroups.com.
>Visit this group at http://groups.google.com/group/rebol?hl=en.
>For more options, visit https://groups.google.com/groups/opt_out.
>
>

Ladislav

unread,
May 14, 2013, 4:05:30 PM5/14/13
to re...@googlegroups.com
Hi, Hallvard

Dne sobota, 11. května 2013 14:11:03 UTC+2 Hallvard Ystad napsal(a):
Already in CureCode (has been reported by Jerry Tsai two years ago, but nobody has corrected it yet, as it looks. ( http://issue.cc/r3/1884 ) "..Carthaginem esse delendam" Being at it, what do you think about http://issue.cc/r3/1622 ?

- Ladislav

Arnold

unread,
May 15, 2013, 3:08:09 AM5/15/13
to re...@googlegroups.com
Hi all,

2013/5/14 Ladislav <ladis...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "REBOL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rebol+un...@googlegroups.com.
To post to this group, send email to re...@googlegroups.com.
  
in my view ODD? or EVEN? on a pair needs a specification, it looks like a shortcut for testing the first element of the pair to be even or odd. You could also think of both x and y being even or odd.
Could also have been added in sheer enthousiasm, simply added everywhere where the previous types were possible as argument, not realising other implications.
 
EVEN? is not NOT ODD? for not integer arguments, having the EVEN? say true to argument 2.1, I can follow the logic thought mentioned in the issue.
 
If you know what is going on things are not so bad, but as always, garbage in => garbage out.
 
Regards,
 
Arnold

John Kenyon

unread,
May 15, 2013, 8:24:01 PM5/15/13
to re...@googlegroups.com
My take on this is to "pair" back the function to a more simple definition.

One definition of odd is as follows:
"(of whole numbers such as 3 and 5) Having one left over as a remainder when divided by two."

Given this definition odd and even only make sense when applied to integer values.

This would give us something like:
even?: func [ number (integer!) ] [ zero? modulo number 2 ]
odd?: func [ number (integer!) ] [ not zero? modulo number 2 ]

Less edge cases to worry about and more consistent behaviour.
Cheers,
John

Gregg Irwin

unread,
May 15, 2013, 9:02:07 PM5/15/13
to John Kenyon
JK> Given this definition odd and even only make sense when applied to
JK> integer values.

Yes, or their integer equivalent. Pair values have no integer
equivalent, so I don't think the funcs apply well to them. At least
until someone posts a great solution that everyone likes.

--Gregg

Ladislav

unread,
May 16, 2013, 3:21:18 AM5/16/13
to re...@googlegroups.com, Gregg Irwin


Dne čtvrtek, 16. května 2013 3:02:07 UTC+2 Gregg napsal(a):
... 
Pair values have no integer
equivalent, so I don't think the funcs apply well to them. At least
until someone posts a great solution that everyone likes.

--Gregg


I tend to agree and propose to remove the pair! datatype from the spec of EVEN? and ODD?

BTW, I added a comment to http://issue.cc/r3/1622 to demonstrate that examining the EVEN? and ODD? functions from "rounding POV" reveals a design problem.

-Ladislav

Carl Read

unread,
May 16, 2013, 4:18:36 AM5/16/13
to re...@googlegroups.com
Some reading...

http://en.wikipedia.org/wiki/Parity_%28mathematics%29

"In mathematics, the parity of an object states whether it is even or odd. This concept begins with integers."

Pairs are often used with two dimensional objects. So, are there any mathematicians here who can say if points on a plane have parity?

-- Carl Read.


On 16-May-2013 Ladislav wrote,

Carl Read

unread,
May 16, 2013, 4:41:19 AM5/16/13
to re...@googlegroups.com
Missed this bit right at the bottom of the Wiki article...

"Integer coordinates of points in Euclidean spaces of two or more dimensions also have a parity, usually defined as the parity of the sum of the coordinates.[citation needed]"

Damn those 'citation needed's!

The sum of the coordinates doesn't seem very useful to me, though mathematicians might disagree. As to me, a chessboard is even, while tic-tac-toe is odd...

-- Carl Read.


On 16-May-2013 Carl Read wrote,

>Some reading...
>
>http://en.wikipedia.org/wiki/Parity_%28mathematics%29
>
>"In mathematics, the parity of an object states whether it is even or odd.
>This concept begins with integers."
>
>Pairs are often used with two dimensional objects. So, are there any
>mathematicians here who can say if points on a plane have parity?
>
>-- Carl Read.
>
>
>On 16-May-2013 Ladislav wrote,
>
>>
>>
>>Dne �tvrtek, 16. kv�tna 2013 3:02:07 UTC+2 Gregg napsal(a):

pd

unread,
May 16, 2013, 7:05:32 AM5/16/13
to re...@googlegroups.com
I think the problem of parity of pair! can be make analogous to the problem of parity of complex numbers, in fact this would be very useful since pair! pairs are commonly used to represent complex numbers

I don't know if there's any mathematical background supporing this analogy but I consider it useful for rebol programmers


On Thu, May 16, 2013 at 10:41 AM, Carl Read <ca...@cybercraft.co.nz> wrote:
Missed this bit right at the bottom of the Wiki article...

"Integer coordinates of points in Euclidean spaces of two or more dimensions also have a parity, usually defined as the parity of the sum of the coordinates.[citation needed]"

Damn those 'citation needed's!

The sum of the coordinates doesn't seem very useful to me, though mathematicians might disagree. As to me, a chessboard is even, while tic-tac-toe is odd...

-- Carl Read.


On 16-May-2013 Carl Read wrote,

>Some reading...
>
>http://en.wikipedia.org/wiki/Parity_%28mathematics%29
>
>"In mathematics, the parity of an object states whether it is even or odd.
>This concept begins with integers."
>
>Pairs are often used with two dimensional objects. So, are there any
>mathematicians here who can say if points on a plane have parity?
>
>-- Carl Read.
>
>
>On 16-May-2013 Ladislav wrote,
>
>>
>>
>>Dne čtvrtek, 16. května 2013 3:02:07 UTC+2 Gregg napsal(a):
Reply all
Reply to author
Forward
0 new messages