
(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 (- 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%
Taylor expanded in z around 0
+-commutativeN/A
distribute-rgt-out--N/A
unsub-negN/A
mul-1-negN/A
*-lft-identityN/A
+-commutativeN/A
+-commutativeN/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 (if (<= x -2e+136) (* x z) (if (<= x -1.0) (* (- y) x) (if (<= x 9.6e-58) (* 1.0 y) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2e+136) {
tmp = x * z;
} else if (x <= -1.0) {
tmp = -y * x;
} else if (x <= 9.6e-58) {
tmp = 1.0 * 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 <= (-2d+136)) then
tmp = x * z
else if (x <= (-1.0d0)) then
tmp = -y * x
else if (x <= 9.6d-58) then
tmp = 1.0d0 * 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 <= -2e+136) {
tmp = x * z;
} else if (x <= -1.0) {
tmp = -y * x;
} else if (x <= 9.6e-58) {
tmp = 1.0 * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2e+136: tmp = x * z elif x <= -1.0: tmp = -y * x elif x <= 9.6e-58: tmp = 1.0 * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2e+136) tmp = Float64(x * z); elseif (x <= -1.0) tmp = Float64(Float64(-y) * x); elseif (x <= 9.6e-58) tmp = Float64(1.0 * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2e+136) tmp = x * z; elseif (x <= -1.0) tmp = -y * x; elseif (x <= 9.6e-58) tmp = 1.0 * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2e+136], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.0], N[((-y) * x), $MachinePrecision], If[LessEqual[x, 9.6e-58], N[(1.0 * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+136}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1:\\
\;\;\;\;\left(-y\right) \cdot x\\
\mathbf{elif}\;x \leq 9.6 \cdot 10^{-58}:\\
\;\;\;\;1 \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -2.00000000000000012e136 or 9.6000000000000002e-58 < x Initial program 95.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6461.3
Applied rewrites61.3%
if -2.00000000000000012e136 < x < -1Initial program 100.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--.f6497.2
Applied rewrites97.2%
Taylor expanded in z around 0
Applied rewrites70.1%
if -1 < x < 9.6000000000000002e-58Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6475.5
Applied rewrites75.5%
Taylor expanded in x around 0
Applied rewrites75.4%
Final simplification68.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- z y)))) (if (<= x -9e-25) t_0 (if (<= x 3e-55) (* 1.0 y) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (z - y);
double tmp;
if (x <= -9e-25) {
tmp = t_0;
} else if (x <= 3e-55) {
tmp = 1.0 * 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 <= (-9d-25)) then
tmp = t_0
else if (x <= 3d-55) then
tmp = 1.0d0 * 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 <= -9e-25) {
tmp = t_0;
} else if (x <= 3e-55) {
tmp = 1.0 * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z - y) tmp = 0 if x <= -9e-25: tmp = t_0 elif x <= 3e-55: tmp = 1.0 * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z - y)) tmp = 0.0 if (x <= -9e-25) tmp = t_0; elseif (x <= 3e-55) tmp = Float64(1.0 * 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 <= -9e-25) tmp = t_0; elseif (x <= 3e-55) tmp = 1.0 * 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, -9e-25], t$95$0, If[LessEqual[x, 3e-55], N[(1.0 * y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z - y\right)\\
\mathbf{if}\;x \leq -9 \cdot 10^{-25}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3 \cdot 10^{-55}:\\
\;\;\;\;1 \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -9.0000000000000002e-25 or 3.00000000000000016e-55 < x Initial program 96.6%
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--.f6494.3
Applied rewrites94.3%
if -9.0000000000000002e-25 < x < 3.00000000000000016e-55Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6477.3
Applied rewrites77.3%
Taylor expanded in x around 0
Applied rewrites77.3%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (<= z -2.2e+185) (* x z) (if (<= z 2.2e+98) (* (- 1.0 x) y) (* x z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e+185) {
tmp = x * z;
} else if (z <= 2.2e+98) {
tmp = (1.0 - x) * 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 (z <= (-2.2d+185)) then
tmp = x * z
else if (z <= 2.2d+98) then
tmp = (1.0d0 - x) * y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e+185) {
tmp = x * z;
} else if (z <= 2.2e+98) {
tmp = (1.0 - x) * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.2e+185: tmp = x * z elif z <= 2.2e+98: tmp = (1.0 - x) * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.2e+185) tmp = Float64(x * z); elseif (z <= 2.2e+98) tmp = Float64(Float64(1.0 - x) * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.2e+185) tmp = x * z; elseif (z <= 2.2e+98) tmp = (1.0 - x) * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.2e+185], N[(x * z), $MachinePrecision], If[LessEqual[z, 2.2e+98], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{+185}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{+98}:\\
\;\;\;\;\left(1 - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -2.2000000000000001e185 or 2.20000000000000009e98 < z Initial program 95.2%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6481.6
Applied rewrites81.6%
if -2.2000000000000001e185 < z < 2.20000000000000009e98Initial program 99.4%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6478.4
Applied rewrites78.4%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (<= x -1.15e-24) (* x z) (if (<= x 9.6e-58) (* 1.0 y) (* x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.15e-24) {
tmp = x * z;
} else if (x <= 9.6e-58) {
tmp = 1.0 * 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 <= (-1.15d-24)) then
tmp = x * z
else if (x <= 9.6d-58) then
tmp = 1.0d0 * 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 <= -1.15e-24) {
tmp = x * z;
} else if (x <= 9.6e-58) {
tmp = 1.0 * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.15e-24: tmp = x * z elif x <= 9.6e-58: tmp = 1.0 * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.15e-24) tmp = Float64(x * z); elseif (x <= 9.6e-58) tmp = Float64(1.0 * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.15e-24) tmp = x * z; elseif (x <= 9.6e-58) tmp = 1.0 * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.15e-24], N[(x * z), $MachinePrecision], If[LessEqual[x, 9.6e-58], N[(1.0 * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{-24}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 9.6 \cdot 10^{-58}:\\
\;\;\;\;1 \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.1500000000000001e-24 or 9.6000000000000002e-58 < x Initial program 96.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6456.2
Applied rewrites56.2%
if -1.1500000000000001e-24 < x < 9.6000000000000002e-58Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6477.3
Applied rewrites77.3%
Taylor expanded in x around 0
Applied rewrites77.3%
Final simplification65.0%
(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 98.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6443.0
Applied rewrites43.0%
Final simplification43.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 2024277
(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)))