
(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 (<= z -3.5e-58) (* x (- (/ y z) -1.0)) (if (<= z 1.6e-138) (* (+ z y) (/ x z)) (fma x (/ y z) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.5e-58) {
tmp = x * ((y / z) - -1.0);
} else if (z <= 1.6e-138) {
tmp = (z + y) * (x / z);
} else {
tmp = fma(x, (y / z), x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -3.5e-58) tmp = Float64(x * Float64(Float64(y / z) - -1.0)); elseif (z <= 1.6e-138) tmp = Float64(Float64(z + y) * Float64(x / z)); else tmp = fma(x, Float64(y / z), x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -3.5e-58], N[(x * N[(N[(y / z), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.6e-138], N[(N[(z + y), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x * N[(y / z), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.5 \cdot 10^{-58}:\\
\;\;\;\;x \cdot \left(\frac{y}{z} - -1\right)\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{-138}:\\
\;\;\;\;\left(z + y\right) \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\
\end{array}
\end{array}
if z < -3.4999999999999999e-58Initial program 79.1%
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%
if -3.4999999999999999e-58 < z < 1.60000000000000005e-138Initial program 93.8%
*-commutative93.8%
associate-/l*97.1%
Simplified97.1%
if 1.60000000000000005e-138 < z Initial program 77.7%
associate-*l/86.8%
remove-double-neg86.8%
unsub-neg86.8%
distribute-rgt-out--85.3%
associate-*r/81.0%
*-commutative81.0%
associate-*r/89.0%
associate-*r/81.0%
distribute-lft-neg-out81.0%
distribute-frac-neg81.0%
distribute-frac-neg281.0%
fma-neg81.0%
distribute-frac-neg81.0%
distribute-lft-neg-out81.0%
*-commutative81.0%
associate-/l*99.8%
*-inverses99.8%
*-rgt-identity99.8%
Simplified99.8%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.5e-57) (not (<= z 2e-138))) (* x (- (/ y z) -1.0)) (* (+ z y) (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.5e-57) || !(z <= 2e-138)) {
tmp = x * ((y / z) - -1.0);
} else {
tmp = (z + 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 ((z <= (-1.5d-57)) .or. (.not. (z <= 2d-138))) then
tmp = x * ((y / z) - (-1.0d0))
else
tmp = (z + y) * (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.5e-57) || !(z <= 2e-138)) {
tmp = x * ((y / z) - -1.0);
} else {
tmp = (z + y) * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.5e-57) or not (z <= 2e-138): tmp = x * ((y / z) - -1.0) else: tmp = (z + y) * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.5e-57) || !(z <= 2e-138)) tmp = Float64(x * Float64(Float64(y / z) - -1.0)); else tmp = Float64(Float64(z + y) * Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.5e-57) || ~((z <= 2e-138))) tmp = x * ((y / z) - -1.0); else tmp = (z + y) * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.5e-57], N[Not[LessEqual[z, 2e-138]], $MachinePrecision]], N[(x * N[(N[(y / z), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(z + y), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.5 \cdot 10^{-57} \lor \neg \left(z \leq 2 \cdot 10^{-138}\right):\\
\;\;\;\;x \cdot \left(\frac{y}{z} - -1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z + y\right) \cdot \frac{x}{z}\\
\end{array}
\end{array}
if z < -1.5e-57 or 2.00000000000000013e-138 < z Initial program 78.4%
associate-/l*99.8%
remove-double-neg99.8%
distribute-frac-neg299.8%
neg-sub099.8%
remove-double-neg99.8%
unsub-neg99.8%
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%
if -1.5e-57 < z < 2.00000000000000013e-138Initial program 93.8%
*-commutative93.8%
associate-/l*97.1%
Simplified97.1%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.5e-42) (not (<= y 63000000.0))) (* x (/ y z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.5e-42) || !(y <= 63000000.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 ((y <= (-6.5d-42)) .or. (.not. (y <= 63000000.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 ((y <= -6.5e-42) || !(y <= 63000000.0)) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.5e-42) or not (y <= 63000000.0): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.5e-42) || !(y <= 63000000.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 ((y <= -6.5e-42) || ~((y <= 63000000.0))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.5e-42], N[Not[LessEqual[y, 63000000.0]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{-42} \lor \neg \left(y \leq 63000000\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -6.4999999999999998e-42 or 6.3e7 < y Initial program 89.1%
associate-/l*91.6%
remove-double-neg91.6%
distribute-frac-neg291.6%
neg-sub091.6%
remove-double-neg91.6%
unsub-neg91.6%
div-sub91.6%
*-inverses91.6%
metadata-eval91.6%
associate--r-91.6%
neg-sub091.6%
distribute-frac-neg291.6%
remove-double-neg91.6%
sub-neg91.6%
Simplified91.6%
Taylor expanded in y around inf 76.4%
associate-*r/71.7%
Simplified71.7%
if -6.4999999999999998e-42 < y < 6.3e7Initial program 78.4%
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 82.9%
Final simplification76.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.35e-42) (not (<= y 230000000.0))) (/ (* x y) z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e-42) || !(y <= 230000000.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 ((y <= (-1.35d-42)) .or. (.not. (y <= 230000000.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 ((y <= -1.35e-42) || !(y <= 230000000.0)) {
tmp = (x * y) / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.35e-42) or not (y <= 230000000.0): tmp = (x * y) / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.35e-42) || !(y <= 230000000.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 ((y <= -1.35e-42) || ~((y <= 230000000.0))) tmp = (x * y) / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.35e-42], N[Not[LessEqual[y, 230000000.0]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-42} \lor \neg \left(y \leq 230000000\right):\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.35e-42 or 2.3e8 < y Initial program 89.1%
associate-/l*91.6%
remove-double-neg91.6%
distribute-frac-neg291.6%
neg-sub091.6%
remove-double-neg91.6%
unsub-neg91.6%
div-sub91.6%
*-inverses91.6%
metadata-eval91.6%
associate--r-91.6%
neg-sub091.6%
distribute-frac-neg291.6%
remove-double-neg91.6%
sub-neg91.6%
Simplified91.6%
Taylor expanded in y around inf 76.4%
if -1.35e-42 < y < 2.3e8Initial program 78.4%
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 82.9%
Final simplification79.2%
(FPCore (x y z) :precision binary64 (if (<= y -1.4e-42) (* y (/ x z)) (if (<= y 4200.0) x (* x (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.4e-42) {
tmp = y * (x / z);
} else if (y <= 4200.0) {
tmp = x;
} else {
tmp = x * (y / 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 <= (-1.4d-42)) then
tmp = y * (x / z)
else if (y <= 4200.0d0) then
tmp = x
else
tmp = x * (y / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.4e-42) {
tmp = y * (x / z);
} else if (y <= 4200.0) {
tmp = x;
} else {
tmp = x * (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.4e-42: tmp = y * (x / z) elif y <= 4200.0: tmp = x else: tmp = x * (y / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.4e-42) tmp = Float64(y * Float64(x / z)); elseif (y <= 4200.0) tmp = x; else tmp = Float64(x * Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.4e-42) tmp = y * (x / z); elseif (y <= 4200.0) tmp = x; else tmp = x * (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.4e-42], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4200.0], x, N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-42}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;y \leq 4200:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\end{array}
\end{array}
if y < -1.39999999999999999e-42Initial program 88.0%
associate-/l*88.0%
remove-double-neg88.0%
distribute-frac-neg288.0%
neg-sub088.0%
remove-double-neg88.0%
unsub-neg88.0%
div-sub88.0%
*-inverses88.0%
metadata-eval88.0%
associate--r-88.0%
neg-sub088.0%
distribute-frac-neg288.0%
remove-double-neg88.0%
sub-neg88.0%
Simplified88.0%
Taylor expanded in y around inf 76.1%
*-commutative76.1%
associate-/l*75.4%
Applied egg-rr75.4%
if -1.39999999999999999e-42 < y < 4200Initial program 78.4%
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 82.9%
if 4200 < y Initial program 90.0%
associate-/l*94.9%
remove-double-neg94.9%
distribute-frac-neg294.9%
neg-sub094.9%
remove-double-neg94.9%
unsub-neg94.9%
div-sub94.9%
*-inverses94.9%
metadata-eval94.9%
associate--r-94.9%
neg-sub094.9%
distribute-frac-neg294.9%
remove-double-neg94.9%
sub-neg94.9%
Simplified94.9%
Taylor expanded in y around inf 76.6%
associate-*r/75.3%
Simplified75.3%
Final simplification78.6%
(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.5%
associate-/l*95.1%
remove-double-neg95.1%
distribute-frac-neg295.1%
neg-sub095.1%
remove-double-neg95.1%
unsub-neg95.1%
div-sub95.1%
*-inverses95.1%
metadata-eval95.1%
associate--r-95.1%
neg-sub095.1%
distribute-frac-neg295.1%
remove-double-neg95.1%
sub-neg95.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 84.5%
associate-/l*95.1%
remove-double-neg95.1%
distribute-frac-neg295.1%
neg-sub095.1%
remove-double-neg95.1%
unsub-neg95.1%
div-sub95.1%
*-inverses95.1%
metadata-eval95.1%
associate--r-95.1%
neg-sub095.1%
distribute-frac-neg295.1%
remove-double-neg95.1%
sub-neg95.1%
Simplified95.1%
Taylor expanded in y around 0 47.6%
Final simplification47.6%
(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 2024077
(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))