
(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 (/ 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 86.4%
associate-*l/85.6%
Simplified85.6%
associate-/r/95.8%
+-commutative95.8%
Applied egg-rr95.8%
Final simplification95.8%
(FPCore (x y z) :precision binary64 (if (<= z -2.3e-60) x (if (<= z 9.8e+26) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.3e-60) {
tmp = x;
} else if (z <= 9.8e+26) {
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 (z <= (-2.3d-60)) then
tmp = x
else if (z <= 9.8d+26) 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 (z <= -2.3e-60) {
tmp = x;
} else if (z <= 9.8e+26) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.3e-60: tmp = x elif z <= 9.8e+26: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.3e-60) tmp = x; elseif (z <= 9.8e+26) tmp = Float64(x * Float64(y / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.3e-60) tmp = x; elseif (z <= 9.8e+26) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.3e-60], x, If[LessEqual[z, 9.8e+26], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.3 \cdot 10^{-60}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 9.8 \cdot 10^{+26}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.3000000000000001e-60 or 9.79999999999999947e26 < z Initial program 76.4%
associate-*l/78.0%
Simplified78.0%
Taylor expanded in z around inf 83.1%
if -2.3000000000000001e-60 < z < 9.79999999999999947e26Initial program 95.2%
associate-*l/92.4%
Simplified92.4%
Taylor expanded in z around 0 75.3%
associate-*r/69.7%
Simplified69.7%
Final simplification76.0%
(FPCore (x y z) :precision binary64 (if (<= z -2.35e-59) x (if (<= z 6.5e+26) (* y (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.35e-59) {
tmp = x;
} else if (z <= 6.5e+26) {
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 (z <= (-2.35d-59)) then
tmp = x
else if (z <= 6.5d+26) 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 (z <= -2.35e-59) {
tmp = x;
} else if (z <= 6.5e+26) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.35e-59: tmp = x elif z <= 6.5e+26: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.35e-59) tmp = x; elseif (z <= 6.5e+26) tmp = Float64(y * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.35e-59) tmp = x; elseif (z <= 6.5e+26) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.35e-59], x, If[LessEqual[z, 6.5e+26], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.35 \cdot 10^{-59}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 6.5 \cdot 10^{+26}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.35e-59 or 6.50000000000000022e26 < z Initial program 76.4%
associate-*l/78.0%
Simplified78.0%
Taylor expanded in z around inf 83.1%
if -2.35e-59 < z < 6.50000000000000022e26Initial program 95.2%
associate-*l/92.4%
Simplified92.4%
Taylor expanded in z around 0 75.3%
associate-/l*69.8%
associate-/r/74.4%
Applied egg-rr74.4%
Final simplification78.5%
(FPCore (x y z) :precision binary64 (if (<= z -2.2e-59) x (if (<= z 7e+26) (/ y (/ z x)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e-59) {
tmp = x;
} else if (z <= 7e+26) {
tmp = y / (z / x);
} 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 (z <= (-2.2d-59)) then
tmp = x
else if (z <= 7d+26) then
tmp = y / (z / x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e-59) {
tmp = x;
} else if (z <= 7e+26) {
tmp = y / (z / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.2e-59: tmp = x elif z <= 7e+26: tmp = y / (z / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.2e-59) tmp = x; elseif (z <= 7e+26) tmp = Float64(y / Float64(z / x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.2e-59) tmp = x; elseif (z <= 7e+26) tmp = y / (z / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.2e-59], x, If[LessEqual[z, 7e+26], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{-59}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 7 \cdot 10^{+26}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.1999999999999999e-59 or 6.9999999999999998e26 < z Initial program 76.4%
associate-*l/78.0%
Simplified78.0%
Taylor expanded in z around inf 83.1%
if -2.1999999999999999e-59 < z < 6.9999999999999998e26Initial program 95.2%
associate-*l/92.4%
Simplified92.4%
Taylor expanded in z around 0 75.3%
associate-*r/69.7%
Simplified69.7%
associate-*r/75.3%
*-commutative75.3%
associate-/l*74.5%
Applied egg-rr74.5%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (if (<= z -2.2e-59) x (if (<= z 6.2e+26) (/ (* x y) z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e-59) {
tmp = x;
} else if (z <= 6.2e+26) {
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 (z <= (-2.2d-59)) then
tmp = x
else if (z <= 6.2d+26) 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 (z <= -2.2e-59) {
tmp = x;
} else if (z <= 6.2e+26) {
tmp = (x * y) / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.2e-59: tmp = x elif z <= 6.2e+26: tmp = (x * y) / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.2e-59) tmp = x; elseif (z <= 6.2e+26) tmp = Float64(Float64(x * y) / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.2e-59) tmp = x; elseif (z <= 6.2e+26) tmp = (x * y) / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.2e-59], x, If[LessEqual[z, 6.2e+26], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{-59}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 6.2 \cdot 10^{+26}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.1999999999999999e-59 or 6.1999999999999999e26 < z Initial program 76.4%
associate-*l/78.0%
Simplified78.0%
Taylor expanded in z around inf 83.1%
if -2.1999999999999999e-59 < z < 6.1999999999999999e26Initial program 95.2%
associate-*l/92.4%
Simplified92.4%
Taylor expanded in z around 0 75.3%
Final simplification78.9%
(FPCore (x y z) :precision binary64 (* x (+ 1.0 (/ y z))))
double code(double x, double y, double z) {
return x * (1.0 + (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 * (1.0d0 + (y / z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 + (y / z));
}
def code(x, y, z): return x * (1.0 + (y / z))
function code(x, y, z) return Float64(x * Float64(1.0 + Float64(y / z))) end
function tmp = code(x, y, z) tmp = x * (1.0 + (y / z)); end
code[x_, y_, z_] := N[(x * N[(1.0 + N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 + \frac{y}{z}\right)
\end{array}
Initial program 86.4%
associate-*r/95.8%
remove-double-neg95.8%
sub-neg95.8%
div-sub95.8%
distribute-frac-neg95.8%
*-inverses95.8%
metadata-eval95.8%
sub-neg95.8%
metadata-eval95.8%
*-inverses95.8%
distribute-lft-out95.8%
*-inverses95.8%
*-rgt-identity95.8%
fma-def95.8%
Simplified95.8%
Taylor expanded in x around 0 95.8%
Final simplification95.8%
(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 86.4%
associate-*l/85.6%
Simplified85.6%
Taylor expanded in z around inf 51.3%
Final simplification51.3%
(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 2023333
(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))