
(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:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c (+ (/ b d) (* a (/ c (* d d))))) a) d)))
(if (<= d -1.52e+85)
t_0
(if (<= d -4.6e-106)
(/ (- (* c b) (* d a)) (+ (* d d) (* c c)))
(if (<= d 7.7e+74) (/ (- b (* a (/ d c))) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * ((b / d) + (a * (c / (d * d))))) - a) / d;
double tmp;
if (d <= -1.52e+85) {
tmp = t_0;
} else if (d <= -4.6e-106) {
tmp = ((c * b) - (d * a)) / ((d * d) + (c * c));
} else if (d <= 7.7e+74) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = ((c * ((b / d) + (a * (c / (d * d))))) - a) / d
if (d <= (-1.52d+85)) then
tmp = t_0
else if (d <= (-4.6d-106)) then
tmp = ((c * b) - (d * a)) / ((d * d) + (c * c))
else if (d <= 7.7d+74) then
tmp = (b - (a * (d / c))) / c
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((c * ((b / d) + (a * (c / (d * d))))) - a) / d;
double tmp;
if (d <= -1.52e+85) {
tmp = t_0;
} else if (d <= -4.6e-106) {
tmp = ((c * b) - (d * a)) / ((d * d) + (c * c));
} else if (d <= 7.7e+74) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * ((b / d) + (a * (c / (d * d))))) - a) / d tmp = 0 if d <= -1.52e+85: tmp = t_0 elif d <= -4.6e-106: tmp = ((c * b) - (d * a)) / ((d * d) + (c * c)) elif d <= 7.7e+74: tmp = (b - (a * (d / c))) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * Float64(Float64(b / d) + Float64(a * Float64(c / Float64(d * d))))) - a) / d) tmp = 0.0 if (d <= -1.52e+85) tmp = t_0; elseif (d <= -4.6e-106) tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(d * d) + Float64(c * c))); elseif (d <= 7.7e+74) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * ((b / d) + (a * (c / (d * d))))) - a) / d; tmp = 0.0; if (d <= -1.52e+85) tmp = t_0; elseif (d <= -4.6e-106) tmp = ((c * b) - (d * a)) / ((d * d) + (c * c)); elseif (d <= 7.7e+74) tmp = (b - (a * (d / c))) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * N[(N[(b / d), $MachinePrecision] + N[(a * N[(c / N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.52e+85], t$95$0, If[LessEqual[d, -4.6e-106], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 7.7e+74], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot \left(\frac{b}{d} + a \cdot \frac{c}{d \cdot d}\right) - a}{d}\\
\mathbf{if}\;d \leq -1.52 \cdot 10^{+85}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -4.6 \cdot 10^{-106}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{elif}\;d \leq 7.7 \cdot 10^{+74}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.52e85 or 7.70000000000000042e74 < d Initial program 47.8%
clear-numN/A
associate-/r/N/A
flip-+N/A
clear-numN/A
*-lowering-*.f64N/A
clear-numN/A
flip-+N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6447.8%
Applied egg-rr47.8%
Taylor expanded in d around inf
/-lowering-/.f64N/A
Simplified84.2%
if -1.52e85 < d < -4.6000000000000002e-106Initial program 93.5%
if -4.6000000000000002e-106 < d < 7.70000000000000042e74Initial program 67.6%
Taylor expanded in a around inf
mul-1-negN/A
neg-sub0N/A
associate-+l-N/A
unsub-negN/A
mul-1-negN/A
+-commutativeN/A
neg-sub0N/A
*-lowering-*.f64N/A
neg-sub0N/A
Simplified55.0%
Taylor expanded in c around inf
/-lowering-/.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6489.3%
Simplified89.3%
Final simplification88.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (/ (* c b) d) a) d)))
(if (<= d -1.25e+85)
t_0
(if (<= d -4.5e-106)
(/ (- (* c b) (* d a)) (+ (* d d) (* c c)))
(if (<= d 1.4e+82) (/ (- b (* a (/ d c))) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (((c * b) / d) - a) / d;
double tmp;
if (d <= -1.25e+85) {
tmp = t_0;
} else if (d <= -4.5e-106) {
tmp = ((c * b) - (d * a)) / ((d * d) + (c * c));
} else if (d <= 1.4e+82) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = (((c * b) / d) - a) / d
if (d <= (-1.25d+85)) then
tmp = t_0
else if (d <= (-4.5d-106)) then
tmp = ((c * b) - (d * a)) / ((d * d) + (c * c))
else if (d <= 1.4d+82) then
tmp = (b - (a * (d / c))) / c
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (((c * b) / d) - a) / d;
double tmp;
if (d <= -1.25e+85) {
tmp = t_0;
} else if (d <= -4.5e-106) {
tmp = ((c * b) - (d * a)) / ((d * d) + (c * c));
} else if (d <= 1.4e+82) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (((c * b) / d) - a) / d tmp = 0 if d <= -1.25e+85: tmp = t_0 elif d <= -4.5e-106: tmp = ((c * b) - (d * a)) / ((d * d) + (c * c)) elif d <= 1.4e+82: tmp = (b - (a * (d / c))) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(Float64(c * b) / d) - a) / d) tmp = 0.0 if (d <= -1.25e+85) tmp = t_0; elseif (d <= -4.5e-106) tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(d * d) + Float64(c * c))); elseif (d <= 1.4e+82) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (((c * b) / d) - a) / d; tmp = 0.0; if (d <= -1.25e+85) tmp = t_0; elseif (d <= -4.5e-106) tmp = ((c * b) - (d * a)) / ((d * d) + (c * c)); elseif (d <= 1.4e+82) tmp = (b - (a * (d / c))) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.25e+85], t$95$0, If[LessEqual[d, -4.5e-106], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.4e+82], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\frac{c \cdot b}{d} - a}{d}\\
\mathbf{if}\;d \leq -1.25 \cdot 10^{+85}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -4.5 \cdot 10^{-106}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{elif}\;d \leq 1.4 \cdot 10^{+82}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.25e85 or 1.4e82 < d Initial program 48.3%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6480.9%
Simplified80.9%
if -1.25e85 < d < -4.49999999999999955e-106Initial program 93.5%
if -4.49999999999999955e-106 < d < 1.4e82Initial program 67.0%
Taylor expanded in a around inf
mul-1-negN/A
neg-sub0N/A
associate-+l-N/A
unsub-negN/A
mul-1-negN/A
+-commutativeN/A
neg-sub0N/A
*-lowering-*.f64N/A
neg-sub0N/A
Simplified54.5%
Taylor expanded in c around inf
/-lowering-/.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6488.6%
Simplified88.6%
Final simplification86.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (/ (* c b) d) a) d)))
(if (<= d -1.45e-16)
t_0
(if (<= d 1.45e+81) (/ (- b (* a (/ d c))) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (((c * b) / d) - a) / d;
double tmp;
if (d <= -1.45e-16) {
tmp = t_0;
} else if (d <= 1.45e+81) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = (((c * b) / d) - a) / d
if (d <= (-1.45d-16)) then
tmp = t_0
else if (d <= 1.45d+81) then
tmp = (b - (a * (d / c))) / c
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (((c * b) / d) - a) / d;
double tmp;
if (d <= -1.45e-16) {
tmp = t_0;
} else if (d <= 1.45e+81) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (((c * b) / d) - a) / d tmp = 0 if d <= -1.45e-16: tmp = t_0 elif d <= 1.45e+81: tmp = (b - (a * (d / c))) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(Float64(c * b) / d) - a) / d) tmp = 0.0 if (d <= -1.45e-16) tmp = t_0; elseif (d <= 1.45e+81) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (((c * b) / d) - a) / d; tmp = 0.0; if (d <= -1.45e-16) tmp = t_0; elseif (d <= 1.45e+81) tmp = (b - (a * (d / c))) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.45e-16], t$95$0, If[LessEqual[d, 1.45e+81], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\frac{c \cdot b}{d} - a}{d}\\
\mathbf{if}\;d \leq -1.45 \cdot 10^{-16}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.45 \cdot 10^{+81}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.4499999999999999e-16 or 1.45e81 < d Initial program 57.3%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
associate-/r*N/A
div-subN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6477.5%
Simplified77.5%
if -1.4499999999999999e-16 < d < 1.45e81Initial program 72.0%
Taylor expanded in a around inf
mul-1-negN/A
neg-sub0N/A
associate-+l-N/A
unsub-negN/A
mul-1-negN/A
+-commutativeN/A
neg-sub0N/A
*-lowering-*.f64N/A
neg-sub0N/A
Simplified59.2%
Taylor expanded in c around inf
/-lowering-/.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6484.5%
Simplified84.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ a (- 0.0 d))))
(if (<= d -27500000.0)
t_0
(if (<= d 7.5e+128) (/ (- b (* a (/ d c))) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = a / (0.0 - d);
double tmp;
if (d <= -27500000.0) {
tmp = t_0;
} else if (d <= 7.5e+128) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = a / (0.0d0 - d)
if (d <= (-27500000.0d0)) then
tmp = t_0
else if (d <= 7.5d+128) then
tmp = (b - (a * (d / c))) / c
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = a / (0.0 - d);
double tmp;
if (d <= -27500000.0) {
tmp = t_0;
} else if (d <= 7.5e+128) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = a / (0.0 - d) tmp = 0 if d <= -27500000.0: tmp = t_0 elif d <= 7.5e+128: tmp = (b - (a * (d / c))) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(a / Float64(0.0 - d)) tmp = 0.0 if (d <= -27500000.0) tmp = t_0; elseif (d <= 7.5e+128) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = a / (0.0 - d); tmp = 0.0; if (d <= -27500000.0) tmp = t_0; elseif (d <= 7.5e+128) tmp = (b - (a * (d / c))) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / N[(0.0 - d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -27500000.0], t$95$0, If[LessEqual[d, 7.5e+128], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{0 - d}\\
\mathbf{if}\;d \leq -27500000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 7.5 \cdot 10^{+128}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.75e7 or 7.50000000000000076e128 < d Initial program 54.0%
Taylor expanded in c around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
/-lowering-/.f6472.0%
Simplified72.0%
if -2.75e7 < d < 7.50000000000000076e128Initial program 72.7%
Taylor expanded in a around inf
mul-1-negN/A
neg-sub0N/A
associate-+l-N/A
unsub-negN/A
mul-1-negN/A
+-commutativeN/A
neg-sub0N/A
*-lowering-*.f64N/A
neg-sub0N/A
Simplified61.5%
Taylor expanded in c around inf
/-lowering-/.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6480.4%
Simplified80.4%
Final simplification76.8%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ a (- 0.0 d)))) (if (<= d -1.12e-36) t_0 (if (<= d 8.2e-8) (/ b c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = a / (0.0 - d);
double tmp;
if (d <= -1.12e-36) {
tmp = t_0;
} else if (d <= 8.2e-8) {
tmp = b / c;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = a / (0.0d0 - d)
if (d <= (-1.12d-36)) then
tmp = t_0
else if (d <= 8.2d-8) then
tmp = b / c
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = a / (0.0 - d);
double tmp;
if (d <= -1.12e-36) {
tmp = t_0;
} else if (d <= 8.2e-8) {
tmp = b / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = a / (0.0 - d) tmp = 0 if d <= -1.12e-36: tmp = t_0 elif d <= 8.2e-8: tmp = b / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(a / Float64(0.0 - d)) tmp = 0.0 if (d <= -1.12e-36) tmp = t_0; elseif (d <= 8.2e-8) tmp = Float64(b / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = a / (0.0 - d); tmp = 0.0; if (d <= -1.12e-36) tmp = t_0; elseif (d <= 8.2e-8) tmp = b / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / N[(0.0 - d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.12e-36], t$95$0, If[LessEqual[d, 8.2e-8], N[(b / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{0 - d}\\
\mathbf{if}\;d \leq -1.12 \cdot 10^{-36}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 8.2 \cdot 10^{-8}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.12e-36 or 8.20000000000000063e-8 < d Initial program 57.9%
Taylor expanded in c around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
/-lowering-/.f6463.8%
Simplified63.8%
if -1.12e-36 < d < 8.20000000000000063e-8Initial program 73.6%
Taylor expanded in c around inf
/-lowering-/.f6468.6%
Simplified68.6%
Final simplification65.9%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (* a (/ -1.0 d)))) (if (<= d -5.2e-38) t_0 (if (<= d 8e-8) (/ b c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = a * (-1.0 / d);
double tmp;
if (d <= -5.2e-38) {
tmp = t_0;
} else if (d <= 8e-8) {
tmp = b / c;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = a * ((-1.0d0) / d)
if (d <= (-5.2d-38)) then
tmp = t_0
else if (d <= 8d-8) then
tmp = b / c
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = a * (-1.0 / d);
double tmp;
if (d <= -5.2e-38) {
tmp = t_0;
} else if (d <= 8e-8) {
tmp = b / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = a * (-1.0 / d) tmp = 0 if d <= -5.2e-38: tmp = t_0 elif d <= 8e-8: tmp = b / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(a * Float64(-1.0 / d)) tmp = 0.0 if (d <= -5.2e-38) tmp = t_0; elseif (d <= 8e-8) tmp = Float64(b / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = a * (-1.0 / d); tmp = 0.0; if (d <= -5.2e-38) tmp = t_0; elseif (d <= 8e-8) tmp = b / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a * N[(-1.0 / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.2e-38], t$95$0, If[LessEqual[d, 8e-8], N[(b / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot \frac{-1}{d}\\
\mathbf{if}\;d \leq -5.2 \cdot 10^{-38}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 8 \cdot 10^{-8}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -5.20000000000000022e-38 or 8.0000000000000002e-8 < d Initial program 57.9%
Taylor expanded in a around inf
mul-1-negN/A
neg-sub0N/A
associate-+l-N/A
unsub-negN/A
mul-1-negN/A
+-commutativeN/A
neg-sub0N/A
*-lowering-*.f64N/A
neg-sub0N/A
Simplified53.8%
Taylor expanded in c around 0
/-lowering-/.f6463.5%
Simplified63.5%
if -5.20000000000000022e-38 < d < 8.0000000000000002e-8Initial program 73.6%
Taylor expanded in c around inf
/-lowering-/.f6468.6%
Simplified68.6%
(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}
Initial program 64.7%
Taylor expanded in c around inf
/-lowering-/.f6439.4%
Simplified39.4%
(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}
herbie shell --seed 2024158
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(! :herbie-platform default (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))))