
(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 -1.25e+207) (* (+ y z) (/ x z)) (/ x (/ z (+ y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.25e+207) {
tmp = (y + z) * (x / z);
} else {
tmp = x / (z / (y + 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.25d+207)) then
tmp = (y + z) * (x / z)
else
tmp = x / (z / (y + z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.25e+207) {
tmp = (y + z) * (x / z);
} else {
tmp = x / (z / (y + z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.25e+207: tmp = (y + z) * (x / z) else: tmp = x / (z / (y + z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.25e+207) tmp = Float64(Float64(y + z) * Float64(x / z)); else tmp = Float64(x / Float64(z / Float64(y + z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.25e+207) tmp = (y + z) * (x / z); else tmp = x / (z / (y + z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.25e+207], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.25 \cdot 10^{+207}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y + z}}\\
\end{array}
\end{array}
if y < -1.25e207Initial program 90.8%
*-commutative90.8%
associate-/l*95.6%
Simplified95.6%
if -1.25e207 < y Initial program 82.1%
associate-/l*97.5%
Simplified97.5%
clear-num97.4%
un-div-inv97.6%
Applied egg-rr97.6%
Final simplification97.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -9e-22) (not (<= y 6.8e-35))) (* x (/ y z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9e-22) || !(y <= 6.8e-35)) {
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 <= (-9d-22)) .or. (.not. (y <= 6.8d-35))) 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 <= -9e-22) || !(y <= 6.8e-35)) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9e-22) or not (y <= 6.8e-35): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9e-22) || !(y <= 6.8e-35)) 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 <= -9e-22) || ~((y <= 6.8e-35))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9e-22], N[Not[LessEqual[y, 6.8e-35]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-22} \lor \neg \left(y \leq 6.8 \cdot 10^{-35}\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -8.99999999999999973e-22 or 6.8000000000000005e-35 < y Initial program 86.6%
associate-/l*91.8%
Simplified91.8%
Taylor expanded in y around inf 70.0%
associate-/l*66.6%
Simplified66.6%
if -8.99999999999999973e-22 < y < 6.8000000000000005e-35Initial program 78.2%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 84.1%
Final simplification74.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.45e-24) (not (<= y 1.45e-35))) (* y (/ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.45e-24) || !(y <= 1.45e-35)) {
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 <= (-2.45d-24)) .or. (.not. (y <= 1.45d-35))) 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 <= -2.45e-24) || !(y <= 1.45e-35)) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.45e-24) or not (y <= 1.45e-35): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.45e-24) || !(y <= 1.45e-35)) 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 <= -2.45e-24) || ~((y <= 1.45e-35))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.45e-24], N[Not[LessEqual[y, 1.45e-35]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.45 \cdot 10^{-24} \lor \neg \left(y \leq 1.45 \cdot 10^{-35}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.45e-24 or 1.4500000000000001e-35 < y Initial program 86.6%
associate-/l*91.8%
Simplified91.8%
Taylor expanded in y around inf 70.0%
*-commutative70.0%
associate-/l*72.9%
Applied egg-rr72.9%
if -2.45e-24 < y < 1.4500000000000001e-35Initial program 78.2%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 84.1%
Final simplification78.0%
(FPCore (x y z) :precision binary64 (if (<= y -7.5e+206) (* (+ y z) (/ x z)) (* x (/ (+ y z) z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.5e+206) {
tmp = (y + z) * (x / z);
} else {
tmp = x * ((y + z) / 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 <= (-7.5d+206)) then
tmp = (y + z) * (x / z)
else
tmp = x * ((y + z) / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -7.5e+206) {
tmp = (y + z) * (x / z);
} else {
tmp = x * ((y + z) / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7.5e+206: tmp = (y + z) * (x / z) else: tmp = x * ((y + z) / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7.5e+206) tmp = Float64(Float64(y + z) * Float64(x / z)); else tmp = Float64(x * Float64(Float64(y + z) / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -7.5e+206) tmp = (y + z) * (x / z); else tmp = x * ((y + z) / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7.5e+206], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(y + z), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{+206}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y + z}{z}\\
\end{array}
\end{array}
if y < -7.49999999999999958e206Initial program 90.8%
*-commutative90.8%
associate-/l*95.6%
Simplified95.6%
if -7.49999999999999958e206 < y Initial program 82.1%
associate-/l*97.5%
Simplified97.5%
Final simplification97.3%
(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(x * Float64(Float64(y + z) / z)) end
function tmp = code(x, y, z) tmp = x * ((y + z) / z); end
code[x_, y_, z_] := N[(x * N[(N[(y + z), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{y + z}{z}
\end{array}
Initial program 82.8%
associate-/l*95.5%
Simplified95.5%
Final simplification95.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 82.8%
associate-/l*95.5%
Simplified95.5%
Taylor expanded in y around 0 51.7%
Final simplification51.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 2024039
(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))