g | x | w | all
Bytes Lang Time Link
040AWK250910T142308Zxrs
043JavaScript230305T003226ZEzioMerc
014TIBasic230304T151850ZYouserna
018Pip230304T154759ZThe Thon
nan230304T154026ZThe Thon
010Pyt230304T153045ZKip the
038Arturo230304T031914Zchunes
027Raku220916T191201ZSean
nanFig220915T210346ZSeggan
051C clang220728T090414ZNoodle9
050Knight220803T202418Z97.100.9
033x86 32bit machine code220731T095645Zm90
035Factor + math.unicode220728T024152Zchunes
043JavaScript220730T214305Znoodle p
052C# Visual C# Interactive Compiler220730T010913ZGymhgy
1716J220728T020507ZJonah
013Pyth220728T235006Zmath jun
037Perl 5 MListUtil=product220728T221749ZXcali
044Ruby220728T212651ZLevel Ri
009MathGolf220728T090908ZKevin Cr
013K ngn/k220728T011656ZBubbler
014BQN220728T085828ZDominic
036Desmos220728T084956ZAiden Ch
015Burlesque220728T083306ZDeathInc
038Haskell220728T075737Zalephalp
028R220728T062547Zpajonk
00805AB1E220728T065004ZKevin Cr
011Charcoal220728T060943ZNeil
025lin220728T054709ZMama Fun
020Wolfram Language Mathematica220728T012858Zalephalp
015Dyalog APL220728T032401Zrabbitgr
032Python NumPy220728T031059Zloopy wa
006Jelly220728T022615Zemanresu
008Vyxal220728T004413Zlyxal
047Python220728T010648ZnaffetS

AWK, 40 bytes

$0=(4*$1^2*$2^2-($1^2+$2^2-$3^2)^2)^.5/4

Attempt This Online!

JavaScript, 43 bytes

Tried to beat 43 bytes but got a different form :)

$$ \sqrt{s(s-a)(s-b)(s-c)} $$

where \$s=\frac{a + b + c}{2}\$ is equal to:

$$ \frac{1}{4}\sqrt{4abd - d^2} $$

where \$d=(a + b)^2 - c^2\$

(a,b,c)=>(4*a*b*(d=(a+b)**2-c*c)-d*d)**.5/4

Try it:

f=(a,b,c)=>(4*a*b*(d=(a+b)**2-c*c)-d*d)**.5/4

;[
  [1, 1, 1], // 0.4330
  [3, 4, 5], // 6.0000
  [9, 3, 7], // 8.7856
].forEach(([a,b,c])=>console.log(f(a,b,c)))

TI-Basic, 14 bytes

