Golf a transcendental number

46

4

Definitions

  • An algebraic number is a number that is a zero of a non-zero polynomial with integer coefficients. For example, the square root of 2 is algebraic, because it is a zero of x^2 - 2.
  • A transcendental number is a real number which is not algebraic.

Task

You are to choose a transcendental number.

Then, write a program/function that takes a positive integer n and output the n-th decimal digit after the decimal point of your chosen transcendental number. You must state clearly in your submission, which transcendental number is used.

You can use 0-indexing or 1-indexing.

Example

e^2=7.389056098... is a transcendental number. For this number:

n output
1 3
2 8
3 9
4 0
5 5
6 6
7 0
8 9
9 8
...

Note that the initial 7 is ignored.

As I mentioned above, you can choose other transcendental numbers.

Scoring

This is . Lowest score in bytes wins.

Leaky Nun

Posted 2017-05-15T02:27:27.370

Reputation: 45 011

How do the different answers handle the fact that there is a finite number of integers that can be used as an argument? 0 would be an acceptable answer since a transcendental number exists whose first maxInteger digits are 0 – WNG – 2017-05-16T18:45:23.433

1@WNG Languages have arbitrary precision. There is no maxinteger. – Leaky Nun – 2017-05-16T18:45:58.987

1@WNG You can think of the input index as a string, not an integer, in languages that don't have arbitrarily large number types. – isaacg – 2017-05-18T00:25:27.160

Answers

114

Python, 3 bytes

min

Try it online!

Takes a number string, outputs its smallest digit as a smallest character. For example, 254 gives 2. The decimal with these digits starts

0.0123456789011111111101222222220123333333012344444401234555550123456666012345678801234567

This is OEIS A054054.

Claim: This number c is transcendental

Proof: Note that c is very sparse: almost all of its digits are zero. That's because large n, there's high probability n has a zero digit, giving a digit min of zero. Moreover, c has long runs of consecutive zeroes. We use an existing result that states this means c is transcendental.

Following this math.SE question, let Z(k) represent the position of the k'th nonzero digit of c, and let c_k be that nonzero digit, a whole number between 1 and 9. Then, we express the decimal expansion of c, but only taking the nonzero digits, as as the sum over k=1,2,3,... of c_k/10^Z(k).

We use the result of point 4 of this answer by George Lowther: that c is transcendental if there are infinitely many runs of zeroes that are at least a constant fraction of the number of digits so far. Formally, there must be an ε>0 so that Z(k+1)/Z(k) > 1+ε for infinitely many k. We'll use ε=1/9

For any number of digits d, take k with Z(k) = 99...99 with d nines. Such a k exists because this digit in c is a 9, and so nonzero. Counting up from 99...99, these numbers all contain a zero digit, so it marks the start of a long run of zeroes in c. The next nonzero digit isn't until Z(k+1) = 1111...11 with d+1 ones. The ratio Z(k+1)/Z(k) slightly exceeds 1+1/9.

This satisfies the condition for every d, implying the result.

xnor

Posted 2017-05-15T02:27:27.370

Reputation: 115 687

I would be quite excited to see the proof. – Leaky Nun – 2017-05-15T03:01:53.980

1Is this allowed? min itself doesn't take any input and doesn't provide any output, something that seems to be a requirement by the question. Sure, it's the key function in the whole, but it doesn't do anything without the generator and print statement apparent in the 'Try it online'. – Mast – 2017-05-16T08:02:34.367

6

@Mast Yes, the problem is to output the n'th digit given n, not to generate the decimal. The test code is to show the sequence of digits. And an expression that evaluates to a function, including a function literal, is a valid function submission.

– xnor – 2017-05-16T09:00:09.077

1delightful :))) – Noodle9 – 2017-05-17T04:49:03.243

Holy sh1t, this is clever! – RGS – 2020-02-10T18:21:50.583

38

Pyth, 1 byte

h

Input and output are strings. The function takes the first digit of the index. The resulting transcendental number looks like:

0.0123456789111111111122222222223 ...

This is transcendental because it is 1/9 plus a number which has stretches of zeroes of length at least a constant fraction of the number. Based on this math.stackexchange answer, that means that the number is transcendental.

