\[\sqrt{re \cdot re + im \cdot im}\]
Test:
math.abs on complex
Bits:
128 bits
Bits error versus re
Bits error versus im
Time: 5.7 s
Input Error: 13.4
Output Error: 6.4
Log:
Profile: 🕒
\(\begin{cases} -re & \text{when } re \le -1.5511732f+19 \\ \sqrt{{re}^2 + im \cdot im} & \text{when } re \le 7.052067f+15 \\ re + \frac{\frac{1}{2} \cdot im}{\frac{re}{im}} & \text{otherwise} \end{cases}\)

    if re < -1.5511732f+19

    1. Started with
      \[\sqrt{re \cdot re + im \cdot im}\]
      27.4
    2. Applied simplify to get
      \[\color{red}{\sqrt{re \cdot re + im \cdot im}} \leadsto \color{blue}{\sqrt{{re}^2 + im \cdot im}}\]
      27.4
    3. Applied taylor to get
      \[\sqrt{{re}^2 + im \cdot im} \leadsto -1 \cdot re\]
      0
    4. Taylor expanded around -inf to get
      \[\color{red}{-1 \cdot re} \leadsto \color{blue}{-1 \cdot re}\]
      0
    5. Applied simplify to get
      \[\color{red}{-1 \cdot re} \leadsto \color{blue}{-re}\]
      0

    if -1.5511732f+19 < re < 7.052067f+15

    1. Started with
      \[\sqrt{re \cdot re + im \cdot im}\]
      8.9
    2. Applied simplify to get
      \[\color{red}{\sqrt{re \cdot re + im \cdot im}} \leadsto \color{blue}{\sqrt{{re}^2 + im \cdot im}}\]
      8.9

    if 7.052067f+15 < re

    1. Started with
      \[\sqrt{re \cdot re + im \cdot im}\]
      24.0
    2. Applied simplify to get
      \[\color{red}{\sqrt{re \cdot re + im \cdot im}} \leadsto \color{blue}{\sqrt{{re}^2 + im \cdot im}}\]
      24.0
    3. Using strategy rm
      24.0
    4. Applied add-cube-cbrt to get
      \[\color{red}{\sqrt{{re}^2 + im \cdot im}} \leadsto \color{blue}{{\left(\sqrt[3]{\sqrt{{re}^2 + im \cdot im}}\right)}^3}\]
      24.1
    5. Using strategy rm
      24.1
    6. Applied add-sqr-sqrt to get
      \[{\color{red}{\left(\sqrt[3]{\sqrt{{re}^2 + im \cdot im}}\right)}}^3 \leadsto {\color{blue}{\left({\left(\sqrt{\sqrt[3]{\sqrt{{re}^2 + im \cdot im}}}\right)}^2\right)}}^3\]
      24.1
    7. Using strategy rm
      24.1
    8. Applied add-log-exp to get
      \[{\left({\color{red}{\left(\sqrt{\sqrt[3]{\sqrt{{re}^2 + im \cdot im}}}\right)}}^2\right)}^3 \leadsto {\left({\color{blue}{\left(\log \left(e^{\sqrt{\sqrt[3]{\sqrt{{re}^2 + im \cdot im}}}}\right)\right)}}^2\right)}^3\]
      27.7
    9. Applied taylor to get
      \[{\left({\left(\log \left(e^{\sqrt{\sqrt[3]{\sqrt{{re}^2 + im \cdot im}}}}\right)\right)}^2\right)}^3 \leadsto re + \frac{1}{2} \cdot \frac{{im}^2}{re}\]
      5.0
    10. Taylor expanded around 0 to get
      \[\color{red}{re + \frac{1}{2} \cdot \frac{{im}^2}{re}} \leadsto \color{blue}{re + \frac{1}{2} \cdot \frac{{im}^2}{re}}\]
      5.0
    11. Applied simplify to get
      \[re + \frac{1}{2} \cdot \frac{{im}^2}{re} \leadsto re + \frac{\frac{1}{2} \cdot im}{\frac{re}{im}}\]
      0.0

    12. Applied final simplification

  1. Removed slow pow expressions

Original test:


(lambda ((re default) (im default))
  #:name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))