3
$\begingroup$

I want to name a bunch of tables after the OEIS entries which describe them.

Is there any way to use these names for both the table name and the link at the same time?

The second line uses the entry number as a variable: could I use the hyperlink in its place? This would allow clicking the link to reference the documentation from any place the file is referenced.

lcm[n_] := Module[{a = 1}, For[b = n, b > 1, b--, a = LCM[a, b]]; a]
A002944 = Table[lcm[n]/n, {n, 1, 15}]
Hyperlink["A002944", "http://oeis.org/A002944"]
Hyperlink[A002944[[1 ;; 6]], "http://oeis.org/A002944"]  

Edit The last line displays the first few characters of the sequence, so I can click it to see more.

$\endgroup$
  • $\begingroup$ I'd be interested in a solution too. I'm guessing it will need the front end to intercept any variable of the form A+[6 digits] and display it as a Hyperlink. $\endgroup$ – PlaysDice May 19 '14 at 0:00
  • $\begingroup$ Slightly related: could anyone locate the file EISFormat.m or confirm that it has become completely obsolete? OEIS still links to it but the link is dead: oeis.org/wiki/Wolfram_Mathematica#EISFormat.m $\endgroup$ – akater May 19 '14 at 1:07
  • 1
    $\begingroup$ @Akater, try oeis.org/wiki/User:Enrique_P%C3%A9rez_Herrero/… $\endgroup$ – Fred Kline May 19 '14 at 1:31
2
$\begingroup$

Its possible $PrePrint works for this - it changes the way Output is displayed, but does not change its underlying form. (Regex experts may be able to build a leaner approach for "A" followed by 6 digits).

$PrePrint= If[Length@StringCases[ToString@#, 
"A"~~DigitCharacter~~DigitCharacter~~DigitCharacter~~DigitCharacter~~DigitCharacter~~
DigitCharacter] > 0, Hyperlink[ToString@#, StringJoin["http://oeis.org/", ToString@#]],  #] &;

Sample:
In[] = A123456

(*output*)
Out[]= A123456 (a hyperlink to http://oeis.org/A123456)

And to remove the $PrePrint effect,

$PrePrint=.

per the documentation

ADDING COMPLEXITY / SIMPLICITY

In this approach, each number series is placed in a list of Rules

Clear[A123456, A000027, rules]
tempA123456 = Table[lcm[n]/n, {n, 1, 15}];
tempIncr = Range[25];
rules = {A123456 -> tempA123456, A000027 -> tempIncr};
A123456 /. rules
A000027 /. rules
A000027
A123456

Each series can be recovered using [name] and Replace /. so

A000027/.rules 

recovers the full series we generated

{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25}

If you run the revised $PrePrint (uses StringCount to find instances)

   $PrePrint=If[StringCount[ToString@#,"A"~~DigitCharacter~~DigitCharacter~~  DigitCharacter~~DigitCharacter~~DigitCharacter~~DigitCharacter]>0,Hyperlink[StringTake[ToString@#,7]<>StringSplit[ToString@(#/.rules)][[1;;6]]<>"..}",StringJoin["http://oeis.org/",StringTake[ToString@#,7]]],#]&;

it replaces the given name of an integer sequence with a hyperlink (to oeis.org/) that contains the name and an extract of the series (set to show the first 6 entries) e.g.

A000027{1,2,3,4,5,6..}    (*is a hyperlink to the OEIS page*)
$\endgroup$
  • $\begingroup$ Assignment (=) doesn't work. This does work A003814 == Table[n, {n, 1, 10}] except the hyperlink keeps the entire string so doesn't find anything. So the StringJoin should truncate at 7 characters. $\endgroup$ – Fred Kline Jun 16 '14 at 17:02
  • $\begingroup$ So something like StringTake[<stuff here> ,7] (taking first 7 characters) would fit your need? $\endgroup$ – PlaysDice Jun 16 '14 at 18:53
  • $\begingroup$ I tried it and it's getting closer. It finds the OEIS page. I'm still playing with it. $\endgroup$ – Fred Kline Jun 16 '14 at 19:37
  • $\begingroup$ A003814 == (j = Table[n, {n, 1, 10}]) works! $\endgroup$ – Fred Kline Jun 16 '14 at 19:42
2
$\begingroup$

My approach would be to keep the presentation and content separate by using a wrapper function oeis that acts as if it weren't there, except when it's displayed:

ClearAll[oeis, A002944];
Attributes[oeis] = {HoldFirst};
oeis /: MakeBoxes[oeis[aa_], __] := 
 ToBoxes[Hyperlink[Short[aa], 
   "http://oeis.org/" <> ToString[HoldForm[aa]]]]
oeis /: f_[x___, oeis[aa_], y___] := f[x, aa, y]

With these definitions, we can do variable assignments as follows:

lcm[n_] := Module[{a = 1}, For[b = n, b > 1, b--, a = LCM[a, b]]; a]

oeis[A002944] = Table[lcm[n]/n, {n, 1, 15}]

(*
==> {1, 1, 2, 3, 12, 10, 60, 105, 280, 252, 2520, 2310, 27720, \
25740, 24024}
*)

Now let's see how this displays when we recall this symbol:

oeis[A002944]

link

This is a hyperlink to the desired web page. Here, I used Short which by default displays some of the first and last elements (it's just closer to the usual Mathematica style; you can adjust this if you don't like it).

However, if I want to do any kind of further calculation or processing with this definition, it's no problem:

oeis[A002944][[4]]

(* ==> 3 *)

Total[oeis[A002944]]

(* ==> 83040 *)

This works because of the last line in the first code block, which removes the wrapper when the oeis[A002944] appears inside any other function, other than the display step, MakeBoxes.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.