Re: [sage-devel] Sage code for educational purposes only?

2015-03-02 Thread Thierry
Hi,

On Wed, Feb 25, 2015 at 06:55:11PM +0100, Jeroen Demeyer wrote:
 Hello,
 
 Should there be code in Sage which is extremely slow and for
 educational purposes only? I am talking about eratosthenes() which
 is just a very slow alternative to prime_range().
 
 I would just remove that code, but maybe people have other opinions...

An issue is that names of functions/methods are usually about /what/ is
being done, not /how/, hence i am in favor to deprecate eratosthenes()
function and move the code as an 'algorithm' option of prime_range(). It
should be noticed that the other algorithms depend on pari, hence having
at least one self-contained implementation could be of some help, e.g.
for consistency testing (and hypothetically for far-future
modularization).

Recording such self-contained implementations is not only interesting for
educational purpose (this is sometimes frustrating to do function?? and
only see some calls to an external lib whose source code is not easily
available from Sage), but also in a context such as
http://wiki.sagemath.org/GSoC/2015#Generic_Dispatcher

I remember a discussion with Luca at Orsay during preparation of H2020
stuff, about using Sage as a research tool, where being able to tell Sage
i want to rely only on such libs makes sense. So, having a way to record
which lib is called in a dispatcher (in particular when no lib is
required) is pretty interesting, in particular about reproductibility
concerns.

Further (and less directly related), i would have proposed to move most
*_prime or prime_* functions from the global namespace to methods of the
Primes() class (e.g. primes_first_n() vs Primes().__getitem__() or
is_prime() vs Primes().__contains__() and so on). This is indeed easier to
find primes-related methods, for example, how can i discover the existence
of the next_prime() function from the tab completion ?

Ciao,
Thierry



 Jeroen.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sage-devel group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to sage-devel+unsubscr...@googlegroups.com.
 To post to this group, send email to sage-devel@googlegroups.com.
 Visit this group at http://groups.google.com/group/sage-devel.
 For more options, visit https://groups.google.com/d/optout.
 
 

-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Sage code for educational purposes only?

2015-02-27 Thread Nathann Cohen


 It is certainly not designed for production work, yet you import things 
 like `LPProblem` in the global namespace ? I will write a patch right now 
 that adds interactive in front of all these classes.


See http://trac.sagemath.org/ticket/17867 (needs_review)

Nathann 

-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Sage code for educational purposes only?

2015-02-27 Thread Nathann Cohen


 Um, can it be perhaps slightly less diminishing? Like education.[tab] or 
 edu.[tab]?

 E.g. I wrote

 http://sagemath.org/doc/reference/numerical/sage/numerical/interactive_simplex_method.html
 which is certainly not designed for production work, but it was quite a 
 bit of work on its own ;-)


It is certainly not designed for production work, yet you import things 
like `LPProblem` in the global namespace ? I will write a patch right now 
that adds interactive in front of all these classes.

Nathann

-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Sage code for educational purposes only?

2015-02-26 Thread Niles Johnson
I'm in favor of moving such toys to an educational-library.

-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Sage code for educational purposes only?

2015-02-26 Thread Vincent Delecroix
I really do not see the point of an educational-library if the code
will not appear in the documentation. It is precisely the code which
is interesting!

Vincent

-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Sage code for educational purposes only?

2015-02-26 Thread Jori Mantysalo

On Thu, 26 Feb 2015, Pedro Cruz wrote:


+1 for the  package educational-algorithms but called
educational-packages or educational-library.


Yes, '-packages' or '-library' is better name.

Hmmm... actually there could be, in principle, three kind of algorithms:

1) Fast ones, that we normally use.

2) Educational, algorithms that made it easy to see some computational 
proof etc.


3) Most basic and directly from formal definition made algorithms to 
cross-check fast ones.


Usually type 2 and 3 are same thing. Always?


--
Jori Mäntysalo


Re: [sage-devel] Sage code for educational purposes only?

2015-02-26 Thread Pedro Cruz

+1 for the  package educational-algorithms but called 
educational-packages or educational-library.

MathSciNet catalog has the category Mathematics education

http://www.ams.org/mathscinet/msc/msc2010.html?t=97-XX

being the last topic after all the mathematical edge cutting works.

