
(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 (+ (/ y (/ z y)) x))
double code(double x, double y, double z) {
return (y / (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 = (y / (z / y)) + x
end function
public static double code(double x, double y, double z) {
return (y / (z / y)) + x;
}
def code(x, y, z): return (y / (z / y)) + x
function code(x, y, z) return Float64(Float64(y / Float64(z / y)) + x) end
function tmp = code(x, y, z) tmp = (y / (z / y)) + x; end
code[x_, y_, z_] := N[(N[(y / N[(z / y), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{\frac{z}{y}} + x
\end{array}
Initial program 94.1%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= (* y y) 1e-58) (/ (* z x) z) (* (/ y z) y)))
double code(double x, double y, double z) {
double tmp;
if ((y * y) <= 1e-58) {
tmp = (z * x) / z;
} 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) :: tmp
if ((y * y) <= 1d-58) then
tmp = (z * x) / z
else
tmp = (y / z) * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y * y) <= 1e-58) {
tmp = (z * x) / z;
} else {
tmp = (y / z) * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * y) <= 1e-58: tmp = (z * x) / z else: tmp = (y / z) * y return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * y) <= 1e-58) tmp = Float64(Float64(z * x) / z); else tmp = Float64(Float64(y / z) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * y) <= 1e-58) tmp = (z * x) / z; else tmp = (y / z) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * y), $MachinePrecision], 1e-58], N[(N[(z * x), $MachinePrecision] / z), $MachinePrecision], N[(N[(y / z), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 10^{-58}:\\
\;\;\;\;\frac{z \cdot x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z} \cdot y\\
\end{array}
\end{array}
if (*.f64 y y) < 1e-58Initial program 97.5%
Taylor expanded in z around 0
lower-/.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6480.8
Applied rewrites80.8%
Taylor expanded in z around inf
Applied rewrites75.6%
if 1e-58 < (*.f64 y y) Initial program 91.5%
Taylor expanded in z around 0
lower-/.f64N/A
unpow2N/A
lower-*.f6473.7
Applied rewrites73.7%
Applied rewrites81.8%
Final simplification79.1%
(FPCore (x y z) :precision binary64 (fma (/ y z) y x))
double code(double x, double y, double z) {
return fma((y / z), y, x);
}
function code(x, y, z) return fma(Float64(y / z), y, x) end
code[x_, y_, z_] := N[(N[(y / z), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{z}, y, x\right)
\end{array}
Initial program 94.1%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (* (/ y z) y))
double code(double x, double y, double z) {
return (y / 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 = (y / z) * y
end function
public static double code(double x, double y, double z) {
return (y / z) * y;
}
def code(x, y, z): return (y / z) * y
function code(x, y, z) return Float64(Float64(y / z) * y) end
function tmp = code(x, y, z) tmp = (y / z) * y; end
code[x_, y_, z_] := N[(N[(y / z), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{z} \cdot y
\end{array}
Initial program 94.1%
Taylor expanded in z around 0
lower-/.f64N/A
unpow2N/A
lower-*.f6445.9
Applied rewrites45.9%
Applied rewrites51.2%
(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 2024268
(FPCore (x y z)
:name "Crypto.Random.Test:calculate from crypto-random-0.0.9"
:precision binary64
:alt
(! :herbie-platform default (+ x (* y (/ y z))))
(+ x (/ (* y y) z)))