
(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 (/ x (/ z (+ z y))))
double code(double x, double y, double z) {
return x / (z / (z + y));
}
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 / (z + y))
end function
public static double code(double x, double y, double z) {
return x / (z / (z + y));
}
def code(x, y, z): return x / (z / (z + y))
function code(x, y, z) return Float64(x / Float64(z / Float64(z + y))) end
function tmp = code(x, y, z) tmp = x / (z / (z + y)); end
code[x_, y_, z_] := N[(x / N[(z / N[(z + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{z}{z + y}}
\end{array}
Initial program 83.9%
associate-*l/88.6%
Simplified88.6%
associate-/r/98.0%
+-commutative98.0%
Applied egg-rr98.0%
Final simplification98.0%
(FPCore (x y z)
:precision binary64
(if (or (<= y -4e-25)
(and (not (<= y -1.05e-63))
(or (<= y -2.6e-116) (not (<= y 5.3e-99)))))
(* x (/ y z))
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4e-25) || (!(y <= -1.05e-63) && ((y <= -2.6e-116) || !(y <= 5.3e-99)))) {
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 <= (-4d-25)) .or. (.not. (y <= (-1.05d-63))) .and. (y <= (-2.6d-116)) .or. (.not. (y <= 5.3d-99))) 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 <= -4e-25) || (!(y <= -1.05e-63) && ((y <= -2.6e-116) || !(y <= 5.3e-99)))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4e-25) or (not (y <= -1.05e-63) and ((y <= -2.6e-116) or not (y <= 5.3e-99))): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4e-25) || (!(y <= -1.05e-63) && ((y <= -2.6e-116) || !(y <= 5.3e-99)))) 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 <= -4e-25) || (~((y <= -1.05e-63)) && ((y <= -2.6e-116) || ~((y <= 5.3e-99))))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4e-25], And[N[Not[LessEqual[y, -1.05e-63]], $MachinePrecision], Or[LessEqual[y, -2.6e-116], N[Not[LessEqual[y, 5.3e-99]], $MachinePrecision]]]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{-25} \lor \neg \left(y \leq -1.05 \cdot 10^{-63}\right) \land \left(y \leq -2.6 \cdot 10^{-116} \lor \neg \left(y \leq 5.3 \cdot 10^{-99}\right)\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.00000000000000015e-25 or -1.05e-63 < y < -2.6e-116 or 5.3000000000000003e-99 < y Initial program 86.2%
associate-*l/90.3%
Simplified90.3%
Taylor expanded in z around 0 70.8%
associate-*r/72.9%
Simplified72.9%
if -4.00000000000000015e-25 < y < -1.05e-63 or -2.6e-116 < y < 5.3000000000000003e-99Initial program 79.8%
associate-*l/85.6%
Simplified85.6%
Taylor expanded in z around inf 83.7%
Final simplification76.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ x (/ z y))))
(if (<= y -1.8e-27)
t_0
(if (<= y -8.5e-64)
x
(if (<= y -1.7e-115) (* x (/ y z)) (if (<= y 6.3e-102) x t_0))))))
double code(double x, double y, double z) {
double t_0 = x / (z / y);
double tmp;
if (y <= -1.8e-27) {
tmp = t_0;
} else if (y <= -8.5e-64) {
tmp = x;
} else if (y <= -1.7e-115) {
tmp = x * (y / z);
} else if (y <= 6.3e-102) {
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 / (z / y)
if (y <= (-1.8d-27)) then
tmp = t_0
else if (y <= (-8.5d-64)) then
tmp = x
else if (y <= (-1.7d-115)) then
tmp = x * (y / z)
else if (y <= 6.3d-102) 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 / (z / y);
double tmp;
if (y <= -1.8e-27) {
tmp = t_0;
} else if (y <= -8.5e-64) {
tmp = x;
} else if (y <= -1.7e-115) {
tmp = x * (y / z);
} else if (y <= 6.3e-102) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x / (z / y) tmp = 0 if y <= -1.8e-27: tmp = t_0 elif y <= -8.5e-64: tmp = x elif y <= -1.7e-115: tmp = x * (y / z) elif y <= 6.3e-102: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x / Float64(z / y)) tmp = 0.0 if (y <= -1.8e-27) tmp = t_0; elseif (y <= -8.5e-64) tmp = x; elseif (y <= -1.7e-115) tmp = Float64(x * Float64(y / z)); elseif (y <= 6.3e-102) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x / (z / y); tmp = 0.0; if (y <= -1.8e-27) tmp = t_0; elseif (y <= -8.5e-64) tmp = x; elseif (y <= -1.7e-115) tmp = x * (y / z); elseif (y <= 6.3e-102) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.8e-27], t$95$0, If[LessEqual[y, -8.5e-64], x, If[LessEqual[y, -1.7e-115], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6.3e-102], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{\frac{z}{y}}\\
\mathbf{if}\;y \leq -1.8 \cdot 10^{-27}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -8.5 \cdot 10^{-64}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -1.7 \cdot 10^{-115}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{elif}\;y \leq 6.3 \cdot 10^{-102}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1.7999999999999999e-27 or 6.29999999999999999e-102 < y Initial program 87.0%
associate-*l/91.1%
Simplified91.1%
associate-/r/96.8%
+-commutative96.8%
Applied egg-rr96.8%
Taylor expanded in z around 0 71.6%
associate-/l*72.1%
Simplified72.1%
if -1.7999999999999999e-27 < y < -8.49999999999999996e-64 or -1.6999999999999999e-115 < y < 6.29999999999999999e-102Initial program 79.8%
associate-*l/85.6%
Simplified85.6%
Taylor expanded in z around inf 83.7%
if -8.49999999999999996e-64 < y < -1.6999999999999999e-115Initial program 76.1%
associate-*l/79.8%
Simplified79.8%
Taylor expanded in z around 0 60.5%
associate-*r/84.2%
Simplified84.2%
Final simplification76.8%
(FPCore (x y z)
:precision binary64
(if (<= y -3.1e-29)
(/ (* x y) z)
(if (<= y -7.2e-64)
x
(if (<= y -1.95e-115) (* x (/ y z)) (if (<= y 5e-99) x (/ x (/ z y)))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.1e-29) {
tmp = (x * y) / z;
} else if (y <= -7.2e-64) {
tmp = x;
} else if (y <= -1.95e-115) {
tmp = x * (y / z);
} else if (y <= 5e-99) {
tmp = x;
} 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 <= (-3.1d-29)) then
tmp = (x * y) / z
else if (y <= (-7.2d-64)) then
tmp = x
else if (y <= (-1.95d-115)) then
tmp = x * (y / z)
else if (y <= 5d-99) then
tmp = x
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 <= -3.1e-29) {
tmp = (x * y) / z;
} else if (y <= -7.2e-64) {
tmp = x;
} else if (y <= -1.95e-115) {
tmp = x * (y / z);
} else if (y <= 5e-99) {
tmp = x;
} else {
tmp = x / (z / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.1e-29: tmp = (x * y) / z elif y <= -7.2e-64: tmp = x elif y <= -1.95e-115: tmp = x * (y / z) elif y <= 5e-99: tmp = x else: tmp = x / (z / y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.1e-29) tmp = Float64(Float64(x * y) / z); elseif (y <= -7.2e-64) tmp = x; elseif (y <= -1.95e-115) tmp = Float64(x * Float64(y / z)); elseif (y <= 5e-99) tmp = x; else tmp = Float64(x / Float64(z / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.1e-29) tmp = (x * y) / z; elseif (y <= -7.2e-64) tmp = x; elseif (y <= -1.95e-115) tmp = x * (y / z); elseif (y <= 5e-99) tmp = x; else tmp = x / (z / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.1e-29], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[y, -7.2e-64], x, If[LessEqual[y, -1.95e-115], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 5e-99], x, N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.1 \cdot 10^{-29}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{elif}\;y \leq -7.2 \cdot 10^{-64}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -1.95 \cdot 10^{-115}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-99}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\end{array}
\end{array}
if y < -3.10000000000000026e-29Initial program 88.5%
associate-*l/89.5%
Simplified89.5%
Taylor expanded in z around 0 75.0%
if -3.10000000000000026e-29 < y < -7.1999999999999996e-64 or -1.9499999999999999e-115 < y < 4.99999999999999969e-99Initial program 79.8%
associate-*l/85.6%
Simplified85.6%
Taylor expanded in z around inf 83.7%
if -7.1999999999999996e-64 < y < -1.9499999999999999e-115Initial program 76.1%
associate-*l/79.8%
Simplified79.8%
Taylor expanded in z around 0 60.5%
associate-*r/84.2%
Simplified84.2%
if 4.99999999999999969e-99 < y Initial program 86.0%
associate-*l/92.4%
Simplified92.4%
associate-/r/97.7%
+-commutative97.7%
Applied egg-rr97.7%
Taylor expanded in z around 0 69.1%
associate-/l*72.1%
Simplified72.1%
Final simplification77.5%
(FPCore (x y z) :precision binary64 (* (/ x z) (+ z y)))
double code(double x, double y, double z) {
return (x / z) * (z + y);
}
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) * (z + y)
end function
public static double code(double x, double y, double z) {
return (x / z) * (z + y);
}
def code(x, y, z): return (x / z) * (z + y)
function code(x, y, z) return Float64(Float64(x / z) * Float64(z + y)) end
function tmp = code(x, y, z) tmp = (x / z) * (z + y); end
code[x_, y_, z_] := N[(N[(x / z), $MachinePrecision] * N[(z + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{z} \cdot \left(z + y\right)
\end{array}
Initial program 83.9%
associate-*l/88.6%
Simplified88.6%
Final simplification88.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 83.9%
associate-*l/88.6%
Simplified88.6%
Taylor expanded in z around inf 46.7%
Final simplification46.7%
(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 2023318
(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))