This could inspire an educational-library (this name is maybe more 
general than just algorithms).

Pedro

 


On Thursday, February 26, 2015 at 6:23:36 AM UTC, Jori Mantysalo wrote:

 On Wed, 25 Feb 2015, Jeroen Demeyer wrote: 

  Should there be code in Sage which is extremely slow and for educational 
  purposes only? 

 As an additional package educational-algorithms? 

 -- 
 Jori Mäntysalo 


-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Sage code for educational purposes only?

2015-02-26 Thread parisse


Le mercredi 25 février 2015 20:56:06 UTC+1, kcrisman a écrit :

 Who on earth thinks that the Sieve of Eratosthenes is designed for modern 
 production work??? 


Me. I´m using it for the ithprime function in Giac. ithprime(70) 
returns 10570841 in 0.07 second while in sage prime_range(1,10570841) takes 
about the same time (0.08s) to compute (much more to display).

-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Sage code for educational purposes only?

2015-02-25 Thread Jeroen Demeyer

Hello,

Should there be code in Sage which is extremely slow and for educational 
purposes only? I am talking about eratosthenes() which is just a very 
slow alternative to prime_range().


I would just remove that code, but maybe people have other opinions...

Jeroen.

--
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Sage code for educational purposes only?

2015-02-25 Thread Michael Orlitzky
On 02/25/2015 02:10 PM, William Stein wrote:
 
 toys.eratosthenes()
 
 or possibly eratosthenes_toy()...
 

In this case, the name refers to the implementation, not the
functionality, so I don't think it's a big deal. It's not a prime
number routine that just happens to be slow -- it's the sieve of
Eratosthenes, running as fast as it can. Any other implementation will
be just as slow.

-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Sage code for educational purposes only?

2015-02-25 Thread Vincent Delecroix
I also feel like we should remove it from the source code. The purpose
of eratosthene is very different from what Andrey pointed out with his
module about the simplex method. The function eratosthene is just an
illustration of how you code a nice Python function. While the
simplex module is more of exploration and experimentation of an
algorithm. For eratosthene you need to read the code while for the
simplex module you just experiment the functionalities of the object.

So I propose to move eratosthene from the source to the documentation
(where is another question). And, as William pointed out, it would
be a good example to illustrate the power of Cython. And I definitely
think that Andrey simplex stuff has its place inside the source.

Vincent

-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Sage code for educational purposes only?

2015-02-25 Thread David Joyner
On Wed, Feb 25, 2015 at 2:10 PM, William Stein wst...@gmail.com wrote:
 On Wed, Feb 25, 2015 at 10:15 AM, Michael Orlitzky mich...@orlitzky.com 
 wrote:

...


 I think it's best to name any functionality that is is extremely slow
 and for educational
 purposes explicitly with toy somewhere in the name. If you do:

sage: search_src(toy)

 you'll see this convention often in sage.

 I would be for deprecating eratosthenes() and replacing it by something like


 toys.eratosthenes()

 or possibly eratosthenes_toy()...

 I like the idea of a toys.[tab] that gathers together toy implementations...


+1



...


 --
 You received this message because you are subscribed to the Google Groups 
 sage-devel group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to sage-devel+unsubscr...@googlegroups.com.
 To post to this group, send email to sage-devel@googlegroups.com.
 Visit this group at http://groups.google.com/group/sage-devel.
 For more options, visit https://groups.google.com/d/optout.



 --
 William (http://wstein.org)

 --
 You received this message because you are subscribed to the Google Groups 
 sage-devel group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to sage-devel+unsubscr...@googlegroups.com.
 To post to this group, send email to sage-devel@googlegroups.com.
 Visit this group at http://groups.google.com/group/sage-devel.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Sage code for educational purposes only?

2015-02-25 Thread Andrey Novoseltsev
Um, can it be perhaps slightly less diminishing? Like education.[tab] or 
edu.[tab]?

E.g. I wrote
http://sagemath.org/doc/reference/numerical/sage/numerical/interactive_simplex_method.html
which is certainly not designed for production work, but it was quite a bit 
of work on its own ;-)

I am also not a fan of prefixing/suffixing all names with something or 
grouping it into a special folder - toy number theory should still go into 
number theory tree and included into its documentation, just perhaps 
exported through a dedicated module somewhere.

