Which big number is bigger?

23

2

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

Anush

Posted 2019-04-25T09:34:24.023

Reputation: 3 202

Comments are not for extended discussion; this conversation has been moved to chat.

– James – 2019-05-01T14:28:58.767

Answers

16

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.

Jo King

Posted 2019-04-25T09:34:24.023

Reputation: 38 234

I believe this fails for 2^3^12 == 8^3^11. – Ørjan Johansen – 2019-04-26T02:09:12.060

@ØrjanJohansen This should be fixed now. let me know if it fails for anything else – Jo King – 2019-04-26T02:34:28.770

-2 by removing the unneeded spaces – Grimmy – 2019-04-26T16:20:21.163

@Grimy Thanks! I could have sworn I tried that... – Jo King – 2019-04-26T16:26:36.113

7

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

digEmAll

Posted 2019-04-25T09:34:24.023

Reputation: 4 599

4This is wrong for f(2,2,20,2,20,2) – H.PWiz – 2019-04-25T10:24:47.927

Fixed, using your suggestion to @Arnauld answer ;) – digEmAll – 2019-04-25T10:51:12.597

I believe this fails for 2^3^12 == 8^3^11. – Ørjan Johansen – 2019-04-26T02:11:43.653

1Fails for both 1^20^20 == 1^1^1 and 1^1^1 == 1^20^20. – Olivier Grégoire – 2019-04-26T08:05:15.830

6

05AB1E, 11 9 11 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.

Try it online or verify all test cases.

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)

Kevin Cruijssen

Posted 2019-04-25T09:34:24.023

Reputation: 67 575

1You second version can be εć.²š]P`› – Emigna – 2019-04-25T10:02:29.277

@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! – Kevin Cruijssen – 2019-04-25T10:04:08.300

This seems to be incorrect (because Arnauld's answer was incorrect until the recent fix). – Anush – 2019-04-25T10:32:07.317

@Anush Fixed and 4 bytes saved by taking the inputs in a different order now. :) – Kevin Cruijssen – 2019-04-25T11:18:24.217

5

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

Olivier Grégoire

Posted 2019-04-25T09:34:24.023

Reputation: 10 647

I believe this fails for 2^3^12 == 8^3^11. – Ørjan Johansen – 2019-04-26T02:08:31.423

@ØrjanJohansen Fixed – Olivier Grégoire – 2019-04-26T06:48:08.490

4

Wolfram Language (Mathematica), 23 bytes

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

Try it online!

J42161217

Posted 2019-04-25T09:34:24.023

Reputation: 15 931

This doesn't terminate for a1=20, a2=20, a3=20. – Anush – 2019-04-25T09:42:41.727

@Anush fixed... – J42161217 – 2019-04-25T10:11:26.273

1Too 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}}) – Greg Martin – 2019-04-26T08:37:29.050

3

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

Jonah

Posted 2019-04-25T09:34:24.023

Reputation: 8 729

3

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.

Artemis still doesn't trust SE

Posted 2019-04-25T09:34:24.023

Reputation: 525

^ is called ** in Python. And with that changed, you won't be able to run all the OP's test cases. – Ørjan Johansen – 2019-04-26T01:03:54.180

Should be all fixed now, 66 bytes though. – Artemis still doesn't trust SE – 2019-04-26T01:37:52.833

I believe this fails for 2^3^12 == 8^3^11. – Ørjan Johansen – 2019-04-26T02:01:28.257

@ØrjanJohansen should be fixed – Artemis still doesn't trust SE – 2019-04-26T02:16:28.053

Seems like it. Apart from the logarithmic base change for the fix, this looks like Arnauld's method. – Ørjan Johansen – 2019-04-26T02:30:27.000

@ØrjanJohansen I thought that too but then the ordene confused me. I see it know. – Artemis still doesn't trust SE – 2019-04-26T06:24:02.690

you don't need the extra sets of brackets around the exponents – Jo King – 2019-04-26T16:04:35.597

3

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.

Οurous

Posted 2019-04-25T09:34:24.023

Reputation: 7 916

1I believe this fails for 2^3^12 == 8^3^11. – Ørjan Johansen – 2019-04-26T02:01:40.343

@ØrjanJohansen Fixed. – Οurous – 2019-04-26T02:25:06.933

2

05AB1E, 13 bytes

Uses the method from Arnauld's JS answer

2F.²IIm*ˆ}¯`›

Try it online!

Emigna

Posted 2019-04-25T09:34:24.023

Reputation: 50 798

