
(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 6.3e+91) (fma (/ y z) x x) (/ (* (+ z y) x) z)))
double code(double x, double y, double z) {
double tmp;
if (y <= 6.3e+91) {
tmp = fma((y / z), x, x);
} else {
tmp = ((z + y) * x) / z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 6.3e+91) tmp = fma(Float64(y / z), x, x); else tmp = Float64(Float64(Float64(z + y) * x) / z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 6.3e+91], N[(N[(y / z), $MachinePrecision] * x + x), $MachinePrecision], N[(N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.3 \cdot 10^{+91}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(z + y\right) \cdot x}{z}\\
\end{array}
\end{array}
if y < 6.3e91Initial program 85.2%
Taylor expanded in x around 0
associate-/l*N/A
*-commutativeN/A
+-commutativeN/A
*-lft-identityN/A
metadata-evalN/A
cancel-sign-sub-invN/A
div-subN/A
*-inversesN/A
associate-*r/N/A
unsub-negN/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-/.f6497.6
Applied rewrites97.6%
if 6.3e91 < y Initial program 96.4%
Final simplification97.4%
(FPCore (x y z) :precision binary64 (if (<= z -4.5e+57) (/ x 1.0) (if (<= z 3.2e+26) (/ (* x y) z) (/ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.5e+57) {
tmp = x / 1.0;
} else if (z <= 3.2e+26) {
tmp = (x * y) / z;
} else {
tmp = x / 1.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) :: tmp
if (z <= (-4.5d+57)) then
tmp = x / 1.0d0
else if (z <= 3.2d+26) then
tmp = (x * y) / z
else
tmp = x / 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -4.5e+57) {
tmp = x / 1.0;
} else if (z <= 3.2e+26) {
tmp = (x * y) / z;
} else {
tmp = x / 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.5e+57: tmp = x / 1.0 elif z <= 3.2e+26: tmp = (x * y) / z else: tmp = x / 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.5e+57) tmp = Float64(x / 1.0); elseif (z <= 3.2e+26) tmp = Float64(Float64(x * y) / z); else tmp = Float64(x / 1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.5e+57) tmp = x / 1.0; elseif (z <= 3.2e+26) tmp = (x * y) / z; else tmp = x / 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.5e+57], N[(x / 1.0), $MachinePrecision], If[LessEqual[z, 3.2e+26], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], N[(x / 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{+57}:\\
\;\;\;\;\frac{x}{1}\\
\mathbf{elif}\;z \leq 3.2 \cdot 10^{+26}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1}\\
\end{array}
\end{array}
if z < -4.49999999999999996e57 or 3.20000000000000029e26 < z Initial program 77.6%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites84.2%
if -4.49999999999999996e57 < z < 3.20000000000000029e26Initial program 94.2%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6474.3
Applied rewrites74.3%
Final simplification78.3%
(FPCore (x y z) :precision binary64 (if (<= z -7.5e+28) (/ x 1.0) (if (<= z 3.2e+26) (* (/ x z) y) (/ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.5e+28) {
tmp = x / 1.0;
} else if (z <= 3.2e+26) {
tmp = (x / z) * y;
} else {
tmp = x / 1.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) :: tmp
if (z <= (-7.5d+28)) then
tmp = x / 1.0d0
else if (z <= 3.2d+26) then
tmp = (x / z) * y
else
tmp = x / 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -7.5e+28) {
tmp = x / 1.0;
} else if (z <= 3.2e+26) {
tmp = (x / z) * y;
} else {
tmp = x / 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7.5e+28: tmp = x / 1.0 elif z <= 3.2e+26: tmp = (x / z) * y else: tmp = x / 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7.5e+28) tmp = Float64(x / 1.0); elseif (z <= 3.2e+26) tmp = Float64(Float64(x / z) * y); else tmp = Float64(x / 1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7.5e+28) tmp = x / 1.0; elseif (z <= 3.2e+26) tmp = (x / z) * y; else tmp = x / 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7.5e+28], N[(x / 1.0), $MachinePrecision], If[LessEqual[z, 3.2e+26], N[(N[(x / z), $MachinePrecision] * y), $MachinePrecision], N[(x / 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.5 \cdot 10^{+28}:\\
\;\;\;\;\frac{x}{1}\\
\mathbf{elif}\;z \leq 3.2 \cdot 10^{+26}:\\
\;\;\;\;\frac{x}{z} \cdot y\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1}\\
\end{array}
\end{array}
if z < -7.4999999999999998e28 or 3.20000000000000029e26 < z Initial program 78.2%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
Applied rewrites82.9%
if -7.4999999999999998e28 < z < 3.20000000000000029e26Initial program 94.1%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6492.3
lift-+.f64N/A
+-commutativeN/A
lower-+.f6492.3
Applied rewrites92.3%
Taylor expanded in y around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6473.5
Applied rewrites73.5%
(FPCore (x y z) :precision binary64 (if (<= x 3.4e-57) (fma (/ x z) y x) (fma (/ y z) x x)))
double code(double x, double y, double z) {
double tmp;
if (x <= 3.4e-57) {
tmp = fma((x / z), y, x);
} else {
tmp = fma((y / z), x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= 3.4e-57) tmp = fma(Float64(x / z), y, x); else tmp = fma(Float64(y / z), x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, 3.4e-57], N[(N[(x / z), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(y / z), $MachinePrecision] * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.4 \cdot 10^{-57}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\
\end{array}
\end{array}
if x < 3.40000000000000016e-57Initial program 88.6%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6493.8
lift-+.f64N/A
+-commutativeN/A
lower-+.f6493.8
Applied rewrites93.8%
lift-/.f64N/A
div-invN/A
lift-/.f64N/A
associate-/r/N/A
lift-+.f64N/A
distribute-lft-inN/A
lft-mult-inverseN/A
associate-/r/N/A
clear-numN/A
lift-/.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
lift-/.f64N/A
associate-*l/N/A
*-commutativeN/A
associate-*l/N/A
lift-/.f64N/A
*-lft-identityN/A
lower-fma.f6493.1
Applied rewrites93.1%
if 3.40000000000000016e-57 < x Initial program 84.7%
Taylor expanded in x around 0
associate-/l*N/A
*-commutativeN/A
+-commutativeN/A
*-lft-identityN/A
metadata-evalN/A
cancel-sign-sub-invN/A
div-subN/A
*-inversesN/A
associate-*r/N/A
unsub-negN/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (fma (/ y z) x x))
double code(double x, double y, double z) {
return fma((y / z), x, x);
}
function code(x, y, z) return fma(Float64(y / z), x, x) end
code[x_, y_, z_] := N[(N[(y / z), $MachinePrecision] * x + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{z}, x, x\right)
\end{array}
Initial program 87.5%
Taylor expanded in x around 0
associate-/l*N/A
*-commutativeN/A
+-commutativeN/A
*-lft-identityN/A
metadata-evalN/A
cancel-sign-sub-invN/A
div-subN/A
*-inversesN/A
associate-*r/N/A
unsub-negN/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-/.f6495.2
Applied rewrites95.2%
(FPCore (x y z) :precision binary64 (/ x 1.0))
double code(double x, double y, double z) {
return x / 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 / 1.0d0
end function
public static double code(double x, double y, double z) {
return x / 1.0;
}
def code(x, y, z): return x / 1.0
function code(x, y, z) return Float64(x / 1.0) end
function tmp = code(x, y, z) tmp = x / 1.0; end
code[x_, y_, z_] := N[(x / 1.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{1}
\end{array}
Initial program 87.5%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6495.5
lift-+.f64N/A
+-commutativeN/A
lower-+.f6495.5
Applied rewrites95.5%
Taylor expanded in y around 0
Applied rewrites48.0%
(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 2024331
(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))