
(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 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
accelerator-lowering-fma.f64N/A
Simplified100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (- 0.0 x) y y))) (if (<= y -5.2e-69) t_0 (if (<= y 75000000000.0) (fma z x y) t_0))))
double code(double x, double y, double z) {
double t_0 = fma((0.0 - x), y, y);
double tmp;
if (y <= -5.2e-69) {
tmp = t_0;
} else if (y <= 75000000000.0) {
tmp = fma(z, x, y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(Float64(0.0 - x), y, y) tmp = 0.0 if (y <= -5.2e-69) tmp = t_0; elseif (y <= 75000000000.0) tmp = fma(z, x, y); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(0.0 - x), $MachinePrecision] * y + y), $MachinePrecision]}, If[LessEqual[y, -5.2e-69], t$95$0, If[LessEqual[y, 75000000000.0], N[(z * x + y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(0 - x, y, y\right)\\
\mathbf{if}\;y \leq -5.2 \cdot 10^{-69}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 75000000000:\\
\;\;\;\;\mathsf{fma}\left(z, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -5.2000000000000004e-69 or 7.5e10 < y Initial program 95.8%
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
accelerator-lowering-fma.f64N/A
Simplified100.0%
sub-negN/A
distribute-lft-inN/A
associate-+l+N/A
*-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f6497.2
Applied egg-rr97.2%
associate-+r+N/A
+-commutativeN/A
associate-+r+N/A
sub0-negN/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
accelerator-lowering-fma.f64N/A
neg-lowering-neg.f64N/A
accelerator-lowering-fma.f6498.6
Applied egg-rr98.6%
Taylor expanded in z around 0
Simplified87.6%
if -5.2000000000000004e-69 < y < 7.5e10Initial program 100.0%
Taylor expanded in x around 0
Simplified88.7%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6488.7
Applied egg-rr88.7%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (<= x -2.4e-30) (* x z) (if (<= x 4.4e-58) y (* x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e-30) {
tmp = x * z;
} else if (x <= 4.4e-58) {
tmp = y;
} else {
tmp = x * z;
}
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 (x <= (-2.4d-30)) then
tmp = x * z
else if (x <= 4.4d-58) then
tmp = y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e-30) {
tmp = x * z;
} else if (x <= 4.4e-58) {
tmp = y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.4e-30: tmp = x * z elif x <= 4.4e-58: tmp = y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.4e-30) tmp = Float64(x * z); elseif (x <= 4.4e-58) tmp = y; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.4e-30) tmp = x * z; elseif (x <= 4.4e-58) tmp = y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.4e-30], N[(x * z), $MachinePrecision], If[LessEqual[x, 4.4e-58], y, N[(x * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{-30}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 4.4 \cdot 10^{-58}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -2.39999999999999985e-30 or 4.40000000000000011e-58 < x Initial program 96.0%
Taylor expanded in y around 0
+-rgt-identityN/A
accelerator-lowering-fma.f6451.9
Simplified51.9%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6451.9
Applied egg-rr51.9%
if -2.39999999999999985e-30 < x < 4.40000000000000011e-58Initial program 100.0%
Taylor expanded in x around 0
Simplified80.9%
Final simplification63.9%
(FPCore (x y z) :precision binary64 (fma z x y))
double code(double x, double y, double z) {
return fma(z, x, y);
}
function code(x, y, z) return fma(z, x, y) end
code[x_, y_, z_] := N[(z * x + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, x, y\right)
\end{array}
Initial program 97.6%
Taylor expanded in x around 0
Simplified74.3%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6474.3
Applied egg-rr74.3%
(FPCore (x y z) :precision binary64 y)
double code(double x, double y, double z) {
return y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y
end function
public static double code(double x, double y, double z) {
return y;
}
def code(x, y, z): return y
function code(x, y, z) return y end
function tmp = code(x, y, z) tmp = y; end
code[x_, y_, z_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 97.6%
Taylor expanded in x around 0
Simplified37.1%
(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 2024196
(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)))