There are stretches of zeroes are from digit 100 ... 000 to 199 ... 999, so ratio of Z(k+1) to Z(k) is 2 infinitely often.

Thus, the above number minus 1/9 is transcendental, and so the above number is transcendental.

isaacg

Posted 2017-05-15T02:27:27.370

Reputation: 39 268

2Note that the question asked in the linked M.SE post does not apply to this number, but point 4 of the answer by George Lowther does. – hmakholm left over Monica – 2017-05-16T15:46:25.323

16

Python 2, 19 bytes

lambda n:1>>(n&~-n)

The nth digit is 1 if n is a power of 2 and 0 otherwise.

Try it online!

Dennis

Posted 2017-05-15T02:27:27.370

Reputation: 196 637

3I was going to answer this, but I found no proof of its transcendence. What makes you believe this number is transcendent? n&~-n>0 is shorter by the way. – orlp – 2017-05-15T02:54:52.017

3

@orlp All sufficiently sparse numbers are transcendental.

– xnor – 2017-05-15T02:56:56.713

1

@orlp Fredholm's number

– Leaky Nun – 2017-05-15T02:57:08.510

@orlp I'd have to ask the OP if Booleans are fine. – Dennis – 2017-05-15T02:57:29.790

@Dennis I would prefer not. – Leaky Nun – 2017-05-15T02:58:02.800

@Dennis What booleans?

– Khuldraeseth na'Barya – 2018-04-22T21:44:15.857

1

@Scrooble These Booleans.

– Dennis – 2018-04-23T01:41:41.047

@orlp You could submit for gcc/g++: -Df(n)=n&~-n>0 – None – 2018-09-11T19:55:53.843

11

brainfuck, 2 bytes

,.

Similarly to some other answers, returns the first decimal digit and ignores the rest.

KSab

Posted 2017-05-15T02:27:27.370

Reputation: 5 984

6

Jelly, 3 bytes

e!€

Uses Liouville's constant.

Try it online!

Dennis

Posted 2017-05-15T02:27:27.370

Reputation: 196 637

5

Retina, 4 bytes

1!`.

Returns the first digit of the input number. Because that port was so boring, here are some more ports:

O`.
1!`.

(8 bytes) Returns the minimum digit of the input number.

.+
$*
+`^(11)+$
$#1$*
^1$

(25 bytes) Returns 1 if the input number is a power of 2.

.+
$*_

