g | x | w | all
Bytes Lang Time Link
nan250621T002647ZRARE Kpo
009Julia 1.0230615T191640ZAshlin H
002Thunno 2230615T181950ZThe Thon
002Vyxal210730T230424Zemanresu
125dc170205T053921ZR. Kap
00205AB1E210111T190632ZMakonede
011Bean170205T063405ZPatrick
004Quetzalcoatl160405T152122ZNoOneIsH
00305AB1E160614T104745ZAdnan
001Pyth160407T234101ZLeaky Nu
010Excel170920T133004ZWernisch
024Common Lisp170915T220408Zceilingc
002J160223T044529ZDennis
018SmileBASIC170201T220340Z12Me21
009QBIC160224T163216Zsteenber
023tcl170115T000904Zsergiol
007Mathematica160223T042159ZCalculat
005MATL160223T133205ZLuis Men
034Python 3160613T225255Zgeorge
023C160223T232523Zuser4594
014Desmos160606T185333Zweatherm
060SQL MySQL160413T050034Zuser4594
014Mumps160408T201101Zzmerch
003Pyth160223T035520ZDoorknob
022Racket160315T235309ZWinny
003Convex160316T024655ZGamrCorp
010Factor160316T014852Zcat
006dc160405T211741Zmriklojn
020Lua160331T032701ZLeaky Nu
007Brachylog160316T162941Za spaghe
011Perl160227T080414ZSake
009PARI/GP160223T141945ZCharles
041C#160224T161025Zfroggyof
006CJam160223T063613ZDennis
415Vitsy160227T002934ZAddison
033Scala160224T215010ZMichal
025C#160224T212112ZHeiko Ob
013Mouse2002160224T173836Zcat
006Pyke commit 29160223T154046ZBlue
011MATLAB160224T150142ZTom Carp
008Awk160224T134722ZHastur
013Gnuplot160224T134539ZHastur
011Haskell160223T220503Zflawr
057𝔼𝕊𝕄𝕚𝕟160223T062355ZMama Fun
011Javascript ES2016160223T062803ZMama Fun
006O160224T023248Zuser4594
005Jolf160224T015854ZConor O&
056Python 2160223T234908ZMaltysen
002NARS APL160223T221854Zmarinus
005Milky Way 1.6.5160223T233615ZZach Gat
041Java160223T174617ZDarrel H
015Ruby160223T231342ZEli Sado
029PHP 5.6160223T150013Zricdesi
004TIBasic160223T230106ZTimtech
017R160223T053229Zmnel
048C++160223T214848Zuser4594
018Java 8160223T212652ZGamrCorp
003Japt160223T210241ZETHprodu
018JavaScript ES6160223T042621ZDowngoat
003TIBASIC160223T161812ZNinjaBea
005Pylons160223T160700ZMorgan T
016Codename Dragon160223T155812ZConor O&
010Perl 5160223T072554Zmsh210
002Jelly160223T043724ZDennis
017Python 3160223T042843Zuser4594
005Seriously160223T040051Zuser4594

awk

jot 50
awk '$2=$1^$1^-1'

1 1
2 1.4142135623731
3 1.44224957030741
4 1.4142135623731
5 1.37972966146121
6 1.34800615459728
7 1.32046924775612
8 1.29683955465101
9 1.27651800700924
10 1.25892541179417
11 1.24357522791237
12 1.23007550557797
13 1.21811404356077
14 1.20744202741841
15 1.19786005826964
16 1.18920711500272
17 1.18135207462555
18 1.17418725309966
19 1.16762348369611
20 1.16158634964154
21 1.1560132810008
22 1.15085130035828
23 1.14605525822348
24 1.14158644063216
25 1.13741146175603
26 1.13350137645871
27 1.12983096390975
28 1.12637814525087
29 1.12312350709179
30 1.1200499091502
31 1.11714215925046
32 1.11438674259589
33 1.11177159504321
34 1.10928591226304
35 1.10691998833269
36 1.1046650785975
37 1.10251328264561
38 1.10045744403373
39 1.09849106402815
40 1.09660822712436
41 1.0948035365073
42 1.09307205793482
43 1.09140927078651
44 1.08981102522989
45 1.08827350462819
46 1.08679319245417
47 1.08536684309049
48 1.08399145599242
49 1.08266425276848
50 1.08138265680029

