
(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 84.0%
associate-*l/84.3%
remove-double-neg84.3%
unsub-neg84.3%
distribute-rgt-out--80.6%
associate-*r/74.5%
*-commutative74.5%
associate-*r/78.5%
associate-*r/83.3%
distribute-lft-neg-out83.3%
distribute-frac-neg83.3%
distribute-frac-neg283.3%
fma-neg83.3%
distribute-frac-neg83.3%
distribute-lft-neg-out83.3%
*-commutative83.3%
associate-/l*96.2%
*-inverses96.2%
*-rgt-identity96.2%
Simplified96.2%
Final simplification96.2%
(FPCore (x y z) :precision binary64 (if (<= z -9.5e-71) x (if (<= z 24000.0) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.5e-71) {
tmp = x;
} else if (z <= 24000.0) {
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 (z <= (-9.5d-71)) then
tmp = x
else if (z <= 24000.0d0) 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 (z <= -9.5e-71) {
tmp = x;
} else if (z <= 24000.0) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.5e-71: tmp = x elif z <= 24000.0: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.5e-71) tmp = x; elseif (z <= 24000.0) tmp = Float64(x * Float64(y / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9.5e-71) tmp = x; elseif (z <= 24000.0) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.5e-71], x, If[LessEqual[z, 24000.0], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.5 \cdot 10^{-71}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 24000:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.4999999999999994e-71 or 24000 < z Initial program 75.3%
associate-/l*99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
neg-sub099.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
*-inverses99.9%
metadata-eval99.9%
associate--r-99.9%
neg-sub099.9%
distribute-frac-neg299.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 80.1%
if -9.4999999999999994e-71 < z < 24000Initial program 93.1%
associate-/l*92.3%
remove-double-neg92.3%
distribute-frac-neg292.3%
neg-sub092.3%
remove-double-neg92.3%
unsub-neg92.3%
div-sub92.3%
*-inverses92.3%
metadata-eval92.3%
associate--r-92.3%
neg-sub092.3%
distribute-frac-neg292.3%
remove-double-neg92.3%
sub-neg92.3%
Simplified92.3%
Taylor expanded in y around inf 76.3%
associate-*r/72.1%
Simplified72.1%
Final simplification76.2%
(FPCore (x y z) :precision binary64 (if (<= z -9.5e-71) x (if (<= z 34000.0) (* y (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.5e-71) {
tmp = x;
} else if (z <= 34000.0) {
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 (z <= (-9.5d-71)) then
tmp = x
else if (z <= 34000.0d0) 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 (z <= -9.5e-71) {
tmp = x;
} else if (z <= 34000.0) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.5e-71: tmp = x elif z <= 34000.0: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.5e-71) tmp = x; elseif (z <= 34000.0) tmp = Float64(y * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9.5e-71) tmp = x; elseif (z <= 34000.0) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.5e-71], x, If[LessEqual[z, 34000.0], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.5 \cdot 10^{-71}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 34000:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.4999999999999994e-71 or 34000 < z Initial program 75.3%
associate-/l*99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
neg-sub099.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
*-inverses99.9%
metadata-eval99.9%
associate--r-99.9%
neg-sub099.9%
distribute-frac-neg299.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 80.1%
if -9.4999999999999994e-71 < z < 34000Initial program 93.1%
associate-/l*92.3%
remove-double-neg92.3%
distribute-frac-neg292.3%
neg-sub092.3%
remove-double-neg92.3%
unsub-neg92.3%
div-sub92.3%
*-inverses92.3%
metadata-eval92.3%
associate--r-92.3%
neg-sub092.3%
distribute-frac-neg292.3%
remove-double-neg92.3%
sub-neg92.3%
Simplified92.3%
Taylor expanded in y around inf 76.3%
associate-*l/75.2%
*-commutative75.2%
Simplified75.2%
Final simplification77.7%
(FPCore (x y z) :precision binary64 (if (<= z -9.5e-71) x (if (<= z 24000.0) (/ y (/ z x)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.5e-71) {
tmp = x;
} else if (z <= 24000.0) {
tmp = y / (z / x);
} 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 <= (-9.5d-71)) then
tmp = x
else if (z <= 24000.0d0) then
tmp = y / (z / x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -9.5e-71) {
tmp = x;
} else if (z <= 24000.0) {
tmp = y / (z / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.5e-71: tmp = x elif z <= 24000.0: tmp = y / (z / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.5e-71) tmp = x; elseif (z <= 24000.0) tmp = Float64(y / Float64(z / x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9.5e-71) tmp = x; elseif (z <= 24000.0) tmp = y / (z / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.5e-71], x, If[LessEqual[z, 24000.0], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.5 \cdot 10^{-71}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 24000:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.4999999999999994e-71 or 24000 < z Initial program 75.3%
associate-/l*99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
neg-sub099.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
*-inverses99.9%
metadata-eval99.9%
associate--r-99.9%
neg-sub099.9%
distribute-frac-neg299.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 80.1%
if -9.4999999999999994e-71 < z < 24000Initial program 93.1%
associate-/l*92.3%
remove-double-neg92.3%
distribute-frac-neg292.3%
neg-sub092.3%
remove-double-neg92.3%
unsub-neg92.3%
div-sub92.3%
*-inverses92.3%
metadata-eval92.3%
associate--r-92.3%
neg-sub092.3%
distribute-frac-neg292.3%
remove-double-neg92.3%
sub-neg92.3%
Simplified92.3%
Taylor expanded in y around inf 76.3%
associate-*r/72.1%
Simplified72.1%
associate-*r/76.3%
*-commutative76.3%
associate-*r/75.2%
clear-num75.2%
un-div-inv75.3%
Applied egg-rr75.3%
Final simplification77.7%
(FPCore (x y z) :precision binary64 (if (<= z -1.32e-71) x (if (<= z 40000.0) (/ (* x y) z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.32e-71) {
tmp = x;
} else if (z <= 40000.0) {
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 (z <= (-1.32d-71)) then
tmp = x
else if (z <= 40000.0d0) 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 (z <= -1.32e-71) {
tmp = x;
} else if (z <= 40000.0) {
tmp = (x * y) / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.32e-71: tmp = x elif z <= 40000.0: tmp = (x * y) / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.32e-71) tmp = x; elseif (z <= 40000.0) tmp = Float64(Float64(x * y) / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.32e-71) tmp = x; elseif (z <= 40000.0) tmp = (x * y) / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.32e-71], x, If[LessEqual[z, 40000.0], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.32 \cdot 10^{-71}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 40000:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.32e-71 or 4e4 < z Initial program 75.3%
associate-/l*99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
neg-sub099.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
*-inverses99.9%
metadata-eval99.9%
associate--r-99.9%
neg-sub099.9%
distribute-frac-neg299.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 80.1%
if -1.32e-71 < z < 4e4Initial program 93.1%
associate-/l*92.3%
remove-double-neg92.3%
distribute-frac-neg292.3%
neg-sub092.3%
remove-double-neg92.3%
unsub-neg92.3%
div-sub92.3%
*-inverses92.3%
metadata-eval92.3%
associate--r-92.3%
neg-sub092.3%
distribute-frac-neg292.3%
remove-double-neg92.3%
sub-neg92.3%
Simplified92.3%
Taylor expanded in y around inf 76.3%
Final simplification78.2%
(FPCore (x y z) :precision binary64 (* x (- (/ y z) -1.0)))
double code(double x, double y, double z) {
return x * ((y / z) - -1.0);
}
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) - (-1.0d0))
end function
public static double code(double x, double y, double z) {
return x * ((y / z) - -1.0);
}
def code(x, y, z): return x * ((y / z) - -1.0)
function code(x, y, z) return Float64(x * Float64(Float64(y / z) - -1.0)) end
function tmp = code(x, y, z) tmp = x * ((y / z) - -1.0); end
code[x_, y_, z_] := N[(x * N[(N[(y / z), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(\frac{y}{z} - -1\right)
\end{array}
Initial program 84.0%
associate-/l*96.2%
remove-double-neg96.2%
distribute-frac-neg296.2%
neg-sub096.2%
remove-double-neg96.2%
unsub-neg96.2%
div-sub96.2%
*-inverses96.2%
metadata-eval96.2%
associate--r-96.2%
neg-sub096.2%
distribute-frac-neg296.2%
remove-double-neg96.2%
sub-neg96.2%
Simplified96.2%
Final simplification96.2%
(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 84.0%
associate-/l*96.2%
remove-double-neg96.2%
distribute-frac-neg296.2%
neg-sub096.2%
remove-double-neg96.2%
unsub-neg96.2%
div-sub96.2%
*-inverses96.2%
metadata-eval96.2%
associate--r-96.2%
neg-sub096.2%
distribute-frac-neg296.2%
remove-double-neg96.2%
sub-neg96.2%
Simplified96.2%
Taylor expanded in y around 0 51.4%
Final simplification51.4%
(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 2024078
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:alt
(/ x (/ z (+ y z)))
(/ (* x (+ y z)) z))