
(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 6 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 (<= y 1e-28) (* x (/ (+ y z) z)) (* (+ y z) (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1e-28) {
tmp = x * ((y + z) / 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 (y <= 1d-28) then
tmp = x * ((y + z) / 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 (y <= 1e-28) {
tmp = x * ((y + z) / z);
} else {
tmp = (y + z) * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1e-28: tmp = x * ((y + z) / z) else: tmp = (y + z) * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1e-28) tmp = Float64(x * Float64(Float64(y + z) / 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 (y <= 1e-28) tmp = x * ((y + z) / z); else tmp = (y + z) * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1e-28], N[(x * N[(N[(y + z), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 10^{-28}:\\
\;\;\;\;x \cdot \frac{y + z}{z}\\
\mathbf{else}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < 9.99999999999999971e-29Initial program 87.6%
associate-*r/97.2%
Simplified97.2%
if 9.99999999999999971e-29 < y Initial program 87.4%
associate-*l/96.4%
Simplified96.4%
Final simplification96.9%
(FPCore (x y z)
:precision binary64
(if (or (<= y -2.5e+43)
(not
(or (<= y 110000.0) (and (not (<= y 2.25e+80)) (<= y 2.2e+109)))))
(* x (/ y z))
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e+43) || !((y <= 110000.0) || (!(y <= 2.25e+80) && (y <= 2.2e+109)))) {
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 <= (-2.5d+43)) .or. (.not. (y <= 110000.0d0) .or. (.not. (y <= 2.25d+80)) .and. (y <= 2.2d+109))) 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 <= -2.5e+43) || !((y <= 110000.0) || (!(y <= 2.25e+80) && (y <= 2.2e+109)))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.5e+43) or not ((y <= 110000.0) or (not (y <= 2.25e+80) and (y <= 2.2e+109))): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.5e+43) || !((y <= 110000.0) || (!(y <= 2.25e+80) && (y <= 2.2e+109)))) 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 <= -2.5e+43) || ~(((y <= 110000.0) || (~((y <= 2.25e+80)) && (y <= 2.2e+109))))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.5e+43], N[Not[Or[LessEqual[y, 110000.0], And[N[Not[LessEqual[y, 2.25e+80]], $MachinePrecision], LessEqual[y, 2.2e+109]]]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+43} \lor \neg \left(y \leq 110000 \lor \neg \left(y \leq 2.25 \cdot 10^{+80}\right) \land y \leq 2.2 \cdot 10^{+109}\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.5000000000000002e43 or 1.1e5 < y < 2.25000000000000003e80 or 2.1999999999999999e109 < y Initial program 91.2%
associate-*r/90.5%
Simplified90.5%
Taylor expanded in y around inf 77.7%
if -2.5000000000000002e43 < y < 1.1e5 or 2.25000000000000003e80 < y < 2.1999999999999999e109Initial program 84.3%
associate-*r/99.2%
Simplified99.2%
Taylor expanded in y around 0 81.5%
Final simplification79.7%
(FPCore (x y z)
:precision binary64
(if (or (<= y -3.8e+43)
(and (not (<= y 780000.0))
(or (<= y 2.05e+80) (not (<= y 1.78e+109)))))
(* y (/ x z))
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.8e+43) || (!(y <= 780000.0) && ((y <= 2.05e+80) || !(y <= 1.78e+109)))) {
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 <= (-3.8d+43)) .or. (.not. (y <= 780000.0d0)) .and. (y <= 2.05d+80) .or. (.not. (y <= 1.78d+109))) 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 <= -3.8e+43) || (!(y <= 780000.0) && ((y <= 2.05e+80) || !(y <= 1.78e+109)))) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.8e+43) or (not (y <= 780000.0) and ((y <= 2.05e+80) or not (y <= 1.78e+109))): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.8e+43) || (!(y <= 780000.0) && ((y <= 2.05e+80) || !(y <= 1.78e+109)))) 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 <= -3.8e+43) || (~((y <= 780000.0)) && ((y <= 2.05e+80) || ~((y <= 1.78e+109))))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.8e+43], And[N[Not[LessEqual[y, 780000.0]], $MachinePrecision], Or[LessEqual[y, 2.05e+80], N[Not[LessEqual[y, 1.78e+109]], $MachinePrecision]]]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+43} \lor \neg \left(y \leq 780000\right) \land \left(y \leq 2.05 \cdot 10^{+80} \lor \neg \left(y \leq 1.78 \cdot 10^{+109}\right)\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.80000000000000008e43 or 7.8e5 < y < 2.05000000000000001e80 or 1.7800000000000001e109 < y Initial program 91.2%
associate-*r/90.5%
Simplified90.5%
Taylor expanded in y around inf 82.3%
*-commutative82.3%
associate-*r/85.1%
Simplified85.1%
if -3.80000000000000008e43 < y < 7.8e5 or 2.05000000000000001e80 < y < 1.7800000000000001e109Initial program 84.3%
associate-*r/99.2%
Simplified99.2%
Taylor expanded in y around 0 81.5%
Final simplification83.2%
(FPCore (x y z)
:precision binary64
(if (<= y -2.2e+45)
(/ (* y x) z)
(if (<= y 0.032)
x
(if (or (<= y 2.25e+80) (not (<= y 1.78e+109))) (* y (/ x z)) x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.2e+45) {
tmp = (y * x) / z;
} else if (y <= 0.032) {
tmp = x;
} else if ((y <= 2.25e+80) || !(y <= 1.78e+109)) {
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 <= (-2.2d+45)) then
tmp = (y * x) / z
else if (y <= 0.032d0) then
tmp = x
else if ((y <= 2.25d+80) .or. (.not. (y <= 1.78d+109))) 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 <= -2.2e+45) {
tmp = (y * x) / z;
} else if (y <= 0.032) {
tmp = x;
} else if ((y <= 2.25e+80) || !(y <= 1.78e+109)) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.2e+45: tmp = (y * x) / z elif y <= 0.032: tmp = x elif (y <= 2.25e+80) or not (y <= 1.78e+109): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.2e+45) tmp = Float64(Float64(y * x) / z); elseif (y <= 0.032) tmp = x; elseif ((y <= 2.25e+80) || !(y <= 1.78e+109)) 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 <= -2.2e+45) tmp = (y * x) / z; elseif (y <= 0.032) tmp = x; elseif ((y <= 2.25e+80) || ~((y <= 1.78e+109))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.2e+45], N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[y, 0.032], x, If[Or[LessEqual[y, 2.25e+80], N[Not[LessEqual[y, 1.78e+109]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{+45}:\\
\;\;\;\;\frac{y \cdot x}{z}\\
\mathbf{elif}\;y \leq 0.032:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.25 \cdot 10^{+80} \lor \neg \left(y \leq 1.78 \cdot 10^{+109}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.2e45Initial program 96.1%
associate-*r/92.9%
Simplified92.9%
Taylor expanded in y around inf 83.4%
if -2.2e45 < y < 0.032000000000000001 or 2.25000000000000003e80 < y < 1.7800000000000001e109Initial program 84.3%
associate-*r/99.2%
Simplified99.2%
Taylor expanded in y around 0 81.5%
if 0.032000000000000001 < y < 2.25000000000000003e80 or 1.7800000000000001e109 < y Initial program 87.2%
associate-*r/88.5%
Simplified88.5%
Taylor expanded in y around inf 81.4%
*-commutative81.4%
associate-*r/87.0%
Simplified87.0%
Final simplification83.3%
(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(x * Float64(Float64(y + z) / z)) end
function tmp = code(x, y, z) tmp = x * ((y + z) / z); end
code[x_, y_, z_] := N[(x * N[(N[(y + z), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{y + z}{z}
\end{array}
Initial program 87.6%
associate-*r/95.1%
Simplified95.1%
Final simplification95.1%
(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 87.6%
associate-*r/95.1%
Simplified95.1%
Taylor expanded in y around 0 50.5%
Final simplification50.5%
(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 2023271
(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))