Re: Domains? [Re: r28597 - docs/Perl6/Spec/S32-setting-library]

2009-10-13 Thread Ville Koskinen
On Tue, 13 Oct 2009 09:21 +0200, "Michael Zedeler" 
wrote:
> 'a' .. 'z' followed by 'ä', 'ö', 'å' (Swedish)

'a' .. 'z', 'å', 'ä', 'ö' (Finnish)
'a' .. 's', 'š', 'z', 'ž', 't' .. 'w', 'õ', 'ä', 'ö', 'ü', 'x', 'y'
(Estonian)

So yes, you are definitely on the right track with Domains.

Regards,
Ville Koskinen




Domains? [Re: r28597 - docs/Perl6/Spec/S32-setting-library]

2009-10-13 Thread Michael Zedeler

yary wrote:

...
  

Also, the domain should define how to compare objects and could provide
details about whether the set is finite, countable or uncountable.


...

Sounds like a role "Domain" that provides methods (off the top of my head)-

ordering - returns Nil if the domain is unordered, or a method
implementing "cmp" if it is ordered

succ, pred- returns Nil if the domain is uncountable, or method
implementing "next item", "prior item" if countable.
  

Exactly.

count - returns Inf if it's an infinite domain, or count of objects if
finite. What if counting is an expensive operation?
In most cases, the developer will know whether the domain is infinite 
and just hardwire the result to Inf.

Then the .. operator can accept anything that does Domain where
ordering is non-Nil, and the ... operator can add the condition that
succ/pred are non-Nil.
  

Yes.

Moreover, I have realized that Domains can solve a lot of other 
problems, such as collations. In English, it makes sense to write 
something like


'a' .. 'z'

but the Danish and Swedish counterparts are

'a' .. 'z' followed by 'æ', 'ø', 'å' (Danish)

and

'a' .. 'z' followed by 'ä', 'ö', 'å' (Swedish)

since there is only one 'z' in unicode (for obvious reasons), collation 
is something separate from the charset, which can be provided in a 
domain. Also, encoding magical month names becomes easy (the double 
parens here are casting to a domain):


my $month = ((DateDomain['en_US', '%b']))'Jan';
$month++;
say $month; # Feb

...and even...

my $date = ((DateDomain['en_US', '%D']))'01/14/2001';
$date++;
say $date; # 01/15/2001

Also, this is an extension of the notion of subtypes, augmenting it with 
ordering and some other relations. Next question is whether the domain 
shouldn't also provide arithmetic.


There is a lot of plumbing to do to fully use this concept, but I 
believe it could be really useful.


Regards,

Michael.

where



Re: r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-12 Thread yary
...
> Also, the domain should define how to compare objects and could provide
> details about whether the set is finite, countable or uncountable.
...

Sounds like a role "Domain" that provides methods (off the top of my head)-

ordering - returns Nil if the domain is unordered, or a method
implementing "cmp" if it is ordered

succ, pred- returns Nil if the domain is uncountable, or method
implementing "next item", "prior item" if countable.

count - returns Inf if it's an infinite domain, or count of objects if
finite. What if counting is an expensive operation? perhaps there
should also be an "is_infinite" method that returns true or false.

Then the .. operator can accept anything that does Domain where
ordering is non-Nil, and the ... operator can add the condition that
succ/pred are non-Nil.


Re: r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-12 Thread Michael Zedeler

David Green wrote:

On 2009-Oct-4, at 2:07 pm, Moritz Lenz wrote:

Michael Zedeler wrote:

It doesn't, because succ should always give the next, smallest possible
element given some ordering relation.

Where's that definition from?
The dictionary.  =)  It would be confusing to have a "successor" 
method for something that isn't orderable and discrete.  An ordered 
continuous type like Real could have .inc and .dec; it just happens 
that in the common case of Ints, .succ and .inc mean the same thing.


Complex could have an .inc method, but I don't think there's any 
especially obvious choice (because .inc probably wants an ordered 
type).  Would it add 1? or 1+i?  Better to spell it out explicitly.

Well, Real implies ordering (at least to me ;-), I don't think we have a
class or role for countability.
A Discrete role would be useful, but is Set good enough for that? 
Sets could be acting as domains for things such as Integers, so we are 
on two different abstraction levels there (having Integer implement Set 
would probably never make much sense, but an Integer object can be part 
of a Set).