$.`
+1`.(\d*)_
$1
1!`.

(30 bytes) Champernowne's constant.

Neil

Posted 2017-05-15T02:27:27.370

Reputation: 95 035

4

Brachylog 2, 7 bytes

⟦₁c;?∋₎

Try it online!

Calculates digits of the Champernowne constant (possibly times a power of ten due to indexing issues, which clearly don't matter here). Basically, this just concatenates together integers, and then takes the nth digit.

user62131

Posted 2017-05-15T02:27:27.370

Reputation:

Why do you need ⟦₁? – Leaky Nun – 2017-05-15T02:39:37.517

@LeakyNun: Because otherwise we'd start concatenating numbers with 0, and you can't do that because 0123 is not a number (it has a leading zero, which doesn't fit within Brachylog's concept of what a number is). – None – 2017-05-15T02:41:48.417

4

Python 2, 13 bytes

Input and output are strings.

lambda n:n[0]

The number's nth digit is the most significant digit of n when it is written in decimal.

feersum

Posted 2017-05-15T02:27:27.370

Reputation: 29 566

4You should include why this number is transcendental. – orlp – 2017-05-15T02:57:03.807

2@orlp Looks like xnor's reference can easily be applied here too -- subtract 1/9 from the number and then Z(n+1) / Z(n) ~= 2 infinitely often (between 10^x and 2 * 10^x). – feersum – 2017-05-15T03:46:57.447

4

MATL, 7 bytes

4YA50<A

This uses the first of the two numbers given here divided by 3 (which maintains transcendence):

1.100110000000000110011...

Input is 1-based. Try it online! Or see the first 20 decimals.

Explanation

4YA     % Convert to base 4 using chars '0', '1', '2', '3' as digits
50<A    % Are all digits less than '2'? Gives 0 (false) or 1 (true) 

Luis Mendo

Posted 2017-05-15T02:27:27.370

Reputation: 87 464

3

Python 2, 43 bytes

Champernowne's constant.

lambda n:"".join(`i`for i in range(n+1))[n]

orlp

Posted 2017-05-15T02:27:27.370

Reputation: 37 067

Why do you need n+1? – Leaky Nun – 2017-05-15T02:39:21.200

@LeakyNun Because else I get indexing errors for n <= 1. – orlp – 2017-05-15T02:40:05.370

You can use 1-indexing. – Leaky Nun – 2017-05-15T02:40:27.300

@LeakyNun n <= 1. – orlp – 2017-05-15T02:40:36.113

I think you need to specify Python 2 for this one. – numbermaniac – 2017-05-15T07:18:05.497

3

JavaScript, 51 bytes

This function computes nth digit of Champernowne's Constant. Add f= at the beginning and invoke like f(arg). Note that n is 1-indexed.

n=>[..."1".repeat(n)].map((c,i)=>c*++i).join``[n-1]

Explanation

This function takes in a single argument n. It, then, creates an n-characters long String of repetitive 1s. Then, it splits that String into an Array of 1s . After that, it iterates over every element of the Array and multiplies them with their index in the Array incremented by 1. Then, it joins the Array together over "" (empty String) to form a String. At last, it returns the nth element of the obtained String.

Note: The type of the returned value is always String.

Test Snippet

let f =

n=>[..."1".repeat(n)].map((c,i)=>c*++i).join``[n-1]

i.oninput = e => o.innerHTML = f(parseInt(e.target.value,10));
<input id=i><pre id=o></pre>

Arjun

Posted 2017-05-15T02:27:27.370

Reputation: 4 544

3

APL (Dyalog), 3 bytes

2|⍴

Try it online! (the test suite generates a range of numbers from 1 to 10000, converts them to a string, and then applies the train 2|⍴ on them).

Takes the input number as a string and returns its length mod 2. So 123 => 3 mod 2 => 1.

The sequence starts off like so:

1  1  1  1  1  1  1  1  1  0  0  0  0  0  0  ...

so this can be generalised like so: 9 1s 90 0s 900 1s ...

Multiplying this number by 9 gives us a Liouville number, which is proven to be transcendental.

user41805

Posted 2017-05-15T02:27:27.370

Reputation: 16 320

I don't think this is necessarily a Liouville number - it's not obvious to me that you can get n>10. It does fit the stronger theorem other people here have been using, though. – Ørjan Johansen – 2017-05-15T18:30:48.260

@ØrjanJohansen You can express it as 1 - 10^-9 + 10^-99 - 10^-999 + 10^-9999 - 10^-99999 + ..., so it is a Liouville number. – Leaky Nun – 2017-05-16T08:21:25.317

@LeakyNun The fraction of consecutive exponents is approximately 10, but to fit the definition on Wikipedia it needs to be unbounded - that's why the original Liouville's constant's 1-indices use a factorial, and not an exponential. – Ørjan Johansen – 2017-05-16T16:05:59.000

3

Haskell, 25 bytes 17 bytes

(!!)$concat$map show[1..]

Champernowne's Constant can be 0 or 1 indexed as C10*.01 is still transcendental.

Edit: as per nimis comment you can use the list monad to reduce this to

(!!)$show=<<[1..]

Matt R

Posted 2017-05-15T02:27:27.370

Reputation: 31

2=<< from the list monad is concat.map: (!!)$show=<<[1..]. – nimi – 2018-09-16T15:01:39.407

2

JavaScript, 73 bytes

This is a program which computes the nth digit of the Liouville Constant, where n is the input number given by invoking the function g as g(arg) (and n is 1-indexed). Note that the newline in the code is necessary.

f=n=>n<1?1:n*f(n-1);g=(n,r=0)=>{for(i=0;i<=n;i++)if(f(i)==n)r=1
return r}

Explanation

The program consists of two functions, f and g. f is a recursive factorial-computing function, and g is the main function of the program. g assumes to have a single argument n. It defines a default argument r with a value of 0. It, then, iterates over all the Integers from 0 to n, and, in each iteration, checks whether the function f applied over i (the current index) equals n, i.e. whether n is a factorial of i. If that happens to be the case, r's value is set to 1. At the end of the function, r is returned.

Snippet for Testing

f=n=>n<1?1:n*f(n-1);g=(n,r=0)=>{for(i=0;i<=n;i++)if(f(i)==n)r=1
return r}

i.oninput = e => o.innerHTML = g(parseInt(e.target.value,10))
<input id=i><pre id=o></pre>

Warning: Don't put a very large value in the Snippet's input box! Otherwise, your device may freeze!

Arjun

Posted 2017-05-15T02:27:27.370

Reputation: 4 544

1

Pyth, 7 5 4 bytes

@jkS

Try it online!

Uses Champernowne's constant.

Saved 2 3 bytes thanks to Leaky Nun.

clap

Posted 2017-05-15T02:27:27.370

Reputation: 834

1you can use jk to replace sm\d`, I believe. – Leaky Nun – 2017-05-15T02:42:26.413