√(sum(Ans)/2prod(sum(Ans)/2-Ans

or

.25√(sum(Ans)prod(sum(Ans)-2Ans

Takes input in Ans as a list.

Pip, 18 bytes

RT$*Y($+YgPE0)/2-y

Attempt This Online!

Port of Kevin Cruijssen's 05AB1E answer.

Explanation

RT$*Y($+YgPE0)/2-y  # Input on command line
         gPE0       # Prepend 0 to the input
      $+Y           # Sum and store in y
     (       )/2    # Halve
                -y  # And subtract y
  $*Y               # Get the product
RT                  # And square root
                    # Implicit output

Thunno, \$ 10 \log_{256}(96) \approx \$ 8.23 bytes

0ZNDS2/_Pt

Attempt This Online!

Port of Kevin Cruijssen's 05AB1E answer.

Explanation

0ZNDS2/_Pt  # Implicit input
0ZN         # Prepend a 0
   DS       # Duplicate and sum
     2/     # Halve
       _    # Subtract the list
        P   # Product
         t  # Square root
            # Implicit output

Pyt, 10 bytes

ĐƩᵮ₂Đ↔-Π*√

Try it online!

Straightforward implementation of Heron's formula

Đ                 implicit input; Đuplicate
 Ʃ                Ʃum
  ᵮ₂              cast to ᵮloat; halve
    Đ             Đuplicate
     ↔            flip stack
      -           subtract
       Π          take product of list
        *         multiply by s
         √        square root; implicit print

Arturo, 38 bytes

$[a][d://∑a 2sqrt d*∏map a=>[d-&]]

Try it

Raku, 27 bytes

{sqrt [*] @_.sum/2 X-0,|@_}

Try it online!

@_ is the array of arguments to the function: a, b, and c. @_.sum / 2 is half the sum of the arguments, what the problem statement calls s. X- subtracts the numbers 0 and |@_, the flattened arguments, from that number, producing the numbers s, s - a, s - b, and s - c. Then [*] multiplies them together and sqrt takes the square root.

Fig, \$9\log_{256}(96)\approx\$ 7.408 bytes

mqr-J0xHS

Try it online!

Jelly beats me... again. Takes input as a list of the side lengths.

mqr-J0xHS
        S # Sum the lengths
       H  # Halve it
   -      # That ^ minus...
      x   # The input
    J0    # With a 0 prepended
  r       # Product
mq        # Square root

C (clang), 59 51 bytes

#define f(a,b,c)sqrt(4*a*a*b*b-(c=a*a+b*b-c*c)*c)/4

Try it online!

Saved 8 bytes thanks to jdt!!!

Knight, 50 bytes

;=x=s-**4=a^P2=b^P2^+a-b^P2 2;W>x=x/+x/s x 2xO/x 4

Try it online!

This is the elusive "triple Heron" answer:

(It doesn't work in the TIO because it hasn't implemented the no-op.) It turns out I just misread the spec.

Here's the expanded code:

;=a^P2
;=b^P2
;=c^P2
;=s (-(*(*4a) b)(^(+a(-b c)) 2))
;=x s
;WHILE >x (=x(/+x(/s x) 2)) 
  x
OUTPUT /x 4

x86 32-bit machine code, 33 bytes

6A 03 59 D9 E8 D9 EE DC E1 DA 04 8C E2 FB D9 FD 6A 03 59 D9 C0 DA 2C 8C DE CA E2 F7 DE C9 D9 FA C3

Try it online!

Uses the cdecl calling convention, taking three 32-bit integers on the stack and returning a value on the FPU register stack.

In assembly:

f:  push 3; pop ecx     # Set ECX to 3.
    fld1                # Push 1 onto the FPU register stack.
    fldz                # Push 0 onto the FPU register stack.
    fsubr st(1), st(0)  # Change the 1 to 0-1=-1.
l0: fiadd DWORD PTR [esp+4*ecx] # Add an argument to the top value.
    loop l0                     # Loop 3 times, making the top value a+b+c.
    fscale              # Multiply the top value by 2^(value below)=2^-1=1/2.
    push 3; pop ecx     # Set ECX to 3 again.
l1: fld st(0)                   # Duplicate the top value, which is s.
    fisubr DWORD PTR [esp+4*ecx]# Change the top value to a-s or b-s or c-s.
    fmulp st(2), st(0)          # Multiply the third-from-top value
                                # (which was -1) by that and pop it.
    loop l1                     # Loop 3 times.
                        # The FPU register stack is now -(a-s)(b-s)(c-s), s.
    fmulp st(1), st(0)  # Multiply those values and pop, leaving the product.
    fsqrt               # Take the square root.
    ret                 # Return.

I had another version using SIMD instructions to do multiple calculations at once, but it was longer, at 48 bytes:

5A 6A 00 89 E1 F8 C5 F8 5B 01 0F 59 C0 C5 FB 7C C8 C5 F3 7C C9 F3 0F 11 09 D9 01 F5 72 EC D8 C0 D9 C1 DE CA DE E9 D9 FA 58 6A 04 DA 31 58 FF E2
f:  pop edx
    push 0
    mov ecx, esp
    clc
    vcvtdq2ps xmm0, [ecx]
r:  mulps xmm0, xmm0
    vhaddps xmm1, xmm0, xmm0
    vhaddps xmm1, xmm1, xmm1
    movss [ecx], xmm1
    fld DWORD PTR [ecx]
    cmc
    jc r
    fadd st(0), st(0)
    fld st(1)
    fmulp st(2), st(0)
    fsubp
    fsqrt
    pop eax
    push 4
    fidiv DWORD PTR [ecx]
    pop eax
    jmp edx

Factor + math.unicode, 36 35 bytes

[ dup Σ 2 / dup rot n-v Π * √ ]

Try it online!

-1 byte because I remembered is 1 byte shorter than sqrt.

        ! { 3 4 5 }
dup     ! { 3 4 5 } { 3 4 5 }
Σ       ! { 3 4 5 } 12
2       ! { 3 4 5 } 12 2
/       ! { 3 4 5 } 6
dup     ! { 3 4 5 } 6 6
rot     ! 6 6 { 3 4 5 }
n-v     ! 6 { 3 2 1 }
Π       ! 6 6
*       ! 36
√       ! 6.0

JavaScript, 43 bytes (@Steffan)

Ported from Steffan's Python answer by him:

f=
(a,b,c)=>(4*a*a*b*b-(a*a+b*b-c*c)**2)**.5/4

console.log(f(1, 1, 1), 0.4330)
console.log(f(3, 4, 5), 6.0000)
console.log(f(9, 3, 7), 8.7856)

JavaScript, 46 bytes (me)

Boring answer :/ but couldn't think of anything better. \$A=\sqrt{s(s-a)(s-b)(s-c)}\textrm{, where } s=\frac{a+b+c}{2}\$.

f=
(a,b,c,s=(a+b+c)/2)=>(s*(s-a)*(s-b)*(s-c))**.5

console.log(f(1, 1, 1), 0.4330)
console.log(f(3, 4, 5), 6.0000)
console.log(f(9, 3, 7), 8.7856)

C# (Visual C# Interactive Compiler), 52 bytes

(a,b,c)=>Math.Sqrt((a-(a=(a+b+c)/2))*(b-a)*(c-a)*-a)

Try it online!

J, 17 16 bytes

2%:[:*/0&,-+/%2:

Try it online!

-1 thanks to Bubbler's K approach

The interesting insight (obvious when spelled out but not always when searching for a golf) is: When taking the product of an even number of elements, it is equivalent to taking the product of their negatives.

original, 17 bytes

2%:[:*/+/-:@-0,+:

Try it online!

Pyth, 14 13 bytes

@*F-LcsQ2+QZ2

Try it online!

Perl 5 -MList::Util=product,sum -pal, 37 bytes

$_=sqrt product map{sum(@F)/2-$_}0,@F

Try it online!

Ruby, 44 bytes

->a,b,c{(4*a*a*b*b-(a*a+b*b-c*c)**2)**0.5/4}

Try it online!

Ruby, 45 bytes

->a{a.inject(s=a.sum/2.0){|p,i|p*(s-i)}**0.5}

Try it online!

MathGolf, 9 bytes

0Γ_Σ½-ε*√

I/O as decimals.

Try it online.

Explanation:

Similar approach as my 05AB1E answer, except with subtract instead of absolute difference, since with four values the negatives balance themselves out anyway.

0          # Push a 0
 Γ         # Wrap the top four items into a list (using the three implicit inputs)
  _        # Duplicate this list
   Σ       # Sum
    ½      # Halve
     -     # Subtract it from each value in the list
      ε*   # Product: reduce by multiplication
        √  # Square root
           # (after which the entire stack is output implicitly as result)

K (ngn/k), 13 bytes

{%*/x-/x%2}0,

Try it online!

There is! -2 bytes thanks to @ovs.

{%*/x-/x%2}0,  x: a length-3 array containing the three sides
           0,  prepend a 0
       x%2     (0; a/2; b/2; c/2)
    x-/        (0 a b c) - a/2 - b/2 - c/2
 %*/           sqrt(product of the above)

K (ngn/k), 16 bytes

{%-s*/x-s:+/x%2}

Try it online!

There must be a shorter way..?

{%-s*/x-s:+/x%2}  x: a length-3 array containing the three sides
        s:+/x%2   s: half sum of x
      x-          (a-s; b-s; c-s)
  -s*/            -s * (a-s) * (b-s) * (c-s)
 %                sqrt

BQN, 14 bytes

√·×´+´∘÷⟜2-0⊸∾

Try it at BQN REPL

            0⊸∾     # each element of the argument, prepended by a zero
           -        # subtracted from
    +´∘             # the sum of
       ÷⟜2          # each element of the argument divided by 2
  ×´                # get the product (fold-multiply),
√·                  # and take the square root

Desmos, 36 bytes

f(l)=(total(ll)^2-2l^4.total)^{.5}/4

Input is a list of the three side lengths.

Try It On Desmos!

Port of Steffan's Python answer also gives 36 bytes:

f(a,b,c)=(4aabb-(aa+bb-cc)^2)^{.5}/4

Burlesque, 15 bytes

0+]J++2./?-pdr@

Try it online!

A port of Kevin Cruijssen's 05AB1E answer

0+] # Prepend 0
J   # Duplicate
++  # Sum
2./ # Halve
?-  # Difference with original
pd  # Product
r@  # Square root

Haskell, 38 bytes

sqrt.product.(map=<<(-).(/2).sum).(0:)

Attempt This Online!


Haskell, 38 bytes

sqrt.product.(map.(-).(/2).sum<*>(0:))

Attempt This Online!

With the help of pointfree.io.

R, 30 28 bytes

\(x)prod(sum(x)/2-c(0,x))^.5

Attempt This Online!

Inspired by @Kevin Cruijssen's 05AB1E answer.


R, 32 30 bytes

Edit: -2 bytes by looking at @loopywalt's answer.

\(x)((x%*%x)^2-2*x^3%*%x)^.5/4

Attempt This Online!

Takes input as a vector of sides.

Uses the formula $$ A= \frac{1}{4}\sqrt{(a^2+b^2+c^2)^2-2(a^4+b^4+c^4)}$$

with observation that sum of squares of elements from x is a dot product of x with itself. So with \$x=[a,b,c]\$ and \$y=[a^3,b^3,c^3]\$:

$$ A= \frac{1}{4}\sqrt{(x \cdot x)^2-2(y\cdot x)}$$

05AB1E, 8 bytes

0šDO;αPt

Try it online or verify all test cases.

Explanation:

Uses the default formula:

$$s=\frac{0+a+b+c}{2}$$ $$ A=\sqrt{abs(0-s)\times abs(a-s)\times abs(b-s)\times abs(c-s)}$$

0š        # Prepend a 0 in front of the (implicit) input-triplet
  D       # Duplicate the list
   O      # Sum the copy
    ;     # Halve the sum
     α    # Get the absolute difference between this sum and the values in the list
      P   # Take the product
       t  # Square root
          # (which is output implicitly as result)

Charcoal, 11 bytes

I₂Π⁻⊘Σθ⊞Oθ⁰

Try it online! Link is to verbose version of code. Takes input as an array. Explanation:

      θ     Input array
     Σ      Summed
    ⊘       Halved
   ⁻        Vectorised subtract
          ⁰ Literal integer `0`
       ⊞O   Appended to
         θ  Input array
  Π         Take the product
 ₂          Take the square root
I           Cast to string
            Implicitly print

lin, 25 bytes

.+ \+ `/2/.~0' - \* `/.5^

Try it here!

For testing purposes (use -i flag if running locally):

[1 1 1] ;
.+ \+ `/2/.~0' - \* `/.5^

Explanation

Prettified code:

.+ \+ `/ 2/.~ 0' - \* `/ .5^

Wolfram Language (Mathematica), 20 bytes

N@*Area@*SSSTriangle

Try it online!

Built-in.


Wolfram Language (Mathematica), 22 bytes

((#.#)^2-2#.#^3)^.5/4&

Try it online!

-2 bytes by porting loopy walt's Python answer.

Takes input as a list. Using the formula \$A= \frac{1}{4}\sqrt{(a^2+b^2+c^2)^2-2(a^4+b^4+c^4)}\$.


Wolfram Language (Mathematica), 24 bytes

1##&@@(+##/2-{0,##})^.5&

Try it online!

Based on chyanog's answer to another challenge.

Using the formlula \$A=\sqrt{s(s-a)(s-b)(s-c)}\textrm{, where } s=\frac{a+b+c}{2}\$.

Dyalog APL, 16 15 bytes

-1 thanks to @Bubbler.

.5*⍨0∘,×.-2÷⍨+/

Attempt This Online!

┌──┼───────┐
.5 *⍨  ┌───┼────┐
      0∘, ×.- ┌─┼──┐
              2 ÷⍨ +/

    0∘,          left  argument: input with 0 prepended     0 a b c
          2÷⍨+/  right argument: sum of input divided by 2  (a+b+c)/2 = s
       ×.-       left minus right, then take the product    (0-s)(a-s)(b-s)(c-s)
.5*⍨             square root

(0-s)(a-s)(b-s)(c-s) is equivalent to (s-0)(s-a)(s-b)(s-c) as there is an even number of items being multiplied.

Python NumPy, 32 bytes

lambda v:((v@v-2*v*v)*v@v)**.5/4

Attempt This Online!

Previous Python NumPy, 33 bytes

lambda v:(v@v*v@v-2*v**3@v)**.5/4

Attempt This Online!

Previous Python NumPy, 36 bytes (@alephalpha)

lambda v:(v@v*v@v-2*v**2@v**2)**.5/4

Attempt This Online!

Previous Python NumPy, 37 bytes

lambda v:((v@v)**2-2*v**2@v**2)**.5/4

Attempt This Online!

Expects a numpy vector containing the three side lenghts.

Jelly, 6 bytes

HSạŻP½

Try it online!

Don't ask me why the chaining works...

H      # Half of
 S     # The sum of the input
  ạ    # Absolute difference with
   Ż   # The input, with a 0 prepended
    P½ # Take the square root of the product

Vyxal, 9 8 bytes

∑½₌N-Π*√

Try it Online!

A 7 byter with -r

Outputs as a fraction representation. Try it Online! if you want decimals as output.

Takes the 3 side lengths as a list of numbers.

Quite literal implementation of Heron's formula, with some extra insight from Bubbler's answer.

Explained

∑½₌N-Π*√
∑½       # Half sum of the side lengths
  ₌N-    # Push the half sum negated, as well as each side length minus the half sum
     Π*  # Take the product of the subtracted side lengths and multiply it by the negated half sum
       √ # Take the square root of that

Python, 47 bytes

lambda a,b,c:(4*a*a*b*b-(a*a+b*b-c*c)**2)**.5/4

Attempt This Online!

Classic boring solution. There might be a shorter way to express this formula, but I can't find it.