
(FPCore (x y z) :precision binary64 (- x (* y z)))
double code(double x, double y, double z) {
return x - (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 * z)
end function
public static double code(double x, double y, double z) {
return x - (y * z);
}
def code(x, y, z): return x - (y * z)
function code(x, y, z) return Float64(x - Float64(y * z)) end
function tmp = code(x, y, z) tmp = x - (y * z); end
code[x_, y_, z_] := N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - y \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- x (* y z)))
double code(double x, double y, double z) {
return x - (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 * z)
end function
public static double code(double x, double y, double z) {
return x - (y * z);
}
def code(x, y, z): return x - (y * z)
function code(x, y, z) return Float64(x - Float64(y * z)) end
function tmp = code(x, y, z) tmp = x - (y * z); end
code[x_, y_, z_] := N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - y \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (- x (* y z)))
double code(double x, double y, double z) {
return x - (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 * z)
end function
public static double code(double x, double y, double z) {
return x - (y * z);
}
def code(x, y, z): return x - (y * z)
function code(x, y, z) return Float64(x - Float64(y * z)) end
function tmp = code(x, y, z) tmp = x - (y * z); end
code[x_, y_, z_] := N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - y \cdot z
\end{array}
Initial program 100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- 0.0 z)))) (if (<= (* y z) -2.05e+65) t_0 (if (<= (* y z) 5e-38) x t_0))))
double code(double x, double y, double z) {
double t_0 = y * (0.0 - z);
double tmp;
if ((y * z) <= -2.05e+65) {
tmp = t_0;
} else if ((y * z) <= 5e-38) {
tmp = x;
} 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 = y * (0.0d0 - z)
if ((y * z) <= (-2.05d+65)) then
tmp = t_0
else if ((y * z) <= 5d-38) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (0.0 - z);
double tmp;
if ((y * z) <= -2.05e+65) {
tmp = t_0;
} else if ((y * z) <= 5e-38) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (0.0 - z) tmp = 0 if (y * z) <= -2.05e+65: tmp = t_0 elif (y * z) <= 5e-38: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(0.0 - z)) tmp = 0.0 if (Float64(y * z) <= -2.05e+65) tmp = t_0; elseif (Float64(y * z) <= 5e-38) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (0.0 - z); tmp = 0.0; if ((y * z) <= -2.05e+65) tmp = t_0; elseif ((y * z) <= 5e-38) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(0.0 - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y * z), $MachinePrecision], -2.05e+65], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 5e-38], x, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(0 - z\right)\\
\mathbf{if}\;y \cdot z \leq -2.05 \cdot 10^{+65}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq 5 \cdot 10^{-38}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -2.0500000000000001e65 or 5.00000000000000033e-38 < (*.f64 y z) Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
*-lowering-*.f6486.1%
Simplified86.1%
sub0-negN/A
neg-lowering-neg.f64N/A
*-lowering-*.f6486.1%
Applied egg-rr86.1%
if -2.0500000000000001e65 < (*.f64 y z) < 5.00000000000000033e-38Initial program 100.0%
Taylor expanded in x around inf
Simplified79.3%
Final simplification82.4%
(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 100.0%
Taylor expanded in x around inf
Simplified49.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ x (* y z)))) (/ t_0 (/ t_0 (- x (* y z))))))
double code(double x, double y, double z) {
double t_0 = x + (y * z);
return t_0 / (t_0 / (x - (y * z)));
}
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
t_0 = x + (y * z)
code = t_0 / (t_0 / (x - (y * z)))
end function
public static double code(double x, double y, double z) {
double t_0 = x + (y * z);
return t_0 / (t_0 / (x - (y * z)));
}
def code(x, y, z): t_0 = x + (y * z) return t_0 / (t_0 / (x - (y * z)))
function code(x, y, z) t_0 = Float64(x + Float64(y * z)) return Float64(t_0 / Float64(t_0 / Float64(x - Float64(y * z)))) end
function tmp = code(x, y, z) t_0 = x + (y * z); tmp = t_0 / (t_0 / (x - (y * z))); end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]}, N[(t$95$0 / N[(t$95$0 / N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + y \cdot z\\
\frac{t\_0}{\frac{t\_0}{x - y \cdot z}}
\end{array}
\end{array}
herbie shell --seed 2024150
(FPCore (x y z)
:name "Diagrams.Solve.Tridiagonal:solveTriDiagonal from diagrams-solve-0.1, C"
:precision binary64
:alt
(! :herbie-platform default (/ (+ x (* y z)) (/ (+ x (* y z)) (- x (* y z)))))
(- x (* y z)))