
(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 5 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 79.4%
associate-/l*95.9%
Simplified95.9%
Final simplification95.9%
(FPCore (x y z)
:precision binary64
(if (<= z -4.1e-75)
x
(if (or (<= z 2.45e-145) (and (not (<= z 2.1e-80)) (<= z 3.8e+79)))
(* x (/ y z))
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.1e-75) {
tmp = x;
} else if ((z <= 2.45e-145) || (!(z <= 2.1e-80) && (z <= 3.8e+79))) {
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 <= (-4.1d-75)) then
tmp = x
else if ((z <= 2.45d-145) .or. (.not. (z <= 2.1d-80)) .and. (z <= 3.8d+79)) 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 <= -4.1e-75) {
tmp = x;
} else if ((z <= 2.45e-145) || (!(z <= 2.1e-80) && (z <= 3.8e+79))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.1e-75: tmp = x elif (z <= 2.45e-145) or (not (z <= 2.1e-80) and (z <= 3.8e+79)): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.1e-75) tmp = x; elseif ((z <= 2.45e-145) || (!(z <= 2.1e-80) && (z <= 3.8e+79))) 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 <= -4.1e-75) tmp = x; elseif ((z <= 2.45e-145) || (~((z <= 2.1e-80)) && (z <= 3.8e+79))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.1e-75], x, If[Or[LessEqual[z, 2.45e-145], And[N[Not[LessEqual[z, 2.1e-80]], $MachinePrecision], LessEqual[z, 3.8e+79]]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.1 \cdot 10^{-75}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.45 \cdot 10^{-145} \lor \neg \left(z \leq 2.1 \cdot 10^{-80}\right) \land z \leq 3.8 \cdot 10^{+79}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.10000000000000002e-75 or 2.44999999999999984e-145 < z < 2.10000000000000001e-80 or 3.8000000000000002e79 < z Initial program 70.7%
associate-*r/99.3%
Simplified99.3%
Taylor expanded in y around 0 79.6%
if -4.10000000000000002e-75 < z < 2.44999999999999984e-145 or 2.10000000000000001e-80 < z < 3.8000000000000002e79Initial program 91.8%
associate-*r/91.0%
Simplified91.0%
Taylor expanded in y around inf 70.9%
Final simplification76.1%
(FPCore (x y z)
:precision binary64
(if (<= z -6e-73)
x
(if (<= z 2.45e-145)
(* y (/ x z))
(if (<= z 1.12e-80) x (if (<= z 2.75e+79) (* x (/ y z)) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -6e-73) {
tmp = x;
} else if (z <= 2.45e-145) {
tmp = y * (x / z);
} else if (z <= 1.12e-80) {
tmp = x;
} else if (z <= 2.75e+79) {
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 <= (-6d-73)) then
tmp = x
else if (z <= 2.45d-145) then
tmp = y * (x / z)
else if (z <= 1.12d-80) then
tmp = x
else if (z <= 2.75d+79) 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 <= -6e-73) {
tmp = x;
} else if (z <= 2.45e-145) {
tmp = y * (x / z);
} else if (z <= 1.12e-80) {
tmp = x;
} else if (z <= 2.75e+79) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6e-73: tmp = x elif z <= 2.45e-145: tmp = y * (x / z) elif z <= 1.12e-80: tmp = x elif z <= 2.75e+79: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6e-73) tmp = x; elseif (z <= 2.45e-145) tmp = Float64(y * Float64(x / z)); elseif (z <= 1.12e-80) tmp = x; elseif (z <= 2.75e+79) 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 <= -6e-73) tmp = x; elseif (z <= 2.45e-145) tmp = y * (x / z); elseif (z <= 1.12e-80) tmp = x; elseif (z <= 2.75e+79) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6e-73], x, If[LessEqual[z, 2.45e-145], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.12e-80], x, If[LessEqual[z, 2.75e+79], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{-73}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.45 \cdot 10^{-145}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;z \leq 1.12 \cdot 10^{-80}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.75 \cdot 10^{+79}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6e-73 or 2.44999999999999984e-145 < z < 1.12e-80 or 2.75000000000000003e79 < z Initial program 70.7%
associate-*r/99.3%
Simplified99.3%
Taylor expanded in y around 0 79.6%
if -6e-73 < z < 2.44999999999999984e-145Initial program 90.5%
associate-*r/88.3%
Simplified88.3%
Taylor expanded in y around inf 79.7%
associate-*r/83.3%
Simplified83.3%
if 1.12e-80 < z < 2.75000000000000003e79Initial program 96.4%
associate-*r/99.9%
Simplified99.9%
Taylor expanded in y around inf 67.6%
Final simplification79.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(Float64(z + y) / z)) end
function tmp = code(x, y, z) tmp = x * ((z + y) / z); end
code[x_, y_, z_] := N[(x * N[(N[(z + y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{z + y}{z}
\end{array}
Initial program 79.4%
associate-*r/95.9%
Simplified95.9%
Final simplification95.9%
(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 79.4%
associate-*r/95.9%
Simplified95.9%
Taylor expanded in y around 0 55.7%
Final simplification55.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 2023274
(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))