
(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.05e+196) (* (/ x z) (+ y z)) (/ x (/ z (+ y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.05e+196) {
tmp = (x / z) * (y + 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.05d+196)) then
tmp = (x / z) * (y + 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.05e+196) {
tmp = (x / z) * (y + z);
} else {
tmp = x / (z / (y + z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.05e+196: tmp = (x / z) * (y + z) else: tmp = x / (z / (y + z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.05e+196) tmp = Float64(Float64(x / z) * Float64(y + 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.05e+196) tmp = (x / z) * (y + z); else tmp = x / (z / (y + z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.05e+196], N[(N[(x / z), $MachinePrecision] * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{+196}:\\
\;\;\;\;\frac{x}{z} \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y + z}}\\
\end{array}
\end{array}
if y < -1.05000000000000007e196Initial program 92.6%
associate-*l/93.9%
Simplified93.9%
if -1.05000000000000007e196 < y Initial program 78.7%
associate-*l/86.1%
Simplified86.1%
associate-/r/97.6%
+-commutative97.6%
Applied egg-rr97.6%
Final simplification97.2%
(FPCore (x y z)
:precision binary64
(if (<= z -300000000000.0)
x
(if (or (<= z -9.5e-42) (and (not (<= z -2.4e-130)) (<= z 4.6e-26)))
(* x (/ y z))
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -300000000000.0) {
tmp = x;
} else if ((z <= -9.5e-42) || (!(z <= -2.4e-130) && (z <= 4.6e-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 <= (-300000000000.0d0)) then
tmp = x
else if ((z <= (-9.5d-42)) .or. (.not. (z <= (-2.4d-130))) .and. (z <= 4.6d-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 <= -300000000000.0) {
tmp = x;
} else if ((z <= -9.5e-42) || (!(z <= -2.4e-130) && (z <= 4.6e-26))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -300000000000.0: tmp = x elif (z <= -9.5e-42) or (not (z <= -2.4e-130) and (z <= 4.6e-26)): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -300000000000.0) tmp = x; elseif ((z <= -9.5e-42) || (!(z <= -2.4e-130) && (z <= 4.6e-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 <= -300000000000.0) tmp = x; elseif ((z <= -9.5e-42) || (~((z <= -2.4e-130)) && (z <= 4.6e-26))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -300000000000.0], x, If[Or[LessEqual[z, -9.5e-42], And[N[Not[LessEqual[z, -2.4e-130]], $MachinePrecision], LessEqual[z, 4.6e-26]]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -300000000000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -9.5 \cdot 10^{-42} \lor \neg \left(z \leq -2.4 \cdot 10^{-130}\right) \land z \leq 4.6 \cdot 10^{-26}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3e11 or -9.49999999999999948e-42 < z < -2.39999999999999997e-130 or 4.60000000000000018e-26 < z Initial program 71.4%
associate-*l/81.8%
Simplified81.8%
Taylor expanded in z around inf 80.1%
if -3e11 < z < -9.49999999999999948e-42 or -2.39999999999999997e-130 < z < 4.60000000000000018e-26Initial program 90.9%
associate-*l/93.2%
Simplified93.2%
Taylor expanded in z around 0 78.6%
*-commutative78.6%
associate-*r/74.0%
Simplified74.0%
Final simplification77.3%
(FPCore (x y z)
:precision binary64
(if (<= z -280000000000.0)
x
(if (or (<= z -1.65e-82) (and (not (<= z -2.4e-130)) (<= z 6e-25)))
(* y (/ x z))
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -280000000000.0) {
tmp = x;
} else if ((z <= -1.65e-82) || (!(z <= -2.4e-130) && (z <= 6e-25))) {
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 <= (-280000000000.0d0)) then
tmp = x
else if ((z <= (-1.65d-82)) .or. (.not. (z <= (-2.4d-130))) .and. (z <= 6d-25)) 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 <= -280000000000.0) {
tmp = x;
} else if ((z <= -1.65e-82) || (!(z <= -2.4e-130) && (z <= 6e-25))) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -280000000000.0: tmp = x elif (z <= -1.65e-82) or (not (z <= -2.4e-130) and (z <= 6e-25)): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -280000000000.0) tmp = x; elseif ((z <= -1.65e-82) || (!(z <= -2.4e-130) && (z <= 6e-25))) 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 <= -280000000000.0) tmp = x; elseif ((z <= -1.65e-82) || (~((z <= -2.4e-130)) && (z <= 6e-25))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -280000000000.0], x, If[Or[LessEqual[z, -1.65e-82], And[N[Not[LessEqual[z, -2.4e-130]], $MachinePrecision], LessEqual[z, 6e-25]]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -280000000000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.65 \cdot 10^{-82} \lor \neg \left(z \leq -2.4 \cdot 10^{-130}\right) \land z \leq 6 \cdot 10^{-25}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.8e11 or -1.65000000000000011e-82 < z < -2.39999999999999997e-130 or 5.9999999999999995e-25 < z Initial program 68.7%
associate-*l/80.1%
Simplified80.1%
Taylor expanded in z around inf 83.2%
if -2.8e11 < z < -1.65000000000000011e-82 or -2.39999999999999997e-130 < z < 5.9999999999999995e-25Initial program 91.7%
associate-*l/93.8%
Simplified93.8%
Taylor expanded in z around 0 76.1%
associate-*r/76.4%
Simplified76.4%
Final simplification79.8%
(FPCore (x y z)
:precision binary64
(if (<= z -250000000000.0)
x
(if (<= z -5.2e-83)
(* y (/ x z))
(if (<= z -2.4e-130) x (if (<= z 4.6e-26) (/ y (/ z x)) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -250000000000.0) {
tmp = x;
} else if (z <= -5.2e-83) {
tmp = y * (x / z);
} else if (z <= -2.4e-130) {
tmp = x;
} else if (z <= 4.6e-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 <= (-250000000000.0d0)) then
tmp = x
else if (z <= (-5.2d-83)) then
tmp = y * (x / z)
else if (z <= (-2.4d-130)) then
tmp = x
else if (z <= 4.6d-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 <= -250000000000.0) {
tmp = x;
} else if (z <= -5.2e-83) {
tmp = y * (x / z);
} else if (z <= -2.4e-130) {
tmp = x;
} else if (z <= 4.6e-26) {
tmp = y / (z / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -250000000000.0: tmp = x elif z <= -5.2e-83: tmp = y * (x / z) elif z <= -2.4e-130: tmp = x elif z <= 4.6e-26: tmp = y / (z / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -250000000000.0) tmp = x; elseif (z <= -5.2e-83) tmp = Float64(y * Float64(x / z)); elseif (z <= -2.4e-130) tmp = x; elseif (z <= 4.6e-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 <= -250000000000.0) tmp = x; elseif (z <= -5.2e-83) tmp = y * (x / z); elseif (z <= -2.4e-130) tmp = x; elseif (z <= 4.6e-26) tmp = y / (z / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -250000000000.0], x, If[LessEqual[z, -5.2e-83], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, -2.4e-130], x, If[LessEqual[z, 4.6e-26], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -250000000000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -5.2 \cdot 10^{-83}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;z \leq -2.4 \cdot 10^{-130}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.6 \cdot 10^{-26}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.5e11 or -5.20000000000000018e-83 < z < -2.39999999999999997e-130 or 4.60000000000000018e-26 < z Initial program 68.7%
associate-*l/80.1%
Simplified80.1%
Taylor expanded in z around inf 83.2%
if -2.5e11 < z < -5.20000000000000018e-83Initial program 99.7%
associate-*l/99.8%
Simplified99.8%
Taylor expanded in z around 0 62.3%
associate-*r/62.5%
Simplified62.5%
if -2.39999999999999997e-130 < z < 4.60000000000000018e-26Initial program 89.7%
associate-*l/92.2%
Simplified92.2%
Taylor expanded in z around 0 79.7%
*-commutative79.7%
associate-*r/74.4%
Simplified74.4%
*-commutative74.4%
associate-/r/80.9%
Applied egg-rr80.9%
Final simplification80.2%
(FPCore (x y z) :precision binary64 (if (<= z -1.66e+114) x (if (<= z 2.35e+151) (* (/ x z) (+ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.66e+114) {
tmp = x;
} else if (z <= 2.35e+151) {
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 <= (-1.66d+114)) then
tmp = x
else if (z <= 2.35d+151) 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 <= -1.66e+114) {
tmp = x;
} else if (z <= 2.35e+151) {
tmp = (x / z) * (y + z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.66e+114: tmp = x elif z <= 2.35e+151: tmp = (x / z) * (y + z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.66e+114) tmp = x; elseif (z <= 2.35e+151) 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 <= -1.66e+114) tmp = x; elseif (z <= 2.35e+151) tmp = (x / z) * (y + z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.66e+114], x, If[LessEqual[z, 2.35e+151], N[(N[(x / z), $MachinePrecision] * N[(y + z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.66 \cdot 10^{+114}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.35 \cdot 10^{+151}:\\
\;\;\;\;\frac{x}{z} \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.66000000000000008e114 or 2.34999999999999995e151 < z Initial program 53.4%
associate-*l/73.1%
Simplified73.1%
Taylor expanded in z around inf 92.5%
if -1.66000000000000008e114 < z < 2.34999999999999995e151Initial program 90.4%
associate-*l/92.2%
Simplified92.2%
Final simplification92.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 80.1%
associate-*l/86.9%
Simplified86.9%
Taylor expanded in z around inf 52.6%
Final simplification52.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 2023208
(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))