# Which big number is bigger?

Input

Integers a1, a2, a3, b1, b2, b3 each in the range 1 to 20.

Output

True if a1^(a2^a3) > b1^(b2^b3) and False otherwise.


^ is exponentiation in this question.

Rules

This is code-golf. Your code must terminate correctly within 10 seconds for any valid input on a standard desktop PC.

You can output anything Truthy for True and anything Falsey for False.

You can assume any input order you like as long as its specified in the answer and always the same.

For this question your code should always be correct. That is it should not fail because of floating point inaccuracies. Due to the limited range of the input this should not be too hard to achieve.

Test cases

3^(4^5) > 5^(4^3)
1^(2^3) < 3^(2^1)
3^(6^5) < 5^(20^3)
20^(20^20) > 20^(20^19)
20^(20^20) == 20^(20^20)
2^2^20 > 2^20^2
2^3^12 == 8^3^11
1^20^20 == 1^1^1
1^1^1 == 1^20^20

• Comments are not for extended discussion; this conversation has been moved to chat. May 1, 2019 at 14:28

# Perl 6, 31 29 bytes

-2 bytes thanks to Grimy

*.log10* * ***>*.log10* * ***


Try it online!

Believe it or not, this is not an esolang, even if it is composed of mostly asterisks. This uses Arnauld's formula, with log10 instead of ln.

• I believe this fails for 2^3^12 == 8^3^11. Apr 26, 2019 at 2:09
• @ØrjanJohansen This should be fixed now. let me know if it fails for anything else
– Jo King
Apr 26, 2019 at 2:34
• -2 by removing the unneeded spaces Apr 26, 2019 at 16:20
• @Grimy Thanks! I could have sworn I tried that...
– Jo King
Apr 26, 2019 at 16:26

# R, 39 bytes

function(x,y,z)rank(log2(x)*(y^z))[1]<2


Try it online!

Returns FALSE when a > b and TRUE if b < a

• This is wrong for f(2,2,20,2,20,2) Apr 25, 2019 at 10:24
• Fixed, using your suggestion to @Arnauld answer ;) Apr 25, 2019 at 10:51
• I believe this fails for 2^3^12 == 8^3^11. Apr 26, 2019 at 2:11
• Fails for both 1^20^20 == 1^1^1 and 1^1^1 == 1^20^20. Apr 26, 2019 at 8:05

# 05AB1E, 11911 7 bytes

.²Šm*›


Port of @Arnauld's JavaScript and @digEmAll's R approaches (I saw them post around the same time)
-2 bytes thanks to @Emigna
+2 bytes as bug-fix after @Arnauld's and @digEmAll's answers contained an error
-4 bytes now that a different input order is allowed after @LuisMendo's comments

Input as [a1,b1], [a3,b3], [a2,b2] as three separated inputs.

Explanation:

.²       # Take the logarithm with base 2 of the implicit [a1,b1]-input
Š      # Triple-swap a,b,c to c,a,b with the implicit inputs
#  The stack order is now: [log2(a1),log2(b1)], [a2,b2], [a3,b3]
m     # Take the power, resulting in [a2**a3,b2**b3]
*    # Multiply it with the log2-list, resulting in [log2(a1)*a2**a3,log2(b1)*b2**b3]
# Push both values separated to the stack
›  # And check if log2(a1)*a2**a3 is larger than log2(b1)*b2**b3
# (after which the result is output implicitly)

• You second version can be εć.²š]P› Apr 25, 2019 at 10:02
• @Emigna Ah nice, I was looking at an approach with ć, but completely forgot about using š (not sure why now that I see it, haha). Thanks! Apr 25, 2019 at 10:04
• This seems to be incorrect (because Arnauld's answer was incorrect until the recent fix).
– user9207
Apr 25, 2019 at 10:32
• @Anush Fixed and 4 bytes saved by taking the inputs in a different order now. :) Apr 25, 2019 at 11:18

# Java (JDK), 56 bytes

(a,b,c,d,e,f)->a>Math.pow(d,Math.pow(e,f)/Math.pow(b,c))


Try it online!

## Credits

• I believe this fails for 2^3^12 == 8^3^11. Apr 26, 2019 at 2:08
• @ØrjanJohansen Fixed Apr 26, 2019 at 6:48

# Wolfram Language (Mathematica), 23 bytes

#2^#3Log@#>#5^#6Log@#4&


Try it online!

• This doesn't terminate for a1=20, a2=20, a3=20.
– user9207
Apr 25, 2019 at 9:42
• @Anush fixed... Apr 25, 2019 at 10:11
• Too bad about overflow, otherwise ##>0&@@(##^1&@@@#)& is only 19 bytes and even more mind-bogglingly un-Mathematica-like than the code above. (infput format {{a,b,c},{d,e,f}}) Apr 26, 2019 at 8:37

# J, 11 9 bytes

>&(^.@^/)


Try it online!

Arguments given as lists.

