
(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 92.2%
associate-*l/99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (/ (* y y) z))) (if (<= t_0 -5e-25) (* y (/ y z)) (if (<= t_0 2e-50) x (/ y (/ z y))))))
double code(double x, double y, double z) {
double t_0 = (y * y) / z;
double tmp;
if (t_0 <= -5e-25) {
tmp = y * (y / z);
} else if (t_0 <= 2e-50) {
tmp = x;
} else {
tmp = y / (z / y);
}
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) :: t_0
real(8) :: tmp
t_0 = (y * y) / z
if (t_0 <= (-5d-25)) then
tmp = y * (y / z)
else if (t_0 <= 2d-50) then
tmp = x
else
tmp = y / (z / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y * y) / z;
double tmp;
if (t_0 <= -5e-25) {
tmp = y * (y / z);
} else if (t_0 <= 2e-50) {
tmp = x;
} else {
tmp = y / (z / y);
}
return tmp;
}
def code(x, y, z): t_0 = (y * y) / z tmp = 0 if t_0 <= -5e-25: tmp = y * (y / z) elif t_0 <= 2e-50: tmp = x else: tmp = y / (z / y) return tmp
function code(x, y, z) t_0 = Float64(Float64(y * y) / z) tmp = 0.0 if (t_0 <= -5e-25) tmp = Float64(y * Float64(y / z)); elseif (t_0 <= 2e-50) tmp = x; else tmp = Float64(y / Float64(z / y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y * y) / z; tmp = 0.0; if (t_0 <= -5e-25) tmp = y * (y / z); elseif (t_0 <= 2e-50) tmp = x; else tmp = y / (z / y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y * y), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t$95$0, -5e-25], N[(y * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e-50], x, N[(y / N[(z / y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y \cdot y}{z}\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{-25}:\\
\;\;\;\;y \cdot \frac{y}{z}\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{-50}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{z}{y}}\\
\end{array}
\end{array}
if (/.f64 (*.f64 y y) z) < -4.99999999999999962e-25Initial program 84.7%
associate-*l/99.9%
Simplified99.9%
+-commutative99.9%
associate-*l/84.7%
*-un-lft-identity84.7%
add-sqr-sqrt0.0%
times-frac0.0%
fma-def0.0%
pow1/20.0%
pow-flip0.0%
metadata-eval0.0%
Applied egg-rr0.0%
associate-/l*0.0%
Simplified0.0%
Taylor expanded in y around inf 77.6%
unpow277.6%
Simplified77.6%
associate-/l*86.3%
associate-/r/86.4%
Applied egg-rr86.4%
if -4.99999999999999962e-25 < (/.f64 (*.f64 y y) z) < 2.00000000000000002e-50Initial program 99.2%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around inf 91.0%
if 2.00000000000000002e-50 < (/.f64 (*.f64 y y) z) Initial program 88.2%
associate-*l/99.7%
Simplified99.7%
+-commutative99.7%
associate-*l/88.2%
*-un-lft-identity88.2%
add-sqr-sqrt88.0%
times-frac88.0%
fma-def88.0%
pow1/288.0%
pow-flip88.0%
metadata-eval88.0%
Applied egg-rr88.0%
associate-/l*95.3%
Simplified95.3%
Taylor expanded in y around inf 83.6%
unpow283.6%
associate-/l*92.4%
Simplified92.4%
Final simplification90.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.1e-25) (not (<= y 5.8e-20))) (* y (/ y z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.1e-25) || !(y <= 5.8e-20)) {
tmp = y * (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.1d-25)) .or. (.not. (y <= 5.8d-20))) then
tmp = y * (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.1e-25) || !(y <= 5.8e-20)) {
tmp = y * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.1e-25) or not (y <= 5.8e-20): tmp = y * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.1e-25) || !(y <= 5.8e-20)) tmp = Float64(y * Float64(y / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.1e-25) || ~((y <= 5.8e-20))) tmp = y * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.1e-25], N[Not[LessEqual[y, 5.8e-20]], $MachinePrecision]], N[(y * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{-25} \lor \neg \left(y \leq 5.8 \cdot 10^{-20}\right):\\
\;\;\;\;y \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.1000000000000001e-25 or 5.8e-20 < y Initial program 86.2%
associate-*l/99.9%
Simplified99.9%
+-commutative99.9%
associate-*l/86.2%
*-un-lft-identity86.2%
add-sqr-sqrt40.1%
times-frac40.1%
fma-def40.1%
pow1/240.1%
pow-flip40.1%
metadata-eval40.1%
Applied egg-rr40.1%
associate-/l*43.5%
Simplified43.5%
Taylor expanded in y around inf 76.1%
unpow276.1%
Simplified76.1%
associate-/l*85.0%
associate-/r/85.0%
Applied egg-rr85.0%
if -1.1000000000000001e-25 < y < 5.8e-20Initial program 99.2%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in x around inf 84.5%
Final simplification84.7%
(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 92.2%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in x around inf 47.5%
Final simplification47.5%
(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 2023173
(FPCore (x y z)
:name "Crypto.Random.Test:calculate from crypto-random-0.0.9"
:precision binary64
:herbie-target
(+ x (* y (/ y z)))
(+ x (/ (* y y) z)))