This doesn't terminate for a1=20, a2=20, a3=20. – Anush – 2019-04-25T09:43:22.197

1

@Anush: Seems to terminate in less than a second to me.

– Emigna – 2019-04-25T09:45:10.850

you have to set all the variables to 20. See https://tio.run/##yy9OTMpM/f9f79Du3GK9Q6tzHzXs@v8/2shAB4xiuRBMAA

– Anush – 2019-04-25T09:46:09.657

@Anush: Ah, you meant b1=b2=b3=20 ,yeah that doesn't terminate. – Emigna – 2019-04-25T09:46:56.967

Yes, sorry. That is what I meant. – Anush – 2019-04-25T09:58:46.673

Ah, you edited and undeleted a few seconds before I finished my answer.. Your alternative is the same as I had. :D – Kevin Cruijssen – 2019-04-25T09:59:45.557

1@Anush: It is fixed now. Thanks for pointing out my mistake :) – Emigna – 2019-04-25T09:59:45.933

This seems to be incorrect (because Arnauld's answer was incorrect until the recent fix). – Anush – 2019-04-25T10:32:21.817

@Anush: Yes, this had the same issue, which should now be fixed. – Emigna – 2019-04-25T10:59:28.380

I'm a bit confused that you had to fix it, because when I tried to check my test case on all the answers with TIOs, the 05AB1E ones looked like they worked. Hm, trying the old TIO again it may be that your arguments are in the opposite order of what I thought. – Ørjan Johansen – 2019-04-26T21:39:55.920

2

Excel, 28 bytes

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

Excel implementation of the same formula already used.

Wernisch

Posted 2019-04-25T09:34:24.023

Reputation: 2 534

My understanding is that Excel has 15 digits of precision, so there may be cases where rounding result in this returning the wrong answer. – Acccumulation – 2019-04-25T20:26:58.407

2

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.

Naruyoko

Posted 2019-04-25T09:34:24.023

Reputation: 459

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. – Ørjan Johansen – 2019-04-29T00:24:46.417

@Ørjan Johansen Moved l(h) to the right, and maybe it works now?

Edit: Wait, it doesn't. – Naruyoko – 2019-04-29T00:58:49.653

Added equality tolerance 0.01. – Naruyoko – 2019-04-29T01:12:39.420

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. – Ørjan Johansen – 2019-04-29T02:24:01.780

@Ørjan Johansen Ok, thanks! – Naruyoko – 2019-04-29T17:04:13.660

1

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?
                                                 ; leave answer in "Ans"
                                                 ;implicit print of "Ans"

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

Tau

Posted 2019-04-25T09:34:24.023

Reputation: 1 935

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. – Nick Kennedy – 2019-04-25T21:36:54.907

@NickKennedy Yes, you are correct about that! I'll update the post to account for this. – Tau – 2019-04-25T23:10:37.400

1

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!

Nick Kennedy

Posted 2019-04-25T09:34:24.023

Reputation: 11 829

1I believe this fails for 2^3^12 == 8^3^11. – Ørjan Johansen – 2019-04-26T02:06:08.820

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.

– Kevin Cruijssen – 2019-04-26T07:31:13.583

@KevinCruijssen oops. Yes they are indeed equal. The reason the original two are marked as different relates to floating point error. – Nick Kennedy – 2019-04-26T07:54:02.350

1

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.

user73921

Posted 2019-04-25T09:34:24.023

Reputation:

I love a bc answer! Just need one in bash now :) – Anush – 2019-04-26T05:32:53.597

1

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.

Neil A.

Posted 2019-04-25T09:34:24.023

Reputation: 2 038

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. – Ørjan Johansen – 2019-04-26T02:50:35.533

@ØrjanJohansen: good catch! I guess I have to use the pow method then. – Neil A. – 2019-04-26T02:53:57.200

The alternate one has the 2^3^12 == 8^3^11 problem I've pointed out for others. – Ørjan Johansen – 2019-04-26T02:54:19.027

@ØrjanJohansen: well, I guess I'm using your fixed formula then. – Neil A. – 2019-04-26T02:58:59.230

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. – Ørjan Johansen – 2019-04-26T03:11:40.423

You can use this for 86 bytes

– Οurous – 2019-04-26T05:30:52.487

@Οurous: thanks for the fix! updated. – Neil A. – 2019-04-26T14:28:51.770

Suggest int*i instead of int i[] – ceilingcat – 2019-04-26T18:45:40.257

1

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.

RosLuP

Posted 2019-04-25T09:34:24.023

Reputation: 3 036