[Question]
  [
## Background
Given a triangle \$ABC\$, extend its three sides by the opposite side length, as shown in the figure below. Then the six points surprisingly lie on a circle called the [**Conway circle**](https://mathworld.wolfram.com/ConwayCircle.html), whose center coincides with the incenter (the center of [incircle](https://mathworld.wolfram.com/Incircle.html), the circle that is tangent to the three sides from the inside).
[![enter image description here](https://i.stack.imgur.com/Ce0wV.gif)](https://i.stack.imgur.com/Ce0wV.gif)
## Task
Given three side lengths \$a,b,c\$ of the triangle \$ABC\$, calculate the perimeter of the hexagon \$A\_b B\_a B\_c C\_b C\_a A\_c\$ (formed by the six points on the Conway circle).
The answer must be within `1e-6` relative error from the expected. You can assume the side lengths form a valid non-degenerate triangle.
The shortest code in bytes wins.
## Test cases
```
a   b   c         ans
---------------------
1   1   1    9.000000
2   2   3   20.399495
3   4   5   35.293155
6   7   12  65.799785
2.3 4.5 6.7 31.449770
```
  
[Answer]
# [Python 3](https://docs.python.org/3/), ~~89 87 69~~ 68 bytes
*Thanks @xnor for finding a shorter expression, saving 1 byte!*
```
f=lambda a,b,c,n=3:n and(a+b+c)*(c*c/a/b-a/b-b/a+2)**.5+f(b,c,a,n-1)
```
[Try it online!](https://tio.run/##NU3LboMwELz7K1Y52TwcwBjqqOmPVD2sDVaRiEHGlwjx7dSO0pVmV7Mzs7s@w@/ixHna@4wPPSBgoQtTuLu4OUA3UMx1blhGTWaueNVlgr5i3rAs4zK3NNmxcGXNzumxLj7A9twIsYuHeXIjTC4t@BaGyd0IvB@g2@AOD1ypnRcMxcvLt3WeAmUs2nyULX2ZEzWL96MJcYl6o76MefZZj2UXtdVPLlB72fEoYNepmQPKL9j9Ad/7O3r8XNhZA8A/QPHqVaSJJEGkWXGhVKskSayNkEmRvFGilpJ0kfXpQgx0kvdK9R@SNFxAyyV0vAdR87ZVfV/9AQ "Python 3 – Try It Online")
A recursive function, takes in 3 sides of the triangle as input.
Recursion is used to repeats the function 3 times, each time with the positions of `a,b,c` swapped in order to calculate each of the 3 summands in the formula below.
### How
We can see that each side of the hexagon is the base of an isosceles triangle, whose vertex angle is an angle of the original triangle. For example:
* \$C\_aC\_b\$ is the base of \$CC\_aC\_b\$ - an isosceles triangle with leg \$c\$ and vertex angle \$\widehat{C}\$.
* \$A\_bB\_a\$ is the base of \$CA\_bB\_a\$ - an isosceles triangle with leg \$a+b\$ and vertex angle \$\widehat{C}\$.
Given the leg \$l\$ and vertex angle \$\theta\$ of an isosleces triangle, the base is calculated as:
$$l\sqrt{2-2\cos{\theta}}$$
Consider 2 opposites side of the hexagon, says \$C\_aC\_b\$ and \$A\_bB\_a\$. Since their corresponding triangles have the same vertex angle, their total length is:
$$c\sqrt{2-2\cos{\widehat{C}}}+(a+b)\sqrt{2-2\cos{\widehat{C}}}$$$$=(a+b+c)\sqrt{2-2\cos{\widehat{C}}}$$
Then the perimeter of the hexagon is the sum of 3 opposite pairs:
$$(a+b+c)\left(\sqrt{2-2\cos{\widehat{A}}}+\sqrt{2-2\cos{\widehat{B}}}+\sqrt{2-2\cos{\widehat{C}}}\right)$$
The cosine of an angle can be calculated from the sides of the triangle:
$$2-2\cos{\widehat{C}}=\frac{c^2-(a-b)^2}{ab}$$
Thus, the final formula for the hexagon's perimeter is:
$$(a+b+c)\left(\sqrt{\frac{a^2-(b-c)^2}{bc}}+\sqrt{\frac{b^2-(a-c)^2}{ac}}+\sqrt{\frac{c^2-(a-b)^2}{ab}}\right)$$
[Answer]
# [Python 3](https://docs.python.org/3/), 64 bytes
```
lambda*t:eval("+((-(%s-%s)**2+%s**2)/%s/%s)**.5"*3%(t*5))*sum(t)
```
[Try it online!](https://tio.run/##NUzbaoQwEH3PVwyCkGQ1q8aYZun2R9o@RFepoFGStLCI324TaQfODOc269N/LYYfw/3jmPTcPjT1t/5HTzi5YJzj1OWpI5RWl9SFTa6pu54CEwnlKfZUEELd94w9OcZ5XawH93QIDYuFaTQ9jCYKzPnHaG4IQGdt1mXaOLjDrFc8TIv22Zllbp1GjwkJMRvsAZ/hSLvF2r7zQdStwzYPffJa9nkTvNWOxuMh2fSewdbG1e2Qv8Fmd3jf/qr7Z0KOEgD@AYoV56AqkAgeb8G4UrUSKLI6QERHsErxUgjUBCbjh1BoBJNKyReBKsahZgIaJoGXrK6VlMUv "Python 3 – Try It Online")
Uses an adaptation of a formula [by Surculose Sputum](https://codegolf.stackexchange.com/a/203855/20260), written so that the variables `a,b,c` repeat in a cycle when the formula is read left to right.
```
+((-(a-b)**2+c**2)/a/b)**.5+((-(c-a)**2+b**2)/c/a)**.5+((-(b-c)**2+a**2)/b/c)**.5
```
This lets us insert the input values into the formula as literals by string interpolation on the tuple `(a,b,c)` repeated 5 times, and then call `eval` to evaluate the resulting expression.
---
# [Python 3](https://docs.python.org/3/), 76 bytes
```
lambda a,b,c:sum((2-(a*a+b*b+c*c-2*x*x)*x/a/b/c)**.5*(a+b+c)for x in[a,b,c])
```
[Try it online!](https://tio.run/##NY3dboQgFITveYqTvQJU/EXLptsX2e4FsJqa@BegiRvjs1uwLclwMuebgeXlvuapPLrb5zHIUT0lyFjF@mq/R4yLBEsqI0VVpKlOCrrSldA1lalKNaGUcYo9jjTpZgMr9NP9bD/I0Y/LbBzYl0UowKGfWs/Dgln37Kcrgt@vYjlZuMEoF9wNs3TxmWV2GXqHCfEx43GHz3Cwejam1c4vpbLYJL5P3vM2qT1bTD853F02ucewqXDpHZIP2MwO9@2vuj8u5MgB4F8gWHYeVHgTVIaZsVKISnAUXOXFA@GsEGXOOaq9a8ILvlBz1gjRvHFUsBIqxqFmDZQ5qyrRNNkP "Python 3 – Try It Online")
I took [Surculose Sputum's formula and solution](https://codegolf.stackexchange.com/a/203855/20260) and wrote the three summands in a closer-to-symmetric form like:
$$(a+b+c)\sqrt{2-\frac{a^2+b^2-c^2}{ab}}$$
The idea is that we want the summand to be as symmetric in \$a,b,c\$ as possible so that we can iterate a single variable \$x\$ over \$a,b,c\$ to produce each summand.
To this end, we write the core term $$\frac{a^2+b^2-c^2}{ab}$$ as the somewhat clunky
$$\frac{a^2+b^2+c^2-2c^2}{abc}\cdot c$$
so that we can write it in this symmetric form:
$$\frac{a^2+b^2+c^2-2x^2}{abc}\cdot x$$
Substituting \$x=a\$, \$x=b\$, and \$x=c\$ gives the three respective summands.
Perhaps there's a better way to put this fraction into a near-symmetric form than doing so for the numerator and denominator individually. We can split it up as $$a/b+b/a-c^2/(ab)$$ 
but I don't see where to go from there.
[Answer]
# [dc](https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html), 68 bytes
```
9k?scsbsa[lad*lblc-d*-lblc*/v]dsFxlalbsasblFxlalcsasclFx++lalblc++*p
```
[Try it online!](https://tio.run/##S0n@/98y2744uTipODE6JzFFKycpJ1k3RUsXRGvpl8WmFLtV5CTmAKWLk3LAzGQgMxnI1NYGiecka2trFfz/b6RnrGCiZ6pgpmcOAA "dc – Try It Online")
[Or check out all the test cases.](https://tio.run/##NY1NCsJADIX3OcWjuOrQlo5aEURXdusBxMU0M1gxWun404V3rzOiBJIvLy9JY3w7srljfeu7Y28uWK2S7a5OxuV549k33uzF2FQa4cymWaxp8TxYXw9iJIx9I1/kgBxQqagLK5XexnCJiNtLZ/FQA34/6NWexKF3xkJOV0eA7UICHLcdkkkUE7xhGXnxX4qmqxtLhCANjSlNMcOcKixQatJ5aPM5qnxBHw)
This is a direct implementation of [Surculose Sputum's answer (the original iterative one)](https://codegolf.stackexchange.com/a/203855/59825), which is the type of formula that dc ("desk calculator") can be pretty good for!
**Explanation:**
```
9k     Set precision to 9 decimal places.
?      Read input line (push a, b, and c on the stack).
scsbsa Save the input numbers in registers a, b, and c.
[      Start a macro.
       This macro takes the values in registers a, b, and c,
       and computes the first square root in the formula,
       leaving that result on the stack, as follows:
  lad*   Push a^2.
  lblc-  Push b-c.
  d*     Replace b-c at the top of the stack with (b-c)^2.
  -      Replace the top 2 items on the stack with a^2-(b-c)^2.
  lblc*  Push b*c.
  /      Divide to compute the formula under the radical sign.
  v      Compute the square root.
]      End of macro.
dsFx       Save macro for later use under the name F, and also run it now.
lalbsasb   Swap registers a and b.
lFx        Call macro F to compute the second square root.
lalcsasc   Swap registers a and c.
lFx        Call macro F to compute the third square root.
++         Add the three square roots.
lalblc++   Compute a+b+c.
*          Multiply a+b+c by the sum of the square roots.
p          Print the result.
```
[Answer]
# [Desmos](https://www.desmos.com/), 1455 bytes
[![enter image description here](https://i.stack.imgur.com/SNgtbm.png)](https://i.stack.imgur.com/SNgtb.png)
[Try it online!](https://www.desmos.com/calculator/8fi6eyddzx) Link is Desmos. Interactive! Click and drag triangle points.
Obviously this answer is not going for shortest, I just wanted to show off an interactive demo. The bytes score was calculated by taking the length of concatenating all of the LaTeX from each formula in the calculator used to compute the perimeter (formulas used for interactive components were not counted).
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 15 bytes
*Port of [Surculose Seputum's Python solution](https://codegolf.stackexchange.com/a/203855/6484)*
```
œεnÆy¦P/}ÌtO*O;
```
[Try it online!](https://tio.run/##yy9OTMpM/f//6ORzW/MOt1UeWhagX3u4p8Rfy9/6//9oIx0FIDKOBQA "05AB1E – Try It Online")
[Answer]
# [Io](http://iolanguage.org/), 104 bytes
Port of Surculose Sputum's answer.
```
f :=method(a,b,c,n,if(n!=0,(a+b+c)*(c*c/a/b-a/b-b/a+2)**.5+f(b,c,a,n-1),n))
g :=method(a,b,c,f(a,b,c,3))
```
[Try it online!](https://tio.run/##XYxRCsIwEET/e4r6t5tMU5PaFoQeJokmFjQV6f1jCiJVlmXhzduZl5xDfZ4e1/W2XMjCwSNhDpQO0xFkpZOeBXnhW9u6ZlvXWmlYCNXLQJtvkRrNSMxV/O8Kn9sx50gaZbh@vua03lMVycCUaAc6nNDvwYAR2vz8qCKpHoMavzi/AQ "Io – Try It Online")
[Answer]
# Wolfram Mathematica, 99 bytes
```
(#1+#2+#3)(Sqrt[(#1^2-(#2-#3)^2)/#2/#3]+Sqrt[(#2^2-(#1-#3)^2)/#1/#3]+Sqrt[(#3^2-(#1-#2)^2)/#1/#2])&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n277X0PZUFvZSFvZWFMjuLCoJBrIjzPS1VA20gUKxRlp6isb6Ssbx2pDJY3AkoZwSUNkSWOYpBFc0ihWU@1/QFFmXomCQ3q0oQ4QxnLB@cZ6OiY6pkgCpno6hkY6hsax//8DAA)
I am pretty sure that this code can be improved. But I wasn't able to wrap my head around it. So I just post this in the hope of learning something new from more experienced users.
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), ~~45~~ 44 bytes
```
+/×{+/{a b c←⍵⋄√(a×a÷b×c)+2-(⊢+÷)b÷c}⌽∘⍵¨⍳3}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/X1v/8PRqbf3qRIUkheRHbRMe9W591N3yqGOWRuLh6YmHtycdnp6sqW2kq/Goa5H24e2aSYe3J9c@6tn7qGMGUOmhFY96NxvX/k8D6@x71NV8aL3xo7aJj/qmBgc5A8kQD8/g/2kKhiDIlaZgBITGQNpYwUTBFEibKZgrGBqBJPSAQnqmCmZ65gA "APL (Dyalog Extended) – Try It Online")
Bubbler has a [27 byte solution](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfmvrX94erW2/qOOWUYah6frH97@qHfFo96tunqHp4NZS3QOrdDV1zR51LvF8FHPXqBULZe2PlgXkK0B1KcLVNm1@PB07cPbgQYAdQB5mka6@sha/kO0POpaRJSOrkX/0x61TXjU2/eoq/nQeuNHbRMf9U0NDnIGkiEensH/0xSMFUwUTAE) with a complete train, but I think it deserves it's own answer.
This is a port of Surculose Suptum's formula, simplified by Kevin Cruijssen.
-1 byte from dzaima.
[Answer]
# Java 8, 104 bytes
```
(a,b,c)->{double r=0,t,n=3;for(;n-->0;t=a,a=b,b=c,c=t)r+=(a+b+c)*Math.sqrt(c*c/a/b-a/b-b/a+2);return r;}
```
Iterative port of [*@SurculoseSputum*'s Python answer](https://codegolf.stackexchange.com/a/203855/52210), so make sure to upvote him!
[Try it online.](https://tio.run/##fVFBbsIwELzzilVONtkYCAWkRuYHcOFY9bA2pg0FhzoLVYV4e@pAqsKlsrwer8bamfGWTpRt1x@N3VFdw4JKf@4BlJ5d2JB1sGyvAOvqaHYOrOgAYQfML7CyiMxLL5YleNCNIDRoZTY/d4ygh8jo9bjYVEEUPsvmw4I1IWmDRlu0mmVItaDUpFb2F8Tvqv4MLGzfDmhgsnabAaW5LILjY/AQiktTtDMPcURpoWbieJyqcg37aEasOJT@7eUVSN6csKtZjDCuq@CukWOO4/vGGJ9wct@Y4gxH@cMbFUlqglM1@/N@L@DK@iewm6DVd81ur6ojq0PUyjsfA0gwiSG01abJMySpd1/X3xFSeWW7bLuxl@YH)
**Explanation:**
```
(a,b,c)->{                  // Method with double as all three parameters and return-type
  double r=0,               // Result-sum, starting at 0
         t,                 // Temp-double
  n=3;for(;n-->0            // Loop 3 times:
          ;                 //   After every iteration:
           t=a,a=b,b=c,c=t) //    Rotate `a,b,c` to `b,c,a` respectively
    r+=                     //  Increase the result-sum by:
      (a+b+c)               //   The sum of `a,b,c`
      *Math.sqrt(           //   Multiplied by the square-root of:
         c*c                //    `c` squared
            /a/b            //    Divided by both `a` and `b`
         -a/b               //    Minus `a` divided by `b`
         -b/a               //    as well as `b` divided by `a`
         +2);               //    Plus 2
  return r;}                //  After the loop, return the result-sum
```
Or as a single formula:
$$p = (a+b+c)\sqrt{c^2\div a\div b-\frac{a}{b}-\frac{b}{a}+2}$$
$$+(a+b+c)\sqrt{a^2\div b\div c-\frac{b}{c}-\frac{c}{b}+2}$$
$$+(a+b+c)\sqrt{b^2\div c\div a-\frac{c}{a}-\frac{a}{c}+2}$$
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 24 bytes
```
Ｉ×ΣθΣＥθ₂⁻²∕×ι⁻ΣＸθ²⊗×ιιΠθ
```
[Try it online!](https://tio.run/##RY29DsIwDIRfJaMjhaXQiZGulSJgqzqEJBKW0pr8lcdPEwHCi093/s76qYIm5UqRAdcEFxUT3HGxEW55Ac8Fa3tUL/BV@qyCvRIlGHHNETrBBtzQ2C@Dgn2CBkl629CwjteagfLDWfM/RM6bLwOZrFN99ZtzKdN0FOwkWD/P5bC5HQ "Charcoal – Try It Online") Link is to verbose version of code. Port of @xnor's formula. Explanation:
```
     Ｅθ                     Map over sides
              ΣＸθ²          Sum of sides squared
             ⁻              Subtract
                   ×ιι      Square of current side
                  ⊗         Doubled
           ×ι               Multiply by current side
          ∕           Πθ    Divide by product of sides
        ⁻²                  Subtract from 2
       ₂                    Square root
    Σ                       Take the sum
 ×                          Multiplied by
  Σθ                        Sum of sides
Ｉ                           Cast to string for implicit print
```
Unfortunately `SquareRoot` doesn't seem to vectorise so I have to do that inside the `Map` which makes it marginally less efficient.
[Answer]
# JavaScript (ES7), 62 bytes
Now a port of [Surculose Sputum's answer](https://codegolf.stackexchange.com/a/203855/58563).
```
f=(a,b,c,n)=>n^3&&(a+b+c)*(c*c/a/b-a/b-b/a+2)**.5+f(b,c,a,-~n)
```
[Try it online!](https://tio.run/##bc5NDoIwEAXgvaeYlWmhTKE/1C5w6TFMSgWDMa1RYlx5dbS4Ep1k3mq@vDm5u7v563AZixAP3TT1DXGsZZ4F2mzDXq7XxOVt7mlGfOa5422RtuUuFzTLUOc9SeeOFc9AJx/DLZ47PMcj6UnFAOATABTHuBse3YHUlALnABbLeVbfSiQwh/yjRInSWmX1QskEVAr9R0mNwspKL1WdgJk/FL@q1misNZulEvhuU6gZ1Gh@uypUyhpTTi8 "JavaScript (Node.js) – Try It Online")
]