sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.4k stars 473 forks source link

extract code from OEIS #29217

Closed fchapoton closed 4 years ago

fchapoton commented 4 years ago

at least try to, and open the possibility to check the code there

CC: @sagetrac-tmonteil @mo271 @videlec @seblabbe @tscrim @kcrisman

Component: combinatorics

Author: Frédéric Chapoton

Branch: c0d93fc

Reviewer: Thierry Monteil, Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/29217

fchapoton commented 4 years ago

Branch: u/chapoton/29217

fchapoton commented 4 years ago

Commit: bf4c299

fchapoton commented 4 years ago

New commits:

bf4c299trying to extract pari,sage,maxima code from OEIS program field
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from bf4c299 to 925309c

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

925309ctypo
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 925309c to 4a52989

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

4a52989better extraction of code from oeis
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 4a52989 to 92a2a9e

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

92a2a9emore care, remove comments in sage code
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

e920166using preparse for sage code from oeis
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 92a2a9e to e920166

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from e920166 to 4d0a6cc

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

4d0a6cctrac 29217 fine tuning oeis parsing
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

b2be1ddMerge branch 'u/chapoton/29217' of ssh://trac.sagemath.org:22/sage into oeis_scan
8053798trac 29217 do not look at dead sequences
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 4d0a6cc to 8053798

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 8053798 to abfa5bf

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

abfa5bfmore testing/validating functions for sage code in oeis
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from abfa5bf to 914c834

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

914c834trying to extract pari,sage,maxima code from OEIS program field
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 914c834 to 29ab760

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

29ab760some fixes in oeis extraction
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

cc5cb4cMerge branch 'u/chapoton/29217' of ssh://trac.sagemath.org:22/sage into oeis
42b92f4little fix
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 29ab760 to 42b92f4

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 42b92f4 to 068961e

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

8f6741bMerge branch 'u/chapoton/29217' of ssh://trac.sagemath.org:22/sage into oeis
068961eallow to keep comments
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

036b27dtrying to extract pari,sage,maxima code from OEIS program field
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 068961e to 036b27d

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

7034faatrying to extract pari,sage,maxima code from OEIS program field
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 036b27d to 7034faa

fchapoton commented 4 years ago
comment:15

ok, this should be ready to go. Un volontaire ?

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

8e851detrying to extract pari,sage,maxima code from OEIS program field
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 7034faa to 8e851de

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 8e851de to f6e4468

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

f6e4468fix detail
edd8e884-f507-429a-b577-5d554626c0fe commented 4 years ago
comment:18

What about improving the existing program method instead of creating a new method ?

I would suggest to offer the possiblilty to type s.program('pari') and get a FancyTuple of the corresponding programs (as it is for maple and mathematica). It is also more friendly for the user than having to parse the tuples in the search for programs in a given language. If no argument is given, i would suggest to return a dictionary "language -> FancyTuple of programs", that is easier to deal with than list of tuples.

Regarding the test_compile_sage_code, you could add a check option to the program method.

edd8e884-f507-429a-b577-5d554626c0fe commented 4 years ago

Reviewer: Thierry Monteil

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

863f9bbintegration of OEIS code extraction into programs method
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from f6e4468 to 863f9bb

fchapoton commented 4 years ago
comment:20

Salut Thierry, merci pour les commentaires.

Voici un nouvel essai. J'ai intégré dans "programs" l'extraction des codes, mais pas la vérification. Comme la vérification ne concerne que le code sage, je pense qu'il vaut mieux la garder à part pour le moment. A la limite, je peux l'enlever si tu veux.

Tout cette extraction est rendu bien pénible par l'état de l'OEIS, et par leur refus de créer un champ par langage, qui serait la seule chose logique à faire.

Mon objectif à long terme serait de vérifier automatiquement tout le code sage dans l'OEIS. On en est encore bien loin, mais j'ai déjà trouvé des problèmes, et poussé fort vers la compatibilité avec Python3.

fchapoton commented 4 years ago

Author: Frédéric Chapoton

kcrisman commented 4 years ago
comment:22

Auto-translate from a non-reliable auto-translator in case it proves useful to some reviewers. I assume "wise" is "sage" which is pretty darned funny. No implication should be inferred that Trac comments need to be in English, by the way! Contributions welcome from A to Z.


Hi Thierry, thanks for the comments.

Here is a new test. I integrated in "programs" the extraction of the codes, but not the verification. As the verification only concerns the wise code, I think it is better to keep it separate for the moment. Ultimately, I can remove it if you want.

All this extraction is made very painful by the state of the OEIS, and by their refusal to create a field by language, which would be the only logical thing to do.

My long term goal would be to automatically check all of the wise code in the OEIS. We are still far from it, but I have already found problems, and pushed hard towards compatibility with Python3.

