
(FPCore (x y z) :precision binary64 (+ x (/ (* y y) z)))
double code(double x, double y, double z) {
return x + ((y * 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 + ((y * y) / z)
end function
public static double code(double x, double y, double z) {
return x + ((y * y) / z);
}
def code(x, y, z): return x + ((y * y) / z)
function code(x, y, z) return Float64(x + Float64(Float64(y * y) / z)) end
function tmp = code(x, y, z) tmp = x + ((y * y) / z); end
code[x_, y_, z_] := N[(x + N[(N[(y * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot y}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (/ (* y y) z)))
double code(double x, double y, double z) {
return x + ((y * 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 + ((y * y) / z)
end function
public static double code(double x, double y, double z) {
return x + ((y * y) / z);
}
def code(x, y, z): return x + ((y * y) / z)
function code(x, y, z) return Float64(x + Float64(Float64(y * y) / z)) end
function tmp = code(x, y, z) tmp = x + ((y * y) / z); end
code[x_, y_, z_] := N[(x + N[(N[(y * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot y}{z}
\end{array}
(FPCore (x y z) :precision binary64 (+ x (* y (/ y z))))
double code(double x, double y, double z) {
return x + (y * (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 + (y * (y / z))
end function
public static double code(double x, double y, double z) {
return x + (y * (y / z));
}
def code(x, y, z): return x + (y * (y / z))
function code(x, y, z) return Float64(x + Float64(y * Float64(y / z))) end
function tmp = code(x, y, z) tmp = x + (y * (y / z)); end
code[x_, y_, z_] := N[(x + N[(y * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \frac{y}{z}
\end{array}
Initial program 89.2%
associate-/l*99.9%
Simplified99.9%
(FPCore (x y z) :precision binary64 (if (<= y 3.5e+43) x (/ z (/ z x))))
double code(double x, double y, double z) {
double tmp;
if (y <= 3.5e+43) {
tmp = x;
} else {
tmp = z / (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 <= 3.5d+43) then
tmp = x
else
tmp = z / (z / x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 3.5e+43) {
tmp = x;
} else {
tmp = z / (z / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 3.5e+43: tmp = x else: tmp = z / (z / x) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 3.5e+43) tmp = x; else tmp = Float64(z / Float64(z / x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 3.5e+43) tmp = x; else tmp = z / (z / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 3.5e+43], x, N[(z / N[(z / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.5 \cdot 10^{+43}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{z}{\frac{z}{x}}\\
\end{array}
\end{array}
if y < 3.5000000000000001e43Initial program 90.7%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 54.1%
if 3.5000000000000001e43 < y Initial program 83.1%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in z around 0 71.9%
Taylor expanded in x around inf 10.8%
*-commutative10.8%
Simplified10.8%
associate-/l*33.6%
*-commutative33.6%
Applied egg-rr33.6%
*-commutative33.6%
clear-num33.5%
un-div-inv33.6%
Applied egg-rr33.6%
(FPCore (x y z) :precision binary64 (if (<= y 3e+43) x (* z (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 3e+43) {
tmp = x;
} else {
tmp = z * (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 <= 3d+43) then
tmp = x
else
tmp = z * (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 3e+43) {
tmp = x;
} else {
tmp = z * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 3e+43: tmp = x else: tmp = z * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 3e+43) tmp = x; else tmp = Float64(z * Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 3e+43) tmp = x; else tmp = z * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 3e+43], x, N[(z * N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{+43}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < 3.00000000000000017e43Initial program 90.7%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 54.1%
if 3.00000000000000017e43 < y Initial program 83.1%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in z around 0 71.9%
Taylor expanded in x around inf 10.8%
*-commutative10.8%
Simplified10.8%
associate-/l*33.6%
*-commutative33.6%
Applied egg-rr33.6%
Final simplification50.0%
(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 89.2%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 48.9%
(FPCore (x y z) :precision binary64 (+ x (* y (/ y z))))
double code(double x, double y, double z) {
return x + (y * (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 + (y * (y / z))
end function
public static double code(double x, double y, double z) {
return x + (y * (y / z));
}
def code(x, y, z): return x + (y * (y / z))
function code(x, y, z) return Float64(x + Float64(y * Float64(y / z))) end
function tmp = code(x, y, z) tmp = x + (y * (y / z)); end
code[x_, y_, z_] := N[(x + N[(y * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \frac{y}{z}
\end{array}
herbie shell --seed 2024103
(FPCore (x y z)
:name "Crypto.Random.Test:calculate from crypto-random-0.0.9"
:precision binary64
:alt
(+ x (* y (/ y z)))
(+ x (/ (* y y) z)))