
(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+103) (fma x (/ y z) x) (* (+ y z) (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 2e+103) {
tmp = fma(x, (y / z), x);
} else {
tmp = (y + z) * (x / z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 2e+103) tmp = fma(x, Float64(y / z), x); else tmp = Float64(Float64(y + z) * Float64(x / z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 2e+103], N[(x * N[(y / z), $MachinePrecision] + x), $MachinePrecision], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2 \cdot 10^{+103}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < 2e103Initial program 88.2%
remove-double-neg88.2%
distribute-lft-neg-out88.2%
*-commutative88.2%
distribute-lft-neg-in88.2%
associate-/l*81.0%
distribute-neg-in81.0%
unsub-neg81.0%
div-sub76.5%
distribute-frac-neg76.5%
associate-/r/77.1%
distribute-rgt-neg-out77.1%
remove-double-neg77.1%
associate-/r/98.2%
*-inverses98.2%
*-lft-identity98.2%
*-commutative98.2%
fma-neg98.2%
remove-double-neg98.2%
Simplified98.2%
if 2e103 < y Initial program 87.6%
associate-*l/94.8%
*-commutative94.8%
Simplified94.8%
Final simplification97.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (+ y z) (/ x z))))
(if (<= z -2.1e+83)
x
(if (<= z -2.15e-216)
t_0
(if (<= z 2.7e-228) (/ (* y x) z) (if (<= z 1.2e+182) t_0 x))))))
double code(double x, double y, double z) {
double t_0 = (y + z) * (x / z);
double tmp;
if (z <= -2.1e+83) {
tmp = x;
} else if (z <= -2.15e-216) {
tmp = t_0;
} else if (z <= 2.7e-228) {
tmp = (y * x) / z;
} else if (z <= 1.2e+182) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = (y + z) * (x / z)
if (z <= (-2.1d+83)) then
tmp = x
else if (z <= (-2.15d-216)) then
tmp = t_0
else if (z <= 2.7d-228) then
tmp = (y * x) / z
else if (z <= 1.2d+182) then
tmp = t_0
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y + z) * (x / z);
double tmp;
if (z <= -2.1e+83) {
tmp = x;
} else if (z <= -2.15e-216) {
tmp = t_0;
} else if (z <= 2.7e-228) {
tmp = (y * x) / z;
} else if (z <= 1.2e+182) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = (y + z) * (x / z) tmp = 0 if z <= -2.1e+83: tmp = x elif z <= -2.15e-216: tmp = t_0 elif z <= 2.7e-228: tmp = (y * x) / z elif z <= 1.2e+182: tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(y + z) * Float64(x / z)) tmp = 0.0 if (z <= -2.1e+83) tmp = x; elseif (z <= -2.15e-216) tmp = t_0; elseif (z <= 2.7e-228) tmp = Float64(Float64(y * x) / z); elseif (z <= 1.2e+182) tmp = t_0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y + z) * (x / z); tmp = 0.0; if (z <= -2.1e+83) tmp = x; elseif (z <= -2.15e-216) tmp = t_0; elseif (z <= 2.7e-228) tmp = (y * x) / z; elseif (z <= 1.2e+182) tmp = t_0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.1e+83], x, If[LessEqual[z, -2.15e-216], t$95$0, If[LessEqual[z, 2.7e-228], N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[z, 1.2e+182], t$95$0, x]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y + z\right) \cdot \frac{x}{z}\\
\mathbf{if}\;z \leq -2.1 \cdot 10^{+83}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -2.15 \cdot 10^{-216}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{-228}:\\
\;\;\;\;\frac{y \cdot x}{z}\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{+182}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.10000000000000002e83 or 1.20000000000000005e182 < z Initial program 70.8%
associate-*l/63.7%
*-commutative63.7%
Simplified63.7%
Taylor expanded in y around 0 84.0%
if -2.10000000000000002e83 < z < -2.1499999999999999e-216 or 2.69999999999999984e-228 < z < 1.20000000000000005e182Initial program 92.9%
associate-*l/92.8%
*-commutative92.8%
Simplified92.8%
if -2.1499999999999999e-216 < z < 2.69999999999999984e-228Initial program 97.6%
associate-*l/75.7%
*-commutative75.7%
Simplified75.7%
Taylor expanded in y around inf 92.7%
Final simplification90.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.8e+74) (not (<= y 1.56e-34))) (* x (/ y z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.8e+74) || !(y <= 1.56e-34)) {
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 <= (-5.8d+74)) .or. (.not. (y <= 1.56d-34))) 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 <= -5.8e+74) || !(y <= 1.56e-34)) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.8e+74) or not (y <= 1.56e-34): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.8e+74) || !(y <= 1.56e-34)) 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 <= -5.8e+74) || ~((y <= 1.56e-34))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.8e+74], N[Not[LessEqual[y, 1.56e-34]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{+74} \lor \neg \left(y \leq 1.56 \cdot 10^{-34}\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.8000000000000005e74 or 1.55999999999999992e-34 < y Initial program 92.0%
associate-*l/90.8%
*-commutative90.8%
Simplified90.8%
Taylor expanded in y around inf 84.0%
associate-*r/79.5%
Simplified79.5%
if -5.8000000000000005e74 < y < 1.55999999999999992e-34Initial program 84.7%
associate-*l/75.5%
*-commutative75.5%
Simplified75.5%
Taylor expanded in y around 0 74.4%
Final simplification76.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.8e+74) (not (<= y 4.8e-34))) (* y (/ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.8e+74) || !(y <= 4.8e-34)) {
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 ((y <= (-5.8d+74)) .or. (.not. (y <= 4.8d-34))) 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 ((y <= -5.8e+74) || !(y <= 4.8e-34)) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.8e+74) or not (y <= 4.8e-34): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.8e+74) || !(y <= 4.8e-34)) tmp = Float64(y * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.8e+74) || ~((y <= 4.8e-34))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.8e+74], N[Not[LessEqual[y, 4.8e-34]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{+74} \lor \neg \left(y \leq 4.8 \cdot 10^{-34}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.8000000000000005e74 or 4.79999999999999982e-34 < y Initial program 92.0%
associate-*l/90.8%
*-commutative90.8%
Simplified90.8%
Taylor expanded in y around inf 84.0%
associate-*l/84.7%
*-commutative84.7%
Simplified84.7%
if -5.8000000000000005e74 < y < 4.79999999999999982e-34Initial program 84.7%
associate-*l/75.5%
*-commutative75.5%
Simplified75.5%
Taylor expanded in y around 0 74.4%
Final simplification79.2%
(FPCore (x y z) :precision binary64 (if (<= y -5.8e+74) (/ (* y x) z) (if (<= y 3.5e-34) x (* y (/ x z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.8e+74) {
tmp = (y * x) / z;
} else if (y <= 3.5e-34) {
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 <= (-5.8d+74)) then
tmp = (y * x) / z
else if (y <= 3.5d-34) 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 <= -5.8e+74) {
tmp = (y * x) / z;
} else if (y <= 3.5e-34) {
tmp = x;
} else {
tmp = y * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.8e+74: tmp = (y * x) / z elif y <= 3.5e-34: tmp = x else: tmp = y * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.8e+74) tmp = Float64(Float64(y * x) / z); elseif (y <= 3.5e-34) 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 <= -5.8e+74) tmp = (y * x) / z; elseif (y <= 3.5e-34) tmp = x; else tmp = y * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.8e+74], N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[y, 3.5e-34], x, N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{+74}:\\
\;\;\;\;\frac{y \cdot x}{z}\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{-34}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < -5.8000000000000005e74Initial program 93.2%
associate-*l/91.0%
*-commutative91.0%
Simplified91.0%
Taylor expanded in y around inf 88.3%
if -5.8000000000000005e74 < y < 3.5e-34Initial program 84.7%
associate-*l/75.5%
*-commutative75.5%
Simplified75.5%
Taylor expanded in y around 0 74.4%
if 3.5e-34 < y Initial program 90.9%
associate-*l/90.7%
*-commutative90.7%
Simplified90.7%
Taylor expanded in y around inf 80.1%
associate-*l/83.0%
*-commutative83.0%
Simplified83.0%
Final simplification79.5%
(FPCore (x y z) :precision binary64 (if (<= y 4.2e+99) (/ x (/ z (+ y z))) (* (+ y z) (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 4.2e+99) {
tmp = x / (z / (y + z));
} else {
tmp = (y + 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.2d+99) then
tmp = x / (z / (y + z))
else
tmp = (y + z) * (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 4.2e+99) {
tmp = x / (z / (y + z));
} else {
tmp = (y + z) * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 4.2e+99: tmp = x / (z / (y + z)) else: tmp = (y + z) * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 4.2e+99) tmp = Float64(x / Float64(z / Float64(y + z))); else tmp = Float64(Float64(y + z) * Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 4.2e+99) tmp = x / (z / (y + z)); else tmp = (y + z) * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 4.2e+99], N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.2 \cdot 10^{+99}:\\
\;\;\;\;\frac{x}{\frac{z}{y + z}}\\
\mathbf{else}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < 4.2000000000000002e99Initial program 88.2%
associate-*l/80.5%
*-commutative80.5%
Simplified80.5%
*-commutative80.5%
associate-/r/98.1%
Applied egg-rr98.1%
if 4.2000000000000002e99 < y Initial program 87.6%
associate-*l/94.8%
*-commutative94.8%
Simplified94.8%
Final simplification97.6%
(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 88.1%
associate-*l/82.6%
*-commutative82.6%
Simplified82.6%
Taylor expanded in y around 0 46.2%
Final simplification46.2%
(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 2024036
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(/ x (/ z (+ y z)))
(/ (* x (+ y z)) z))