Complex division, imag part

Percentage Accurate: 61.8% → 98.8%
Time: 11.2s
Alternatives: 7
Speedup: 0.1×

Specification

?
\[\begin{array}{l} \\ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 7 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 61.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}

Alternative 1: 98.8% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\mathsf{hypot}\left(c, d\right)} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* c (/ b (hypot c d))) (* (/ d (hypot c d)) a)) (hypot c d)))
double code(double a, double b, double c, double d) {
	return ((c * (b / hypot(c, d))) - ((d / hypot(c, d)) * a)) / hypot(c, d);
}
public static double code(double a, double b, double c, double d) {
	return ((c * (b / Math.hypot(c, d))) - ((d / Math.hypot(c, d)) * a)) / Math.hypot(c, d);
}
def code(a, b, c, d):
	return ((c * (b / math.hypot(c, d))) - ((d / math.hypot(c, d)) * a)) / math.hypot(c, d)
function code(a, b, c, d)
	return Float64(Float64(Float64(c * Float64(b / hypot(c, d))) - Float64(Float64(d / hypot(c, d)) * a)) / hypot(c, d))
end
function tmp = code(a, b, c, d)
	tmp = ((c * (b / hypot(c, d))) - ((d / hypot(c, d)) * a)) / hypot(c, d);
