
(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 5 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 (fma (- z) y x))
double code(double x, double y, double z) {
return fma(-z, y, x);
}
function code(x, y, z) return fma(Float64(-z), y, x) end
code[x_, y_, z_] := N[((-z) * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-z, y, x\right)
\end{array}
Initial program 100.0%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (or (<= (* y z) -5e+90) (not (<= (* y z) 50.0))) (* (- y) z) (fma z y x)))
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -5e+90) || !((y * z) <= 50.0)) {
tmp = -y * z;
} else {
tmp = fma(z, y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -5e+90) || !(Float64(y * z) <= 50.0)) tmp = Float64(Float64(-y) * z); else tmp = fma(z, y, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -5e+90], N[Not[LessEqual[N[(y * z), $MachinePrecision], 50.0]], $MachinePrecision]], N[((-y) * z), $MachinePrecision], N[(z * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+90} \lor \neg \left(y \cdot z \leq 50\right):\\
\;\;\;\;\left(-y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -5.0000000000000004e90 or 50 < (*.f64 y z) Initial program 100.0%
Taylor expanded in x around 0
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6480.3
Applied rewrites80.3%
if -5.0000000000000004e90 < (*.f64 y z) < 50Initial program 100.0%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
lift-fma.f64N/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
rem-sqrt-square-revN/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
*-commutativeN/A
neg-fabsN/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
*-commutativeN/A
lower-fma.f6476.3
Applied rewrites76.3%
Final simplification78.0%
(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 (fma z y x))
double code(double x, double y, double z) {
return fma(z, y, x);
}
function code(x, y, z) return fma(z, y, x) end
code[x_, y_, z_] := N[(z * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y, x\right)
\end{array}
Initial program 100.0%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
lift-fma.f64N/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
rem-sqrt-square-revN/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
*-commutativeN/A
neg-fabsN/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
*-commutativeN/A
lower-fma.f6452.7
Applied rewrites52.7%
(FPCore (x y z) :precision binary64 (* z y))
double code(double x, double y, double z) {
return 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 = z * y
end function
public static double code(double x, double y, double z) {
return z * y;
}
def code(x, y, z): return z * y
function code(x, y, z) return Float64(z * y) end
function tmp = code(x, y, z) tmp = z * y; end
code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6447.3
Applied rewrites47.3%
Applied rewrites2.3%
(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 2024332
(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)))