g | x | w | all
Bytes Lang Time Link
029Python3160614T102218Zgeorge
028Microscript II220303T203224ZSuperJed
116ForceLang160614T212655ZSuperJed
026Math++220303T192519ZSuperJed
039Forth gforth190408T193147Zreffu
024Java JDK190408T095729ZOlivier
012TIBASIC170630T225321ZScott Mi
024Noether170609T222915ZBeta Dec
012Actually160621T023935Zuser4594
045PHP160614T121258ZXanderha
021dc160615T102944ZToby Spe
021TIBasic160614T220844ZTimtech
024Haskell160614T202101ZJules
022Julia160614T163643ZDennis
038TSQL160614T180916ZRoss Pre
009Jelly160614T161558ZDennis
011Dyalog APL160614T160046ZAdá
016CJam160614T143526ZA Simmon
024Matlab160614T142147Zsintax
039Oracle SQL 11.2160614T143029ZJeto
034PowerShell160614T130957ZAdmBorkB
011J160614T104958ZLeaky Nu
024Javascript160614T085552ZBál
017Mathematica160614T094808ZMartin E
014Pyth160614T084759ZLeaky Nu
009MATL160614T091927ZLuis Men
012Pyke160614T085736ZBlue

Python3, 55 31 29 bytes

Python is awful for getting inputs as each input needs int(input()) but here is my solution anyway:

v,u=int(input()),int(input());print((v+u)/(1+v*u/9e16))

Thanks to @Jakube I don't actually need the whole program, just the function. Hence:

lambda u,v:(v+u)/(1+v*u/9e16)

Rather self explanatory, get inputs, computes. I've used c^2 and simplified that as 9e16 is shorter than (3e8**2).

Python2, 42 bytes

v,u=input(),input();print(v+u)/(1+v*u/9e16)

Thanks to @muddyfish

Microscript II, 28 bytes

1s16Es9*s>Fs>Fs<d*</+s<o<+</

ForceLang, 116 bytes

def r io.readnum()
set s set
s u r
s v r
s w u+v
s c 3e8
s u u.mult v.mult c.pow -2
s u 1+u
io.write w.mult u.pow -1

Math++, 26 bytes

?>u
?>v
(v+u)/(1+v*u/9e16)

Forth (gforth), 39 bytes

: f 2dup + s>f * s>f 9e16 f/ 1e f+ f/ ;

Try it online!

Code Explanation

: f            \ start a new work definition
  2dup +       \ get the sum of u and v
  s>f          \ move to top of floating point stack
  * s>f        \ get the product of u and v and move to top of floating point stack
  9e16 f/      \ divide product by 9e16 (c^2)
  1e f+        \ add 1
  f/           \ divide the sum of u and v by the result
;              \ end word definition

Java (JDK), 24 bytes

u->v->(u+v)/(1+u*v/9e16)

Try it online!

TI-BASIC, 12 bytes

