
(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 (* x (/ y z))))
double code(double x, double y, double z) {
return x + (x * (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 + (x * (y / z))
end function
public static double code(double x, double y, double z) {
return x + (x * (y / z));
}
def code(x, y, z): return x + (x * (y / z))
function code(x, y, z) return Float64(x + Float64(x * Float64(y / z))) end
function tmp = code(x, y, z) tmp = x + (x * (y / z)); end
code[x_, y_, z_] := N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + x \cdot \frac{y}{z}
\end{array}
Initial program 81.9%
associate-*l/85.0%
distribute-rgt-in79.8%
*-commutative79.8%
associate-/r/92.8%
*-inverses92.8%
/-rgt-identity92.8%
associate-*r/90.8%
*-commutative90.8%
associate-*r/96.2%
fma-def96.2%
Simplified96.2%
fma-udef96.2%
Applied egg-rr96.2%
Final simplification96.2%
(FPCore (x y z)
:precision binary64
(if (<= z -2200000000.0)
x
(if (or (<= z 1.15e-34) (and (not (<= z 4e+123)) (<= z 7.5e+168)))
(* x (/ y z))
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2200000000.0) {
tmp = x;
} else if ((z <= 1.15e-34) || (!(z <= 4e+123) && (z <= 7.5e+168))) {
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 <= (-2200000000.0d0)) then
tmp = x
else if ((z <= 1.15d-34) .or. (.not. (z <= 4d+123)) .and. (z <= 7.5d+168)) 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 <= -2200000000.0) {
tmp = x;
} else if ((z <= 1.15e-34) || (!(z <= 4e+123) && (z <= 7.5e+168))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2200000000.0: tmp = x elif (z <= 1.15e-34) or (not (z <= 4e+123) and (z <= 7.5e+168)): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2200000000.0) tmp = x; elseif ((z <= 1.15e-34) || (!(z <= 4e+123) && (z <= 7.5e+168))) 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 <= -2200000000.0) tmp = x; elseif ((z <= 1.15e-34) || (~((z <= 4e+123)) && (z <= 7.5e+168))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2200000000.0], x, If[Or[LessEqual[z, 1.15e-34], And[N[Not[LessEqual[z, 4e+123]], $MachinePrecision], LessEqual[z, 7.5e+168]]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2200000000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{-34} \lor \neg \left(z \leq 4 \cdot 10^{+123}\right) \land z \leq 7.5 \cdot 10^{+168}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.2e9 or 1.15000000000000006e-34 < z < 3.99999999999999991e123 or 7.4999999999999999e168 < z Initial program 74.0%
associate-*l/79.8%
Simplified79.8%
Taylor expanded in z around inf 77.0%
if -2.2e9 < z < 1.15000000000000006e-34 or 3.99999999999999991e123 < z < 7.4999999999999999e168Initial program 89.2%
associate-*l/89.9%
Simplified89.9%
Taylor expanded in z around 0 74.0%
*-commutative74.0%
associate-*r/75.5%
Simplified75.5%
Final simplification76.2%
(FPCore (x y z)
:precision binary64
(if (<= z -2200000000000.0)
x
(if (<= z 1.05e-32)
(* y (/ x z))
(if (<= z 4e+123) x (if (<= z 7.5e+168) (* x (/ y z)) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2200000000000.0) {
tmp = x;
} else if (z <= 1.05e-32) {
tmp = y * (x / z);
} else if (z <= 4e+123) {
tmp = x;
} else if (z <= 7.5e+168) {
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 <= (-2200000000000.0d0)) then
tmp = x
else if (z <= 1.05d-32) then
tmp = y * (x / z)
else if (z <= 4d+123) then
tmp = x
else if (z <= 7.5d+168) 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 <= -2200000000000.0) {
tmp = x;
} else if (z <= 1.05e-32) {
tmp = y * (x / z);
} else if (z <= 4e+123) {
tmp = x;
} else if (z <= 7.5e+168) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2200000000000.0: tmp = x elif z <= 1.05e-32: tmp = y * (x / z) elif z <= 4e+123: tmp = x elif z <= 7.5e+168: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2200000000000.0) tmp = x; elseif (z <= 1.05e-32) tmp = Float64(y * Float64(x / z)); elseif (z <= 4e+123) tmp = x; elseif (z <= 7.5e+168) 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 <= -2200000000000.0) tmp = x; elseif (z <= 1.05e-32) tmp = y * (x / z); elseif (z <= 4e+123) tmp = x; elseif (z <= 7.5e+168) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2200000000000.0], x, If[LessEqual[z, 1.05e-32], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 4e+123], x, If[LessEqual[z, 7.5e+168], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2200000000000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{-32}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;z \leq 4 \cdot 10^{+123}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 7.5 \cdot 10^{+168}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.2e12 or 1.05e-32 < z < 3.99999999999999991e123 or 7.4999999999999999e168 < z Initial program 74.0%
associate-*l/79.8%
Simplified79.8%
Taylor expanded in z around inf 77.0%
if -2.2e12 < z < 1.05e-32Initial program 90.0%
associate-*l/91.5%
Simplified91.5%
Taylor expanded in z around 0 74.5%
associate-*r/80.6%
Simplified80.6%
if 3.99999999999999991e123 < z < 7.4999999999999999e168Initial program 76.6%
associate-*l/65.4%
Simplified65.4%
Taylor expanded in z around 0 65.8%
*-commutative65.8%
associate-*r/88.8%
Simplified88.8%
Final simplification79.1%
(FPCore (x y z)
:precision binary64
(if (<= z -720000000000.0)
x
(if (<= z 7e-32)
(/ y (/ z x))
(if (<= z 4e+123) x (if (<= z 2.5e+169) (* x (/ y z)) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -720000000000.0) {
tmp = x;
} else if (z <= 7e-32) {
tmp = y / (z / x);
} else if (z <= 4e+123) {
tmp = x;
} else if (z <= 2.5e+169) {
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 <= (-720000000000.0d0)) then
tmp = x
else if (z <= 7d-32) then
tmp = y / (z / x)
else if (z <= 4d+123) then
tmp = x
else if (z <= 2.5d+169) 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 <= -720000000000.0) {
tmp = x;
} else if (z <= 7e-32) {
tmp = y / (z / x);
} else if (z <= 4e+123) {
tmp = x;
} else if (z <= 2.5e+169) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -720000000000.0: tmp = x elif z <= 7e-32: tmp = y / (z / x) elif z <= 4e+123: tmp = x elif z <= 2.5e+169: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -720000000000.0) tmp = x; elseif (z <= 7e-32) tmp = Float64(y / Float64(z / x)); elseif (z <= 4e+123) tmp = x; elseif (z <= 2.5e+169) 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 <= -720000000000.0) tmp = x; elseif (z <= 7e-32) tmp = y / (z / x); elseif (z <= 4e+123) tmp = x; elseif (z <= 2.5e+169) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -720000000000.0], x, If[LessEqual[z, 7e-32], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 4e+123], x, If[LessEqual[z, 2.5e+169], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -720000000000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 7 \cdot 10^{-32}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{elif}\;z \leq 4 \cdot 10^{+123}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.5 \cdot 10^{+169}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.2e11 or 6.9999999999999997e-32 < z < 3.99999999999999991e123 or 2.50000000000000009e169 < z Initial program 74.0%
associate-*l/79.8%
Simplified79.8%
Taylor expanded in z around inf 77.0%
if -7.2e11 < z < 6.9999999999999997e-32Initial program 90.0%
associate-*l/91.5%
Simplified91.5%
Taylor expanded in z around 0 74.5%
*-commutative74.5%
associate-*r/74.7%
Simplified74.7%
*-commutative74.7%
associate-/r/80.7%
Applied egg-rr80.7%
if 3.99999999999999991e123 < z < 2.50000000000000009e169Initial program 76.6%
associate-*l/65.4%
Simplified65.4%
Taylor expanded in z around 0 65.8%
*-commutative65.8%
associate-*r/88.8%
Simplified88.8%
Final simplification79.1%
(FPCore (x y z) :precision binary64 (if (<= z -2.45e+175) x (if (<= z 4.5e+187) (* (/ x z) (+ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.45e+175) {
tmp = x;
} else if (z <= 4.5e+187) {
tmp = (x / z) * (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.45d+175)) then
tmp = x
else if (z <= 4.5d+187) then
tmp = (x / z) * (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.45e+175) {
tmp = x;
} else if (z <= 4.5e+187) {
tmp = (x / z) * (y + z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.45e+175: tmp = x elif z <= 4.5e+187: tmp = (x / z) * (y + z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.45e+175) tmp = x; elseif (z <= 4.5e+187) tmp = Float64(Float64(x / z) * Float64(y + z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.45e+175) tmp = x; elseif (z <= 4.5e+187) tmp = (x / z) * (y + z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.45e+175], x, If[LessEqual[z, 4.5e+187], N[(N[(x / z), $MachinePrecision] * N[(y + z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.45 \cdot 10^{+175}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{+187}:\\
\;\;\;\;\frac{x}{z} \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.45e175 or 4.50000000000000026e187 < z Initial program 62.6%
associate-*l/65.0%
Simplified65.0%
Taylor expanded in z around inf 90.3%
if -2.45e175 < z < 4.50000000000000026e187Initial program 86.9%
associate-*l/90.3%
Simplified90.3%
Final simplification90.3%
(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 81.9%
associate-*l/85.0%
Simplified85.0%
Taylor expanded in z around inf 46.6%
Final simplification46.6%
(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 2023199
(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))