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

    if re < -3.1677181f+13

    1. Started with
      \[\sqrt{re \cdot re + im \cdot im}\]
      23.6
    2. Applied simplify to get
      \[\color{red}{\sqrt{re \cdot re + im \cdot im}} \leadsto \color{blue}{\sqrt{{re}^2 + im \cdot im}}\]
      23.6
    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 -3.1677181f+13 < re < 1.1667896f+15

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

    if 1.1667896f+15 < re

    1. Started with
      \[\sqrt{re \cdot re + im \cdot im}\]
      23.6
    2. Applied simplify to get
      \[\color{red}{\sqrt{re \cdot re + im \cdot im}} \leadsto \color{blue}{\sqrt{{re}^2 + im \cdot im}}\]
      23.6
    3. Using strategy rm
      23.6
    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}\]
      23.7
    5. Applied taylor to get
      \[{\left(\sqrt[3]{\sqrt{{re}^2 + im \cdot im}}\right)}^3 \leadsto re + \frac{1}{2} \cdot \frac{{im}^2}{re}\]
      4.8
    6. 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}}\]
      4.8
    7. 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

    8. 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))))