
(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 98.0%
sub-neg98.0%
+-commutative98.0%
distribute-rgt1-in98.0%
associate-+l+98.0%
+-commutative98.0%
*-commutative98.0%
neg-mul-198.0%
associate-*r*98.0%
*-commutative98.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ (* y (- 1.0 x)) (* x z)))) (if (<= t_0 1e+304) t_0 (* x (- z y)))))
double code(double x, double y, double z) {
double t_0 = (y * (1.0 - x)) + (x * z);
double tmp;
if (t_0 <= 1e+304) {
tmp = t_0;
} else {
tmp = x * (z - y);
}
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 * (1.0d0 - x)) + (x * z)
if (t_0 <= 1d+304) then
tmp = t_0
else
tmp = x * (z - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y * (1.0 - x)) + (x * z);
double tmp;
if (t_0 <= 1e+304) {
tmp = t_0;
} else {
tmp = x * (z - y);
}
return tmp;
}
def code(x, y, z): t_0 = (y * (1.0 - x)) + (x * z) tmp = 0 if t_0 <= 1e+304: tmp = t_0 else: tmp = x * (z - y) return tmp
function code(x, y, z) t_0 = Float64(Float64(y * Float64(1.0 - x)) + Float64(x * z)) tmp = 0.0 if (t_0 <= 1e+304) tmp = t_0; else tmp = Float64(x * Float64(z - y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y * (1.0 - x)) + (x * z); tmp = 0.0; if (t_0 <= 1e+304) tmp = t_0; else tmp = x * (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e+304], t$95$0, N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(1 - x\right) + x \cdot z\\
\mathbf{if}\;t_0 \leq 10^{+304}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z - y\right)\\
\end{array}
\end{array}
if (+.f64 (*.f64 (-.f64 1 x) y) (*.f64 x z)) < 9.9999999999999994e303Initial program 100.0%
if 9.9999999999999994e303 < (+.f64 (*.f64 (-.f64 1 x) y) (*.f64 x z)) Initial program 82.8%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= x -1.95e+148)
t_0
(if (<= x -1.18e-54)
(* x z)
(if (<= x 5.5e-20)
y
(if (<= x 3.2e+168) (* x z) (if (<= x 3.5e+268) t_0 (* x z))))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (x <= -1.95e+148) {
tmp = t_0;
} else if (x <= -1.18e-54) {
tmp = x * z;
} else if (x <= 5.5e-20) {
tmp = y;
} else if (x <= 3.2e+168) {
tmp = x * z;
} else if (x <= 3.5e+268) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = y * -x
if (x <= (-1.95d+148)) then
tmp = t_0
else if (x <= (-1.18d-54)) then
tmp = x * z
else if (x <= 5.5d-20) then
tmp = y
else if (x <= 3.2d+168) then
tmp = x * z
else if (x <= 3.5d+268) then
tmp = t_0
else
tmp = x * z
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 <= -1.95e+148) {
tmp = t_0;
} else if (x <= -1.18e-54) {
tmp = x * z;
} else if (x <= 5.5e-20) {
tmp = y;
} else if (x <= 3.2e+168) {
tmp = x * z;
} else if (x <= 3.5e+268) {
tmp = t_0;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if x <= -1.95e+148: tmp = t_0 elif x <= -1.18e-54: tmp = x * z elif x <= 5.5e-20: tmp = y elif x <= 3.2e+168: tmp = x * z elif x <= 3.5e+268: tmp = t_0 else: tmp = x * z return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (x <= -1.95e+148) tmp = t_0; elseif (x <= -1.18e-54) tmp = Float64(x * z); elseif (x <= 5.5e-20) tmp = y; elseif (x <= 3.2e+168) tmp = Float64(x * z); elseif (x <= 3.5e+268) tmp = t_0; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -x; tmp = 0.0; if (x <= -1.95e+148) tmp = t_0; elseif (x <= -1.18e-54) tmp = x * z; elseif (x <= 5.5e-20) tmp = y; elseif (x <= 3.2e+168) tmp = x * z; elseif (x <= 3.5e+268) tmp = t_0; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[x, -1.95e+148], t$95$0, If[LessEqual[x, -1.18e-54], N[(x * z), $MachinePrecision], If[LessEqual[x, 5.5e-20], y, If[LessEqual[x, 3.2e+168], N[(x * z), $MachinePrecision], If[LessEqual[x, 3.5e+268], t$95$0, N[(x * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -1.95 \cdot 10^{+148}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -1.18 \cdot 10^{-54}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 5.5 \cdot 10^{-20}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{+168}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{+268}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.95000000000000001e148 or 3.2000000000000001e168 < x < 3.49999999999999972e268Initial program 91.9%
Taylor expanded in y around inf 68.7%
distribute-lft-out--68.7%
*-rgt-identity68.7%
Simplified68.7%
Taylor expanded in x around inf 68.7%
mul-1-neg68.7%
distribute-rgt-neg-out68.7%
Simplified68.7%
if -1.95000000000000001e148 < x < -1.17999999999999996e-54 or 5.4999999999999996e-20 < x < 3.2000000000000001e168 or 3.49999999999999972e268 < x Initial program 98.8%
Taylor expanded in y around 0 64.0%
if -1.17999999999999996e-54 < x < 5.4999999999999996e-20Initial program 100.0%
Taylor expanded in x around 0 84.0%
Final simplification74.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.8e-54) (not (<= x 2.15e-17))) (* x (- z y)) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e-54) || !(x <= 2.15e-17)) {
tmp = x * (z - y);
} else {
tmp = y;
}
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 <= (-3.8d-54)) .or. (.not. (x <= 2.15d-17))) then
tmp = x * (z - y)
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e-54) || !(x <= 2.15e-17)) {
tmp = x * (z - y);
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.8e-54) or not (x <= 2.15e-17): tmp = x * (z - y) else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.8e-54) || !(x <= 2.15e-17)) tmp = Float64(x * Float64(z - y)); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.8e-54) || ~((x <= 2.15e-17))) tmp = x * (z - y); else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.8e-54], N[Not[LessEqual[x, 2.15e-17]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-54} \lor \neg \left(x \leq 2.15 \cdot 10^{-17}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -3.8000000000000002e-54 or 2.15000000000000012e-17 < x Initial program 96.3%
Taylor expanded in x around inf 96.8%
mul-1-neg96.8%
unsub-neg96.8%
Simplified96.8%
if -3.8000000000000002e-54 < x < 2.15000000000000012e-17Initial program 100.0%
Taylor expanded in x around 0 84.0%
Final simplification90.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.8e-54) (not (<= x 0.0035))) (* x (- z y)) (- y (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e-54) || !(x <= 0.0035)) {
tmp = x * (z - y);
} else {
tmp = y - (x * y);
}
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 <= (-3.8d-54)) .or. (.not. (x <= 0.0035d0))) then
tmp = x * (z - y)
else
tmp = y - (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e-54) || !(x <= 0.0035)) {
tmp = x * (z - y);
} else {
tmp = y - (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.8e-54) or not (x <= 0.0035): tmp = x * (z - y) else: tmp = y - (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.8e-54) || !(x <= 0.0035)) tmp = Float64(x * Float64(z - y)); else tmp = Float64(y - Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.8e-54) || ~((x <= 0.0035))) tmp = x * (z - y); else tmp = y - (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.8e-54], N[Not[LessEqual[x, 0.0035]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-54} \lor \neg \left(x \leq 0.0035\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y - x \cdot y\\
\end{array}
\end{array}
if x < -3.8000000000000002e-54 or 0.00350000000000000007 < x Initial program 96.1%
Taylor expanded in x around inf 99.0%
mul-1-neg99.0%
unsub-neg99.0%
Simplified99.0%
if -3.8000000000000002e-54 < x < 0.00350000000000000007Initial program 100.0%
Taylor expanded in y around inf 83.2%
distribute-lft-out--83.2%
*-rgt-identity83.2%
Simplified83.2%
Final simplification91.2%
(FPCore (x y z) :precision binary64 (if (<= x -6.6e-55) (* x z) (if (<= x 1.5e-17) y (* x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.6e-55) {
tmp = x * z;
} else if (x <= 1.5e-17) {
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 <= (-6.6d-55)) then
tmp = x * z
else if (x <= 1.5d-17) 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 <= -6.6e-55) {
tmp = x * z;
} else if (x <= 1.5e-17) {
tmp = y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6.6e-55: tmp = x * z elif x <= 1.5e-17: tmp = y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6.6e-55) tmp = Float64(x * z); elseif (x <= 1.5e-17) tmp = y; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -6.6e-55) tmp = x * z; elseif (x <= 1.5e-17) tmp = y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6.6e-55], N[(x * z), $MachinePrecision], If[LessEqual[x, 1.5e-17], y, N[(x * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.6 \cdot 10^{-55}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 1.5 \cdot 10^{-17}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -6.5999999999999999e-55 or 1.50000000000000003e-17 < x Initial program 96.3%
Taylor expanded in y around 0 54.4%
if -6.5999999999999999e-55 < x < 1.50000000000000003e-17Initial program 100.0%
Taylor expanded in x around 0 84.0%
Final simplification68.4%
(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 41.9%
Final simplification41.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 2023229
(FPCore (x y z)
:name "Diagrams.Color.HSV:lerp from diagrams-contrib-1.3.0.5"
:precision binary64
:herbie-target
(- y (* x (- y z)))
(+ (* (- 1.0 x) y) (* x z)))