Andrey

On Wednesday, 25 February 2015 12:24:41 UTC-7, David Joyner wrote:

 On Wed, Feb 25, 2015 at 2:10 PM, William Stein wst...@gmail.com 
 javascript: wrote: 
  On Wed, Feb 25, 2015 at 10:15 AM, Michael Orlitzky mic...@orlitzky.com 
 javascript: wrote: 

 ... 

  
  I think it's best to name any functionality that is is extremely slow 
  and for educational 
  purposes explicitly with toy somewhere in the name. If you do: 
  
 sage: search_src(toy) 
  
  you'll see this convention often in sage. 
  
  I would be for deprecating eratosthenes() and replacing it by something 
 like 
  
  
  toys.eratosthenes() 
  
  or possibly eratosthenes_toy()... 
  
  I like the idea of a toys.[tab] that gathers together toy 
 implementations... 
  

 +1 

  

 ... 

  
  -- 
  You received this message because you are subscribed to the Google 
 Groups sage-devel group. 
  To unsubscribe from this group and stop receiving emails from it, send 
 an email to sage-devel+...@googlegroups.com javascript:. 
  To post to this group, send email to sage-...@googlegroups.com 
 javascript:. 
  Visit this group at http://groups.google.com/group/sage-devel. 
  For more options, visit https://groups.google.com/d/optout. 
  
  
  
  -- 
  William (http://wstein.org) 
  
  -- 
  You received this message because you are subscribed to the Google 
 Groups sage-devel group. 
  To unsubscribe from this group and stop receiving emails from it, send 
 an email to sage-devel+...@googlegroups.com javascript:. 
  To post to this group, send email to sage-...@googlegroups.com 
 javascript:. 
  Visit this group at http://groups.google.com/group/sage-devel. 
  For more options, visit https://groups.google.com/d/optout. 


-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Sage code for educational purposes only?

2015-02-25 Thread kcrisman


 Um, can it be perhaps slightly less diminishing? Like education.[tab] or 
 edu.[tab]?


We have a number of crypto examples of toy things, and David J. long ago 
wrote quite a few things like Euler's method and so forth.  It is very, 
very worthwhile (if for no other reason than to have opportunities for 
people to understand how to code math!).
 
 

 I am also not a fan of prefixing/suffixing all names with something or 
 grouping it into a special folder - toy number theory should still go into 
 number theory tree and included into its documentation, just perhaps 
 exported through a dedicated module somewhere.


I don't think we need toy.[tab] or number_theory.toy.[tab] or anything. 
 Who on earth thinks that the Sieve of Eratosthenes is designed for modern 
production work???  Or Euler's Method (well, I'm not a numerical analyst, 
so maybe, but I assume other integration is more prominent).  In some cases 
of course this is useful to prefix, and we 
have 
http://www.sagemath.org/doc/reference/polynomial_rings/sage/rings/polynomial/toy_buchberger.html
 
and things like that for such cases.

If the documentation of any given method says it's for educational purposes 
only - and there are a number of those - then that seems fine to me.

- kcrisman

-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Sage code for educational purposes only?

2015-02-25 Thread William Stein
On Wed, Feb 25, 2015 at 11:57 AM, Michael Orlitzky mich...@orlitzky.com wrote:
 On 02/25/2015 02:10 PM, William Stein wrote:

 toys.eratosthenes()

 or possibly eratosthenes_toy()...


 In this case, the name refers to the implementation, not the
 functionality, so I don't think it's a big deal. It's not a prime
 number routine that just happens to be slow -- it's the sieve of
 Eratosthenes, running as fast as it can.

 Any other implementation will be just as slow.

I'm not sure I agree.  This eratosthenes function is pure Python code.
  It would probably be 100 times faster if rewritten in Cython using
int's or long's.  In fact, this is (more or less) the canonical first
example of a function that benefits directly from being compiled
rather than pure Python -- it's the first example on the Pyrex page:

http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/

That you would think it's the sieve of Eratosthenes, running as fast
as it can.   Any other implementation will be just as slow is in fact
to me a very strong argument for why it *should* have toy in the name.
Since if it did, it's highly unlikely you would think it is running
as fast as it can.

William


