
(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 (- 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%
*-commutativeN/A
cancel-sign-subN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
cancel-sign-sub-invN/A
*-commutativeN/A
sub-negN/A
distribute-lft-inN/A
*-rgt-identityN/A
associate-+r+N/A
distribute-rgt-inN/A
sub-negN/A
distribute-lft-neg-inN/A
+-commutativeN/A
*-commutativeN/A
distribute-lft-neg-inN/A
fma-defineN/A
fma-lowering-fma.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f64100.0%
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z y) x))) (if (<= x -430000000000.0) t_0 (if (<= x 1.6e-6) (+ y (* z x)) t_0))))
double code(double x, double y, double z) {
double t_0 = (z - y) * x;
double tmp;
if (x <= -430000000000.0) {
tmp = t_0;
} else if (x <= 1.6e-6) {
tmp = y + (z * x);
} 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 = (z - y) * x
if (x <= (-430000000000.0d0)) then
tmp = t_0
else if (x <= 1.6d-6) then
tmp = y + (z * x)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (z - y) * x;
double tmp;
if (x <= -430000000000.0) {
tmp = t_0;
} else if (x <= 1.6e-6) {
tmp = y + (z * x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (z - y) * x tmp = 0 if x <= -430000000000.0: tmp = t_0 elif x <= 1.6e-6: tmp = y + (z * x) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(z - y) * x) tmp = 0.0 if (x <= -430000000000.0) tmp = t_0; elseif (x <= 1.6e-6) tmp = Float64(y + Float64(z * x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z - y) * x; tmp = 0.0; if (x <= -430000000000.0) tmp = t_0; elseif (x <= 1.6e-6) tmp = y + (z * x); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z - y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -430000000000.0], t$95$0, If[LessEqual[x, 1.6e-6], N[(y + N[(z * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z - y\right) \cdot x\\
\mathbf{if}\;x \leq -430000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{-6}:\\
\;\;\;\;y + z \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -4.3e11 or 1.5999999999999999e-6 < x Initial program 96.1%
Taylor expanded in x around inf
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
distribute-lft-out--N/A
unsub-negN/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
--lowering--.f6499.8%
Simplified99.8%
if -4.3e11 < x < 1.5999999999999999e-6Initial program 100.0%
Taylor expanded in x around 0
Simplified98.3%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z y) x))) (if (<= x -1.8) t_0 (if (<= x 1e-18) (* y (- 1.0 x)) t_0))))
double code(double x, double y, double z) {
double t_0 = (z - y) * x;
double tmp;
if (x <= -1.8) {
tmp = t_0;
} else if (x <= 1e-18) {
tmp = y * (1.0 - x);
} 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 = (z - y) * x
if (x <= (-1.8d0)) then
tmp = t_0
else if (x <= 1d-18) then
tmp = y * (1.0d0 - x)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (z - y) * x;
double tmp;
if (x <= -1.8) {
tmp = t_0;
} else if (x <= 1e-18) {
tmp = y * (1.0 - x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (z - y) * x tmp = 0 if x <= -1.8: tmp = t_0 elif x <= 1e-18: tmp = y * (1.0 - x) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(z - y) * x) tmp = 0.0 if (x <= -1.8) tmp = t_0; elseif (x <= 1e-18) tmp = Float64(y * Float64(1.0 - x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z - y) * x; tmp = 0.0; if (x <= -1.8) tmp = t_0; elseif (x <= 1e-18) tmp = y * (1.0 - x); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z - y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1.8], t$95$0, If[LessEqual[x, 1e-18], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z - y\right) \cdot x\\
\mathbf{if}\;x \leq -1.8:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 10^{-18}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.80000000000000004 or 1.0000000000000001e-18 < x Initial program 96.3%
Taylor expanded in x around inf
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
distribute-lft-out--N/A
unsub-negN/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
--lowering--.f6498.4%
Simplified98.4%
if -1.80000000000000004 < x < 1.0000000000000001e-18Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
--lowering--.f6475.3%
Simplified75.3%
Final simplification87.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z y) x))) (if (<= x -5.5e-22) t_0 (if (<= x 7.6e-18) y t_0))))
double code(double x, double y, double z) {
double t_0 = (z - y) * x;
double tmp;
if (x <= -5.5e-22) {
tmp = t_0;
} else if (x <= 7.6e-18) {
tmp = 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 = (z - y) * x
if (x <= (-5.5d-22)) then
tmp = t_0
else if (x <= 7.6d-18) then
tmp = y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (z - y) * x;
double tmp;
if (x <= -5.5e-22) {
tmp = t_0;
} else if (x <= 7.6e-18) {
tmp = y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (z - y) * x tmp = 0 if x <= -5.5e-22: tmp = t_0 elif x <= 7.6e-18: tmp = y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(z - y) * x) tmp = 0.0 if (x <= -5.5e-22) tmp = t_0; elseif (x <= 7.6e-18) tmp = y; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z - y) * x; tmp = 0.0; if (x <= -5.5e-22) tmp = t_0; elseif (x <= 7.6e-18) tmp = y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z - y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -5.5e-22], t$95$0, If[LessEqual[x, 7.6e-18], y, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z - y\right) \cdot x\\
\mathbf{if}\;x \leq -5.5 \cdot 10^{-22}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 7.6 \cdot 10^{-18}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -5.5000000000000001e-22 or 7.5999999999999996e-18 < x Initial program 96.4%
Taylor expanded in x around inf
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
distribute-lft-out--N/A
unsub-negN/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
--lowering--.f6496.6%
Simplified96.6%
if -5.5000000000000001e-22 < x < 7.5999999999999996e-18Initial program 100.0%
Taylor expanded in x around 0
Simplified75.9%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (if (<= x -5.5e-22) (* z x) (if (<= x 6.8e-20) y (* z x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.5e-22) {
tmp = z * x;
} else if (x <= 6.8e-20) {
tmp = y;
} 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 (x <= (-5.5d-22)) then
tmp = z * x
else if (x <= 6.8d-20) then
tmp = y
else
tmp = z * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.5e-22) {
tmp = z * x;
} else if (x <= 6.8e-20) {
tmp = y;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.5e-22: tmp = z * x elif x <= 6.8e-20: tmp = y else: tmp = z * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.5e-22) tmp = Float64(z * x); elseif (x <= 6.8e-20) tmp = y; else tmp = Float64(z * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.5e-22) tmp = z * x; elseif (x <= 6.8e-20) tmp = y; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.5e-22], N[(z * x), $MachinePrecision], If[LessEqual[x, 6.8e-20], y, N[(z * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{-22}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq 6.8 \cdot 10^{-20}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if x < -5.5000000000000001e-22 or 6.7999999999999994e-20 < x Initial program 96.4%
Taylor expanded in y around 0
*-lowering-*.f6449.5%
Simplified49.5%
if -5.5000000000000001e-22 < x < 6.7999999999999994e-20Initial program 100.0%
Taylor expanded in x around 0
Simplified75.9%
Final simplification61.4%
(FPCore (x y z) :precision binary64 (+ y (* (- z y) x)))
double code(double x, double y, double z) {
return y + ((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 = y + ((z - y) * x)
end function
public static double code(double x, double y, double z) {
return y + ((z - y) * x);
}
def code(x, y, z): return y + ((z - y) * x)
function code(x, y, z) return Float64(y + Float64(Float64(z - y) * x)) end
function tmp = code(x, y, z) tmp = y + ((z - y) * x); end
code[x_, y_, z_] := N[(y + N[(N[(z - y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + \left(z - y\right) \cdot x
\end{array}
Initial program 98.0%
*-commutativeN/A
distribute-rgt-out--N/A
*-lft-identityN/A
associate-+l-N/A
--lowering--.f64N/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Final simplification100.0%
(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 98.0%
Taylor expanded in x around 0
Simplified36.9%
(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 2024164
(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)))