:sum(Ans/(1+prod(Ans/3ᴇ8

Takes input as a list of {U,V} on Ans.

Noether, 24 bytes

Non-competing

I~vI~u+1vu*10 8^3*2^/+/P

Try it here!

Noether seems to be an appropriate language for the challenge given that Emmy Noether pioneered the ideas of symmetry which lead to Einstein's equations (this, E = mc^2 etc.)

Anyway, this is basically a translation of the given equation to reverse polish notation.

Actually, 12 bytes

;8╤3*ì*πu@Σ/

Try it online!

Explanation:

;8╤3*ì*πu@Σ/
;             dupe input
 8╤3*ì*       multiply each element by 1/(3e8)
       πu     product, increment
         @Σ/  sum input, divide sum by product

PHP, 44 45 bytes

Anonymous function, pretty straightforward.

function($v,$u){echo ($v+$u)/(1+$v*$u/9e16);}

dc, 21 bytes

svddlv+rlv*9/I16^/1+/

This assumes that the precision has already been set, e.g. with 20k. Add 3 bytes if you can't make that assumption.

A more accurate version is

svdlv+9I16^*dsc*rlv*lc+/

at 24 bytes.

Both of them are reasonably faithful transcriptions of the formula, with the only notable golfing being the use of 9I16^* for c².

TI-Basic, 21 bytes

Prompt U,V:(U+V)/(1+UV/9ᴇ16

Haskell, 24 bytes

As a single function that can provide either a floating point or fractional number, depending on the context in which it's used...

r u v=(u+v)/(1+v*u/9e16)

Example usage in REPL:

*Main> r 20 30
49.999999999999666
*Main> default (Rational)
*Main> r 20 30 
7500000000000000 % 150000000000001

Julia, 22 bytes

u\v=(u+v)/(1+u*v/9e16)

Try it online!

T-SQL, 38 bytes

DECLARE @U REAL=2000000, @ REAL=2000000;
PRINT FORMAT((@U+@)/(1+@*@U/9E16),'g')

Try it online!

Straightforward formula implementation.

Jelly, 9 bytes

÷3ȷ8P‘÷@S

Try it online! Alternatively, if you prefer fractions, you can execute the same code with M.

How it works

÷3ȷ8P‘÷@S  Main link. Argument: [u, v]

÷3ȷ8       Divide u and v by 3e8.
    P      Take the product of the quotients, yielding uv ÷ 9e16.
     ‘     Increment, yielding 1 + uv ÷ 9e16.
        S  Sum; yield u + v.
      ÷@   Divide the result to the right by the result to the left.

Dyalog APL, 11 bytes

+÷1+9E16÷⍨×

The fraction of the sum and [the increment of the divides of ninety quadrillion and the product]:

┌─┼───┐         
+ ÷ ┌─┼──────┐  
    1 + ┌────┼──┐
        9E16 ÷⍨ ×
               

÷⍨ is "divides", as in "ninety quadrillion divides n" i.e equivalent to n divided by ninety quadrillion.

CJam, 16 Bytes

q~_:+\:*9.e16/)/

I'm still sure there are bytes to be saved here

Matlab, 24 bytes

@(u,v)(u+v)/(1+v*u/9e16)

Anonymous function that takes two inputs. Nothing fancy, just submitted for completeness.

Oracle SQL 11.2, 39 bytes

SELECT (:v+:u)/(1+:v*:u/9e16)FROM DUAL;

PowerShell, 34 bytes

param($u,$v)($u+$v)/(1+$v*$u/9e16)

Extremely straightforward implementation. No hope of catching up with anyone, though, thanks to the 6 $ required.

J, 13 11 bytes

+%1+9e16%~*

Usage

>> f =: +%1+9e16%~*
>> 5e7 f 6e7
<< 1.06452e8

Where >> is STDIN and << is STDOUT.

Javascript 24 bytes

Shaved off 4 bytes thanks to @LeakyNun

v=>u=>(v+u)/(1+v*u/9e16)

Pretty straightforward

Mathematica, 17 bytes

+##/(1+##/9*^16)&

An unnamed function taking two integers and returning an exact fraction.

Explanation

This uses two nice tricks with the argument sequence ##, which allows me to avoid referencing the individual arguments u and v separately. ## expands to a sequence of all arguments, which is sort of an "unwrapped list". Here is a simple example:

{x, ##, y}&[u, v]

gives

{x, u, v, y}

The same works inside arbitrary functions (since {...} is just shorthand for List[...]):

f[x, ##, y]&[u, v]

gives

f[x, u, v, y]

Now we can also hand ## to operators which will first treat them as a single operand as far as the operator is concerned. Then the operator will be expanded to its full form f[...], and only then is the sequence expanded. In this case +## is Plus[##] which is Plus[u, v], i.e. the numerator we want.

In the denominator on the other hand, ## appears as the left-hand operator of /. The reason this multiplies u and v is rather subtle. / is implemented in terms of Times:

FullForm[a/b]
(* Times[a, Power[b, -1]] *)

So when a is ##, it gets expanded afterwards and we end up with

Times[u, v, Power[9*^16, -1]]

Here, *^ is just Mathematica's operator for scientific notation.

Pyth, 14 bytes

csQhc*FQ*9^T16

Test suite.

Formula: sum(input) / (1 + (product(input) / 9e16))

Bonus: click here!

MATL, 9 bytes

sG3e8/pQ/

Try it online!

s      % Take array [u, v] implicitly. Compute its sum: u+v
G      % Push [u, v] again
3e8    % Push 3e8
/      % Divide. Gives [u/c, v/c]
p      % Product of array. Gives u*v/c^2
Q      % Add 1
/      % Divide. Display implicitly

Pyke, 12 bytes

sQB9T16^*/h/

Try it here!