end
code[a_, b_, c_, d_] := N[(N[(N[(c * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\mathsf{hypot}\left(c, d\right)}
\end{array}
Derivation
  1. Initial program 58.2%

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. div-sub55.8%

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}} \]
    2. sub-neg55.8%

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right)} \]
    3. associate-/l*58.1%

      \[\leadsto \color{blue}{\frac{b}{\frac{c \cdot c + d \cdot d}{c}}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    4. fma-def58.1%

      \[\leadsto \frac{b}{\frac{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}}{c}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    5. add-sqr-sqrt58.1%

      \[\leadsto \frac{b}{\frac{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}}{c}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    6. pow258.1%

      \[\leadsto \frac{b}{\frac{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}\right)}^{2}}}{c}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    7. fma-def58.1%

      \[\leadsto \frac{b}{\frac{{\left(\sqrt{\color{blue}{c \cdot c + d \cdot d}}\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    8. hypot-def58.1%

      \[\leadsto \frac{b}{\frac{{\color{blue}{\left(\mathsf{hypot}\left(c, d\right)\right)}}^{2}}{c}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    9. fma-def58.1%

      \[\leadsto \frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}}\right) \]
    10. add-sqr-sqrt58.1%

      \[\leadsto \frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}}\right) \]
    11. pow258.1%

      \[\leadsto \frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}\right)}^{2}}}\right) \]
    12. fma-def58.1%

      \[\leadsto \frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{{\left(\sqrt{\color{blue}{c \cdot c + d \cdot d}}\right)}^{2}}\right) \]
    13. hypot-def58.1%

      \[\leadsto \frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{{\color{blue}{\left(\mathsf{hypot}\left(c, d\right)\right)}}^{2}}\right) \]
  4. Applied egg-rr58.1%

    \[\leadsto \color{blue}{\frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)} \]
  5. Step-by-step derivation
    1. sub-neg58.1%

      \[\leadsto \color{blue}{\frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} - \frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} \]
    2. associate-/r/54.7%

      \[\leadsto \color{blue}{\frac{b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \cdot c} - \frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    3. associate-*l/55.8%

      \[\leadsto \color{blue}{\frac{b \cdot c}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} - \frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    4. *-commutative55.8%

      \[\leadsto \frac{\color{blue}{c \cdot b}}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - \frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    5. *-commutative55.8%

      \[\leadsto \frac{c \cdot b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - \frac{\color{blue}{d \cdot a}}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    6. *-lft-identity55.8%

      \[\leadsto \frac{c \cdot b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - \frac{d \cdot a}{\color{blue}{1 \cdot {\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} \]
    7. times-frac56.0%

      \[\leadsto \frac{c \cdot b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - \color{blue}{\frac{d}{1} \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} \]
    8. /-rgt-identity56.0%

      \[\leadsto \frac{c \cdot b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - \color{blue}{d} \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
  6. Simplified56.0%

    \[\leadsto \color{blue}{\frac{c \cdot b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} \]
  7. Step-by-step derivation
    1. unpow256.0%

      \[\leadsto \frac{c \cdot b}{\color{blue}{\mathsf{hypot}\left(c, d\right) \cdot \mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    2. times-frac75.3%

      \[\leadsto \color{blue}{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
  8. Applied egg-rr75.3%

    \[\leadsto \color{blue}{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
  9. Step-by-step derivation
    1. *-commutative75.3%

      \[\leadsto \color{blue}{\frac{b}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    2. associate-*l/77.2%

      \[\leadsto \color{blue}{\frac{b \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
  10. Simplified77.2%

    \[\leadsto \color{blue}{\frac{b \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
  11. Step-by-step derivation
    1. associate-*r/76.0%

      \[\leadsto \frac{b \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \color{blue}{\frac{d \cdot a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} \]
    2. *-commutative76.0%

      \[\leadsto \frac{\color{blue}{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot b}}{\mathsf{hypot}\left(c, d\right)} - \frac{d \cdot a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    3. associate-*r/74.2%

      \[\leadsto \color{blue}{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}} - \frac{d \cdot a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    4. associate-*l/74.5%

      \[\leadsto \color{blue}{\frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}} - \frac{d \cdot a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    5. unpow274.5%

      \[\leadsto \frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \frac{d \cdot a}{\color{blue}{\mathsf{hypot}\left(c, d\right) \cdot \mathsf{hypot}\left(c, d\right)}} \]
    6. frac-times95.4%

      \[\leadsto \frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \color{blue}{\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}} \]
    7. associate-*r/96.9%

      \[\leadsto \frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \color{blue}{\frac{\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\mathsf{hypot}\left(c, d\right)}} \]
    8. sub-div97.2%

      \[\leadsto \color{blue}{\frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\mathsf{hypot}\left(c, d\right)}} \]
  12. Applied egg-rr97.2%

    \[\leadsto \color{blue}{\frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\mathsf{hypot}\left(c, d\right)}} \]
  13. Final simplification97.2%

    \[\leadsto \frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\mathsf{hypot}\left(c, d\right)} \]
  14. Add Preprocessing

Alternative 2: 63.1% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \frac{b \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \frac{a}{d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (- (/ (* b (/ c (hypot c d))) (hypot c d)) (/ a d)))
double code(double a, double b, double c, double d) {
	return ((b * (c / hypot(c, d))) / hypot(c, d)) - (a / d);
}
public static double code(double a, double b, double c, double d) {
	return ((b * (c / Math.hypot(c, d))) / Math.hypot(c, d)) - (a / d);
}
def code(a, b, c, d):
	return ((b * (c / math.hypot(c, d))) / math.hypot(c, d)) - (a / d)
function code(a, b, c, d)
	return Float64(Float64(Float64(b * Float64(c / hypot(c, d))) / hypot(c, d)) - Float64(a / d))
end
function tmp = code(a, b, c, d)
	tmp = ((b * (c / hypot(c, d))) / hypot(c, d)) - (a / d);
end
code[a_, b_, c_, d_] := N[(N[(N[(b * N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{b \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \frac{a}{d}
\end{array}
Derivation
  1. Initial program 58.2%

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. div-sub55.8%

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}} \]
    2. sub-neg55.8%

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right)} \]
    3. associate-/l*58.1%

      \[\leadsto \color{blue}{\frac{b}{\frac{c \cdot c + d \cdot d}{c}}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    4. fma-def58.1%

      \[\leadsto \frac{b}{\frac{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}}{c}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    5. add-sqr-sqrt58.1%

      \[\leadsto \frac{b}{\frac{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}}{c}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    6. pow258.1%

      \[\leadsto \frac{b}{\frac{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}\right)}^{2}}}{c}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    7. fma-def58.1%

      \[\leadsto \frac{b}{\frac{{\left(\sqrt{\color{blue}{c \cdot c + d \cdot d}}\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    8. hypot-def58.1%

      \[\leadsto \frac{b}{\frac{{\color{blue}{\left(\mathsf{hypot}\left(c, d\right)\right)}}^{2}}{c}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    9. fma-def58.1%

      \[\leadsto \frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}}\right) \]
    10. add-sqr-sqrt58.1%

      \[\leadsto \frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}}\right) \]
    11. pow258.1%

      \[\leadsto \frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}\right)}^{2}}}\right) \]
    12. fma-def58.1%

      \[\leadsto \frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{{\left(\sqrt{\color{blue}{c \cdot c + d \cdot d}}\right)}^{2}}\right) \]
    13. hypot-def58.1%

      \[\leadsto \frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{{\color{blue}{\left(\mathsf{hypot}\left(c, d\right)\right)}}^{2}}\right) \]
  4. Applied egg-rr58.1%

    \[\leadsto \color{blue}{\frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)} \]
  5. Step-by-step derivation
    1. sub-neg58.1%

      \[\leadsto \color{blue}{\frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} - \frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} \]
    2. associate-/r/54.7%

      \[\leadsto \color{blue}{\frac{b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \cdot c} - \frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    3. associate-*l/55.8%

      \[\leadsto \color{blue}{\frac{b \cdot c}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} - \frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    4. *-commutative55.8%

      \[\leadsto \frac{\color{blue}{c \cdot b}}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - \frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    5. *-commutative55.8%

      \[\leadsto \frac{c \cdot b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - \frac{\color{blue}{d \cdot a}}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    6. *-lft-identity55.8%

      \[\leadsto \frac{c \cdot b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - \frac{d \cdot a}{\color{blue}{1 \cdot {\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} \]
    7. times-frac56.0%

      \[\leadsto \frac{c \cdot b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - \color{blue}{\frac{d}{1} \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} \]
    8. /-rgt-identity56.0%

      \[\leadsto \frac{c \cdot b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - \color{blue}{d} \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
  6. Simplified56.0%

    \[\leadsto \color{blue}{\frac{c \cdot b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} \]
  7. Step-by-step derivation
    1. unpow256.0%

      \[\leadsto \frac{c \cdot b}{\color{blue}{\mathsf{hypot}\left(c, d\right) \cdot \mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    2. times-frac75.3%

      \[\leadsto \color{blue}{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
  8. Applied egg-rr75.3%

    \[\leadsto \color{blue}{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
  9. Step-by-step derivation
    1. *-commutative75.3%

      \[\leadsto \color{blue}{\frac{b}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    2. associate-*l/77.2%

      \[\leadsto \color{blue}{\frac{b \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
  10. Simplified77.2%

    \[\leadsto \color{blue}{\frac{b \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
  11. Taylor expanded in d around inf 62.4%

    \[\leadsto \frac{b \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \color{blue}{\frac{a}{d}} \]
  12. Final simplification62.4%

    \[\leadsto \frac{b \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \frac{a}{d} \]
  13. Add Preprocessing

Alternative 3: 62.4% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \frac{b - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\mathsf{hypot}\left(c, d\right)} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- b (* (/ d (hypot c d)) a)) (hypot c d)))
double code(double a, double b, double c, double d) {
	return (b - ((d / hypot(c, d)) * a)) / hypot(c, d);
}
public static double code(double a, double b, double c, double d) {
	return (b - ((d / Math.hypot(c, d)) * a)) / Math.hypot(c, d);
}
def code(a, b, c, d):
	return (b - ((d / math.hypot(c, d)) * a)) / math.hypot(c, d)
function code(a, b, c, d)
	return Float64(Float64(b - Float64(Float64(d / hypot(c, d)) * a)) / hypot(c, d))
end
function tmp = code(a, b, c, d)
	tmp = (b - ((d / hypot(c, d)) * a)) / hypot(c, d);
end
code[a_, b_, c_, d_] := N[(N[(b - N[(N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{b - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\mathsf{hypot}\left(c, d\right)}
\end{array}
Derivation
  1. Initial program 58.2%

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. div-sub55.8%

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}} \]
    2. sub-neg55.8%

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right)} \]
    3. associate-/l*58.1%

      \[\leadsto \color{blue}{\frac{b}{\frac{c \cdot c + d \cdot d}{c}}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    4. fma-def58.1%

      \[\leadsto \frac{b}{\frac{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}}{c}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    5. add-sqr-sqrt58.1%

      \[\leadsto \frac{b}{\frac{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}}{c}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    6. pow258.1%

      \[\leadsto \frac{b}{\frac{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}\right)}^{2}}}{c}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    7. fma-def58.1%

      \[\leadsto \frac{b}{\frac{{\left(\sqrt{\color{blue}{c \cdot c + d \cdot d}}\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    8. hypot-def58.1%

      \[\leadsto \frac{b}{\frac{{\color{blue}{\left(\mathsf{hypot}\left(c, d\right)\right)}}^{2}}{c}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    9. fma-def58.1%

      \[\leadsto \frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}}\right) \]
    10. add-sqr-sqrt58.1%

      \[\leadsto \frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}}\right) \]
    11. pow258.1%

      \[\leadsto \frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}\right)}^{2}}}\right) \]
    12. fma-def58.1%

      \[\leadsto \frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{{\left(\sqrt{\color{blue}{c \cdot c + d \cdot d}}\right)}^{2}}\right) \]
    13. hypot-def58.1%

      \[\leadsto \frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{{\color{blue}{\left(\mathsf{hypot}\left(c, d\right)\right)}}^{2}}\right) \]
  4. Applied egg-rr58.1%

    \[\leadsto \color{blue}{\frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} + \left(-\frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)} \]
  5. Step-by-step derivation
    1. sub-neg58.1%

      \[\leadsto \color{blue}{\frac{b}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{c}} - \frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} \]
    2. associate-/r/54.7%

      \[\leadsto \color{blue}{\frac{b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \cdot c} - \frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    3. associate-*l/55.8%

      \[\leadsto \color{blue}{\frac{b \cdot c}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} - \frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    4. *-commutative55.8%

      \[\leadsto \frac{\color{blue}{c \cdot b}}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - \frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    5. *-commutative55.8%

      \[\leadsto \frac{c \cdot b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - \frac{\color{blue}{d \cdot a}}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    6. *-lft-identity55.8%

      \[\leadsto \frac{c \cdot b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - \frac{d \cdot a}{\color{blue}{1 \cdot {\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} \]
    7. times-frac56.0%

      \[\leadsto \frac{c \cdot b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - \color{blue}{\frac{d}{1} \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} \]
    8. /-rgt-identity56.0%

      \[\leadsto \frac{c \cdot b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - \color{blue}{d} \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
  6. Simplified56.0%

    \[\leadsto \color{blue}{\frac{c \cdot b}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} \]
  7. Step-by-step derivation
    1. unpow256.0%

      \[\leadsto \frac{c \cdot b}{\color{blue}{\mathsf{hypot}\left(c, d\right) \cdot \mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    2. times-frac75.3%

      \[\leadsto \color{blue}{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
  8. Applied egg-rr75.3%

    \[\leadsto \color{blue}{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
  9. Step-by-step derivation
    1. *-commutative75.3%

      \[\leadsto \color{blue}{\frac{b}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    2. associate-*l/77.2%

      \[\leadsto \color{blue}{\frac{b \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
  10. Simplified77.2%

    \[\leadsto \color{blue}{\frac{b \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}} - d \cdot \frac{a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
  11. Step-by-step derivation
    1. associate-*r/76.0%

      \[\leadsto \frac{b \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \color{blue}{\frac{d \cdot a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} \]
    2. *-commutative76.0%

      \[\leadsto \frac{\color{blue}{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot b}}{\mathsf{hypot}\left(c, d\right)} - \frac{d \cdot a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    3. associate-*r/74.2%

      \[\leadsto \color{blue}{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}} - \frac{d \cdot a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    4. associate-*l/74.5%

      \[\leadsto \color{blue}{\frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}} - \frac{d \cdot a}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \]
    5. unpow274.5%

      \[\leadsto \frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \frac{d \cdot a}{\color{blue}{\mathsf{hypot}\left(c, d\right) \cdot \mathsf{hypot}\left(c, d\right)}} \]
    6. frac-times95.4%

      \[\leadsto \frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \color{blue}{\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}} \]
    7. associate-*r/96.9%

      \[\leadsto \frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \color{blue}{\frac{\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\mathsf{hypot}\left(c, d\right)}} \]
    8. sub-div97.2%

      \[\leadsto \color{blue}{\frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\mathsf{hypot}\left(c, d\right)}} \]
  12. Applied egg-rr97.2%

    \[\leadsto \color{blue}{\frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\mathsf{hypot}\left(c, d\right)}} \]
  13. Taylor expanded in c around inf 61.2%

    \[\leadsto \frac{\color{blue}{b} - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\mathsf{hypot}\left(c, d\right)} \]
  14. Final simplification61.2%

    \[\leadsto \frac{b - \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\mathsf{hypot}\left(c, d\right)} \]
  15. Add Preprocessing

Alternative 4: 51.7% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \frac{b}{c} - \frac{a}{c \cdot \left(c \cdot \frac{1}{d}\right)} \end{array} \]
(FPCore (a b c d) :precision binary64 (- (/ b c) (/ a (* c (* c (/ 1.0 d))))))
double code(double a, double b, double c, double d) {
	return (b / c) - (a / (c * (c * (1.0 / d))));
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = (b / c) - (a / (c * (c * (1.0d0 / d))))
end function
public static double code(double a, double b, double c, double d) {
	return (b / c) - (a / (c * (c * (1.0 / d))));
}
def code(a, b, c, d):
	return (b / c) - (a / (c * (c * (1.0 / d))))
function code(a, b, c, d)
	return Float64(Float64(b / c) - Float64(a / Float64(c * Float64(c * Float64(1.0 / d)))))
end
function tmp = code(a, b, c, d)
	tmp = (b / c) - (a / (c * (c * (1.0 / d))));
end
code[a_, b_, c_, d_] := N[(N[(b / c), $MachinePrecision] - N[(a / N[(c * N[(c * N[(1.0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{b}{c} - \frac{a}{c \cdot \left(c \cdot \frac{1}{d}\right)}
\end{array}
Derivation
  1. Initial program 58.2%

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
  2. Add Preprocessing
  3. Taylor expanded in c around inf 50.7%

    \[\leadsto \color{blue}{-1 \cdot \frac{a \cdot d}{{c}^{2}} + \frac{b}{c}} \]
  4. Step-by-step derivation
    1. +-commutative50.7%

      \[\leadsto \color{blue}{\frac{b}{c} + -1 \cdot \frac{a \cdot d}{{c}^{2}}} \]
    2. mul-1-neg50.7%

      \[\leadsto \frac{b}{c} + \color{blue}{\left(-\frac{a \cdot d}{{c}^{2}}\right)} \]
    3. unsub-neg50.7%

      \[\leadsto \color{blue}{\frac{b}{c} - \frac{a \cdot d}{{c}^{2}}} \]
    4. associate-/l*52.5%

      \[\leadsto \frac{b}{c} - \color{blue}{\frac{a}{\frac{{c}^{2}}{d}}} \]
  5. Simplified52.5%

    \[\leadsto \color{blue}{\frac{b}{c} - \frac{a}{\frac{{c}^{2}}{d}}} \]
  6. Step-by-step derivation
    1. div-inv52.5%

      \[\leadsto \frac{b}{c} - \frac{a}{\color{blue}{{c}^{2} \cdot \frac{1}{d}}} \]
    2. unpow252.5%

      \[\leadsto \frac{b}{c} - \frac{a}{\color{blue}{\left(c \cdot c\right)} \cdot \frac{1}{d}} \]
    3. associate-*l*55.5%

      \[\leadsto \frac{b}{c} - \frac{a}{\color{blue}{c \cdot \left(c \cdot \frac{1}{d}\right)}} \]
  7. Applied egg-rr55.5%

    \[\leadsto \frac{b}{c} - \frac{a}{\color{blue}{c \cdot \left(c \cdot \frac{1}{d}\right)}} \]
  8. Final simplification55.5%

    \[\leadsto \frac{b}{c} - \frac{a}{c \cdot \left(c \cdot \frac{1}{d}\right)} \]
  9. Add Preprocessing

Alternative 5: 51.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \frac{b}{c} - \frac{a}{c \cdot \frac{c}{d}} \end{array} \]
(FPCore (a b c d) :precision binary64 (- (/ b c) (/ a (* c (/ c d)))))
double code(double a, double b, double c, double d) {
	return (b / c) - (a / (c * (c / d)));
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = (b / c) - (a / (c * (c / d)))
end function
public static double code(double a, double b, double c, double d) {
	return (b / c) - (a / (c * (c / d)));
}
def code(a, b, c, d):
	return (b / c) - (a / (c * (c / d)))
function code(a, b, c, d)
	return Float64(Float64(b / c) - Float64(a / Float64(c * Float64(c / d))))
end
function tmp = code(a, b, c, d)
	tmp = (b / c) - (a / (c * (c / d)));
end
code[a_, b_, c_, d_] := N[(N[(b / c), $MachinePrecision] - N[(a / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{b}{c} - \frac{a}{c \cdot \frac{c}{d}}
\end{array}
Derivation
  1. Initial program 58.2%

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
  2. Add Preprocessing
  3. Taylor expanded in c around inf 50.7%

    \[\leadsto \color{blue}{-1 \cdot \frac{a \cdot d}{{c}^{2}} + \frac{b}{c}} \]
  4. Step-by-step derivation
    1. +-commutative50.7%

      \[\leadsto \color{blue}{\frac{b}{c} + -1 \cdot \frac{a \cdot d}{{c}^{2}}} \]
    2. mul-1-neg50.7%

      \[\leadsto \frac{b}{c} + \color{blue}{\left(-\frac{a \cdot d}{{c}^{2}}\right)} \]
    3. unsub-neg50.7%

      \[\leadsto \color{blue}{\frac{b}{c} - \frac{a \cdot d}{{c}^{2}}} \]
    4. associate-/l*52.5%

      \[\leadsto \frac{b}{c} - \color{blue}{\frac{a}{\frac{{c}^{2}}{d}}} \]
  5. Simplified52.5%

    \[\leadsto \color{blue}{\frac{b}{c} - \frac{a}{\frac{{c}^{2}}{d}}} \]
  6. Step-by-step derivation
    1. unpow252.5%

      \[\leadsto \frac{b}{c} - \frac{a}{\frac{\color{blue}{c \cdot c}}{d}} \]
    2. *-un-lft-identity52.5%

      \[\leadsto \frac{b}{c} - \frac{a}{\frac{c \cdot c}{\color{blue}{1 \cdot d}}} \]
    3. times-frac55.5%

      \[\leadsto \frac{b}{c} - \frac{a}{\color{blue}{\frac{c}{1} \cdot \frac{c}{d}}} \]
  7. Applied egg-rr55.5%

    \[\leadsto \frac{b}{c} - \frac{a}{\color{blue}{\frac{c}{1} \cdot \frac{c}{d}}} \]
  8. Final simplification55.5%

    \[\leadsto \frac{b}{c} - \frac{a}{c \cdot \frac{c}{d}} \]
  9. Add Preprocessing

Alternative 6: 10.9% accurate, 5.0× speedup?

\[\begin{array}{l} \\ \frac{a}{d} \end{array} \]
(FPCore (a b c d) :precision binary64 (/ a d))
double code(double a, double b, double c, double d) {
	return a / d;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = a / d
end function
public static double code(double a, double b, double c, double d) {
	return a / d;
}
def code(a, b, c, d):
	return a / d
function code(a, b, c, d)
	return Float64(a / d)
end
function tmp = code(a, b, c, d)
	tmp = a / d;
end
code[a_, b_, c_, d_] := N[(a / d), $MachinePrecision]
\begin{array}{l}

\\
\frac{a}{d}
\end{array}
Derivation
  1. Initial program 58.2%

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
  2. Add Preprocessing
  3. Taylor expanded in b around 0 36.0%

    \[\leadsto \frac{\color{blue}{-1 \cdot \left(a \cdot d\right)}}{c \cdot c + d \cdot d} \]
  4. Step-by-step derivation
    1. mul-1-neg36.0%

      \[\leadsto \frac{\color{blue}{-a \cdot d}}{c \cdot c + d \cdot d} \]
    2. distribute-rgt-neg-in36.0%

      \[\leadsto \frac{\color{blue}{a \cdot \left(-d\right)}}{c \cdot c + d \cdot d} \]
  5. Simplified36.0%

    \[\leadsto \frac{\color{blue}{a \cdot \left(-d\right)}}{c \cdot c + d \cdot d} \]
  6. Step-by-step derivation
    1. *-commutative36.0%

      \[\leadsto \frac{\color{blue}{\left(-d\right) \cdot a}}{c \cdot c + d \cdot d} \]
    2. fma-def36.0%

      \[\leadsto \frac{\left(-d\right) \cdot a}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. add-sqr-sqrt36.0%

      \[\leadsto \frac{\left(-d\right) \cdot a}{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}} \]
    4. fma-def36.0%

      \[\leadsto \frac{\left(-d\right) \cdot a}{\sqrt{\color{blue}{c \cdot c + d \cdot d}} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    5. hypot-udef36.0%

      \[\leadsto \frac{\left(-d\right) \cdot a}{\color{blue}{\mathsf{hypot}\left(c, d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    6. fma-def36.0%

      \[\leadsto \frac{\left(-d\right) \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot \sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
    7. hypot-udef36.0%

      \[\leadsto \frac{\left(-d\right) \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot \color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    8. times-frac52.6%

      \[\leadsto \color{blue}{\frac{-d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}} \]
    9. add-sqr-sqrt26.4%

      \[\leadsto \frac{\color{blue}{\sqrt{-d} \cdot \sqrt{-d}}}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)} \]
    10. sqrt-unprod17.6%

      \[\leadsto \frac{\color{blue}{\sqrt{\left(-d\right) \cdot \left(-d\right)}}}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)} \]
    11. sqr-neg17.6%

      \[\leadsto \frac{\sqrt{\color{blue}{d \cdot d}}}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)} \]
    12. sqrt-prod7.1%

      \[\leadsto \frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)} \]
    13. add-sqr-sqrt14.3%

      \[\leadsto \frac{\color{blue}{d}}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)} \]
  7. Applied egg-rr14.3%

    \[\leadsto \color{blue}{\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}} \]
  8. Taylor expanded in d around inf 8.2%

    \[\leadsto \color{blue}{\frac{a}{d}} \]
  9. Final simplification8.2%

    \[\leadsto \frac{a}{d} \]
  10. Add Preprocessing

Alternative 7: 43.0% accurate, 5.0× speedup?

\[\begin{array}{l} \\ \frac{b}{c} \end{array} \]
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
	return b / c;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = b / c
end function
public static double code(double a, double b, double c, double d) {
	return b / c;
}
def code(a, b, c, d):
	return b / c
function code(a, b, c, d)
	return Float64(b / c)
end
function tmp = code(a, b, c, d)
	tmp = b / c;
end
code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
\begin{array}{l}

\\
\frac{b}{c}
\end{array}
Derivation
  1. Initial program 58.2%

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
  2. Add Preprocessing
  3. Taylor expanded in c around inf 45.8%

    \[\leadsto \color{blue}{\frac{b}{c}} \]
  4. Final simplification45.8%

    \[\leadsto \frac{b}{c} \]
  5. Add Preprocessing

Developer target: 99.3% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (< (fabs d) (fabs c))
   (/ (- b (* a (/ d c))) (+ c (* d (/ d c))))
   (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (fabs(d) < fabs(c)) {
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (abs(d) < abs(c)) then
        tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
    else
        tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (Math.abs(d) < Math.abs(c)) {
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if math.fabs(d) < math.fabs(c):
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
	else:
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (abs(d) < abs(c))
		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c))));
	else
		tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d))));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (abs(d) < abs(c))
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
	else
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024033 
(FPCore (a b c d)
  :name "Complex division, imag part"
  :precision binary64

  :herbie-target
  (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))

  (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))