1Can you use S instead of Uh? – Leaky Nun – 2017-05-15T02:49:59.460

I think they are functionally identical, so yes. I totally read through the docs >.> – clap – 2017-05-15T02:54:34.753

They aren't functional identical. S starts with 1 and U starts with 0. – Leaky Nun – 2017-05-15T02:55:08.207

Why did you revert your edit? The resulting number is still transcendental. – Leaky Nun – 2017-05-15T02:56:08.337

Yeah, turns out I have to do that for my answer to be valid actually lol – clap – 2017-05-15T02:56:20.943

@LeakyNun it's not the Champernowne constant though – clap – 2017-05-15T02:56:44.857

But it's still transcendental, right? It is essentially a shifted Champernowne constant. – Leaky Nun – 2017-05-15T02:58:52.343

Yeah, it's transcendental, but using S is shorter anyway – clap – 2017-05-15T03:00:08.470

1

Java 8, 18 bytes

Same as Dennis' answer for Python 2, the Fredholm number

n->(n&(n-1))>0?0:1

JollyJoker

Posted 2017-05-15T02:27:27.370

Reputation: 381

(n-1) can be ~-n or --n to save 2 bytes. Or you can have the exact same as Dennis' answer: n->1>>(n&~-n) or 1>>(n&--n). – Kevin Cruijssen – 2018-04-23T07:59:42.237

1

Jelly, 1 byte

Try it online!

1st digit of quoted 0-indexed input.1

1See isaacg's answer for proof of validity.

Erik the Outgolfer

Posted 2017-05-15T02:27:27.370

Reputation: 38 134

1

Charcoal, 24 bytes (noncompeting)

NαAIUVN⟦UGPi⁺α¹⟧β§β⁺α›α⁰

Try it online!

Note: As of post time, does not work for n where n is a positive multiple of 14.

Explanation

Nα                             Input number to a
   A                  β        Assign to b
     I                         Cast
       UVN                    Evaluate variable N
            ⟦UGPi⁺α¹⟧         With arguments GetVariable(Pi) and a+1
                        §β⁺α›α⁰ Print b[a+(a>0)]

ASCII-only

Posted 2017-05-15T02:27:27.370

Reputation: 4 687

GetVariable(Pi)? So, there's no π predefined variable? – Neil – 2017-05-15T18:30:39.963

@Neil Not yet, and I'm not intending to make π equal to pi because this is an ASCII-art oriented language, not a math-oriented one – ASCII-only – 2017-05-15T22:50:20.757

1

Japt, 3 1+1= 2 1 byte

Another port of feersum's solution.

Takes input as a string.

g

Try it online


Explanation

   :Implicit input of string U
g  :The first character of the string

Shaggy

Posted 2017-05-15T02:27:27.370

Reputation: 24 623

The input can be a string, so you can do g for 1 byte :) – Oliver – 2017-05-18T21:00:59.660

The challenge doesn't make mention of string input, @obarakon, so I used integers in my JS ports and then, in turn, here.

– Shaggy – 2017-05-18T21:27:18.303