Integers, strings and other types have a succ and pred method, but you 
could say that they draw upon a set (acting as their domain) when they 
decide the successor and predecessor of any given element. In 
mathematical terms it makes sense, but I am aware that from an 
implementation perspective, it sounds somewhat odd. It does, however 
solve some of the current problems that we have with iterating on Ranges 
and various other things.


Also, the domain should define how to compare objects and could provide 
details about whether the set is finite, countable or uncountable.


Does anyone know if there has been any prior discussions of such an 
approach?


I started changing the spec, but decided against it since I have some 10 
years of design discussion to catch up on first. Links to prior 
discussions will be greatly appreciated.


Regards,

Michael.



Re: r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-06 Thread Eirik Berg Hanssen
Michael Zedeler  writes:

> Moritz Lenz wrote:
>> Jon Lang wrote:
>>   
>>> How do pred and succ work when given Complex values?
>>> 
>> By adding/substracting 1 from the real part, I'd say. Don't know if that
>> actually makes sense.
>>   
> It doesn't, because succ should always give the next, smallest possible
> element given some ordering relation. Neither does it make sense for
> real numbers. Same thing applies to pred.

  And yet, you somehow manage to fit an infinite number of strings
between a string and its «successor» ...

  Likewise, you could choose to define .succ for reals.


Eirik, for reals!
-- 
The price of success in philosophy is triviality.
-- C. Glymour.


Re: r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-04 Thread David Green

On 2009-Oct-4, at 2:07 pm, Moritz Lenz wrote:

Michael Zedeler wrote:
It doesn't, because succ should always give the next, smallest  
possible

element given some ordering relation.


Where's that definition from?


The dictionary.  =)  It would be confusing to have a "successor"  
method for something that isn't orderable and discrete.  An ordered  
continuous type like Real could have .inc and .dec; it just happens  
that in the common case of Ints, .succ and .inc mean the same thing.


Complex could have an .inc method, but I don't think there's any  
especially obvious choice (because .inc probably wants an ordered  
type).  Would it add 1? or 1+i?  Better to spell it out explicitly.



Well, Real implies ordering (at least to me ;-), I don't think we  
have a

class or role for countability.


A Discrete role would be useful, but is Set good enough for that?



-David



Re: r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-04 Thread Moritz Lenz
Jon Lang wrote:
> Moritz Lenz wrote:
>> Jon Lang wrote:
>>> typos: s[Nuermic] = "Numeric"
>>
>> You do have a pugs commit bit, don't you?
> 
> A what?  AFAICT, I don't have any way of editing the Synopses;

You have now (sorry for assuming earlier that you had). A username and
password should be on the way to your email address.

svn co http://svn.pugscode.org/pugs/docs/Perl6/Spec/
cd Spec
# hack away
svn ci

Cheers,
Moritz


Re: r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-04 Thread Jon Lang
Moritz Lenz wrote:
> Jon Lang wrote:
>> typos: s[Nuermic] = "Numeric"
>
> You do have a pugs commit bit, don't you?

A what?  AFAICT, I don't have any way of editing the Synopses; all I
can do is to comment on what I find.

-- 
Jonathan "Dataweaver" Lang


Re: r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-04 Thread Moritz Lenz
Michael Zedeler wrote:
> Moritz Lenz wrote:
>> Jon Lang wrote:
>>   
>>> How do pred and succ work when given Complex values?
>>> 
>> By adding/substracting 1 from the real part, I'd say. Don't know if that
>> actually makes sense.
>>   
> It doesn't, because succ should always give the next, smallest possible
> element given some ordering relation. 

Where's that definition from? For me .succ was just the backend for
prefix and postfix ++, which desugar to $thing += 1 (except for strings,
where it's magic).

> Neither does it make sense for
> real numbers. Same thing applies to pred.
> 
> It may be necessary to move methods in the Numeric class that require
> ordering and countability to somewhere else.

Well, Real implies ordering (at least to me ;-), I don't think we have a
class or role for countability.

>> You do have a pugs commit bit, don't you?
>> If you find errors, feel free to correct them in the synopsis.
> I do. If anyone doesn't object, I'd be happy to move the methods down to
> a subclass (or -role) - at least in the spec (not sure what to do with
> the code as of now).

The code and tests are later adapted at whim, or so ;-)