fchapoton commented 4 years ago
comment:23

Hello ! For good translations, I am using https://www.deepl.com/translator

In French, we have "sage" for the person and "sauge" for the plant.

Any comments on the ticket idea or on the code ?

kcrisman commented 4 years ago
comment:24

Other than saying that it would be a good idea to have a way to automate code extraction in this way (and for people to include lots more Sage code in the OEIS!), no comments.

edd8e884-f507-429a-b577-5d554626c0fe commented 4 years ago
comment:25

Why are you enclosing the FancyTuple into another layer of list for maple and mathematica ? Each entry of the FancyTuple seems to be either a comment or a on-liner program already:

sage: s = oeis(45)
sage: s.programs('maple')
[0: A000045 := proc(n) combinat[fibonacci](n); end;
 1: ZL:=[S, {a = Atom, b = Atom, S = Prod(X,Sequence(Prod(X,b))), X = Sequence(b,card >= 1)}, unlabelled]: seq(combstruct[count](ZL, size=n), n=0..38); # _Zerinvary Lajos_, Apr 04 2008
 2: spec := [B, {B=Sequence(Set(Z, card>1))}, unlabeled ]: seq(combstruct[count](spec, size=n), n=1..39); # _Zerinvary Lajos_, Apr 04 2008
 3: # The following Maple command isFib(n) yields true or false depending on whether n is a Fibonacci number or not.
 4: with(combinat): isFib := proc(n) local a: a := proc(n) local j: for j while fibonacci(j) <= n do fibonacci(j) end do: fibonacci(j-1) end proc: evalb(a(n) = n) end proc: # _Emeric Deutsch_, Nov 11 2014]
sage: s.programs('mathematica')
[0: Table[Fibonacci[k], {k, 0, 50}] (* _Mohammad K. Azarian_, Jul 11 2015 *)
 1: Table[2^n Sqrt @ Product[(Cos[Pi k/(n + 1)]^2 + 1/4), {k, n}] // FullSimplify, {n, 15}]; (* Kasteleyn's formula specialized, Sarah-Marie Belcastro (smbelcas(AT)toroidalsnark.net), Jul 04 2009 *)
 2: LinearRecurrence[{1, 1}, {0, 1}, 40] (* _Harvey P. Dale_, Aug 03 2014 *)
 3: Fibonacci[Range[0, 20]] (* _Eric W. Weisstein_, Sep 22 2017 *)
 4: CoefficientList[Series[-(x/(-1 + x + x^2)), {x, 0, 20}], x] (* _Eric W. Weisstein_, Sep 22 2017 *)]

Also, for other languages, the cutting seems not working:

sage: s.programs('python')
[0: # As b-file:
 1: from gmpy2 import fib
 2: for n in range(100): print(str(n) + " " + str(fib(n)))  # _Bruno Berselli_, Dec 06 2016,
  0: # From _Jaap Spies_, Jan 05 2007:
  1: def fib():
  2:     """ Generates the Fibonacci numbers, starting with 0 """
  3:     x, y = 0, 1
  4:     while 1:
  5:         yield x
  6:         x, y = y, x+y
  7: f = fib()
  8: a = [next(f) for _ in range(100)]
  9: def A000045(n):
 10:     """ Returns Fibonacci number with index n, offset 0 """
 11:     return a[n]
 12: def A000045_list(N):
 13:     """ Returns a list of the first n Fibonacci numbers """
 14:     return a[:N]]
fchapoton commented 4 years ago
comment:26

Replying to @sagetrac-tmonteil:

Why are you enclosing the FancyTuple into another layer of list for maple and mathematica ? Each entry of the FancyTuple seems to be either a comment or a on-liner program already:

I am not able to cut the maple or mathematica code into pieces, as there is nothing in these fields that separate independant programs, that could very well take several consecutive lines. So I have only "one program" for each. And to be consistent with all other languages, I return a list of one single FancyTuple.

Of course, one can give up coherence, make a special treatment and return one single FancyTuple for these specific languages. Would you prefer to have this very specific behaviour for "maple" and "mathematica" parameters ?

Also, for other languages, the cutting seems not working:

I do not understand your second question. Where is the problem ? The output is a list of two FancyTuple, each FancyTuple contains one independant python program. In the example you give, the cutting has been performed correctly, using the information provided in the field, where lines starting by (langname) mark the start of a new program block.

fchapoton commented 4 years ago
comment:27

Thierry ? Je peux changer le traitement des champs Maple et Mathematica, si tu préfères.

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 863f9bb to a3b9dd8

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

4464040Merge branch 'u/chapoton/29217' of ssh://trac.sagemath.org:22/sage into 9.1.rc0
a3b9dd8details about block separation
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

b3cc4c4fix detail in oeis program extraction
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from a3b9dd8 to b3cc4c4