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

    if re < -3.3457427f+18

    1. Started with
      \[\sqrt{re \cdot re + im \cdot im}\]
      27.0
    2. Applied simplify to get
      \[\color{red}{\sqrt{re \cdot re + im \cdot im}} \leadsto \color{blue}{\sqrt{{re}^2 + im \cdot im}}\]
      27.0
    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.3457427f+18 < re < 2.5568826f+12

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

    if 2.5568826f+12 < re

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