
(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 6 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 x (- z y) y))
double code(double x, double y, double z) {
return fma(x, (z - y), y);
}
function code(x, y, z) return fma(x, Float64(z - y), y) end
code[x_, y_, z_] := N[(x * N[(z - y), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, z - y, y\right)
\end{array}
Initial program 97.6%
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
distribute-rgt-neg-inN/A
lower-fma.f64N/A
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= y -4.8e-104) (fma (- y) x y) (if (<= y 1.1e+45) (* x (- z y)) (- y (* x y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.8e-104) {
tmp = fma(-y, x, y);
} else if (y <= 1.1e+45) {
tmp = x * (z - y);
} else {
tmp = y - (x * y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -4.8e-104) tmp = fma(Float64(-y), x, y); elseif (y <= 1.1e+45) tmp = Float64(x * Float64(z - y)); else tmp = Float64(y - Float64(x * y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -4.8e-104], N[((-y) * x + y), $MachinePrecision], If[LessEqual[y, 1.1e+45], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{-104}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, y\right)\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{+45}:\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y - x \cdot y\\
\end{array}
\end{array}
if y < -4.8000000000000001e-104Initial program 95.9%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6485.8
Applied rewrites85.8%
Applied rewrites85.8%
if -4.8000000000000001e-104 < y < 1.1e45Initial program 100.0%
Taylor expanded in x around inf
+-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
unsub-negN/A
mul-1-negN/A
remove-double-negN/A
lower--.f6482.0
Applied rewrites82.0%
if 1.1e45 < y Initial program 94.3%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6494.1
Applied rewrites94.1%
Final simplification85.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- y (* x y)))) (if (<= y -4.8e-104) t_0 (if (<= y 1.1e+45) (* x (- z y)) t_0))))
double code(double x, double y, double z) {
double t_0 = y - (x * y);
double tmp;
if (y <= -4.8e-104) {
tmp = t_0;
} else if (y <= 1.1e+45) {
tmp = x * (z - y);
} 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 - (x * y)
if (y <= (-4.8d-104)) then
tmp = t_0
else if (y <= 1.1d+45) then
tmp = x * (z - y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y - (x * y);
double tmp;
if (y <= -4.8e-104) {
tmp = t_0;
} else if (y <= 1.1e+45) {
tmp = x * (z - y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y - (x * y) tmp = 0 if y <= -4.8e-104: tmp = t_0 elif y <= 1.1e+45: tmp = x * (z - y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y - Float64(x * y)) tmp = 0.0 if (y <= -4.8e-104) tmp = t_0; elseif (y <= 1.1e+45) tmp = Float64(x * Float64(z - y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y - (x * y); tmp = 0.0; if (y <= -4.8e-104) tmp = t_0; elseif (y <= 1.1e+45) tmp = x * (z - y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.8e-104], t$95$0, If[LessEqual[y, 1.1e+45], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y - x \cdot y\\
\mathbf{if}\;y \leq -4.8 \cdot 10^{-104}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{+45}:\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -4.8000000000000001e-104 or 1.1e45 < y Initial program 95.3%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6489.2
Applied rewrites89.2%
if -4.8000000000000001e-104 < y < 1.1e45Initial program 100.0%
Taylor expanded in x around inf
+-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
unsub-negN/A
mul-1-negN/A
remove-double-negN/A
lower--.f6482.0
Applied rewrites82.0%
Final simplification85.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- y)))) (if (<= y -2.9e+38) t_0 (if (<= y 88.0) (* x z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (y <= -2.9e+38) {
tmp = t_0;
} else if (y <= 88.0) {
tmp = x * z;
} 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
if (y <= (-2.9d+38)) then
tmp = t_0
else if (y <= 88.0d0) then
tmp = x * z
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;
double tmp;
if (y <= -2.9e+38) {
tmp = t_0;
} else if (y <= 88.0) {
tmp = x * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -y tmp = 0 if y <= -2.9e+38: tmp = t_0 elif y <= 88.0: tmp = x * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-y)) tmp = 0.0 if (y <= -2.9e+38) tmp = t_0; elseif (y <= 88.0) tmp = Float64(x * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -y; tmp = 0.0; if (y <= -2.9e+38) tmp = t_0; elseif (y <= 88.0) tmp = x * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[y, -2.9e+38], t$95$0, If[LessEqual[y, 88.0], N[(x * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -2.9 \cdot 10^{+38}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 88:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.90000000000000007e38 or 88 < y Initial program 94.8%
Taylor expanded in x around inf
+-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
unsub-negN/A
mul-1-negN/A
remove-double-negN/A
lower--.f6450.4
Applied rewrites50.4%
Taylor expanded in z around 0
Applied rewrites41.8%
if -2.90000000000000007e38 < y < 88Initial program 100.0%
Taylor expanded in y around 0
lower-*.f6468.6
Applied rewrites68.6%
(FPCore (x y z) :precision binary64 (* x (- z y)))
double code(double x, double y, double z) {
return x * (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 = x * (z - y)
end function
public static double code(double x, double y, double z) {
return x * (z - y);
}
def code(x, y, z): return x * (z - y)
function code(x, y, z) return Float64(x * Float64(z - y)) end
function tmp = code(x, y, z) tmp = x * (z - y); end
code[x_, y_, z_] := N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z - y\right)
\end{array}
Initial program 97.6%
Taylor expanded in x around inf
+-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
unsub-negN/A
mul-1-negN/A
remove-double-negN/A
lower--.f6465.4
Applied rewrites65.4%
(FPCore (x y z) :precision binary64 (* x z))
double code(double x, double y, double z) {
return 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 = x * z
end function
public static double code(double x, double y, double z) {
return x * z;
}
def code(x, y, z): return x * z
function code(x, y, z) return Float64(x * z) end
function tmp = code(x, y, z) tmp = x * z; end
code[x_, y_, z_] := N[(x * z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot z
\end{array}
Initial program 97.6%
Taylor expanded in y around 0
lower-*.f6443.5
Applied rewrites43.5%
(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 2024238
(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)))