-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposed OEIS adapter for searching integer sequences #187
Comments
It seems to be a very interesting and useful adapter. |
I think it would be a very useful feature. We could make it accessible two ways:
In both cases it would very helpful + the output could be automatically syntactically highlighted |
Thank you for the pull-request; it was merged; now I have to bind the script to cheat.sh |
Syntax highlighting
Language selection
Cleaner output
1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, 1, 5, 10, 10, 5, 1 """
Pascal's triangle read by rows: C(n,k) = binomial(n,k) = n!/(k!*(n-k)!), 0 <= k <= n.
1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, 1, 5, 10, 10, 5, 1 ...
""" Adding a formula
Example
"""
Pascal's triangle read by rows: C(n,k) = binomial(n,k) = n!/(k!*(n-k)!), 0 <= k <= n.
1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, 1, 5, 10, 10, 5, 1 ...
a(n, k) = C(n,k) = binomial(n, k).
C(n, k) = C(n-1, k) + C(n-1, k-1).
The triangle is symmetric: C(n,k) = C(n,n-k).
a(n+1, m) = a(n, m) + a(n, m-1), a(n, -1) := 0, a(n, m) := 0, n<m; a(0, 0)=1.
C(n, k)=n!/(k!(n-k)!) if 0<=k<=n, otherwise 0.
G.f.: 1/(1-y-x*y) = Sum(C(n, k)*x^k*y^n, n, k>=0)
G.f.: 1/(1-x-y) = Sum(C(n+k, k)*x^k*y^n, n, k>=0).
G.f. for row n: (1+x)^n = Sum_{k=0..n} C(n, k)x^k.
G.f. for column n: x^n/(1-x)^n.
E.g.f.: A(x, y) = exp(x+x*y).
E.g.f. for column n: x^n*exp(x)/n!.
"""
# See Hobson link. Further programs:
def C(n, k):
if k < 0 or k > n:
return 0
res = 1
for i in range(k):
res *= (n - i) // (i + 1)
return res
# Robert FERREOL, Mar 31 2018
def C(n, k): from numpy import prod; return prod([(n-j)/(j+1) for j in range(k)])
def C(n, k): from functools import reduce; return reduce(lambda x, y: x*(n-y)//(1+y), range(k), 1) # Some characters longer, but using only integers.
# M. F. Hasler, Dec 13 2019 TODO
|
|
We have special option,
vs
Maybe we should use the same semantics here?
Yes Again, we have an option for that: Compare
vs
I think that it is enough, no additional formatting for this particular adapter is needed. |
I am having a problem with cmd.py. Not all of the arguments are getting to the oeis.sh script or are not getting there properly. Could you provide me with a conceptual data-flow that links events and files together? I am a bit lost. Something like:
|
QuestionsI've tried to play with it a little bit, and see that some queries do not work: Let us try from the beginning, and define the query format first. What queries do we want to support:
Correct? Currently none on them work.
I think that these problems are pretty trivial, and we will easily fix them, Answers
Yes, it is correct. Some additional details:
If we specify |
@ErezBinyamin Thank you for the pull request (#209). It seems to work much better now, I've played a little bit with it, and it seems to work pretty good.
|
Great feedback. I'm on it. Todo
I have not found a way to specify that a sequence must start with the numbers given (I could just implement that myself though). However, there are some interesting syntax tricks that we could implement like:
These syntax tricks seem to directly correspond to the OEIS output section names. The way they work seems to be that the argument to trick
|
|
I am experimenting with it; some queries seem to fail:
|
It is better now:
but it must be:
|
I've activated comments and syntax highlighting (see the commit above), |
Commenting and syntax highlighting works:
Please test. Could you please fix a couple of minor things:
|
In #213
|
I have just made a realization and will be doing a full re-write of This is the realization: I have been parsing HTML instead of simply reading text. No functional changes will be made, but I am sure this will speed up search times. |
I've merged and deployed it, please test (regarding html/txt: I think it will not speed up parsing much, but it does not matter; text is of course better to use because this solution will be guaranteed more robust) |
It is much better now. I am not a fan of the C-style block comment though, it seems a bit messy. The asterisks going down the page distract from the content a bit. I am not sure where that is implemented, but perhaps a single TODO: |
Why have you mentioned C-style? I think that we need support for several new programming
For example, from these languages only mathematica, python and haskell are supported. Another problem: Some code is not correctly extracted by the script:
And it must be:
I don't know if you are aware of this feature,
By the way, is it possible to cut automatically the contributor name,
|
I added
I understand why you asked about C formatting, |
Bibliography sectionID: A000009
Expansion of Product_{m >= 1} (1 + x^m); number of partitions of n into distinct parts; number of partitions of n into odd parts.
1, 1, 1, 2, 2, 3, 4, 5, 6, 8, 10, 12, 15, 18, 22, 27, 32, 38, 46, 54, 64, 76, 89, 104, 122, 142, 165, 192, 222, 256 ...
PartitionsQ[Range[0, 60]] (* [1] *)
a[ n_] := SeriesCoefficient[ Product[ 1 + x^k, {k, n}], {x, 0, n}]; (* [2] *)
a[ n_] := SeriesCoefficient[ 1 / Product[ 1 - x^k, {k, 1, n, 2}], {x, 0, n}]; (* [2] *)
a[ n_] := With[ {t = Log[q] / (2 Pi I)}, SeriesCoefficient[ q^(-1/24) DedekindEta[2 t] / DedekindEta[ t], {q, 0, n}]]; (* [2] *)
a[ n_] := SeriesCoefficient[ 1 / QPochhammer[ x, x^2], {x, 0, n}]; (* [2] *)
a[ n_] := SeriesCoefficient[ Series[ QHypergeometricPFQ[ {q}, {q x}, q, - q x], {q, 0, n}] /. x -> 1, {q, 0, n}]; (* [2] *)
a[ n_] := SeriesCoefficient[ QHypergeometricPFQ[{}, {}, q, -1] / 2, {q, 0, n}]; (* [2] *)
nmax = 60; CoefficientList[Series[Exp[Sum[(-1)^(k+1)/k*x^k/(1-x^k), {k, 1, nmax}]], {x, 0, nmax}], x] (* [3] *)
nmax = 100; poly = ConstantArray[0, nmax + 1]; poly[[1]] = 1; poly[[2]] = 1; Do[Do[poly[[j + 1]] += poly[[j - k + 1]], {j, nmax, k, -1}];, {k, 2, nmax}]; poly (* [3] *)
[1] [Harvey Dale]
[2] [Michael Somos]
[3] [Vaclav Kotesovec]
[https://oeis.org/search?q=id:A000009] List of all known OEIS code snippet languages
|
TODO
|
I've merged and deployed it; it looks much better now: $ curl cht.sh/oeis/29069/mathematica
(*
* ID: A029069
* Expansion of 1/((1-x)*(1-x^4)*(1-x^5)*(1-x^12)).
*
* 1, 1, 1, 1, 2, 3, 3, 3, 4, 5, 6, 6, 8, 9, 10, 11, 13, 15, 16, 17, 20,
* 22, 24, 25, 29, 32, 34, 36, 40, 44 ...
*)
CoefficientList[Series[1/((1-x)(1-x^4)(1-x^5)(1-x^12)),{x,0,60}],x] (* [1] *)
(*
* [1] [Harvey P\. Dale, Aug 11 2011]
* [https://oeis.org/search?q=id:A029069]
*) Just a minor thing to be fixed: Sequence search ls commented like C, and highlighted like shell. We could make an exception for OEIS though, because |
We can specify arguments either inline I tend to the first option.
If we simulate grep semantics, it should be "contain" instead of start,
I think 10 is ok, but we need to support an additional parameter for longer output ( |
I did some experiments. The current functionality is like grep in the sequence results simply "contain" the sequence provided. Example1 Example2 Example3 Some of those examples the sub-sequence numbers do not even appear in the result, which gives rise to a new question:
TODO
|
Erez hi! I am back to my opensource projects; sorry for the long disappearance. |
I'm also a bit tied up atm. Will definitely try to finish up those last improvements. The OEIS adapter is certainly almost there. I'm working out how to implement the same search UI on the OEIS website |
What do you mean? What search UI do you mean? |
I mean giving cheat.sh users access to the same search parameters supported by OEIS. |
Need to finish python port #376 I expect a prototype by the end of this week |
Todo
curl cheat.sh/oeis/$RANDOM/mathematica
continually ended up with misplaced error messages (seemingly fromgrep
)Adapter:
cheat.sheets:
Details
The On-Line Encyclopedia of Integer Sequences is a great resource for programmers. It'd be cool to browse sequences from the command line and potentially get code samples to copy and paste. I have a working prototype of the script here. Currently it can either take one argument or many. If many are supplied, a list of potential sequence matches is returned, of one argument is supplied, then the sequence with that ID and a colorized code segment are returned.
Example usage finding a sequence by pattern
Example usage looking up a particular sequence by ID
The text was updated successfully, but these errors were encountered: