
(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 97.6%
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
(let* ((t_0 (* (- y) x)))
(if (<= x -9.6e+159)
t_0
(if (<= x -1.25e-89)
(* z x)
(if (<= x 9.8e-73) (* 1.0 y) (if (<= x 4.2e+208) (* z x) t_0))))))
double code(double x, double y, double z) {
double t_0 = -y * x;
double tmp;
if (x <= -9.6e+159) {
tmp = t_0;
} else if (x <= -1.25e-89) {
tmp = z * x;
} else if (x <= 9.8e-73) {
tmp = 1.0 * y;
} else if (x <= 4.2e+208) {
tmp = 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 = -y * x
if (x <= (-9.6d+159)) then
tmp = t_0
else if (x <= (-1.25d-89)) then
tmp = z * x
else if (x <= 9.8d-73) then
tmp = 1.0d0 * y
else if (x <= 4.2d+208) then
tmp = 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 = -y * x;
double tmp;
if (x <= -9.6e+159) {
tmp = t_0;
} else if (x <= -1.25e-89) {
tmp = z * x;
} else if (x <= 9.8e-73) {
tmp = 1.0 * y;
} else if (x <= 4.2e+208) {
tmp = z * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -y * x tmp = 0 if x <= -9.6e+159: tmp = t_0 elif x <= -1.25e-89: tmp = z * x elif x <= 9.8e-73: tmp = 1.0 * y elif x <= 4.2e+208: tmp = z * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-y) * x) tmp = 0.0 if (x <= -9.6e+159) tmp = t_0; elseif (x <= -1.25e-89) tmp = Float64(z * x); elseif (x <= 9.8e-73) tmp = Float64(1.0 * y); elseif (x <= 4.2e+208) tmp = Float64(z * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -y * x; tmp = 0.0; if (x <= -9.6e+159) tmp = t_0; elseif (x <= -1.25e-89) tmp = z * x; elseif (x <= 9.8e-73) tmp = 1.0 * y; elseif (x <= 4.2e+208) tmp = z * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-y) * x), $MachinePrecision]}, If[LessEqual[x, -9.6e+159], t$95$0, If[LessEqual[x, -1.25e-89], N[(z * x), $MachinePrecision], If[LessEqual[x, 9.8e-73], N[(1.0 * y), $MachinePrecision], If[LessEqual[x, 4.2e+208], N[(z * x), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-y\right) \cdot x\\
\mathbf{if}\;x \leq -9.6 \cdot 10^{+159}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -1.25 \cdot 10^{-89}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq 9.8 \cdot 10^{-73}:\\
\;\;\;\;1 \cdot y\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{+208}:\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -9.5999999999999999e159 or 4.1999999999999997e208 < x Initial program 93.4%
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--.f64100.0
Applied rewrites100.0%
Taylor expanded in z around 0
Applied rewrites66.8%
if -9.5999999999999999e159 < x < -1.24999999999999992e-89 or 9.80000000000000057e-73 < x < 4.1999999999999997e208Initial program 97.5%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6464.9
Applied rewrites64.9%
if -1.24999999999999992e-89 < x < 9.80000000000000057e-73Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6478.3
Applied rewrites78.3%
Taylor expanded in x around 0
Applied rewrites78.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z y) x))) (if (<= x -1.5e-99) t_0 (if (<= x 4.4e-72) (* 1.0 y) t_0))))
double code(double x, double y, double z) {
double t_0 = (z - y) * x;
double tmp;
if (x <= -1.5e-99) {
tmp = t_0;
} else if (x <= 4.4e-72) {
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 = (z - y) * x
if (x <= (-1.5d-99)) then
tmp = t_0
else if (x <= 4.4d-72) 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 = (z - y) * x;
double tmp;
if (x <= -1.5e-99) {
tmp = t_0;
} else if (x <= 4.4e-72) {
tmp = 1.0 * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (z - y) * x tmp = 0 if x <= -1.5e-99: tmp = t_0 elif x <= 4.4e-72: tmp = 1.0 * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(z - y) * x) tmp = 0.0 if (x <= -1.5e-99) tmp = t_0; elseif (x <= 4.4e-72) tmp = Float64(1.0 * 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 <= -1.5e-99) tmp = t_0; elseif (x <= 4.4e-72) tmp = 1.0 * 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, -1.5e-99], t$95$0, If[LessEqual[x, 4.4e-72], N[(1.0 * y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z - y\right) \cdot x\\
\mathbf{if}\;x \leq -1.5 \cdot 10^{-99}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 4.4 \cdot 10^{-72}:\\
\;\;\;\;1 \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.50000000000000003e-99 or 4.40000000000000005e-72 < x Initial program 96.5%
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--.f6491.8
Applied rewrites91.8%
if -1.50000000000000003e-99 < x < 4.40000000000000005e-72Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6479.5
Applied rewrites79.5%
Taylor expanded in x around 0
Applied rewrites79.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- 1.0 x) y))) (if (<= y -1.55e-139) t_0 (if (<= y 3.8e-135) (* z x) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 - x) * y;
double tmp;
if (y <= -1.55e-139) {
tmp = t_0;
} else if (y <= 3.8e-135) {
tmp = 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 = (1.0d0 - x) * y
if (y <= (-1.55d-139)) then
tmp = t_0
else if (y <= 3.8d-135) then
tmp = 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 = (1.0 - x) * y;
double tmp;
if (y <= -1.55e-139) {
tmp = t_0;
} else if (y <= 3.8e-135) {
tmp = z * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 - x) * y tmp = 0 if y <= -1.55e-139: tmp = t_0 elif y <= 3.8e-135: tmp = z * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 - x) * y) tmp = 0.0 if (y <= -1.55e-139) tmp = t_0; elseif (y <= 3.8e-135) tmp = Float64(z * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 - x) * y; tmp = 0.0; if (y <= -1.55e-139) tmp = t_0; elseif (y <= 3.8e-135) tmp = z * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -1.55e-139], t$95$0, If[LessEqual[y, 3.8e-135], N[(z * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - x\right) \cdot y\\
\mathbf{if}\;y \leq -1.55 \cdot 10^{-139}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-135}:\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.55e-139 or 3.8000000000000003e-135 < y Initial program 96.6%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6472.5
Applied rewrites72.5%
if -1.55e-139 < y < 3.8000000000000003e-135Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6479.4
Applied rewrites79.4%
(FPCore (x y z) :precision binary64 (if (<= x -1.25e-89) (* z x) (if (<= x 9.8e-73) (* 1.0 y) (* z x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.25e-89) {
tmp = z * x;
} else if (x <= 9.8e-73) {
tmp = 1.0 * 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 <= (-1.25d-89)) then
tmp = z * x
else if (x <= 9.8d-73) then
tmp = 1.0d0 * 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 <= -1.25e-89) {
tmp = z * x;
} else if (x <= 9.8e-73) {
tmp = 1.0 * y;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.25e-89: tmp = z * x elif x <= 9.8e-73: tmp = 1.0 * y else: tmp = z * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.25e-89) tmp = Float64(z * x); elseif (x <= 9.8e-73) tmp = Float64(1.0 * y); else tmp = Float64(z * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.25e-89) tmp = z * x; elseif (x <= 9.8e-73) tmp = 1.0 * y; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.25e-89], N[(z * x), $MachinePrecision], If[LessEqual[x, 9.8e-73], N[(1.0 * y), $MachinePrecision], N[(z * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{-89}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq 9.8 \cdot 10^{-73}:\\
\;\;\;\;1 \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if x < -1.24999999999999992e-89 or 9.80000000000000057e-73 < x Initial program 96.4%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6457.9
Applied rewrites57.9%
if -1.24999999999999992e-89 < x < 9.80000000000000057e-73Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6478.3
Applied rewrites78.3%
Taylor expanded in x around 0
Applied rewrites78.3%
(FPCore (x y z) :precision binary64 (* z x))
double code(double x, double y, double z) {
return z * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * x
end function
public static double code(double x, double y, double z) {
return z * x;
}
def code(x, y, z): return z * x
function code(x, y, z) return Float64(z * x) end
function tmp = code(x, y, z) tmp = z * x; end
code[x_, y_, z_] := N[(z * x), $MachinePrecision]
\begin{array}{l}
\\
z \cdot x
\end{array}
Initial program 97.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6445.9
Applied rewrites45.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 2024240
(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)))