Cheers,
Moritz


Re: r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-04 Thread Michael Zedeler

Moritz Lenz wrote:

Jon Lang wrote:
  

How do pred and succ work when given Complex values?


By adding/substracting 1 from the real part, I'd say. Don't know if that
actually makes sense.
  

It doesn't, because succ should always give the next, smallest possible
element given some ordering relation. Neither does it make sense for
real numbers. Same thing applies to pred.

It may be necessary to move methods in the Numeric class that require
ordering and countability to somewhere else.

You do have a pugs commit bit, don't you?
If you find errors, feel free to correct them in the synopsis.

I do. If anyone doesn't object, I'd be happy to move the methods down to
a subclass (or -role) - at least in the spec (not sure what to do with
the code as of now).

Regards,

Michael.




Re: r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-04 Thread Moritz Lenz
Jon Lang wrote:
> How do pred and succ work when given Complex values?

By adding/substracting 1 from the real part, I'd say. Don't know if that
actually makes sense.

> More generally: if Complex does Numeric, then Numeric doesn't include
> Ordered (or whatever it's called), because Complex doesn't do Ordered.
>  As such, you can't used Numeric for any function that depends on the
> value being Ordered.

Correct, that's what Real is for.

> On Sun, Oct 4, 2009 at 10:15 AM,   wrote:
>> @@ -255,7 +284,7 @@
>>
>>  =item I
>>
>> - Num multi method func ( Num  $x: TrigBase $base = $?TRIGBASE ) is export
>> + Nuermic multi method func ( Nuermic  $x: TrigBase $base = $?TRIGBASE ) is 
>> export
> 
> typos: s[Nuermic] = "Numeric"

You do have a pugs commit bit, don't you?
If you find errors, feel free to correct them in the synopsis.

Cheers,
Moritz


Re: r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-04 Thread Jon Lang
How do pred and succ work when given Complex values?

More generally: if Complex does Numeric, then Numeric doesn't include
Ordered (or whatever it's called), because Complex doesn't do Ordered.
 As such, you can't used Numeric for any function that depends on the
value being Ordered.

On Sun, Oct 4, 2009 at 10:15 AM,   wrote:
> @@ -255,7 +284,7 @@
>
>  =item I
>
> - Num multi method func ( Num  $x: TrigBase $base = $?TRIGBASE ) is export
> + Nuermic multi method func ( Nuermic  $x: TrigBase $base = $?TRIGBASE ) is 
> export

typos: s[Nuermic] = "Numeric"

>  where I is one of:
>  sin, cos, tan, asin, acos, atan, sec, cosec, cotan, asec, acosec,
> @@ -281,14 +310,58 @@
>
>  =item atan2
>
> - our Num multi method atan2 ( Num $y: Num $x = 1 )
> - our Num multi atan2 ( Num $y, Num $x = 1 )
> + our Nuermic multi method atan2 ( Nuermic $y: Nuermic $x = 1 )
> + our Nuermic multi atan2 ( Nuermic $y, Nuermic $x = 1 )

More typos: s[Nuermic] = "Numeric"


-- 
Jonathan "Dataweaver" Lang


r28597 - docs/Perl6/Spec/S32-setting-library

2009-10-04 Thread pugs-commits
Author: moritz
Date: 2009-10-04 19:15:53 +0200 (Sun, 04 Oct 2009)
New Revision: 28597

Modified:
   docs/Perl6/Spec/S32-setting-library/Numeric.pod
Log:
[S32/Numeric] major overhaul

* Most methods that were in Num are now Numeric
* sign() and the rounding methods are now in Real
* document (at least partially) Rat, Num and Int

Modified: docs/Perl6/Spec/S32-setting-library/Numeric.pod
===
--- docs/Perl6/Spec/S32-setting-library/Numeric.pod 2009-10-04 17:15:43 UTC 
(rev 28596)
+++ docs/Perl6/Spec/S32-setting-library/Numeric.pod 2009-10-04 17:15:53 UTC 
(rev 28597)
@@ -28,7 +28,7 @@
 repository under /docs/Perl6/Spec/S32-setting-library/Numeric.pod so edit it 
there in
 the SVN repository if you would like to make changes.
 
-This documents Bit, Int, Num, Rat, Complex, and Bool.
+This documents Bit, Int, Numeric, Rat, Complex, and Bool.
 
 XXX So where are Bit, Int, and Rat
 
@@ -52,13 +52,17 @@
 
 =back
 
-=head2 Num
+=head2 Numeric
 
-The following are all defined in the C role:
+C is a role for everything that's a scalar number. So C, C,
+C, C and other numeric types do that role. However it is an
+abstract interface, so C<$number.WHAT> will never return C. Users who
+provide their own scalar numeric types are encouraged to implement the
+C role.
 
-B: L
+The following are all defined in the C role:
 
-C provides some constants in addition to the basic
+C provides some constants in addition to the basic
 mathematical functions.
 
 constant pi is export = 3.14159_26535_89793_23846_26433_83279_50288;
@@ -68,74 +72,43 @@
 
 =item succ
 
- our Num multi method succ ( Num $x: ) is export
- our Int multi method succ ( Int $x: ) is export
+ our Numeric multi method succ ( Numeric $x: ) is export
+ our Int multi method succ ( Int $x: ) is export
 
 Returns the successor of C<$x>. This method is used by C<< prefix:<++> >> and
 C<< postfix:<++> >> to increment the value in a container.
 
 =item pred
 
- our Num multi method pred ( Num $x: ) is export
- our Int multi method pred ( Int $x: ) is export
+ our Numeric multi method pred ( Numeric $x: ) is export
+ our Int multi method pred ( Int $x: ) is export
 
 Returns the predeccessor of C<$x>. This method is used by C<< prefix:<--> >>
 and C<< postfix:<--> >> to decrement the value in a container.
 
 =item abs
 
- our Num multi method abs ( Num $x: ) is export
+ our Numeric multi method abs ( Numeric $x: ) is export
 
 Absolute Value.
 
-=item floor
-
- our Int multi method floor ( Num $x: ) is export
-
-Returns the highest integer not greater than C<$x>.
-
-=item ceiling
-
- our Int multi method ceiling ( Num $x: ) is export
-
-Returns the lowest integer not less than C<$x>.
-
-=item round
-
- our Int multi method round ( Num $x: ) is export
-
-Returns the nearest integer to C<$x>.  The algorithm is C.
-(Other rounding algorithms will be given extended names beginning with 
"round".)
-
-=item truncate
-
- our Int multi method truncate ( Num $x: ) is export
-
-Returns the closest integer to C<$x> whose absolute value is not greater
-than the absolute value of C<$x>.  (In other words, just chuck any
-fractional part.)  This is the default rounding function used by
-implicit integer conversions.
-
-You may also truncate using explicit integer casts, either C for
-an arbitrarily large integers, or C for native integers.
-
 =item exp
 
- our Num multi method exp ( Num $exponent: Num :$base = Num::e ) is export
+ our Numeric multi method exp ( Numeric $exponent: Numeric :$base = Num::e ) 
is export
 
 Performs similar to C<$base ** $exponent>. C<$base> defaults to the
 constant I.
 
 =item log
 
- our Num multi method log ( Num $x: Num $base = Num::e ) is export
+ our Numeric multi method log ( Numeric $x: Numeric $base = Num::e ) is export
 
 Logarithm of base C<$base>, default Natural. Calling with C<$x == 0> is an
 error.
 
 =item log10
 
- our Num multi method log10 (Num $x:) is export
+ our Numeric multi method log10 (Numeric $x:) is export
 
 A base C<10> logarithm, othewise identical to C.
 
@@ -148,34 +121,9 @@
 unary C function in Perl 6, so just multiply C by your
 desired multiplier.  For picking a random integer you probably want
 to use something like C<(1..6).pick> instead.
-
-=item sign
-
- our Int multi method sign ( Num $x: ) is export
-
-Returns 1 when C<$x> is greater than 0, -1 when it is less than 0, 0 when it
-is equal to 0, or undefined when the value passed is undefined.
-
-=item srand
-
- multi method srand ( Num $seed: )
- multi srand ( Num $seed = default_seed_algorithm())
-
-Seed the generator C uses. C<$seed> defaults to some combination
-of various platform dependent characteristics to yield a non-deterministic 
seed.
-Note that you get one C for free when you start a Perl program, so
-you I call C yourself if you wish to specify a deterministic 
seed
-(or if you wish to be differently nondeterministic).
-
-=item sqrt
-
- our Num multi method sqrt (