| Bytes | Lang | Time | Link |
|---|---|---|---|
| 029 | Python3 | 160614T102218Z | george |
| 028 | Microscript II | 220303T203224Z | SuperJed |
| 116 | ForceLang | 160614T212655Z | SuperJed |
| 026 | Math++ | 220303T192519Z | SuperJed |
| 039 | Forth gforth | 190408T193147Z | reffu |
| 024 | Java JDK | 190408T095729Z | Olivier |
| 012 | TIBASIC | 170630T225321Z | Scott Mi |
| 024 | Noether | 170609T222915Z | Beta Dec |
| 012 | Actually | 160621T023935Z | user4594 |
| 045 | PHP | 160614T121258Z | Xanderha |
| 021 | dc | 160615T102944Z | Toby Spe |
| 021 | TIBasic | 160614T220844Z | Timtech |
| 024 | Haskell | 160614T202101Z | Jules |
| 022 | Julia | 160614T163643Z | Dennis |
| 038 | TSQL | 160614T180916Z | Ross Pre |
| 009 | Jelly | 160614T161558Z | Dennis |
| 011 | Dyalog APL | 160614T160046Z | Adá |
| 016 | CJam | 160614T143526Z | A Simmon |
| 024 | Matlab | 160614T142147Z | sintax |
| 039 | Oracle SQL 11.2 | 160614T143029Z | Jeto |
| 034 | PowerShell | 160614T130957Z | AdmBorkB |
| 011 | J | 160614T104958Z | Leaky Nu |
| 024 | Javascript | 160614T085552Z | Bál |
| 017 | Mathematica | 160614T094808Z | Martin E |
| 014 | Pyth | 160614T084759Z | Leaky Nu |
| 009 | MATL | 160614T091927Z | Luis Men |
| 012 | Pyke | 160614T085736Z | Blue |
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/ ;
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
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
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@Σ/
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
T-SQL, 38 bytes
DECLARE @U REAL=2000000, @ REAL=2000000;
PRINT FORMAT((@U+@)/(1+@*@U/9E16),'g')
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
Formula: sum(input) / (1 + (product(input) / 9e16))
Bonus: click here!
MATL, 9 bytes
sG3e8/pQ/
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