-- 
William (http://wstein.org)

-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Sage code for educational purposes only?

2015-02-25 Thread William Stein
On Wed, Feb 25, 2015 at 10:15 AM, Michael Orlitzky mich...@orlitzky.com wrote:
 On 02/25/2015 12:55 PM, Jeroen Demeyer wrote:
 Hello,

 Should there be code in Sage which is extremely slow and for educational
 purposes only? I am talking about eratosthenes() which is just a very
 slow alternative to prime_range().

 I would just remove that code, but maybe people have other opinions...

I also agree it is OK to have such *code*.  However, to have it just
there without a name that strongly emphasizes its toy nature is very
bad.  People often think that if f is a function defined in a
respectable math software system (Magma or Sage), then the performance
of f(n) is at least reasonable.

I think it's best to name any functionality that is is extremely slow
and for educational
purposes explicitly with toy somewhere in the name. If you do:

   sage: search_src(toy)

you'll see this convention often in sage.

I would be for deprecating eratosthenes() and replacing it by something like


toys.eratosthenes()

or possibly eratosthenes_toy()...

I like the idea of a toys.[tab] that gathers together toy implementations...


 It's nice to leave in code like this and use it as part of the test
 suite. It would be easy to check that the sieve of Eratosthenes is
 correct, but prime_range() is a long chain of dark magic to me.

 A good test would be that they agree on the primes below (say) 1,000:

   sage: eratosthenes(1000) == prime_range(1000)
   True

 There are some tests for prime_range() already, e.g.

   sage: L = prime_range(25000,250)
   sage: len(L)
   180310

 but who knows if the results are correct.

 --
 You received this message because you are subscribed to the Google Groups 
 sage-devel group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to sage-devel+unsubscr...@googlegroups.com.
 To post to this group, send email to sage-devel@googlegroups.com.
 Visit this group at http://groups.google.com/group/sage-devel.
 For more options, visit https://groups.google.com/d/optout.



-- 
William (http://wstein.org)

-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Sage code for educational purposes only?

2015-02-25 Thread Michael Orlitzky
On 02/25/2015 12:55 PM, Jeroen Demeyer wrote:
 Hello,
 
 Should there be code in Sage which is extremely slow and for educational 
 purposes only? I am talking about eratosthenes() which is just a very 
 slow alternative to prime_range().
 
 I would just remove that code, but maybe people have other opinions...
 

It's nice to leave in code like this and use it as part of the test
suite. It would be easy to check that the sieve of Eratosthenes is
correct, but prime_range() is a long chain of dark magic to me.

A good test would be that they agree on the primes below (say) 1,000:

  sage: eratosthenes(1000) == prime_range(1000)
  True

There are some tests for prime_range() already, e.g.

  sage: L = prime_range(25000,250)
  sage: len(L)
  180310

but who knows if the results are correct.

-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Sage code for educational purposes only?

2015-02-25 Thread Michael Orlitzky
On 02/25/2015 03:04 PM, William Stein wrote:
 
 Any other implementation will be just as slow.
 
 I'm not sure I agree.  This eratosthenes function is pure Python code.
   It would probably be 100 times faster if rewritten in Cython using
 int's or long's.  In fact, this is (more or less) the canonical first
 example of a function that benefits directly from being compiled
 rather than pure Python -- it's the first example on the Pyrex page:
 
 http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
 
 That you would think it's the sieve of Eratosthenes, running as fast
 as it can.   Any other implementation will be just as slow is in fact
 to me a very strong argument for why it *should* have toy in the name.
 Since if it did, it's highly unlikely you would think it is running
 as fast as it can.
 

Surely we aren't going to start naming things toy just because they're
written in Python?

I tested in Cython and was going to post numbers, but looking back, you
only suggested it would be 100 times faster. The speedup is actually
better than that (looks sublinear) -- I just don't consider a factor of
100 on a silly algorithm to be a big difference. You still hit a running
time of (1/100)*forever pretty quickly.

-- 
You received this message because you are subscribed to the Google Groups 
sage-devel group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Sage code for educational purposes only?

2015-02-25 Thread Jori Mantysalo

On Wed, 25 Feb 2015, Jeroen Demeyer wrote:

Should there be code in Sage which is extremely slow and for educational 
purposes only?


As an additional package educational-algorithms?

--
Jori Mäntysalo