
(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 8 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 (/ z y))))
double code(double x, double y, double z) {
return x + (x / (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 + (x / (z / y))
end function
public static double code(double x, double y, double z) {
return x + (x / (z / y));
}
def code(x, y, z): return x + (x / (z / y))
function code(x, y, z) return Float64(x + Float64(x / Float64(z / y))) end
function tmp = code(x, y, z) tmp = x + (x / (z / y)); end
code[x_, y_, z_] := N[(x + N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{x}{\frac{z}{y}}
\end{array}
Initial program 87.5%
associate-*l/85.0%
distribute-rgt-in79.4%
*-commutative79.4%
associate-/r/94.3%
*-inverses94.3%
/-rgt-identity94.3%
associate-*r/94.4%
*-commutative94.4%
associate-*r/95.5%
fma-def95.5%
Simplified95.5%
fma-udef95.5%
Applied egg-rr95.5%
clear-num95.5%
un-div-inv95.6%
Applied egg-rr95.6%
Final simplification95.6%
(FPCore (x y z) :precision binary64 (if (<= z -6e+174) x (if (<= z 1.22e+159) (* (/ x z) (+ z y)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6e+174) {
tmp = x;
} else if (z <= 1.22e+159) {
tmp = (x / z) * (z + y);
} 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+174)) then
tmp = x
else if (z <= 1.22d+159) then
tmp = (x / z) * (z + y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -6e+174) {
tmp = x;
} else if (z <= 1.22e+159) {
tmp = (x / z) * (z + y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6e+174: tmp = x elif z <= 1.22e+159: tmp = (x / z) * (z + y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6e+174) tmp = x; elseif (z <= 1.22e+159) tmp = Float64(Float64(x / z) * Float64(z + y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6e+174) tmp = x; elseif (z <= 1.22e+159) tmp = (x / z) * (z + y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6e+174], x, If[LessEqual[z, 1.22e+159], N[(N[(x / z), $MachinePrecision] * N[(z + y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{+174}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.22 \cdot 10^{+159}:\\
\;\;\;\;\frac{x}{z} \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6e174 or 1.22000000000000004e159 < z Initial program 68.9%
associate-*l/60.8%
Simplified60.8%
Taylor expanded in z around inf 90.1%
if -6e174 < z < 1.22000000000000004e159Initial program 93.3%
associate-*l/92.6%
Simplified92.6%
Final simplification92.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.45e+59) (not (<= y 1.65e+63))) (* x (/ y z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.45e+59) || !(y <= 1.65e+63)) {
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 <= (-1.45d+59)) .or. (.not. (y <= 1.65d+63))) 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 <= -1.45e+59) || !(y <= 1.65e+63)) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.45e+59) or not (y <= 1.65e+63): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.45e+59) || !(y <= 1.65e+63)) 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 <= -1.45e+59) || ~((y <= 1.65e+63))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.45e+59], N[Not[LessEqual[y, 1.65e+63]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{+59} \lor \neg \left(y \leq 1.65 \cdot 10^{+63}\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.44999999999999995e59 or 1.6500000000000001e63 < y Initial program 87.3%
associate-*l/92.6%
Simplified92.6%
Taylor expanded in z around 0 76.2%
*-commutative76.2%
associate-*r/70.7%
Simplified70.7%
if -1.44999999999999995e59 < y < 1.6500000000000001e63Initial program 87.6%
associate-*l/80.3%
Simplified80.3%
Taylor expanded in z around inf 79.0%
Final simplification75.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.9e+57) (not (<= y 2.7e+14))) (* y (/ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.9e+57) || !(y <= 2.7e+14)) {
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 <= (-4.9d+57)) .or. (.not. (y <= 2.7d+14))) 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 <= -4.9e+57) || !(y <= 2.7e+14)) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.9e+57) or not (y <= 2.7e+14): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.9e+57) || !(y <= 2.7e+14)) 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 <= -4.9e+57) || ~((y <= 2.7e+14))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.9e+57], N[Not[LessEqual[y, 2.7e+14]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.9 \cdot 10^{+57} \lor \neg \left(y \leq 2.7 \cdot 10^{+14}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.8999999999999999e57 or 2.7e14 < y Initial program 88.2%
associate-*l/92.8%
Simplified92.8%
Taylor expanded in z around 0 72.9%
associate-*r/72.4%
Simplified72.4%
if -4.8999999999999999e57 < y < 2.7e14Initial program 86.9%
associate-*l/78.7%
Simplified78.7%
Taylor expanded in z around inf 82.1%
Final simplification77.8%
(FPCore (x y z) :precision binary64 (if (<= y -1.95e+56) (/ y (/ z x)) (if (<= y 2.45e+14) x (* y (/ x z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.95e+56) {
tmp = y / (z / x);
} else if (y <= 2.45e+14) {
tmp = x;
} else {
tmp = y * (x / 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.95d+56)) then
tmp = y / (z / x)
else if (y <= 2.45d+14) then
tmp = x
else
tmp = y * (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.95e+56) {
tmp = y / (z / x);
} else if (y <= 2.45e+14) {
tmp = x;
} else {
tmp = y * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.95e+56: tmp = y / (z / x) elif y <= 2.45e+14: tmp = x else: tmp = y * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.95e+56) tmp = Float64(y / Float64(z / x)); elseif (y <= 2.45e+14) tmp = x; else tmp = Float64(y * Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.95e+56) tmp = y / (z / x); elseif (y <= 2.45e+14) tmp = x; else tmp = y * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.95e+56], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.45e+14], x, N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{+56}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{elif}\;y \leq 2.45 \cdot 10^{+14}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < -1.94999999999999997e56Initial program 84.1%
associate-*l/93.7%
Simplified93.7%
Taylor expanded in z around 0 70.1%
*-commutative70.1%
associate-*r/65.1%
Simplified65.1%
*-commutative65.1%
associate-/r/74.2%
Applied egg-rr74.2%
if -1.94999999999999997e56 < y < 2.45e14Initial program 86.9%
associate-*l/78.7%
Simplified78.7%
Taylor expanded in z around inf 82.1%
if 2.45e14 < y Initial program 91.2%
associate-*l/92.2%
Simplified92.2%
Taylor expanded in z around 0 74.9%
associate-*r/71.2%
Simplified71.2%
Final simplification77.8%
(FPCore (x y z) :precision binary64 (if (<= y -1.9e+57) (/ y (/ z x)) (if (<= y 6.5e+15) x (/ (* x y) z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.9e+57) {
tmp = y / (z / x);
} else if (y <= 6.5e+15) {
tmp = x;
} else {
tmp = (x * 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.9d+57)) then
tmp = y / (z / x)
else if (y <= 6.5d+15) then
tmp = x
else
tmp = (x * y) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.9e+57) {
tmp = y / (z / x);
} else if (y <= 6.5e+15) {
tmp = x;
} else {
tmp = (x * y) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.9e+57: tmp = y / (z / x) elif y <= 6.5e+15: tmp = x else: tmp = (x * y) / z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.9e+57) tmp = Float64(y / Float64(z / x)); elseif (y <= 6.5e+15) tmp = x; else tmp = Float64(Float64(x * y) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.9e+57) tmp = y / (z / x); elseif (y <= 6.5e+15) tmp = x; else tmp = (x * y) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.9e+57], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6.5e+15], x, N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{+57}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{+15}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\end{array}
\end{array}
if y < -1.8999999999999999e57Initial program 84.1%
associate-*l/93.7%
Simplified93.7%
Taylor expanded in z around 0 70.1%
*-commutative70.1%
associate-*r/65.1%
Simplified65.1%
*-commutative65.1%
associate-/r/74.2%
Applied egg-rr74.2%
if -1.8999999999999999e57 < y < 6.5e15Initial program 86.9%
associate-*l/78.7%
Simplified78.7%
Taylor expanded in z around inf 82.1%
if 6.5e15 < y Initial program 91.2%
associate-*l/92.2%
Simplified92.2%
Taylor expanded in z around 0 74.9%
Final simplification78.8%
(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 87.5%
associate-*l/85.0%
distribute-rgt-in79.4%
*-commutative79.4%
associate-/r/94.3%
*-inverses94.3%
/-rgt-identity94.3%
associate-*r/94.4%
*-commutative94.4%
associate-*r/95.5%
fma-def95.5%
Simplified95.5%
fma-udef95.5%
Applied egg-rr95.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 87.5%
associate-*l/85.0%
Simplified85.0%
Taylor expanded in z around inf 56.1%
Final simplification56.1%
(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 2023196
(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))