
(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 (fma x (/ y z) x))
double code(double x, double y, double z) {
return fma(x, (y / z), x);
}
function code(x, y, z) return fma(x, Float64(y / z), x) end
code[x_, y_, z_] := N[(x * N[(y / z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \frac{y}{z}, x\right)
\end{array}
Initial program 85.8%
associate-*l/83.0%
distribute-rgt-in80.9%
*-commutative80.9%
associate-/r/93.9%
*-inverses93.9%
/-rgt-identity93.9%
associate-*r/95.1%
*-commutative95.1%
associate-*r/97.3%
fma-def97.3%
Simplified97.3%
Final simplification97.3%
(FPCore (x y z)
:precision binary64
(if (or (<= y -1.45e+44)
(and (not (<= y 1.1e+23)) (or (<= y 1.3e+69) (not (<= y 2.8e+127)))))
(* x (/ y z))
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.45e+44) || (!(y <= 1.1e+23) && ((y <= 1.3e+69) || !(y <= 2.8e+127)))) {
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+44)) .or. (.not. (y <= 1.1d+23)) .and. (y <= 1.3d+69) .or. (.not. (y <= 2.8d+127))) 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+44) || (!(y <= 1.1e+23) && ((y <= 1.3e+69) || !(y <= 2.8e+127)))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.45e+44) or (not (y <= 1.1e+23) and ((y <= 1.3e+69) or not (y <= 2.8e+127))): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.45e+44) || (!(y <= 1.1e+23) && ((y <= 1.3e+69) || !(y <= 2.8e+127)))) 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+44) || (~((y <= 1.1e+23)) && ((y <= 1.3e+69) || ~((y <= 2.8e+127))))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.45e+44], And[N[Not[LessEqual[y, 1.1e+23]], $MachinePrecision], Or[LessEqual[y, 1.3e+69], N[Not[LessEqual[y, 2.8e+127]], $MachinePrecision]]]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{+44} \lor \neg \left(y \leq 1.1 \cdot 10^{+23}\right) \land \left(y \leq 1.3 \cdot 10^{+69} \lor \neg \left(y \leq 2.8 \cdot 10^{+127}\right)\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.4500000000000001e44 or 1.10000000000000004e23 < y < 1.3000000000000001e69 or 2.8000000000000002e127 < y Initial program 92.0%
associate-*l/90.1%
Simplified90.1%
Taylor expanded in z around 0 81.3%
*-commutative81.3%
associate-*r/79.2%
Simplified79.2%
if -1.4500000000000001e44 < y < 1.10000000000000004e23 or 1.3000000000000001e69 < y < 2.8000000000000002e127Initial program 82.0%
associate-*l/78.6%
Simplified78.6%
Taylor expanded in z around inf 75.9%
Final simplification77.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (/ x z))))
(if (<= y -5e+49)
t_0
(if (<= y 1.1e+23)
x
(if (<= y 1e+69) (* x (/ y z)) (if (<= y 6.8e+127) x t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x / z);
double tmp;
if (y <= -5e+49) {
tmp = t_0;
} else if (y <= 1.1e+23) {
tmp = x;
} else if (y <= 1e+69) {
tmp = x * (y / z);
} else if (y <= 6.8e+127) {
tmp = x;
} 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 = y * (x / z)
if (y <= (-5d+49)) then
tmp = t_0
else if (y <= 1.1d+23) then
tmp = x
else if (y <= 1d+69) then
tmp = x * (y / z)
else if (y <= 6.8d+127) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (x / z);
double tmp;
if (y <= -5e+49) {
tmp = t_0;
} else if (y <= 1.1e+23) {
tmp = x;
} else if (y <= 1e+69) {
tmp = x * (y / z);
} else if (y <= 6.8e+127) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x / z) tmp = 0 if y <= -5e+49: tmp = t_0 elif y <= 1.1e+23: tmp = x elif y <= 1e+69: tmp = x * (y / z) elif y <= 6.8e+127: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x / z)) tmp = 0.0 if (y <= -5e+49) tmp = t_0; elseif (y <= 1.1e+23) tmp = x; elseif (y <= 1e+69) tmp = Float64(x * Float64(y / z)); elseif (y <= 6.8e+127) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x / z); tmp = 0.0; if (y <= -5e+49) tmp = t_0; elseif (y <= 1.1e+23) tmp = x; elseif (y <= 1e+69) tmp = x * (y / z); elseif (y <= 6.8e+127) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5e+49], t$95$0, If[LessEqual[y, 1.1e+23], x, If[LessEqual[y, 1e+69], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6.8e+127], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \frac{x}{z}\\
\mathbf{if}\;y \leq -5 \cdot 10^{+49}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{+23}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 10^{+69}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{+127}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -5.0000000000000004e49 or 6.79999999999999955e127 < y Initial program 90.6%
associate-*l/89.4%
Simplified89.4%
Taylor expanded in z around 0 80.2%
associate-*r/78.9%
Simplified78.9%
if -5.0000000000000004e49 < y < 1.10000000000000004e23 or 1.0000000000000001e69 < y < 6.79999999999999955e127Initial program 82.0%
associate-*l/78.6%
Simplified78.6%
Taylor expanded in z around inf 75.9%
if 1.10000000000000004e23 < y < 1.0000000000000001e69Initial program 99.8%
associate-*l/93.7%
Simplified93.7%
Taylor expanded in z around 0 87.4%
*-commutative87.4%
associate-*r/87.4%
Simplified87.4%
Final simplification77.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (* x y) z)))
(if (<= y -1.65e+43)
t_0
(if (<= y 1.28e+23)
x
(if (<= y 9.5e+68) (* x (/ y z)) (if (<= y 3e+127) x t_0))))))
double code(double x, double y, double z) {
double t_0 = (x * y) / z;
double tmp;
if (y <= -1.65e+43) {
tmp = t_0;
} else if (y <= 1.28e+23) {
tmp = x;
} else if (y <= 9.5e+68) {
tmp = x * (y / z);
} else if (y <= 3e+127) {
tmp = x;
} 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 = (x * y) / z
if (y <= (-1.65d+43)) then
tmp = t_0
else if (y <= 1.28d+23) then
tmp = x
else if (y <= 9.5d+68) then
tmp = x * (y / z)
else if (y <= 3d+127) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * y) / z;
double tmp;
if (y <= -1.65e+43) {
tmp = t_0;
} else if (y <= 1.28e+23) {
tmp = x;
} else if (y <= 9.5e+68) {
tmp = x * (y / z);
} else if (y <= 3e+127) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x * y) / z tmp = 0 if y <= -1.65e+43: tmp = t_0 elif y <= 1.28e+23: tmp = x elif y <= 9.5e+68: tmp = x * (y / z) elif y <= 3e+127: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x * y) / z) tmp = 0.0 if (y <= -1.65e+43) tmp = t_0; elseif (y <= 1.28e+23) tmp = x; elseif (y <= 9.5e+68) tmp = Float64(x * Float64(y / z)); elseif (y <= 3e+127) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * y) / z; tmp = 0.0; if (y <= -1.65e+43) tmp = t_0; elseif (y <= 1.28e+23) tmp = x; elseif (y <= 9.5e+68) tmp = x * (y / z); elseif (y <= 3e+127) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[y, -1.65e+43], t$95$0, If[LessEqual[y, 1.28e+23], x, If[LessEqual[y, 9.5e+68], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3e+127], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot y}{z}\\
\mathbf{if}\;y \leq -1.65 \cdot 10^{+43}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1.28 \cdot 10^{+23}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{+68}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+127}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1.6500000000000001e43 or 3.0000000000000002e127 < y Initial program 90.6%
associate-*l/89.4%
Simplified89.4%
Taylor expanded in z around 0 80.2%
if -1.6500000000000001e43 < y < 1.28e23 or 9.50000000000000069e68 < y < 3.0000000000000002e127Initial program 82.0%
associate-*l/78.6%
Simplified78.6%
Taylor expanded in z around inf 75.9%
if 1.28e23 < y < 9.50000000000000069e68Initial program 99.8%
associate-*l/93.7%
Simplified93.7%
Taylor expanded in z around 0 87.4%
*-commutative87.4%
associate-*r/87.4%
Simplified87.4%
Final simplification77.9%
(FPCore (x y z) :precision binary64 (if (<= z -2.7e+144) x (if (<= z 1.95e+93) (* (/ x z) (+ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.7e+144) {
tmp = x;
} else if (z <= 1.95e+93) {
tmp = (x / z) * (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 (z <= (-2.7d+144)) then
tmp = x
else if (z <= 1.95d+93) then
tmp = (x / z) * (y + z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.7e+144) {
tmp = x;
} else if (z <= 1.95e+93) {
tmp = (x / z) * (y + z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.7e+144: tmp = x elif z <= 1.95e+93: tmp = (x / z) * (y + z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.7e+144) tmp = x; elseif (z <= 1.95e+93) tmp = Float64(Float64(x / z) * Float64(y + z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.7e+144) tmp = x; elseif (z <= 1.95e+93) tmp = (x / z) * (y + z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.7e+144], x, If[LessEqual[z, 1.95e+93], N[(N[(x / z), $MachinePrecision] * N[(y + z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.7 \cdot 10^{+144}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.95 \cdot 10^{+93}:\\
\;\;\;\;\frac{x}{z} \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.70000000000000015e144 or 1.9500000000000001e93 < z Initial program 72.4%
associate-*l/63.2%
Simplified63.2%
Taylor expanded in z around inf 87.9%
if -2.70000000000000015e144 < z < 1.9500000000000001e93Initial program 91.8%
associate-*l/91.8%
Simplified91.8%
Final simplification90.6%
(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.8%
associate-*l/83.0%
distribute-rgt-in80.9%
*-commutative80.9%
associate-/r/93.9%
*-inverses93.9%
/-rgt-identity93.9%
associate-*r/95.1%
*-commutative95.1%
associate-*r/97.3%
fma-def97.3%
Simplified97.3%
fma-udef97.3%
Applied egg-rr97.3%
Final simplification97.3%
(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.8%
associate-*l/83.0%
Simplified83.0%
Taylor expanded in z around inf 53.9%
Final simplification53.9%
(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 2023185
(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))