
(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 (<= y 2e-78) (fma (/ y z) x x) (fma (/ x z) y x)))
double code(double x, double y, double z) {
double tmp;
if (y <= 2e-78) {
tmp = fma((y / z), x, x);
} else {
tmp = fma((x / z), y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 2e-78) tmp = fma(Float64(y / z), x, x); else tmp = fma(Float64(x / z), y, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 2e-78], N[(N[(y / z), $MachinePrecision] * x + x), $MachinePrecision], N[(N[(x / z), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2 \cdot 10^{-78}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\
\end{array}
\end{array}
if y < 2e-78Initial program 82.2%
Taylor expanded in x around 0
*-commutativeN/A
associate-*l/N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-/.f6498.3
Applied rewrites98.3%
if 2e-78 < y Initial program 89.3%
lift-/.f64N/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
div-addN/A
frac-addN/A
lower-/.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6460.5
Applied rewrites60.5%
Taylor expanded in x around 0
associate-/l*N/A
unpow2N/A
distribute-rgt-outN/A
unpow2N/A
times-fracN/A
*-inversesN/A
associate-*l*N/A
*-rgt-identityN/A
div-addN/A
distribute-lft-inN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-/.f6498.6
Applied rewrites98.6%
Final simplification98.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (* x (+ y z)) z)))
(if (<= t_0 0.0)
(* (/ y z) x)
(if (<= t_0 2e+296) (/ (* z x) z) (* z (/ x z))))))
double code(double x, double y, double z) {
double t_0 = (x * (y + z)) / z;
double tmp;
if (t_0 <= 0.0) {
tmp = (y / z) * x;
} else if (t_0 <= 2e+296) {
tmp = (z * x) / z;
} else {
tmp = z * (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) :: t_0
real(8) :: tmp
t_0 = (x * (y + z)) / z
if (t_0 <= 0.0d0) then
tmp = (y / z) * x
else if (t_0 <= 2d+296) then
tmp = (z * x) / z
else
tmp = z * (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * (y + z)) / z;
double tmp;
if (t_0 <= 0.0) {
tmp = (y / z) * x;
} else if (t_0 <= 2e+296) {
tmp = (z * x) / z;
} else {
tmp = z * (x / z);
}
return tmp;
}
def code(x, y, z): t_0 = (x * (y + z)) / z tmp = 0 if t_0 <= 0.0: tmp = (y / z) * x elif t_0 <= 2e+296: tmp = (z * x) / z else: tmp = z * (x / z) return tmp
function code(x, y, z) t_0 = Float64(Float64(x * Float64(y + z)) / z) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(Float64(y / z) * x); elseif (t_0 <= 2e+296) tmp = Float64(Float64(z * x) / z); else tmp = Float64(z * Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * (y + z)) / z; tmp = 0.0; if (t_0 <= 0.0) tmp = (y / z) * x; elseif (t_0 <= 2e+296) tmp = (z * x) / z; else tmp = z * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(N[(y / z), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$0, 2e+296], N[(N[(z * x), $MachinePrecision] / z), $MachinePrecision], N[(z * N[(x / z), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(y + z\right)}{z}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\frac{y}{z} \cdot x\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+296}:\\
\;\;\;\;\frac{z \cdot x}{z}\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{x}{z}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 y z)) z) < 0.0Initial program 82.1%
Taylor expanded in x around 0
*-commutativeN/A
associate-*l/N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-/.f6495.6
Applied rewrites95.6%
Taylor expanded in y around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6450.3
Applied rewrites50.3%
Applied rewrites48.5%
if 0.0 < (/.f64 (*.f64 x (+.f64 y z)) z) < 1.99999999999999996e296Initial program 98.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f6462.6
Applied rewrites62.6%
if 1.99999999999999996e296 < (/.f64 (*.f64 x (+.f64 y z)) z) Initial program 61.7%
Taylor expanded in x around 0
*-commutativeN/A
associate-*l/N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
Applied rewrites82.4%
Taylor expanded in y around inf
Applied rewrites60.0%
Taylor expanded in y around 0
Applied rewrites42.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.5e-126) (not (<= y 7.8e+48))) (* (/ x z) y) (* z (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.5e-126) || !(y <= 7.8e+48)) {
tmp = (x / z) * y;
} else {
tmp = z * (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 <= (-4.5d-126)) .or. (.not. (y <= 7.8d+48))) then
tmp = (x / z) * y
else
tmp = z * (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4.5e-126) || !(y <= 7.8e+48)) {
tmp = (x / z) * y;
} else {
tmp = z * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.5e-126) or not (y <= 7.8e+48): tmp = (x / z) * y else: tmp = z * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.5e-126) || !(y <= 7.8e+48)) tmp = Float64(Float64(x / z) * y); else tmp = Float64(z * Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.5e-126) || ~((y <= 7.8e+48))) tmp = (x / z) * y; else tmp = z * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.5e-126], N[Not[LessEqual[y, 7.8e+48]], $MachinePrecision]], N[(N[(x / z), $MachinePrecision] * y), $MachinePrecision], N[(z * N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{-126} \lor \neg \left(y \leq 7.8 \cdot 10^{+48}\right):\\
\;\;\;\;\frac{x}{z} \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < -4.50000000000000025e-126 or 7.8000000000000002e48 < y Initial program 88.9%
Taylor expanded in x around 0
*-commutativeN/A
associate-*l/N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-/.f6493.0
Applied rewrites93.0%
Taylor expanded in y around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6469.6
Applied rewrites69.6%
if -4.50000000000000025e-126 < y < 7.8000000000000002e48Initial program 79.1%
Taylor expanded in x around 0
*-commutativeN/A
associate-*l/N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
Applied rewrites82.2%
Taylor expanded in y around inf
Applied rewrites15.3%
Taylor expanded in y around 0
Applied rewrites69.3%
Final simplification69.5%
(FPCore (x y z) :precision binary64 (if (<= y -2e-78) (/ (* y x) z) (if (<= y 7.8e+48) (* z (/ x z)) (* (/ x z) y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2e-78) {
tmp = (y * x) / z;
} else if (y <= 7.8e+48) {
tmp = z * (x / z);
} else {
tmp = (x / z) * y;
}
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 <= (-2d-78)) then
tmp = (y * x) / z
else if (y <= 7.8d+48) then
tmp = z * (x / z)
else
tmp = (x / z) * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2e-78) {
tmp = (y * x) / z;
} else if (y <= 7.8e+48) {
tmp = z * (x / z);
} else {
tmp = (x / z) * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2e-78: tmp = (y * x) / z elif y <= 7.8e+48: tmp = z * (x / z) else: tmp = (x / z) * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2e-78) tmp = Float64(Float64(y * x) / z); elseif (y <= 7.8e+48) tmp = Float64(z * Float64(x / z)); else tmp = Float64(Float64(x / z) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2e-78) tmp = (y * x) / z; elseif (y <= 7.8e+48) tmp = z * (x / z); else tmp = (x / z) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2e-78], N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[y, 7.8e+48], N[(z * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-78}:\\
\;\;\;\;\frac{y \cdot x}{z}\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{+48}:\\
\;\;\;\;z \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} \cdot y\\
\end{array}
\end{array}
if y < -2e-78Initial program 88.3%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6472.9
Applied rewrites72.9%
if -2e-78 < y < 7.8000000000000002e48Initial program 78.6%
Taylor expanded in x around 0
*-commutativeN/A
associate-*l/N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
Applied rewrites81.5%
Taylor expanded in y around inf
Applied rewrites15.6%
Taylor expanded in y around 0
Applied rewrites67.7%
if 7.8000000000000002e48 < y Initial program 92.3%
Taylor expanded in x around 0
*-commutativeN/A
associate-*l/N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-/.f6486.5
Applied rewrites86.5%
Taylor expanded in y around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6470.9
Applied rewrites70.9%
(FPCore (x y z) :precision binary64 (if (<= y -4e-126) (* (/ y z) x) (if (<= y 7.8e+48) (* z (/ x z)) (* (/ x z) y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4e-126) {
tmp = (y / z) * x;
} else if (y <= 7.8e+48) {
tmp = z * (x / z);
} else {
tmp = (x / z) * y;
}
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 <= (-4d-126)) then
tmp = (y / z) * x
else if (y <= 7.8d+48) then
tmp = z * (x / z)
else
tmp = (x / z) * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4e-126) {
tmp = (y / z) * x;
} else if (y <= 7.8e+48) {
tmp = z * (x / z);
} else {
tmp = (x / z) * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4e-126: tmp = (y / z) * x elif y <= 7.8e+48: tmp = z * (x / z) else: tmp = (x / z) * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4e-126) tmp = Float64(Float64(y / z) * x); elseif (y <= 7.8e+48) tmp = Float64(z * Float64(x / z)); else tmp = Float64(Float64(x / z) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4e-126) tmp = (y / z) * x; elseif (y <= 7.8e+48) tmp = z * (x / z); else tmp = (x / z) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4e-126], N[(N[(y / z), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[y, 7.8e+48], N[(z * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{-126}:\\
\;\;\;\;\frac{y}{z} \cdot x\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{+48}:\\
\;\;\;\;z \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} \cdot y\\
\end{array}
\end{array}
if y < -3.9999999999999998e-126Initial program 86.9%
Taylor expanded in x around 0
*-commutativeN/A
associate-*l/N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-/.f6496.7
Applied rewrites96.7%
Taylor expanded in y around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6468.9
Applied rewrites68.9%
Applied rewrites69.4%
if -3.9999999999999998e-126 < y < 7.8000000000000002e48Initial program 79.1%
Taylor expanded in x around 0
*-commutativeN/A
associate-*l/N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
Applied rewrites82.2%
Taylor expanded in y around inf
Applied rewrites15.3%
Taylor expanded in y around 0
Applied rewrites69.3%
if 7.8000000000000002e48 < y Initial program 92.3%
Taylor expanded in x around 0
*-commutativeN/A
associate-*l/N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-/.f6486.5
Applied rewrites86.5%
Taylor expanded in y around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6470.9
Applied rewrites70.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 84.4%
Taylor expanded in x around 0
*-commutativeN/A
associate-*l/N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-/.f6496.2
Applied rewrites96.2%
(FPCore (x y z) :precision binary64 (* z (/ x z)))
double code(double x, double y, double z) {
return z * (x / z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * (x / z)
end function
public static double code(double x, double y, double z) {
return z * (x / z);
}
def code(x, y, z): return z * (x / z)
function code(x, y, z) return Float64(z * Float64(x / z)) end
function tmp = code(x, y, z) tmp = z * (x / z); end
code[x_, y_, z_] := N[(z * N[(x / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \frac{x}{z}
\end{array}
Initial program 84.4%
Taylor expanded in x around 0
*-commutativeN/A
associate-*l/N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-/.f6496.2
Applied rewrites96.2%
Applied rewrites76.9%
Taylor expanded in y around inf
Applied rewrites36.7%
Taylor expanded in y around 0
Applied rewrites43.5%
(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 2024329
(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))