Julia 1.0, 9 bytes

~x=x^x^-1

Try it online!

This solution handles both complex numbers and infinities.

Thunno 2, 2 bytes

Ị*

Attempt This Online!

calculates the reciprocal, and * does exponentiation.

Vyxal, 2 bytes

Ėe

Try it Online!

The es are coming!

 e # x to the power of
Ė  # 1/x

dc, 125 bytes

15k?ddsk1-A 5^*sw1sn0[A 5^ln+_1^+ln1+dsnlw!<y]syr1<y1lk/*sz[si1[li*li1-dsi0<p]spli0<p]so0dsw[lzlw^lwlox/+lw1+dswA 2^!<b]dsbxp

Unlike the other dc answer, this works for all real \$x\$ greater than or equal to \$1 (\$1 ≤ x$). Accurate to 4-5 places after the decimal.

I would have included a TIO link here, but for some reason this throws a segmentation fault with the version there (dc 1.3) whereas it does not with my local version (dc 1.3.95).

Explanation

As dc does not support raising numbers to non-integer exponents to calculate \$x^\frac1x\$, this takes advantage of the fact that:

$$x^\frac1x = e^\frac{\ln x}x$$

So, to calculate \$\ln(x)\$, this also takes advantage of the fact that:

$$\int \frac1x dx = \ln(x) + c$$

whose definite integral from \$1\$ to \$b = x\$ is numerically-approximated in increments of \$10^{-5}\$ using the following summation formula:

$$\int_1^b \frac1x dx = \sum_{i=1}^{10^{5}(b-1)} \frac 1 {10^5 + i}$$

The resulting sum is then multiplied by \$\frac1x\$ to get \$\frac{\ln(x)}x\$. \$e^{\frac{\ln(x)}x}\$ is then finally calculated using the \$e^x\$ Maclaurin Series to 100 terms as follows:

$$e^x=\sum^{10^2}_{n=0}\frac{x^n}{n!}$$

This results in our relatively accurate output of \$x^\frac1x\$.

05AB1E, 2 bytes

zm

Try it online!

zm  # full program
    # implicit input...
 m  # to the power of...
z   # 1 divided by...
    # implicit input
    # implicit output

Bean, 11 bytes

Hexdump:

00000000 26 4c a0 43 95 4c a5 3a 8e 20 43  &L C.L¥:. C
0000000b

Equivalent JavaScript:

A**(1/A)

Implicitly converts first line of input to number as A and implicitly outputs the result of the expression.

Try the demo here.

Try the test suite here.

Quetzalcoatl, 4 bytes

c.I?

Explanation:

c    # Input
 .   # Duplicate
  I  # Inverse
   ? # Power

05AB1E, 3 bytes

Dzm

Explanation:

D    # Duplicate the input
 z   # Inverse, 1 ÷ input
  m  # Power, calculating input ** (1 ÷ input)

Try it online!.

Pyth, 1 byte

@

Pyth takes implicit input, so @ is really equivalent to @QQ, where Q is the evaluated input.

Try it online!

Excel, 10 bytes

=A1^(1/A1)

Self explanatory.

Common Lisp, 24 bytes

(lambda(x)(expt x(/ x)))

Try it online!

J, 2 bytes

^%

Try it online!.

How it works

^%  Monadic verb. Argument: y

 %  Inverse; yield 1÷y.
^   Power (hook); compute y ** (1÷y).

SmileBASIC, 18 bytes

INPUT X?POW(X,1/X)

QBIC, 9 bytes

:?a^(1/a)

Gets a numeric input from the command line and does the math...

tcl, 23

I post two approaches which occupy the exact same number of bytes.

puts [expr $n**(1./$n)]

puts [expr $n**$n**-1.]

Available to test on http://rextester.com/EMW19680

Mathematica, 8 7 4 7 bytes

#^#^-1&

More builtin-only answers, and now even shorter! Nope. By definition, the next answer should be 13 bytes. (Fibonacci!) The pattern is still broken. :(

MATL, 5 bytes

t-1^^

Try it online!

t       % implicit input x, duplicate
 -1     % push -1
   ^    % power (raise x to -1): gives 1/x
    ^   % power (raise x to 1/x). Implicit display

Python 3: 34

n=complex(input());print(n**(1/n))

Unless I'm missing something this would do nicely. I like that Python normally uses spaces, but this solution doesn't need them.

C, 23 bytes

#define p(a)pow(a,1./a)

This defines a macro function p which evaluates to the ath root of a.

Thanks to Dennis for reminding me that gcc doesn't require math.h to be included.

Thanks to @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ for reminding me that the space after the first ) is not needed.

Try it online

Desmos, 14 bytes

a=1
\sqrt[a]{a}

Demonstration

SQL (MySQL), 60 bytes

CREATE FUNCTION G(X REAL) RETURNS REAL RETURN POWER(X,1./X);

Caps lock is cruise control for cool golf.

Mumps, 14 Bytes

R I W I**(1/I)

R reads from input into variable I, and the W (write) statement does the mathematical calculations.

I will warn you: the output will be ugly as there are no implied newlines in Mumps, and at least the way I read the challenge, the OP didn't require them. If you did want cleaner output, add 2 bytes and add a newline:

R I W !,I**(1/I)

Pyth, 3 bytes

@QQ

Trivial challenge, trivial solution...

(noncompeting, 1 byte)

@

This uses the implicit input feature present in a version of Pyth that postdates this challenge.

Racket, 28 22 bytes

(λ(n)(expt n(/ 1 n)))

@cat gets credit for the 6 byte save. Thanks!

Seriously, Racket is impossible to golf with :). Nothing to see here, move along!

Convex, 3 bytes

Convex is a new language that I am developing that is heavily based on CJam and Golfscript. The interpreter and IDE can be found here. Input is an integer into the command line arguments. Indexes are one-based. Uses the CP-1252 encoding. This answer in non-competing as it was created after this challenge.

_¹#

Explanation:

    Implied input
_   Duplicate top of stack
 ¹  Find reciprocal
  # Power
    Implied output

Factor, 14 10 bytes

1 over / ^

Expects input on top of the stack.

dc, 8 6 chars

Outputs to the top of the stack:

?d1r/^

Or if I can expect the input at the top of the stack, this 5 char solution works too:

d1r/^

Explanation:

?        take input from STDIN and execute it (numbers are executed by pushing to the stack)
 d1r     duplicate top of stack, push 1 and swap them
    /^   divide and exponentiate

Alas, dc does not allow for fractional exponents so this answer does not actually work for any given inputs above 1, and gives the wrong answer for 0 < input < 1. It does the same thing as many of the other programs though.

Lua, 20

n=(...)print(n^n^-1)

How it works:

n=(...)              Take input and store at n
       print(
             n^n^-1  n^(n^(-1))
                   )

Brachylog, 8 7 bytes

Thanks to Fatalize for saving a byte.

^?^-1=.

Explanation

^?^-1=.
     =.   unify output with
^?^-1     input raised to the 1/input power

Perl, 11 bytes

Added 2 bytes for -pn.

$_**=1/$_

Try it here !

PARI/GP, 9 bytes

x->x^x^-1

This is shorter than the alternatives x->x^(1/x) and x->sqrtn(x,x). It uses the right-associativity of ^ and the strong binding of the unary -. GP isn't quite functional enough to curry (a,b)->sqrtn(a,b) into (x)->sqrtn(x,x); the best it can manage is x->call(sqrtn,[x,x]) which is far too long.

C# - 18 43 41 bytes

float a(float x){return Math.Pow(x,1/x);}

-2 byes thanks to @VoteToClose

Try it out

Note:

First actual attempt at golfing - I know I could do this better.

CJam, 6 bytes

rd_W##

Try it online!

How it works

rd     e# Read a double D from STDIN and push it on the stack.
  _    e# Push a copy of D.
   W   e# Push -1.
    #  e# Compute D ** -1.
     # e# Compute D ** (D ** -1).

Vitsy, 4 + 1 (function declaration) = 5 bytes

Hey, look, my language actually does this. Go figure.

Di^^
D    Duplicate the top item (input)
 i   Push -1.
  ^  Pop top (-1), put the second to top to the power of the popped item (x^-1)
   ^ Same as above, except we now have the desired number.

This is a function that leaves the value requested on the stack. For view-ability, I have also made the program output on the Try it Online! link.

Try it Online!

Scala, 33 bytes

def f=(x:Double)=>Math.pow(x,1/x)

C#, 25 bytes, type: double

Bare form of a lambda expression:

x=>System.Math.Pow(x,1/x)

The expression can be assigned to a function variable, e.g. (Func<double, double>), ...

System. can be omitted, if using System; is used (but more bytes).

Complete test program (143 bytes) with the input of the question:

using System;class P{static void Main(){Array.ForEach(new double[]{-.2,-.5,.5,1,2,Math.E,3,100,10000},x=>Console.WriteLine(Math.Pow(x,1/x)));}}

Result:

-3125
4
0,25
1
1,4142135623731
1,44466786100977
1,44224957030741
1,0471285480509
1,0009214583193

C#, 37 bytes, type: Complex

x=>System.Numerics.Complex.Pow(x,1/x)

Also the assembly for System.Numerics needs to be referenced. The division operator is overloaded for complex arguments.

Test program (189 bytes) with the input of the question for complex numbers:

using System;using C=System.Numerics.Complex;class P{static void Main(){Array.ForEach(new C[]{new C(-2,0),new C(0,1),new C(0,2),new C(1,2),new C(2,2)},x=>Console.WriteLine(C.Pow(x,1/x)));}}

Result:

(4,32963728535968E-17, -0,707106781186548)
(4,81047738096535, 0)
(2,0628722350809, -0,745007062179724)
(1,81984053615444, -0,183434723804562)
(1,57500291115344, -0,100274868564155)

Test program (264 bytes) with infinity:

using System;using C=System.Numerics.Complex;class P{static void Main(){var p=double.PositiveInfinity;var n=double.NegativeInfinity;Array.ForEach(new C[]{new C(-1/p,0),new C(0,0),new C(1/p,0),new C(p,0),new C(n,0),new C(n,2) },x=>Console.WriteLine(C.Pow(x,1/x)));}}

Result:

(0, 0)
(0, 0)
(0, 0)
(1, 0)
(1, 0)
(1, 0)

Mouse-2002, 13 bytes

x:x.b/x.&ROOT

Other programs assume the number's on the top of the stack and so shall I.

x:    ~ put TOS in x
x.    ~ push x
b /   ~ divide by 1
x.    ~ push x again
&ROOT ~ y to the x root

Pyke (commit 29), 6 bytes

D1_R^^

Explanation:

D      - duplicate top
 1_    - load -1
   R   - rotate
    ^  - ^**^
     ^ - ^**^

MATLAB, 11bytes

@(x)x^(1/x)

Creates an anonymous function. This will work with all test cases including complex numbers and infinities.

This also works with Octave. You can try online here. Simply enter something like:

f=@(x)x^(1/x)

At the command line of the online interpreter, then do:

f(-1)

To test.

Awk, 8 bytes

$1^$1^-1

A shell command to check it

awk '{print $1^$1^-1}'

Longer version (+1) with

$1^(1/$1)

Gnuplot, 13 bytes

f(x)=x**(1/x)

or

f(x)=x**x**-1

Haskell, 12 11 bytes

Thanks @LambdaFairy for doing some magic:

(**)<*>(1/) 

My old version:

\x->x**(1/x)

𝔼𝕊𝕄𝕚𝕟, 5 chars / 7 bytes

Мű⁽ïï

Try it here (Firefox only).

Trivial.

Javascript (ES2016), 11 bytes

x=>x**(1/x)

I rarely ever use ES7 over ES6.

O, 6 bytes

j.1\/^

No online link because the online IDE doesn't work (specifically, exponentiation is broken)

Explanation:

j.1\/^
j.      push two copies of input
  1\/   push 1/input (always float division)
     ^  push pow(input, 1/input)

Jolf, 5 bytes

Try it here!

^j/1j
 j    input
^ /1j to the 1/j pow.

Python 2 - 56 bytes

The first actual answer, if I'm correct. Uses Newton's method.

n=x=input();exec"x-=(x**n-n)/(1.*n*x**-~n);"*999;print x

NARS APL, 2 bytes

√⍨

NARS supports the function, which gives the ⍺-th root of ⍵. Applying commute (⍨) gives a function that, when used monadically, applies its argument to both sides of the given function. Therefore √⍨ xx √ x.

Other APLs, 3 bytes

⊢*÷

This is a function train, i.e. (F G H) x(F x) G H x. Monadic is identity, dyadic * is power, and monadic ÷ is inverse. Therefore, ⊢*÷ is x raised to 1/x.

Milky Way 1.6.5, 5 bytes

'1'/h

Explanation

'      ` Push input
 1     ` Push the integer literal
  '    ` Push input
   /   ` Divide the STOS by the TOS
    h  ` Push the STOS to the power of the TOS

x**(1/x)


Usage

$ ./mw <path-to-code> -i <input-integer>

Java, 41 bytes

float f(float n){return Math.pow(n,1/n);}

Not exactly competitive because Java, but why not?

Ruby, 15 Bytes

a=->n{n**n**-1}

Ungolfed:

-> is the stabby lambda operator where a=->n is equivalent to a = lambda {|n|}

PHP 5.6, 32 30 29 bytes

function($x){echo$x**(1/$x);}

or

function($x){echo$x**$x**-1;}

30->29, thank you Dennis!

TI-Basic, 4 bytes

Ans^Ansֿ ¹

Since TI-Basic is tokenized, this code is a mere four bytes.

R, 19 17 bytes

function(x)x^x^-1

-2 bytes thanks to @Flounderer

C++, 48 bytes

#include<math.h>
[](auto x){return pow(x,1./x);}

The second line defines an anonymous lambda function. It can be used by assigning it to a function pointer and calling it, or just calling it directly.

Try it online

Java 8, 18 bytes

n->Math.pow(n,1/n)

Java isn't in last place?!?!

Test with the following:

import java.lang.Math;

public class Main {
  public static void main (String[] args) {
    Test test = n->Math.pow(n,1/n);
    System.out.println(test.xthRoot(6.0));
  }
}

interface Test {
  double xthRoot(double x);
}

Japt, 3 bytes

UqU

Test it online!

Very simple: U is the input integer, and q is the root function on numbers.

JavaScript ES6, 18 bytes

n=>Math.pow(n,1/n)

TI-BASIC, 3 bytes

Ans×√Ans

TI-BASIC uses tokens, so Ans and ×√ are both one byte.

Explanation

Ans is the easiest way to give input; it is the result of the last expression. ×√ is a function for the x'th root of x, so for example 5×√32 is 2.

Pylons, 5 bytes.

ideAe

How it works.

i # Get command line input.
d # Duplicate the top of the stack.
e # Raise the top of the stack to the power of the  second to the top element of the stack.
A # Push -1 to the stack (pre initialized variable).
e # Raise the top of the stack to the power of the second to the top element of the stack.
  # Implicitly print the stack.

Codename Dragon, 16 bytes

a=<>;dispa^(1/a)

I'm abusing the lack of a syntax error.

Ungolfed:

disp((a=<>)^(1/a))

This is a simple program that takes input through <>.

You can find an interpreter here, no github site yet.

Perl 5, 10 bytes

9 bytes plus 1 for -p

$_**=1/$_

Jelly, 2 bytes

Try it online!

How it works

*İ    Main link. Input: n

 İ    Inverse; yield 1÷n.
*     Power (fork); compute n ** (1÷n).

Python 3, 17 bytes

lambda x:x**(1/x)

Self-explanatory

Seriously, 5 bytes

,;ì@^

Try it online!

Explanation:

,;ì@^
,;     input, dupe
  ì@   1/x, swap
    ^  pow