Ah, gotcha. A lot of the other answers used string inputs. But you're right, the OP didn't mention it in the challenge. – Oliver – 2017-05-19T13:59:38.317

1

TI-BASIC, 16 bytes

Basically tests if the input N (1-indexed) is a triangular number. This is the same as returning the Nth digit of 0.1010010001…, which is proven to be transcendental. The sequence of digits is OEIS A010054.

Input N
int(√(2N
2N=Ans(Ans+1

kamoroso94

Posted 2017-05-15T02:27:27.370

Reputation: 739

0

Fourier, 16 bytes

I~NL~S10PS~XN/Xo

Try it online!

As other answers have done, outputs the first digit of the input.

An explanation of the code:

N = User Input
S = log(N)
X = 10 ^ S
Print (N/X)

Beta Decay

Posted 2017-05-15T02:27:27.370

Reputation: 21 478

0

JavaScript (ES6)

Just a few ports of some other solutions


feersum's Python solution, 12 bytes

n=>(""+n)[0]

f=
n=>(""+n)[0]
o.innerText=f(i.value=1)
i.oninput=_=>o.innerText=f(+i.value)
<input id=i type=number><pre id=o>

Dennis' Python solution, 13 bytes

n=>1>>(n&--n)

f=
n=>1>>(n&--n)
o.innerText=f(i.value=1)
i.oninput=_=>o.innerText=f(+i.value)
<input id=i type=number><pre id=o>

xnor's Python solution, 20 bytes

n=>Math.min(...""+n)

Shaggy

Posted 2017-05-15T02:27:27.370

Reputation: 24 623

0

Brain-Flak, 6 + 3 ( -c) = 9 bytes

({}<>)

Try it online!

1st digit of 0-index string input (hence the -c flag).

Erik the Outgolfer

Posted 2017-05-15T02:27:27.370

Reputation: 38 134

0

C#, 13 bytes

n=>(n+"")[0];

From feersum's solution. Almost same solution than the js port.

Try it online

aloisdg moving to codidact.com

Posted 2017-05-15T02:27:27.370

Reputation: 1 767

0

05AB1E, 3 1 byte

EDIT: Using the proof from the other answers, returns the first digit of input

¬

1-indexed for π (only up to 100000 digits)

žs¤

How it works

žs  # Implicit input. Gets n digits of pi (including 3 before decimal)
  ¤ # Get last digit

Or, if you prefer e (still 1-indexed) (only up to 10000 digits)

žt¤

Try it online!

Neil A.

Posted 2017-05-15T02:27:27.370

Reputation: 2 038

0

J, 2 Bytes

The same solution everyone else is using:

{.

Returns the first digit of n. IO is on strings

Liouville's Constant, 9 Bytes

(=<.)!inv

Returns 1 if input is the factorial of an integer.

Pi, 13 Bytes

{:":<.@o.10x^

The last non-decimal digit of pi times 10^n.

Bolce Bussiere

Posted 2017-05-15T02:27:27.370

Reputation: 970

0

Jelly, 2 bytes

LḂ

Try it online!

Take the length of the input number modulo 2. Equivalent to this APL answer.

Esolanging Fruit

Posted 2017-05-15T02:27:27.370

Reputation: 13 542

0

Dreaderef, 5 bytes

7 3 6

Try it online!

Returns the first digit of the input.

Esolanging Fruit

Posted 2017-05-15T02:27:27.370

Reputation: 13 542

0

Momema, 5 bytes

-9*-9

Try it online!

Returns the first digit of the input.

Esolanging Fruit

Posted 2017-05-15T02:27:27.370

Reputation: 13 542

0

Shakespeare Programming Language, 76 bytes

,.Ajax,.Ford,.Act I:.Scene I:.[Enter Ajax and Ford]Ford:Open mind.Speak thy.

Try it online!

JosiahRyanW

Posted 2017-05-15T02:27:27.370

Reputation: 2 600

You've got an extra character there – Jo King – 2018-09-11T12:07:52.693

Whoops, that must have been a leftover from something else. Thanks for spotting it. – JosiahRyanW – 2018-09-11T16:53:42.657