
(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 5 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 87.1%
Taylor expanded in x around 0
associate-/l*N/A
+-commutativeN/A
*-lft-identityN/A
metadata-evalN/A
cancel-sign-sub-invN/A
div-subN/A
*-inversesN/A
associate-*r/N/A
distribute-rgt-out--N/A
*-lft-identityN/A
mul-1-negN/A
cancel-sign-subN/A
distribute-rgt1-inN/A
distribute-lft1-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.9
Applied rewrites96.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (/ (* x y) z))) (if (<= y -1.36e-124) t_0 (if (<= y 1.5e-46) x t_0))))
double code(double x, double y, double z) {
double t_0 = (x * y) / z;
double tmp;
if (y <= -1.36e-124) {
tmp = t_0;
} else if (y <= 1.5e-46) {
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.36d-124)) then
tmp = t_0
else if (y <= 1.5d-46) 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.36e-124) {
tmp = t_0;
} else if (y <= 1.5e-46) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x * y) / z tmp = 0 if y <= -1.36e-124: tmp = t_0 elif y <= 1.5e-46: 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.36e-124) tmp = t_0; elseif (y <= 1.5e-46) 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.36e-124) tmp = t_0; elseif (y <= 1.5e-46) 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.36e-124], t$95$0, If[LessEqual[y, 1.5e-46], x, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot y}{z}\\
\mathbf{if}\;y \leq -1.36 \cdot 10^{-124}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{-46}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.3599999999999999e-124 or 1.49999999999999994e-46 < y Initial program 90.3%
Taylor expanded in y around inf
lower-/.f64N/A
lower-*.f6473.8
Applied rewrites73.8%
if -1.3599999999999999e-124 < y < 1.49999999999999994e-46Initial program 81.2%
Taylor expanded in y around 0
lower-*.f6472.9
Applied rewrites72.9%
associate-/l*N/A
*-inversesN/A
*-rgt-identity89.6
Applied rewrites89.6%
(FPCore (x y z) :precision binary64 (if (<= y -1.36e-124) (* x (/ y z)) (if (<= y 1.65e-46) x (* y (/ x z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.36e-124) {
tmp = x * (y / z);
} else if (y <= 1.65e-46) {
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 <= (-1.36d-124)) then
tmp = x * (y / z)
else if (y <= 1.65d-46) 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 <= -1.36e-124) {
tmp = x * (y / z);
} else if (y <= 1.65e-46) {
tmp = x;
} else {
tmp = y * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.36e-124: tmp = x * (y / z) elif y <= 1.65e-46: tmp = x else: tmp = y * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.36e-124) tmp = Float64(x * Float64(y / z)); elseif (y <= 1.65e-46) 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 <= -1.36e-124) tmp = x * (y / z); elseif (y <= 1.65e-46) tmp = x; else tmp = y * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.36e-124], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.65e-46], x, N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.36 \cdot 10^{-124}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{-46}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < -1.3599999999999999e-124Initial program 91.6%
Taylor expanded in y around inf
lower-/.f64N/A
lower-*.f6473.7
Applied rewrites73.7%
associate-*r/N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f6471.6
Applied rewrites71.6%
if -1.3599999999999999e-124 < y < 1.65000000000000007e-46Initial program 81.2%
Taylor expanded in y around 0
lower-*.f6472.9
Applied rewrites72.9%
associate-/l*N/A
*-inversesN/A
*-rgt-identity89.6
Applied rewrites89.6%
if 1.65000000000000007e-46 < y Initial program 88.8%
Taylor expanded in y around inf
lower-/.f64N/A
lower-*.f6473.9
Applied rewrites73.9%
associate-*l/N/A
lift-/.f64N/A
lower-*.f6473.9
Applied rewrites73.9%
Final simplification78.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (/ x z)))) (if (<= y -2.1e-14) t_0 (if (<= y 1.65e-46) x t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x / z);
double tmp;
if (y <= -2.1e-14) {
tmp = t_0;
} else if (y <= 1.65e-46) {
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 <= (-2.1d-14)) then
tmp = t_0
else if (y <= 1.65d-46) 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 <= -2.1e-14) {
tmp = t_0;
} else if (y <= 1.65e-46) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x / z) tmp = 0 if y <= -2.1e-14: tmp = t_0 elif y <= 1.65e-46: 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 <= -2.1e-14) tmp = t_0; elseif (y <= 1.65e-46) 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 <= -2.1e-14) tmp = t_0; elseif (y <= 1.65e-46) 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, -2.1e-14], t$95$0, If[LessEqual[y, 1.65e-46], x, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \frac{x}{z}\\
\mathbf{if}\;y \leq -2.1 \cdot 10^{-14}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{-46}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.0999999999999999e-14 or 1.65000000000000007e-46 < y Initial program 91.4%
Taylor expanded in y around inf
lower-/.f64N/A
lower-*.f6477.5
Applied rewrites77.5%
associate-*l/N/A
lift-/.f64N/A
lower-*.f6474.6
Applied rewrites74.6%
if -2.0999999999999999e-14 < y < 1.65000000000000007e-46Initial program 81.6%
Taylor expanded in y around 0
lower-*.f6465.6
Applied rewrites65.6%
associate-/l*N/A
*-inversesN/A
*-rgt-identity81.4
Applied rewrites81.4%
Final simplification77.5%
(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.1%
Taylor expanded in y around 0
lower-*.f6437.4
Applied rewrites37.4%
associate-/l*N/A
*-inversesN/A
*-rgt-identity46.8
Applied rewrites46.8%
(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 2024219
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:alt
(! :herbie-platform default (/ x (/ z (+ y z))))
(/ (* x (+ y z)) z))