\[\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.1 s
Input Error: 13.3
Output Error: 6.2
Log:
Profile: 🕒
\(\begin{cases} -re & \text{when } re \le -1.8009657f+17 \\ \sqrt{{re}^2 + im \cdot im} & \text{when } re \le 8.580638f+12 \\ re + \frac{\frac{1}{2} \cdot im}{\frac{re}{im}} & \text{otherwise} \end{cases}\)

    if re < -1.8009657f+17

    1. Started with
      \[\sqrt{re \cdot re + im \cdot im}\]
      25.6
    2. Applied simplify to get
      \[\color{red}{\sqrt{re \cdot re + im \cdot im}} \leadsto \color{blue}{\sqrt{{re}^2 + im \cdot im}}\]
      25.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 -1.8009657f+17 < re < 8.580638f+12

    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 8.580638f+12 < re

    1. Started with
      \[\sqrt{re \cdot re + im \cdot im}\]
      22.6
    2. Applied simplify to get
      \[\color{red}{\sqrt{re \cdot re + im \cdot im}} \leadsto \color{blue}{\sqrt{{re}^2 + im \cdot im}}\]
      22.6
    3. Using strategy rm
      22.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}\]
      22.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.9
    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.9
    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))))