
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y + z)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y + z)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= (/ (* x (+ y z)) z) 2e-14) (/ x (/ z (+ y z))) (* (+ y z) (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (((x * (y + z)) / z) <= 2e-14) {
tmp = x / (z / (y + z));
} else {
tmp = (y + z) * (x / z);
}
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) :: tmp
if (((x * (y + z)) / z) <= 2d-14) then
tmp = x / (z / (y + z))
else
tmp = (y + z) * (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((x * (y + z)) / z) <= 2e-14) {
tmp = x / (z / (y + z));
} else {
tmp = (y + z) * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x * (y + z)) / z) <= 2e-14: tmp = x / (z / (y + z)) else: tmp = (y + z) * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(Float64(x * Float64(y + z)) / z) <= 2e-14) tmp = Float64(x / Float64(z / Float64(y + z))); else tmp = Float64(Float64(y + z) * Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((x * (y + z)) / z) <= 2e-14) tmp = x / (z / (y + z)); else tmp = (y + z) * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], 2e-14], N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq 2 \cdot 10^{-14}:\\
\;\;\;\;\frac{x}{\frac{z}{y + z}}\\
\mathbf{else}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 y z)) z) < 2e-14Initial program 87.3%
associate-*l/81.8%
Simplified81.8%
associate-/r/99.3%
+-commutative99.3%
Applied egg-rr99.3%
if 2e-14 < (/.f64 (*.f64 x (+.f64 y z)) z) Initial program 82.1%
associate-*l/98.9%
Simplified98.9%
Final simplification99.1%
(FPCore (x y z)
:precision binary64
(if (or (<= y -1.45e+131)
(and (not (<= y -5.5e+87)) (or (<= y -1950.0) (not (<= y 6.2e+55)))))
(* x (/ y z))
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.45e+131) || (!(y <= -5.5e+87) && ((y <= -1950.0) || !(y <= 6.2e+55)))) {
tmp = x * (y / z);
} else {
tmp = x;
}
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) :: tmp
if ((y <= (-1.45d+131)) .or. (.not. (y <= (-5.5d+87))) .and. (y <= (-1950.0d0)) .or. (.not. (y <= 6.2d+55))) then
tmp = x * (y / z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.45e+131) || (!(y <= -5.5e+87) && ((y <= -1950.0) || !(y <= 6.2e+55)))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.45e+131) or (not (y <= -5.5e+87) and ((y <= -1950.0) or not (y <= 6.2e+55))): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.45e+131) || (!(y <= -5.5e+87) && ((y <= -1950.0) || !(y <= 6.2e+55)))) tmp = Float64(x * Float64(y / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.45e+131) || (~((y <= -5.5e+87)) && ((y <= -1950.0) || ~((y <= 6.2e+55))))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.45e+131], And[N[Not[LessEqual[y, -5.5e+87]], $MachinePrecision], Or[LessEqual[y, -1950.0], N[Not[LessEqual[y, 6.2e+55]], $MachinePrecision]]]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{+131} \lor \neg \left(y \leq -5.5 \cdot 10^{+87}\right) \land \left(y \leq -1950 \lor \neg \left(y \leq 6.2 \cdot 10^{+55}\right)\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.45000000000000005e131 or -5.50000000000000022e87 < y < -1950 or 6.19999999999999987e55 < y Initial program 92.4%
associate-*l/91.6%
Simplified91.6%
Taylor expanded in z around 0 80.6%
associate-*r/77.3%
Simplified77.3%
if -1.45000000000000005e131 < y < -5.50000000000000022e87 or -1950 < y < 6.19999999999999987e55Initial program 79.6%
associate-*l/86.2%
Simplified86.2%
Taylor expanded in z around inf 77.7%
Final simplification77.5%
(FPCore (x y z) :precision binary64 (if (<= z -1.55e+123) x (if (<= z 1.05e+212) (* (+ y z) (/ x z)) (/ 1.0 (/ 1.0 x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.55e+123) {
tmp = x;
} else if (z <= 1.05e+212) {
tmp = (y + z) * (x / z);
} else {
tmp = 1.0 / (1.0 / x);
}
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) :: tmp
if (z <= (-1.55d+123)) then
tmp = x
else if (z <= 1.05d+212) then
tmp = (y + z) * (x / z)
else
tmp = 1.0d0 / (1.0d0 / x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.55e+123) {
tmp = x;
} else if (z <= 1.05e+212) {
tmp = (y + z) * (x / z);
} else {
tmp = 1.0 / (1.0 / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.55e+123: tmp = x elif z <= 1.05e+212: tmp = (y + z) * (x / z) else: tmp = 1.0 / (1.0 / x) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.55e+123) tmp = x; elseif (z <= 1.05e+212) tmp = Float64(Float64(y + z) * Float64(x / z)); else tmp = Float64(1.0 / Float64(1.0 / x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.55e+123) tmp = x; elseif (z <= 1.05e+212) tmp = (y + z) * (x / z); else tmp = 1.0 / (1.0 / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.55e+123], x, If[LessEqual[z, 1.05e+212], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.55 \cdot 10^{+123}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{+212}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{1}{x}}\\
\end{array}
\end{array}
if z < -1.55000000000000003e123Initial program 63.3%
associate-*l/73.4%
Simplified73.4%
Taylor expanded in z around inf 94.9%
if -1.55000000000000003e123 < z < 1.05e212Initial program 89.8%
associate-*l/93.7%
Simplified93.7%
if 1.05e212 < z Initial program 75.0%
associate-*l/59.9%
Simplified59.9%
add-cube-cbrt58.6%
pow358.7%
*-commutative58.7%
clear-num58.6%
un-div-inv58.6%
+-commutative58.6%
Applied egg-rr58.6%
rem-cube-cbrt60.0%
div-inv59.9%
associate-/r*99.8%
+-commutative99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 90.9%
Final simplification93.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -26000.0) (not (<= y 2.45e+56))) (* y (/ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -26000.0) || !(y <= 2.45e+56)) {
tmp = y * (x / z);
} else {
tmp = x;
}
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) :: tmp
if ((y <= (-26000.0d0)) .or. (.not. (y <= 2.45d+56))) then
tmp = y * (x / z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -26000.0) || !(y <= 2.45e+56)) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -26000.0) or not (y <= 2.45e+56): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -26000.0) || !(y <= 2.45e+56)) tmp = Float64(y * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -26000.0) || ~((y <= 2.45e+56))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -26000.0], N[Not[LessEqual[y, 2.45e+56]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -26000 \lor \neg \left(y \leq 2.45 \cdot 10^{+56}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -26000 or 2.4500000000000001e56 < y Initial program 91.6%
associate-*l/90.3%
Simplified90.3%
Taylor expanded in z around 0 76.9%
associate-/l*72.6%
associate-/r/76.7%
Applied egg-rr76.7%
if -26000 < y < 2.4500000000000001e56Initial program 79.3%
associate-*l/86.9%
Simplified86.9%
Taylor expanded in z around inf 79.9%
Final simplification78.3%
(FPCore (x y z) :precision binary64 (if (<= y -2.1) (/ (* x y) z) (if (<= y 2.6e+56) x (* y (/ x z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.1) {
tmp = (x * y) / z;
} else if (y <= 2.6e+56) {
tmp = x;
} else {
tmp = y * (x / z);
}
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) :: tmp
if (y <= (-2.1d0)) then
tmp = (x * y) / z
else if (y <= 2.6d+56) then
tmp = x
else
tmp = y * (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.1) {
tmp = (x * y) / z;
} else if (y <= 2.6e+56) {
tmp = x;
} else {
tmp = y * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.1: tmp = (x * y) / z elif y <= 2.6e+56: tmp = x else: tmp = y * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.1) tmp = Float64(Float64(x * y) / z); elseif (y <= 2.6e+56) tmp = x; else tmp = Float64(y * Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.1) tmp = (x * y) / z; elseif (y <= 2.6e+56) tmp = x; else tmp = y * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.1], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[y, 2.6e+56], x, N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.1:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{+56}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.10000000000000009Initial program 93.9%
associate-*l/88.2%
Simplified88.2%
Taylor expanded in z around 0 76.9%
if -2.10000000000000009 < y < 2.60000000000000011e56Initial program 79.3%
associate-*l/86.9%
Simplified86.9%
Taylor expanded in z around inf 79.9%
if 2.60000000000000011e56 < y Initial program 89.3%
associate-*l/92.5%
Simplified92.5%
Taylor expanded in z around 0 77.0%
associate-/l*71.1%
associate-/r/77.3%
Applied egg-rr77.3%
Final simplification78.5%
(FPCore (x y z) :precision binary64 (+ x (* x (/ y z))))
double code(double x, double y, double z) {
return x + (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 = x + (x * (y / z))
end function
public static double code(double x, double y, double z) {
return x + (x * (y / z));
}
def code(x, y, z): return x + (x * (y / z))
function code(x, y, z) return Float64(x + Float64(x * Float64(y / z))) end
function tmp = code(x, y, z) tmp = x + (x * (y / z)); end
code[x_, y_, z_] := N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + x \cdot \frac{y}{z}
\end{array}
Initial program 85.3%
associate-*r/96.6%
remove-double-neg96.6%
sub-neg96.6%
div-sub96.5%
distribute-frac-neg96.5%
*-inverses96.5%
metadata-eval96.5%
sub-neg96.5%
metadata-eval96.5%
*-inverses96.5%
distribute-lft-out96.6%
*-inverses96.6%
*-rgt-identity96.6%
fma-def96.6%
Simplified96.6%
fma-udef96.6%
Applied egg-rr96.6%
Final simplification96.6%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 85.3%
associate-*l/88.5%
Simplified88.5%
Taylor expanded in z around inf 51.3%
Final simplification51.3%
(FPCore (x y z) :precision binary64 (/ x (/ z (+ y z))))
double code(double x, double y, double z) {
return x / (z / (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 = x / (z / (y + z))
end function
public static double code(double x, double y, double z) {
return x / (z / (y + z));
}
def code(x, y, z): return x / (z / (y + z))
function code(x, y, z) return Float64(x / Float64(z / Float64(y + z))) end
function tmp = code(x, y, z) tmp = x / (z / (y + z)); end
code[x_, y_, z_] := N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{z}{y + z}}
\end{array}
herbie shell --seed 2023320
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(/ x (/ z (+ y z)))
(/ (* x (+ y z)) z))