Closed fchapoton closed 4 years ago
Branch: u/chapoton/29217
New commits:
bf4c299 | trying to extract pari,sage,maxima code from OEIS program field |
Branch pushed to git repo; I updated commit sha1. New commits:
925309c | typo |
Branch pushed to git repo; I updated commit sha1. New commits:
4a52989 | better extraction of code from oeis |
Branch pushed to git repo; I updated commit sha1. New commits:
92a2a9e | more care, remove comments in sage code |
Branch pushed to git repo; I updated commit sha1. New commits:
e920166 | using preparse for sage code from oeis |
Branch pushed to git repo; I updated commit sha1. New commits:
4d0a6cc | trac 29217 fine tuning oeis parsing |
Branch pushed to git repo; I updated commit sha1. New commits:
abfa5bf | more testing/validating functions for sage code in oeis |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
914c834 | trying to extract pari,sage,maxima code from OEIS program field |
Branch pushed to git repo; I updated commit sha1. New commits:
29ab760 | some fixes in oeis extraction |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
036b27d | trying to extract pari,sage,maxima code from OEIS program field |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
7034faa | trying to extract pari,sage,maxima code from OEIS program field |
ok, this should be ready to go. Un volontaire ?
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
8e851de | trying to extract pari,sage,maxima code from OEIS program field |
Branch pushed to git repo; I updated commit sha1. New commits:
f6e4468 | fix detail |
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.
Reviewer: Thierry Monteil
Branch pushed to git repo; I updated commit sha1. New commits:
863f9bb | integration of OEIS code extraction into programs method |
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.
Author: Frédéric Chapoton
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.
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 ?
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.
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]]
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.
Thierry ? Je peux changer le traitement des champs Maple et Mathematica, si tu préfères.
Branch pushed to git repo; I updated commit sha1. New commits:
b3cc4c4 | fix detail in oeis program extraction |
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