
(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 4 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.4%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
associate-+r+N/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
distribute-lft-out--N/A
unsub-negN/A
mul-1-negN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z y) x))) (if (<= x -0.32) t_0 (if (<= x 2.7e-14) (fma (- y) x y) t_0))))
double code(double x, double y, double z) {
double t_0 = (z - y) * x;
double tmp;
if (x <= -0.32) {
tmp = t_0;
} else if (x <= 2.7e-14) {
tmp = fma(-y, x, y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(z - y) * x) tmp = 0.0 if (x <= -0.32) tmp = t_0; elseif (x <= 2.7e-14) tmp = fma(Float64(-y), x, y); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z - y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -0.32], t$95$0, If[LessEqual[x, 2.7e-14], N[((-y) * x + y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z - y\right) \cdot x\\
\mathbf{if}\;x \leq -0.32:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.7 \cdot 10^{-14}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -0.320000000000000007 or 2.6999999999999999e-14 < x Initial program 97.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6499.1
Applied rewrites99.1%
if -0.320000000000000007 < x < 2.6999999999999999e-14Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
associate-+r+N/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
distribute-lft-out--N/A
unsub-negN/A
mul-1-negN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites100.0%
Taylor expanded in y around inf
Applied rewrites72.7%
(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.4%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6466.0
Applied rewrites66.0%
(FPCore (x y z) :precision binary64 (* (- y) x))
double code(double x, double y, double z) {
return -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 * x
end function
public static double code(double x, double y, double z) {
return -y * x;
}
def code(x, y, z): return -y * x
function code(x, y, z) return Float64(Float64(-y) * x) end
function tmp = code(x, y, z) tmp = -y * x; end
code[x_, y_, z_] := N[((-y) * x), $MachinePrecision]
\begin{array}{l}
\\
\left(-y\right) \cdot x
\end{array}
Initial program 98.4%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6466.0
Applied rewrites66.0%
Taylor expanded in y around inf
Applied rewrites26.0%
(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 2024332
(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)))