2
$\begingroup$

The classic string "Hello world!" can be translated to list of characters with ascii-codes:

[72; 101; 108; 108; 111; 32; 87; 111; 114; 108; 100; 33]

Is there a mathematical function to generate this sequence of numbers (without explicitly enumerating them)?

  • 6
    Why would this be more convenient than having the string itself? Anyway, for the letters, you have (alphabet position)+64 for capital letters and (alphabet position)+96 for small letters...2011-04-29
  • 0
    @Tuomas, You should say what exactly you mean by "mathematical function"2011-04-29
  • 5
    You can use say Lagrange interpolation but why?2011-04-29
  • 3
    There is a function, simply take a function such that $f(1)=72$ and $f(2)=101$ and so on to $f(12)=33$. Then take any continuous function which passes through all these points, and if you really want to be cool you can take a polynomial (or Fourier) approximation of the function and round as needed. This is not very constructive though, and you're probably not looking for this answer. No point in posting it as an answer then.2011-04-29
  • 0
    @Asaf: there is a point in posting it as an answer. Then I could upvote it and the question wouldn't come back.2011-04-29
  • 0
    If I were in Asaf's shoes, I'd feel dirty posting that answer (even if I set it CW)... :D2011-04-29
  • 2
    @Ross: As J.M. says - it felt dirty so I copied that answer into a comment. You have lhf's answer to upvote... ;-)2011-04-29
  • 3
    @lhf, @J.M.: There's a sort of sport of creating programs that print out "Hello World!" in original ways -- I suspect the OP was interested in finding a mathematical function that produces the character codes for this purpose, not to do anything more efficiently or conveniently, more like the opposite.2011-04-29
  • 1
    @joriki: You're right. See for instance http://stackoverflow.com/questions/284797/hello-world-in-less-than-20-bytes/ .2011-04-29
  • 1
    @Raeder: Polynomial interpolation (or any interpolation method, really) most certainly won't get you a 20-byte program... :)2011-04-29
  • 1
    I have voted to close as Not a Real Question. There are multiple functions, and I am not sure the answers here will help OP.2011-04-29
  • 4
    Can't see why this was closed, perfectly valid question - as jokiri states, it is a type of sport. Bringing a mathematical dimension to it is all to the good and should not be shunned.2011-04-29
  • 1
    Math is supposed to be used for simplifying the world, not complicating it...2011-04-29
  • 0
    @Orbling: This question is overly broad. If OP is willing to help narrow it down... then it can be reopened.2011-04-29
  • 0
    @J.M.: I consider mathematics as the base language, from which everything else is derived. As such it is capable of simplification and adding complexity, it need not be restricted.2011-04-30

2 Answers 2

4

Yes, see below but you probably do not want this. It is certainly less compact than the original list of values because you have to store more than twice the amount of data, if you want exact rational coefficients. Moreover, if you're writing a program, beware that 19531322383 does not fit in 32 bits.

enter image description here

http://www.wolframalpha.com/input/?i=interpolate+72+101+108+108+111+32+87+111+114+108+100+33

  • 1
    To reiterate my earlier comment for the OP: why would storing these weird coefficients be any more convenient than storing the string proper?2011-04-29
  • 0
    The graph drawn by following the link shows that the function is not particularly enlightening: between $1$ and $2$ it falls to a value of almost $-600$; for $f(13)$ the value is even more negative.2011-04-29
  • 1
    @Henry, did you expect otherwise? Polynomial interpolation does oscillate between data values. See http://en.wikipedia.org/wiki/Runge's_phenomenon2011-04-29
  • 0
    @lhf: It is largely what I expected and I was trying to add to your already good answer. You might consider adding the picture.2011-04-29
  • 1
    And in line with Henry's comments, this polynomial is even more of a disaster to evaluate (even when you use Horner) when the coefficients are turned into floating-point numbers...2011-04-29
  • 0
    If only the occurence of numbers is of interest, then we could regroup that into complex numbers: $$[72.101 + 108.108 i, 111.32 + 87.111 i, 114.108 + 100.33 i]$$ and polinterpolate to get a quadratic polynomial: $$f(x)=(-3.549 + 163.321 i) + (93.8655 - 72.321 i)*x +(-18.2155 + 17.108 i)*x^2 $$ and compute $f(1)$,$f(2)$, and $f(3)$ to get the digits.2011-04-29
  • 0
    Interestingly, the first extrapolation $f(4)$ gives a complex value $ 80.465+147.765 i$ which can be separated into the four numbers $80 ,465, 147, 765$ *(but I think that's not much significant anyway...)*2011-04-29
  • 0
    @Gottfried: (1) 465 and 765 are bigger than 127 or 255, so are outside of ascii or extended ascii. (2) isn't it obvious that for any integer input you can extract from $f(x)$ four numbers, two of which guaranteed to be less than 1000? `:-)`2011-04-29
  • 0
    @Willi: sure - I only just couldn't resist... ;-) (Question is closed anyway)2011-04-29
2

A -likely- nonexpected answer provides the following link. However, the resulting formula is much more messy than the interpolation-formula...
See http://www.xamuel.com/inverse-graphing-calculator.php?phrase=Hello+World and have fun...

  • 0
    That's fun but it generates an *image*, not values.2011-04-29