
(FPCore (x y z) :precision binary64 (+ (* (- 1.0 x) y) (* x z)))
double code(double x, double y, double z) {
return ((1.0 - x) * y) + (x * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((1.0d0 - x) * y) + (x * z)
end function
public static double code(double x, double y, double z) {
return ((1.0 - x) * y) + (x * z);
}
def code(x, y, z): return ((1.0 - x) * y) + (x * z)
function code(x, y, z) return Float64(Float64(Float64(1.0 - x) * y) + Float64(x * z)) end
function tmp = code(x, y, z) tmp = ((1.0 - x) * y) + (x * z); end
code[x_, y_, z_] := N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) \cdot y + x \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* (- 1.0 x) y) (* x z)))
double code(double x, double y, double z) {
return ((1.0 - x) * y) + (x * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((1.0d0 - x) * y) + (x * z)
end function
public static double code(double x, double y, double z) {
return ((1.0 - x) * y) + (x * z);
}
def code(x, y, z): return ((1.0 - x) * y) + (x * z)
function code(x, y, z) return Float64(Float64(Float64(1.0 - x) * y) + Float64(x * z)) end
function tmp = code(x, y, z) tmp = ((1.0 - x) * y) + (x * z); end
code[x_, y_, z_] := N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) \cdot y + x \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (- z y) x y))
double code(double x, double y, double z) {
return fma((z - y), x, y);
}
function code(x, y, z) return fma(Float64(z - y), x, y) end
code[x_, y_, z_] := N[(N[(z - y), $MachinePrecision] * x + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z - y, x, y\right)
\end{array}
Initial program 98.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.4e-186) (not (<= x 1.05e-37))) (* (- z y) x) (fma (- y) x y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.4e-186) || !(x <= 1.05e-37)) {
tmp = (z - y) * x;
} else {
tmp = fma(-y, x, y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -2.4e-186) || !(x <= 1.05e-37)) tmp = Float64(Float64(z - y) * x); else tmp = fma(Float64(-y), x, y); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.4e-186], N[Not[LessEqual[x, 1.05e-37]], $MachinePrecision]], N[(N[(z - y), $MachinePrecision] * x), $MachinePrecision], N[((-y) * x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{-186} \lor \neg \left(x \leq 1.05 \cdot 10^{-37}\right):\\
\;\;\;\;\left(z - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, y\right)\\
\end{array}
\end{array}
if x < -2.40000000000000003e-186 or 1.05e-37 < x Initial program 97.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6491.8
Applied rewrites91.8%
if -2.40000000000000003e-186 < x < 1.05e-37Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
Applied rewrites87.2%
Final simplification90.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -3e-54) (not (<= y 2.12e-16))) (* (- y) x) (* z x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3e-54) || !(y <= 2.12e-16)) {
tmp = -y * x;
} else {
tmp = z * 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 <= (-3d-54)) .or. (.not. (y <= 2.12d-16))) then
tmp = -y * x
else
tmp = z * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3e-54) || !(y <= 2.12e-16)) {
tmp = -y * x;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3e-54) or not (y <= 2.12e-16): tmp = -y * x else: tmp = z * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3e-54) || !(y <= 2.12e-16)) tmp = Float64(Float64(-y) * x); else tmp = Float64(z * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3e-54) || ~((y <= 2.12e-16))) tmp = -y * x; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3e-54], N[Not[LessEqual[y, 2.12e-16]], $MachinePrecision]], N[((-y) * x), $MachinePrecision], N[(z * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{-54} \lor \neg \left(y \leq 2.12 \cdot 10^{-16}\right):\\
\;\;\;\;\left(-y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if y < -3.00000000000000009e-54 or 2.1199999999999999e-16 < y Initial program 96.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6457.0
Applied rewrites57.0%
Taylor expanded in y around inf
Applied rewrites48.0%
if -3.00000000000000009e-54 < y < 2.1199999999999999e-16Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6481.8
Applied rewrites81.8%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f6473.7
Applied rewrites73.7%
Final simplification58.5%
(FPCore (x y z) :precision binary64 (* (- z y) x))
double code(double x, double y, double z) {
return (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 = (z - y) * x
end function
public static double code(double x, double y, double z) {
return (z - y) * x;
}
def code(x, y, z): return (z - y) * x
function code(x, y, z) return Float64(Float64(z - y) * x) end
function tmp = code(x, y, z) tmp = (z - y) * x; end
code[x_, y_, z_] := N[(N[(z - y), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(z - y\right) \cdot x
\end{array}
Initial program 98.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6467.2
Applied rewrites67.2%
(FPCore (x y z) :precision binary64 (* z x))
double code(double x, double y, double z) {
return z * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * x
end function
public static double code(double x, double y, double z) {
return z * x;
}
def code(x, y, z): return z * x
function code(x, y, z) return Float64(z * x) end
function tmp = code(x, y, z) tmp = z * x; end
code[x_, y_, z_] := N[(z * x), $MachinePrecision]
\begin{array}{l}
\\
z \cdot x
\end{array}
Initial program 98.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6467.2
Applied rewrites67.2%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f6439.2
Applied rewrites39.2%
(FPCore (x y z) :precision binary64 (- y (* x (- y z))))
double code(double x, double y, double z) {
return y - (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 = y - (x * (y - z))
end function
public static double code(double x, double y, double z) {
return y - (x * (y - z));
}
def code(x, y, z): return y - (x * (y - z))
function code(x, y, z) return Float64(y - Float64(x * Float64(y - z))) end
function tmp = code(x, y, z) tmp = y - (x * (y - z)); end
code[x_, y_, z_] := N[(y - N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y - x \cdot \left(y - z\right)
\end{array}
herbie shell --seed 2024327
(FPCore (x y z)
:name "Diagrams.Color.HSV:lerp from diagrams-contrib-1.3.0.5"
:precision binary64
:alt
(! :herbie-platform default (- y (* x (- y z))))
(+ (* (- 1.0 x) y) (* x z)))