• > is the left one bigger?
• &(...) but first, transform each argument thusly:
• ^.@^/ reduce it from the right to the left with exponention. But because ordinary exponentiation will limit error even for extended numbers, we take the logs of both sides

# Clean, 44 bytes

import StdEnv
\$a b c d e f=b^c/e^f>ln d/ln a


Try it online!

Uses an adaptation of Arnauld's formula.

• I believe this fails for 2^3^12 == 8^3^11. Apr 26, 2019 at 2:01
• @ØrjanJohansen Fixed. Apr 26, 2019 at 2:25

# Python 3, 68 bytes

lambda a,b,c,d,e,f:log(a,2)*(b**c)>log(d,2)*(e**f)
from math import*


Try it online!

Port of @Arnualds answer, but with the base for log changed.

• ^ is called ** in Python. And with that changed, you won't be able to run all the OP's test cases. Apr 26, 2019 at 1:03
• Should be all fixed now, 66 bytes though. Apr 26, 2019 at 1:37
• I believe this fails for 2^3^12 == 8^3^11. Apr 26, 2019 at 2:01
• @ØrjanJohansen should be fixed Apr 26, 2019 at 2:16
• Seems like it. Apart from the logarithmic base change for the fix, this looks like Arnauld's method. Apr 26, 2019 at 2:30

# Vyxal, 11 bytes

2(?9•??e*)>


I'm beginning to understand Vyxal.

Try it Online!

• 11 bytes May 8, 2021 at 12:25
• @lyxal Why did I not think of that. May 8, 2021 at 12:26
• 9 bytes Jul 12, 2021 at 19:32
• @AaronMiller That doesn't work because time complexity. Jul 12, 2021 at 21:30

# 05AB1E, 13 bytes

Uses the method from Arnauld's JS answer

2F.²IIm*ˆ}¯›


Try it online!

• This doesn't terminate for a1=20, a2=20, a3=20.
– user9207
Apr 25, 2019 at 9:43
• @Anush: Seems to terminate in less than a second to me. Apr 25, 2019 at 9:45
• you have to set all the variables to 20. See tio.run/##yy9OTMpM/f9f79Du3GK9Q6tzHzXs@v8/2shAB4xiuRBMAA
– user9207
Apr 25, 2019 at 9:46
• @Anush: Ah, you meant b1=b2=b3=20 ,yeah that doesn't terminate. Apr 25, 2019 at 9:46
• @Anush: It is fixed now. Thanks for pointing out my mistake :) Apr 25, 2019 at 9:59

## Excel, 28 bytes

=B1^C1*LOG(A1)>E1^F1*LOG(D1)


Excel implementation of the same formula already used.

• My understanding is that Excel has 15 digits of precision, so there may be cases where rounding result in this returning the wrong answer. Apr 25, 2019 at 20:26

# JavaScript, 51 bytes

f=(a,b,c,h,i,j)=>(l=Math.log)(a)*b**c-l(h)*i**j>1e-8


Surprisingly, the test cases doesn't show any floating-point error. I don't know if it ever does at this size.

This just compares the logarithm of the numbers.

Equality tolerance is equal to 1e-8.

• Welcome to PPCG! Alas this does fail with my 2^3^12 == 8^3^11 test case. In fact your answer is very similar to the original answer by Arnauld (sadly deleted rather than fixed) that inspired most of those which failed it. Apr 29, 2019 at 0:24
• @Ørjan Johansen Moved l(h) to the right, and maybe it works now? Edit: Wait, it doesn't. Apr 29, 2019 at 0:58
• Added equality tolerance 0.01. Apr 29, 2019 at 1:12
• I did a quick search and a tolerance should work, but this is a bit too high. The highest you need to exclude is (5.820766091346741e-11,(8.0,3.0,11,2.0,3.0,12)) (my test case), and the lowest you need to include is (9.486076692724055e-4,(17.0,19.0,1,3.0,7.0,2)) (3^7^2 > 17^19^1.) So something like 1e-8 should be safely in the middle and the same byte length. Apr 29, 2019 at 2:24
• @Ørjan Johansen Ok, thanks! Apr 29, 2019 at 17:04

# bc -l, 47 bytes

l(read())*read()^read()>l(read())*read()^read()


with the input read from STDIN, one integer per line.

bc is pretty fast; it handles a=b=c=d=e=f=1,000,000 in a little over a second on my laptop.

• I love a bc answer! Just need one in bash now :)
– user9207
Apr 26, 2019 at 5:32

# C++ (gcc), 86 bytes

Thanks to @ØrjanJohansen for pointing out a flaw in this and @Ourous for giving a fix.

#import<cmath>
int a(int i[]){return pow(i[1],i[2])/pow(i[4],i[5])>log(i[3])/log(*i);}


Try it online!

Takes input as a 6-integer array. Returns 1 if $$\a^{b^c} > d^{e^f}\$$, 0 otherwise.

