
(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 7 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.2%
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
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.65e+159) (* x (- y)) (if (<= x -1.56e-108) (* x z) (if (<= x 0.0021) (fma y x y) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.65e+159) {
tmp = x * -y;
} else if (x <= -1.56e-108) {
tmp = x * z;
} else if (x <= 0.0021) {
tmp = fma(y, x, y);
} else {
tmp = x * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.65e+159) tmp = Float64(x * Float64(-y)); elseif (x <= -1.56e-108) tmp = Float64(x * z); elseif (x <= 0.0021) tmp = fma(y, x, y); else tmp = Float64(x * z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.65e+159], N[(x * (-y)), $MachinePrecision], If[LessEqual[x, -1.56e-108], N[(x * z), $MachinePrecision], If[LessEqual[x, 0.0021], N[(y * x + y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{+159}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{elif}\;x \leq -1.56 \cdot 10^{-108}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 0.0021:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.6499999999999999e159Initial program 90.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
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6499.9
Simplified99.9%
Taylor expanded in z around 0
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6458.7
Simplified58.7%
if -1.6499999999999999e159 < x < -1.56000000000000009e-108 or 0.00209999999999999987 < x Initial program 95.9%
Taylor expanded in y around 0
lower-*.f6469.7
Simplified69.7%
if -1.56000000000000009e-108 < x < 0.00209999999999999987Initial program 100.0%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6470.7
Simplified70.7%
*-commutativeN/A
cancel-sign-sub-invN/A
lift-neg.f64N/A
distribute-rgt1-inN/A
distribute-lft1-inN/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6470.7
Applied egg-rr70.7%
neg-sub0N/A
flip3--N/A
metadata-evalN/A
+-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
+-lft-identityN/A
metadata-evalN/A
sub0-negN/A
cube-negN/A
lift-neg.f64N/A
sqr-powN/A
pow-prod-downN/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
pow2N/A
pow-divN/A
metadata-evalN/A
unpow169.9
Applied egg-rr69.9%
Final simplification68.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- z y)))) (if (<= x -1.56e-108) t_0 (if (<= x 3350000.0) (fma (- y) x y) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (z - y);
double tmp;
if (x <= -1.56e-108) {
tmp = t_0;
} else if (x <= 3350000.0) {
tmp = fma(-y, x, y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * Float64(z - y)) tmp = 0.0 if (x <= -1.56e-108) tmp = t_0; elseif (x <= 3350000.0) tmp = fma(Float64(-y), x, y); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.56e-108], t$95$0, If[LessEqual[x, 3350000.0], N[((-y) * x + y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z - y\right)\\
\mathbf{if}\;x \leq -1.56 \cdot 10^{-108}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3350000:\\
\;\;\;\;\mathsf{fma}\left(-y, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.56000000000000009e-108 or 3.35e6 < x Initial program 94.5%
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
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6495.7
Simplified95.7%
if -1.56000000000000009e-108 < x < 3.35e6Initial program 100.0%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6471.3
Simplified71.3%
*-commutativeN/A
cancel-sign-sub-invN/A
lift-neg.f64N/A
distribute-rgt1-inN/A
distribute-lft1-inN/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6471.4
Applied egg-rr71.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- z y)))) (if (<= x -1.56e-108) t_0 (if (<= x 3350000.0) (- y (* x y)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (z - y);
double tmp;
if (x <= -1.56e-108) {
tmp = t_0;
} else if (x <= 3350000.0) {
tmp = y - (x * 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 = x * (z - y)
if (x <= (-1.56d-108)) then
tmp = t_0
else if (x <= 3350000.0d0) then
tmp = y - (x * y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (z - y);
double tmp;
if (x <= -1.56e-108) {
tmp = t_0;
} else if (x <= 3350000.0) {
tmp = y - (x * y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z - y) tmp = 0 if x <= -1.56e-108: tmp = t_0 elif x <= 3350000.0: tmp = y - (x * y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z - y)) tmp = 0.0 if (x <= -1.56e-108) tmp = t_0; elseif (x <= 3350000.0) tmp = Float64(y - Float64(x * y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (z - y); tmp = 0.0; if (x <= -1.56e-108) tmp = t_0; elseif (x <= 3350000.0) tmp = y - (x * y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.56e-108], t$95$0, If[LessEqual[x, 3350000.0], N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z - y\right)\\
\mathbf{if}\;x \leq -1.56 \cdot 10^{-108}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3350000:\\
\;\;\;\;y - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.56000000000000009e-108 or 3.35e6 < x Initial program 94.5%
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
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6495.7
Simplified95.7%
if -1.56000000000000009e-108 < x < 3.35e6Initial program 100.0%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6471.3
Simplified71.3%
Final simplification83.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- z y)))) (if (<= x -1.56e-108) t_0 (if (<= x 0.0021) (fma y x y) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (z - y);
double tmp;
if (x <= -1.56e-108) {
tmp = t_0;
} else if (x <= 0.0021) {
tmp = fma(y, x, y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * Float64(z - y)) tmp = 0.0 if (x <= -1.56e-108) tmp = t_0; elseif (x <= 0.0021) tmp = fma(y, x, y); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.56e-108], t$95$0, If[LessEqual[x, 0.0021], N[(y * x + y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z - y\right)\\
\mathbf{if}\;x \leq -1.56 \cdot 10^{-108}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.0021:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.56000000000000009e-108 or 0.00209999999999999987 < x Initial program 94.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
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6494.6
Simplified94.6%
if -1.56000000000000009e-108 < x < 0.00209999999999999987Initial program 100.0%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6470.7
Simplified70.7%
*-commutativeN/A
cancel-sign-sub-invN/A
lift-neg.f64N/A
distribute-rgt1-inN/A
distribute-lft1-inN/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6470.7
Applied egg-rr70.7%
neg-sub0N/A
flip3--N/A
metadata-evalN/A
+-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
+-lft-identityN/A
metadata-evalN/A
sub0-negN/A
cube-negN/A
lift-neg.f64N/A
sqr-powN/A
pow-prod-downN/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
pow2N/A
pow-divN/A
metadata-evalN/A
unpow169.9
Applied egg-rr69.9%
(FPCore (x y z) :precision binary64 (if (<= x -1.56e-108) (* x z) (if (<= x 0.0021) (fma y x y) (* x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.56e-108) {
tmp = x * z;
} else if (x <= 0.0021) {
tmp = fma(y, x, y);
} else {
tmp = x * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.56e-108) tmp = Float64(x * z); elseif (x <= 0.0021) tmp = fma(y, x, y); else tmp = Float64(x * z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.56e-108], N[(x * z), $MachinePrecision], If[LessEqual[x, 0.0021], N[(y * x + y), $MachinePrecision], N[(x * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.56 \cdot 10^{-108}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 0.0021:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.56000000000000009e-108 or 0.00209999999999999987 < x Initial program 94.6%
Taylor expanded in y around 0
lower-*.f6463.8
Simplified63.8%
if -1.56000000000000009e-108 < x < 0.00209999999999999987Initial program 100.0%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6470.7
Simplified70.7%
*-commutativeN/A
cancel-sign-sub-invN/A
lift-neg.f64N/A
distribute-rgt1-inN/A
distribute-lft1-inN/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6470.7
Applied egg-rr70.7%
neg-sub0N/A
flip3--N/A
metadata-evalN/A
+-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
+-lft-identityN/A
metadata-evalN/A
sub0-negN/A
cube-negN/A
lift-neg.f64N/A
sqr-powN/A
pow-prod-downN/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
pow2N/A
pow-divN/A
metadata-evalN/A
unpow169.9
Applied egg-rr69.9%
(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.2%
Taylor expanded in y around 0
lower-*.f6448.2
Simplified48.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 2024207
(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)))