
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
double code(double x, double y, double z) {
return fabs((((x + 4.0) / y) - ((x / y) * z)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = abs((((x + 4.0d0) / y) - ((x / y) * z)))
end function
public static double code(double x, double y, double z) {
return Math.abs((((x + 4.0) / y) - ((x / y) * z)));
}
def code(x, y, z): return math.fabs((((x + 4.0) / y) - ((x / y) * z)))
function code(x, y, z) return abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x / y) * z))) end
function tmp = code(x, y, z) tmp = abs((((x + 4.0) / y) - ((x / y) * z))); end
code[x_, y_, z_] := N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
double code(double x, double y, double z) {
return fabs((((x + 4.0) / y) - ((x / y) * z)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = abs((((x + 4.0d0) / y) - ((x / y) * z)))
end function
public static double code(double x, double y, double z) {
return Math.abs((((x + 4.0) / y) - ((x / y) * z)));
}
def code(x, y, z): return math.fabs((((x + 4.0) / y) - ((x / y) * z)))
function code(x, y, z) return abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x / y) * z))) end
function tmp = code(x, y, z) tmp = abs((((x + 4.0) / y) - ((x / y) * z))); end
code[x_, y_, z_] := N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\end{array}
(FPCore (x y z) :precision binary64 (if (<= z -2e+18) (fabs (- (/ 4.0 y) (* z (/ x y)))) (fabs (/ (- x (fma x z -4.0)) y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2e+18) {
tmp = fabs(((4.0 / y) - (z * (x / y))));
} else {
tmp = fabs(((x - fma(x, z, -4.0)) / y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -2e+18) tmp = abs(Float64(Float64(4.0 / y) - Float64(z * Float64(x / y)))); else tmp = abs(Float64(Float64(x - fma(x, z, -4.0)) / y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -2e+18], N[Abs[N[(N[(4.0 / y), $MachinePrecision] - N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(x - N[(x * z + -4.0), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2 \cdot 10^{+18}:\\
\;\;\;\;\left|\frac{4}{y} - z \cdot \frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{x - \mathsf{fma}\left(x, z, -4\right)}{y}\right|\\
\end{array}
\end{array}
if z < -2e18Initial program 99.8%
Taylor expanded in x around 0
lower-/.f6499.8
Simplified99.8%
if -2e18 < z Initial program 89.4%
Taylor expanded in x around 0
+-commutativeN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
associate-/l*N/A
mul-1-negN/A
associate-+r+N/A
+-commutativeN/A
associate-*r/N/A
*-rgt-identityN/A
+-commutativeN/A
associate-+r+N/A
Simplified98.6%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fabs (/ (fma x z -4.0) y)))) (if (<= z -280000.0) t_0 (if (<= z 6.5e-34) (fabs (/ (+ 4.0 x) y)) t_0))))
double code(double x, double y, double z) {
double t_0 = fabs((fma(x, z, -4.0) / y));
double tmp;
if (z <= -280000.0) {
tmp = t_0;
} else if (z <= 6.5e-34) {
tmp = fabs(((4.0 + x) / y));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = abs(Float64(fma(x, z, -4.0) / y)) tmp = 0.0 if (z <= -280000.0) tmp = t_0; elseif (z <= 6.5e-34) tmp = abs(Float64(Float64(4.0 + x) / y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[Abs[N[(N[(x * z + -4.0), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[z, -280000.0], t$95$0, If[LessEqual[z, 6.5e-34], N[Abs[N[(N[(4.0 + x), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{\mathsf{fma}\left(x, z, -4\right)}{y}\right|\\
\mathbf{if}\;z \leq -280000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 6.5 \cdot 10^{-34}:\\
\;\;\;\;\left|\frac{4 + x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.8e5 or 6.49999999999999985e-34 < z Initial program 89.6%
Taylor expanded in x around 0
lower-/.f6495.5
Simplified95.5%
Taylor expanded in y around 0
fabs-subN/A
lower-fabs.f64N/A
associate-*r/N/A
metadata-evalN/A
div-subN/A
lower-/.f64N/A
sub-negN/A
lower-fma.f64N/A
metadata-eval93.1
Simplified93.1%
if -2.8e5 < z < 6.49999999999999985e-34Initial program 93.3%
Taylor expanded in z around 0
remove-double-negN/A
mul-1-negN/A
sub-negN/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
unsub-negN/A
neg-mul-1N/A
remove-double-negN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6499.3
Simplified99.3%
Final simplification96.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fabs (/ (* z x) y)))) (if (<= z -1.05e+50) t_0 (if (<= z 5.1e+47) (fabs (/ (+ 4.0 x) y)) t_0))))
double code(double x, double y, double z) {
double t_0 = fabs(((z * x) / y));
double tmp;
if (z <= -1.05e+50) {
tmp = t_0;
} else if (z <= 5.1e+47) {
tmp = fabs(((4.0 + x) / y));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = abs(((z * x) / y))
if (z <= (-1.05d+50)) then
tmp = t_0
else if (z <= 5.1d+47) then
tmp = abs(((4.0d0 + x) / y))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.abs(((z * x) / y));
double tmp;
if (z <= -1.05e+50) {
tmp = t_0;
} else if (z <= 5.1e+47) {
tmp = Math.abs(((4.0 + x) / y));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.fabs(((z * x) / y)) tmp = 0 if z <= -1.05e+50: tmp = t_0 elif z <= 5.1e+47: tmp = math.fabs(((4.0 + x) / y)) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = abs(Float64(Float64(z * x) / y)) tmp = 0.0 if (z <= -1.05e+50) tmp = t_0; elseif (z <= 5.1e+47) tmp = abs(Float64(Float64(4.0 + x) / y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = abs(((z * x) / y)); tmp = 0.0; if (z <= -1.05e+50) tmp = t_0; elseif (z <= 5.1e+47) tmp = abs(((4.0 + x) / y)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[Abs[N[(N[(z * x), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[z, -1.05e+50], t$95$0, If[LessEqual[z, 5.1e+47], N[Abs[N[(N[(4.0 + x), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{z \cdot x}{y}\right|\\
\mathbf{if}\;z \leq -1.05 \cdot 10^{+50}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 5.1 \cdot 10^{+47}:\\
\;\;\;\;\left|\frac{4 + x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.05e50 or 5.1000000000000001e47 < z Initial program 89.0%
Taylor expanded in z around inf
associate-*r/N/A
lower-/.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
neg-mul-1N/A
lower-neg.f6476.7
Simplified76.7%
Taylor expanded in z around 0
mul-1-negN/A
fabs-negN/A
lower-fabs.f64N/A
lower-/.f64N/A
lower-*.f6476.7
Simplified76.7%
if -1.05e50 < z < 5.1000000000000001e47Initial program 92.8%
Taylor expanded in z around 0
remove-double-negN/A
mul-1-negN/A
sub-negN/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
unsub-negN/A
neg-mul-1N/A
remove-double-negN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6495.0
Simplified95.0%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fabs (/ x y)))) (if (<= x -10.0) t_0 (if (<= x 4.0) (fabs (/ 4.0 y)) t_0))))
double code(double x, double y, double z) {
double t_0 = fabs((x / y));
double tmp;
if (x <= -10.0) {
tmp = t_0;
} else if (x <= 4.0) {
tmp = fabs((4.0 / y));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = abs((x / y))
if (x <= (-10.0d0)) then
tmp = t_0
else if (x <= 4.0d0) then
tmp = abs((4.0d0 / y))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.abs((x / y));
double tmp;
if (x <= -10.0) {
tmp = t_0;
} else if (x <= 4.0) {
tmp = Math.abs((4.0 / y));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.fabs((x / y)) tmp = 0 if x <= -10.0: tmp = t_0 elif x <= 4.0: tmp = math.fabs((4.0 / y)) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = abs(Float64(x / y)) tmp = 0.0 if (x <= -10.0) tmp = t_0; elseif (x <= 4.0) tmp = abs(Float64(4.0 / y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = abs((x / y)); tmp = 0.0; if (x <= -10.0) tmp = t_0; elseif (x <= 4.0) tmp = abs((4.0 / y)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -10.0], t$95$0, If[LessEqual[x, 4.0], N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{x}{y}\right|\\
\mathbf{if}\;x \leq -10:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 4:\\
\;\;\;\;\left|\frac{4}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -10 or 4 < x Initial program 87.7%
Taylor expanded in z around 0
remove-double-negN/A
mul-1-negN/A
sub-negN/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
unsub-negN/A
neg-mul-1N/A
remove-double-negN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6468.7
Simplified68.7%
Taylor expanded in x around inf
lower-/.f6467.1
Simplified67.1%
if -10 < x < 4Initial program 96.1%
Taylor expanded in x around 0
lower-/.f6478.7
Simplified78.7%
(FPCore (x y z) :precision binary64 (fabs (/ (- x (fma x z -4.0)) y)))
double code(double x, double y, double z) {
return fabs(((x - fma(x, z, -4.0)) / y));
}
function code(x, y, z) return abs(Float64(Float64(x - fma(x, z, -4.0)) / y)) end
code[x_, y_, z_] := N[Abs[N[(N[(x - N[(x * z + -4.0), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{x - \mathsf{fma}\left(x, z, -4\right)}{y}\right|
\end{array}
Initial program 91.5%
Taylor expanded in x around 0
+-commutativeN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
associate-/l*N/A
mul-1-negN/A
associate-+r+N/A
+-commutativeN/A
associate-*r/N/A
*-rgt-identityN/A
+-commutativeN/A
associate-+r+N/A
Simplified97.0%
(FPCore (x y z) :precision binary64 (fabs (/ (+ 4.0 x) y)))
double code(double x, double y, double z) {
return fabs(((4.0 + x) / y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = abs(((4.0d0 + x) / y))
end function
public static double code(double x, double y, double z) {
return Math.abs(((4.0 + x) / y));
}
def code(x, y, z): return math.fabs(((4.0 + x) / y))
function code(x, y, z) return abs(Float64(Float64(4.0 + x) / y)) end
function tmp = code(x, y, z) tmp = abs(((4.0 + x) / y)); end
code[x_, y_, z_] := N[Abs[N[(N[(4.0 + x), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{4 + x}{y}\right|
\end{array}
Initial program 91.5%
Taylor expanded in z around 0
remove-double-negN/A
mul-1-negN/A
sub-negN/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
unsub-negN/A
neg-mul-1N/A
remove-double-negN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6473.8
Simplified73.8%
Final simplification73.8%
(FPCore (x y z) :precision binary64 (fabs (/ 4.0 y)))
double code(double x, double y, double z) {
return fabs((4.0 / y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = abs((4.0d0 / y))
end function
public static double code(double x, double y, double z) {
return Math.abs((4.0 / y));
}
def code(x, y, z): return math.fabs((4.0 / y))
function code(x, y, z) return abs(Float64(4.0 / y)) end
function tmp = code(x, y, z) tmp = abs((4.0 / y)); end
code[x_, y_, z_] := N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{4}{y}\right|
\end{array}
Initial program 91.5%
Taylor expanded in x around 0
lower-/.f6438.6
Simplified38.6%
herbie shell --seed 2024215
(FPCore (x y z)
:name "fabs fraction 1"
:precision binary64
(fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))