• The formula after taking log twice should be i[2]*log(i[1])+log(log(*i)). E.g. the current one will fail for 2^2^20 > 4^2^18. Apr 26, 2019 at 2:50
• @ØrjanJohansen: good catch! I guess I have to use the pow method then. Apr 26, 2019 at 2:53
• The alternate one has the 2^3^12 == 8^3^11 problem I've pointed out for others. Apr 26, 2019 at 2:54
• @ØrjanJohansen: well, I guess I'm using your fixed formula then. Apr 26, 2019 at 2:58
• Oh, I'm afraid that formula is only mathematically correct. It still has a floating point error problem, just with a different case, 2^3^20 == 8^3^19. In fact on average the power method fails for fewer, probably because it tends to multiply by powers of two exactly. Others have managed to make it work by just tweaking it slightly. Apr 26, 2019 at 3:11

# Jelly, 8 bytes

l⁵×*/}>/


Try it online!

Based on Arnauld’s JS answer. Expects as input [a1, b1] as left argument and [[a2, b2], [a3, b3]] as right argument.

Now changed to use log to the base 10 which as far as correctly handles all the possible inputs in the range specified. Thanks to Ørjan Johansen for finding the original problem!

• I believe this fails for 2^3^12 == 8^3^11. Apr 26, 2019 at 2:06
• Your Python TIO is incorrect.. You have 8* instead of 8**. @ØrjanJohansen is indeed correct that 2**(3**12) > 8**(3**11) is falsey, since they are equal. Apr 26, 2019 at 7:31
• @KevinCruijssen oops. Yes they are indeed equal. The reason the original two are marked as different relates to floating point error. Apr 26, 2019 at 7:54

# TI-BASIC, 27 31 bytes

ln(Ans(1))Ans(2)^Ans(3)>Ans(5)^Ans(6)(ln(Ans(4


Input is a list of length $$\6\$$ in Ans.
Outputs true if the first big number is greater than the second big number. Outputs false otherwise.

Examples:

{3,4,5,5,4,3
{3 4 5 5 4 3}
prgmCDGF16
1
{20,20,20,20,20,19       ;these two lines go off-screen
{20 20 20 20 20 19}
prgmCDGF16
1
{3,6,5,5,20,3
{3 6 5 5 20 3}
prgmCDGF16
0


Explanation:

ln(Ans(1))Ans(2)^Ans(3)>Ans(5)^Ans(6)(ln(Ans(4   ;full program
;elements of input denoted as:
; {#1 #2 #3 #4 #5 #6}

ln(Ans(1))Ans(2)^Ans(3)                          ;calculate ln(#1)*(#2^#3)
Ans(5)^Ans(6)(ln(Ans(4   ;calculate (#5^#6)*ln(#4)
>                         ;is the first result greater than the
; second result?
;implicit print of "Ans"


Note: TI-BASIC is a tokenized language. Character count does not equal byte count.

• I’m not that familiar with TI-BASIC, but this seems to be log(x) × y × z rather than log(x) × y ^ z. This won’t necessarily lead to the same ordering as the original inequality. Apr 25, 2019 at 21:36
• @NickKennedy Yes, you are correct about that! I'll update the post to account for this. Apr 25, 2019 at 23:10

# APL(NARS), chars 36, bytes 72

{>/{(a b c)←⍵⋄a=1:¯1⋄(⍟⍟a)+c×⍟b}¨⍺⍵}


Here below the function z in (a b c )z(x y t) would return 1 if a^(b^c)>x^(y^t) else would return 0; test

  z←{>/{(a b c)←⍵⋄a=1:¯1⋄(⍟⍟a)+c×⍟b}¨⍺⍵}
3 4 5 z 5 4 3
1
1 2 3 z 3 2 1
0
3 6 5 z 5 20 3
0
20 20 20 z 20 20 19
1
20 20 20 z 20 20 20
0
2 2 20 z 2 20 2
1
2 3 12 z 8 3 11
0
1 20 20 z 1 1 1
0
1 1 1 z 1 20 20
0
1 4 5 z 2 1 1
0


{(a b c)←⍵⋄a=1:¯1⋄(⍟⍟a)+c×⍟b} is the function p(a,b,c)=log(log(a))+c*log(b)=log(log(a^b^c)) and if aa=a^(b^c) with a,b,c >0 and a>1 bb=x^(y^t) with x,y,t >0 and x>1 than

aa>bb <=> log(log(a^b^c))>log(log(x^y^t))  <=>  p(a,b,c)>p(x,y,t)


There is a problem with the function p: When a is 1, log log 1 not exist so I choose to represent that with the number -1; when a=2 so log log a is a negative number but > -1 .

PS. Seen the function in its bigger set in which is defined

p(a,b,c)=log(log(a))+c*log(b)


appear range for a,b,c in 1..20 is too few... If one see when it overflow with log base 10, the range for a,b,c could be 1..10000000 or bigger for a 64 bit float type.