
(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 (/ 1.0 (/ (/ z y) x))))
double code(double x, double y, double z) {
return x + (1.0 / ((z / y) / 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 + (1.0d0 / ((z / y) / x))
end function
public static double code(double x, double y, double z) {
return x + (1.0 / ((z / y) / x));
}
def code(x, y, z): return x + (1.0 / ((z / y) / x))
function code(x, y, z) return Float64(x + Float64(1.0 / Float64(Float64(z / y) / x))) end
function tmp = code(x, y, z) tmp = x + (1.0 / ((z / y) / x)); end
code[x_, y_, z_] := N[(x + N[(1.0 / N[(N[(z / y), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{1}{\frac{\frac{z}{y}}{x}}
\end{array}
Initial program 85.6%
associate-*l/88.0%
distribute-rgt-in82.4%
*-commutative82.4%
associate-/r/94.0%
*-inverses94.0%
/-rgt-identity94.0%
associate-*r/94.5%
*-commutative94.5%
associate-*r/96.9%
fma-def96.9%
Simplified96.9%
fma-udef96.9%
clear-num96.9%
un-div-inv97.2%
Applied egg-rr97.2%
*-un-lft-identity97.2%
div-inv97.2%
times-frac94.4%
Applied egg-rr94.4%
frac-times97.2%
div-inv97.2%
associate-/l*97.3%
Applied egg-rr97.3%
Final simplification97.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -4e+25) (not (<= y 1.35e-43))) (* y (/ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4e+25) || !(y <= 1.35e-43)) {
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 <= (-4d+25)) .or. (.not. (y <= 1.35d-43))) 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 <= -4e+25) || !(y <= 1.35e-43)) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4e+25) or not (y <= 1.35e-43): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4e+25) || !(y <= 1.35e-43)) 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 <= -4e+25) || ~((y <= 1.35e-43))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4e+25], N[Not[LessEqual[y, 1.35e-43]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+25} \lor \neg \left(y \leq 1.35 \cdot 10^{-43}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.00000000000000036e25 or 1.34999999999999996e-43 < y Initial program 91.1%
associate-*l/91.2%
Simplified91.2%
Taylor expanded in z around 0 75.7%
associate-*r/77.2%
Simplified77.2%
if -4.00000000000000036e25 < y < 1.34999999999999996e-43Initial program 79.9%
associate-*l/84.8%
Simplified84.8%
Taylor expanded in z around inf 76.2%
Final simplification76.7%
(FPCore (x y z) :precision binary64 (if (<= y -1.6e+26) (* y (/ x z)) (if (<= y 3.5e-44) x (/ y (/ z x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.6e+26) {
tmp = y * (x / z);
} else if (y <= 3.5e-44) {
tmp = x;
} else {
tmp = y / (z / 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.6d+26)) then
tmp = y * (x / z)
else if (y <= 3.5d-44) then
tmp = x
else
tmp = y / (z / x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.6e+26) {
tmp = y * (x / z);
} else if (y <= 3.5e-44) {
tmp = x;
} else {
tmp = y / (z / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.6e+26: tmp = y * (x / z) elif y <= 3.5e-44: tmp = x else: tmp = y / (z / x) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.6e+26) tmp = Float64(y * Float64(x / z)); elseif (y <= 3.5e-44) tmp = x; else tmp = Float64(y / Float64(z / x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.6e+26) tmp = y * (x / z); elseif (y <= 3.5e-44) tmp = x; else tmp = y / (z / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.6e+26], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.5e-44], x, N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{+26}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{-44}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\end{array}
\end{array}
if y < -1.60000000000000014e26Initial program 94.4%
associate-*l/94.4%
Simplified94.4%
Taylor expanded in z around 0 83.7%
associate-*r/85.5%
Simplified85.5%
if -1.60000000000000014e26 < y < 3.4999999999999998e-44Initial program 79.9%
associate-*l/84.8%
Simplified84.8%
Taylor expanded in z around inf 76.2%
if 3.4999999999999998e-44 < y Initial program 88.8%
associate-*l/88.9%
Simplified88.9%
Taylor expanded in z around 0 70.2%
associate-/l*71.5%
Simplified71.5%
Final simplification76.7%
(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 85.6%
associate-*l/88.0%
distribute-rgt-in82.4%
*-commutative82.4%
associate-/r/94.0%
*-inverses94.0%
/-rgt-identity94.0%
associate-*r/94.5%
*-commutative94.5%
associate-*r/96.9%
fma-def96.9%
Simplified96.9%
Taylor expanded in x around 0 96.9%
Final simplification96.9%
(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 85.6%
associate-*l/88.0%
distribute-rgt-in82.4%
*-commutative82.4%
associate-/r/94.0%
*-inverses94.0%
/-rgt-identity94.0%
associate-*r/94.5%
*-commutative94.5%
associate-*r/96.9%
fma-def96.9%
Simplified96.9%
fma-udef96.9%
clear-num96.9%
un-div-inv97.2%
Applied egg-rr97.2%
Final simplification97.2%
(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 85.6%
associate-*l/88.0%
Simplified88.0%
Taylor expanded in z around inf 49.2%
Final simplification49.2%
(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 2023200
(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))