
(FPCore (x y z) :precision binary64 (- (/ (* x y) 2.0) (/ z 8.0)))
double code(double x, double y, double z) {
return ((x * y) / 2.0) - (z / 8.0);
}
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) / 2.0d0) - (z / 8.0d0)
end function
public static double code(double x, double y, double z) {
return ((x * y) / 2.0) - (z / 8.0);
}
def code(x, y, z): return ((x * y) / 2.0) - (z / 8.0)
function code(x, y, z) return Float64(Float64(Float64(x * y) / 2.0) - Float64(z / 8.0)) end
function tmp = code(x, y, z) tmp = ((x * y) / 2.0) - (z / 8.0); end
code[x_, y_, z_] := N[(N[(N[(x * y), $MachinePrecision] / 2.0), $MachinePrecision] - N[(z / 8.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y}{2} - \frac{z}{8}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (/ (* x y) 2.0) (/ z 8.0)))
double code(double x, double y, double z) {
return ((x * y) / 2.0) - (z / 8.0);
}
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) / 2.0d0) - (z / 8.0d0)
end function
public static double code(double x, double y, double z) {
return ((x * y) / 2.0) - (z / 8.0);
}
def code(x, y, z): return ((x * y) / 2.0) - (z / 8.0)
function code(x, y, z) return Float64(Float64(Float64(x * y) / 2.0) - Float64(z / 8.0)) end
function tmp = code(x, y, z) tmp = ((x * y) / 2.0) - (z / 8.0); end
code[x_, y_, z_] := N[(N[(N[(x * y), $MachinePrecision] / 2.0), $MachinePrecision] - N[(z / 8.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y}{2} - \frac{z}{8}
\end{array}
(FPCore (x y z) :precision binary64 (- (/ (* x y) 2.0) (/ z 8.0)))
double code(double x, double y, double z) {
return ((x * y) / 2.0) - (z / 8.0);
}
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) / 2.0d0) - (z / 8.0d0)
end function
public static double code(double x, double y, double z) {
return ((x * y) / 2.0) - (z / 8.0);
}
def code(x, y, z): return ((x * y) / 2.0) - (z / 8.0)
function code(x, y, z) return Float64(Float64(Float64(x * y) / 2.0) - Float64(z / 8.0)) end
function tmp = code(x, y, z) tmp = ((x * y) / 2.0) - (z / 8.0); end
code[x_, y_, z_] := N[(N[(N[(x * y), $MachinePrecision] / 2.0), $MachinePrecision] - N[(z / 8.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y}{2} - \frac{z}{8}
\end{array}
Initial program 100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (* x y) 2.0)))
(if (<= (* x y) -2.1e-54)
t_0
(if (<= (* x y) 1.25e+70) (- (* x y) (/ z 8.0)) t_0))))
double code(double x, double y, double z) {
double t_0 = (x * y) / 2.0;
double tmp;
if ((x * y) <= -2.1e-54) {
tmp = t_0;
} else if ((x * y) <= 1.25e+70) {
tmp = (x * y) - (z / 8.0);
} else {
tmp = t_0;
}
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 = (x * y) / 2.0d0
if ((x * y) <= (-2.1d-54)) then
tmp = t_0
else if ((x * y) <= 1.25d+70) then
tmp = (x * y) - (z / 8.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * y) / 2.0;
double tmp;
if ((x * y) <= -2.1e-54) {
tmp = t_0;
} else if ((x * y) <= 1.25e+70) {
tmp = (x * y) - (z / 8.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x * y) / 2.0 tmp = 0 if (x * y) <= -2.1e-54: tmp = t_0 elif (x * y) <= 1.25e+70: tmp = (x * y) - (z / 8.0) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x * y) / 2.0) tmp = 0.0 if (Float64(x * y) <= -2.1e-54) tmp = t_0; elseif (Float64(x * y) <= 1.25e+70) tmp = Float64(Float64(x * y) - Float64(z / 8.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * y) / 2.0; tmp = 0.0; if ((x * y) <= -2.1e-54) tmp = t_0; elseif ((x * y) <= 1.25e+70) tmp = (x * y) - (z / 8.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * y), $MachinePrecision] / 2.0), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -2.1e-54], t$95$0, If[LessEqual[N[(x * y), $MachinePrecision], 1.25e+70], N[(N[(x * y), $MachinePrecision] - N[(z / 8.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot y}{2}\\
\mathbf{if}\;x \cdot y \leq -2.1 \cdot 10^{-54}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \cdot y \leq 1.25 \cdot 10^{+70}:\\
\;\;\;\;x \cdot y - \frac{z}{8}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 x y) < -2.1e-54 or 1.2500000000000001e70 < (*.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites83.1%
if -2.1e-54 < (*.f64 x y) < 1.2500000000000001e70Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites83.6%
(FPCore (x y z) :precision binary64 (/ (* x y) 2.0))
double code(double x, double y, double z) {
return (x * y) / 2.0;
}
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) / 2.0d0
end function
public static double code(double x, double y, double z) {
return (x * y) / 2.0;
}
def code(x, y, z): return (x * y) / 2.0
function code(x, y, z) return Float64(Float64(x * y) / 2.0) end
function tmp = code(x, y, z) tmp = (x * y) / 2.0; end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y}{2}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites53.9%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * 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 * y
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites53.9%
Taylor expanded in x around 0
Applied rewrites20.5%
herbie shell --seed 2024321
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, D"
:precision binary64
:pre (TRUE)
(- (/ (* x y) 2.0) (/ z 8.0)))