
(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 (- 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}
Initial program 96.9%
remove-double-neg96.9%
distribute-rgt-neg-out96.9%
neg-sub096.9%
neg-sub096.9%
*-commutative96.9%
distribute-lft-neg-in96.9%
remove-double-neg96.9%
distribute-rgt-out--96.9%
*-lft-identity96.9%
associate-+l-96.9%
distribute-lft-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= x -6.2e+215)
(* x z)
(if (<= x -1.38e+20)
t_0
(if (<= x -8.2e-83)
(* x z)
(if (<= x 1e-85)
y
(if (or (<= x 47000000.0) (and (not (<= x 9e+126)) (<= x 4.2e+282)))
(* x z)
t_0)))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (x <= -6.2e+215) {
tmp = x * z;
} else if (x <= -1.38e+20) {
tmp = t_0;
} else if (x <= -8.2e-83) {
tmp = x * z;
} else if (x <= 1e-85) {
tmp = y;
} else if ((x <= 47000000.0) || (!(x <= 9e+126) && (x <= 4.2e+282))) {
tmp = x * z;
} 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 <= (-6.2d+215)) then
tmp = x * z
else if (x <= (-1.38d+20)) then
tmp = t_0
else if (x <= (-8.2d-83)) then
tmp = x * z
else if (x <= 1d-85) then
tmp = y
else if ((x <= 47000000.0d0) .or. (.not. (x <= 9d+126)) .and. (x <= 4.2d+282)) then
tmp = x * z
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 <= -6.2e+215) {
tmp = x * z;
} else if (x <= -1.38e+20) {
tmp = t_0;
} else if (x <= -8.2e-83) {
tmp = x * z;
} else if (x <= 1e-85) {
tmp = y;
} else if ((x <= 47000000.0) || (!(x <= 9e+126) && (x <= 4.2e+282))) {
tmp = x * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if x <= -6.2e+215: tmp = x * z elif x <= -1.38e+20: tmp = t_0 elif x <= -8.2e-83: tmp = x * z elif x <= 1e-85: tmp = y elif (x <= 47000000.0) or (not (x <= 9e+126) and (x <= 4.2e+282)): tmp = x * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (x <= -6.2e+215) tmp = Float64(x * z); elseif (x <= -1.38e+20) tmp = t_0; elseif (x <= -8.2e-83) tmp = Float64(x * z); elseif (x <= 1e-85) tmp = y; elseif ((x <= 47000000.0) || (!(x <= 9e+126) && (x <= 4.2e+282))) tmp = Float64(x * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -x; tmp = 0.0; if (x <= -6.2e+215) tmp = x * z; elseif (x <= -1.38e+20) tmp = t_0; elseif (x <= -8.2e-83) tmp = x * z; elseif (x <= 1e-85) tmp = y; elseif ((x <= 47000000.0) || (~((x <= 9e+126)) && (x <= 4.2e+282))) tmp = x * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[x, -6.2e+215], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.38e+20], t$95$0, If[LessEqual[x, -8.2e-83], N[(x * z), $MachinePrecision], If[LessEqual[x, 1e-85], y, If[Or[LessEqual[x, 47000000.0], And[N[Not[LessEqual[x, 9e+126]], $MachinePrecision], LessEqual[x, 4.2e+282]]], N[(x * z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -6.2 \cdot 10^{+215}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.38 \cdot 10^{+20}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -8.2 \cdot 10^{-83}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 10^{-85}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 47000000 \lor \neg \left(x \leq 9 \cdot 10^{+126}\right) \land x \leq 4.2 \cdot 10^{+282}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -6.1999999999999998e215 or -1.38e20 < x < -8.1999999999999999e-83 or 9.9999999999999998e-86 < x < 4.7e7 or 8.99999999999999947e126 < x < 4.19999999999999975e282Initial program 92.1%
fma-def95.5%
Simplified95.5%
Taylor expanded in y around 0 75.8%
if -6.1999999999999998e215 < x < -1.38e20 or 4.7e7 < x < 8.99999999999999947e126 or 4.19999999999999975e282 < x Initial program 98.5%
fma-def98.5%
Simplified98.5%
Taylor expanded in x around inf 98.9%
mul-1-neg98.9%
unsub-neg98.9%
Simplified98.9%
Taylor expanded in z around 0 66.5%
mul-1-neg66.5%
distribute-rgt-neg-out66.5%
Simplified66.5%
if -8.1999999999999999e-83 < x < 9.9999999999999998e-86Initial program 100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 74.4%
Final simplification72.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.02e-86) (not (<= x 1e-85))) (* x (- z y)) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.02e-86) || !(x <= 1e-85)) {
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 <= (-1.02d-86)) .or. (.not. (x <= 1d-85))) 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 <= -1.02e-86) || !(x <= 1e-85)) {
tmp = x * (z - y);
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.02e-86) or not (x <= 1e-85): tmp = x * (z - y) else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.02e-86) || !(x <= 1e-85)) 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 <= -1.02e-86) || ~((x <= 1e-85))) tmp = x * (z - y); else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.02e-86], N[Not[LessEqual[x, 1e-85]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.02 \cdot 10^{-86} \lor \neg \left(x \leq 10^{-85}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.02000000000000005e-86 or 9.9999999999999998e-86 < x Initial program 94.8%
fma-def96.8%
Simplified96.8%
Taylor expanded in x around inf 95.0%
mul-1-neg95.0%
unsub-neg95.0%
Simplified95.0%
if -1.02000000000000005e-86 < x < 9.9999999999999998e-86Initial program 100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 74.4%
Final simplification87.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.7e-84) (not (<= x 3.4e-86))) (* x (- z y)) (- y (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.7e-84) || !(x <= 3.4e-86)) {
tmp = x * (z - y);
} else {
tmp = y - (y * 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.7d-84)) .or. (.not. (x <= 3.4d-86))) then
tmp = x * (z - y)
else
tmp = y - (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.7e-84) || !(x <= 3.4e-86)) {
tmp = x * (z - y);
} else {
tmp = y - (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.7e-84) or not (x <= 3.4e-86): tmp = x * (z - y) else: tmp = y - (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.7e-84) || !(x <= 3.4e-86)) tmp = Float64(x * Float64(z - y)); else tmp = Float64(y - Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.7e-84) || ~((x <= 3.4e-86))) tmp = x * (z - y); else tmp = y - (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.7e-84], N[Not[LessEqual[x, 3.4e-86]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{-84} \lor \neg \left(x \leq 3.4 \cdot 10^{-86}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot x\\
\end{array}
\end{array}
if x < -1.7000000000000001e-84 or 3.4e-86 < x Initial program 94.8%
fma-def96.8%
Simplified96.8%
Taylor expanded in x around inf 95.0%
mul-1-neg95.0%
unsub-neg95.0%
Simplified95.0%
if -1.7000000000000001e-84 < x < 3.4e-86Initial program 100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
neg-sub0100.0%
neg-sub0100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
remove-double-neg100.0%
distribute-rgt-out--100.0%
*-lft-identity100.0%
associate-+l-100.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 74.4%
Final simplification87.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.05) (not (<= x 1.95e-20))) (* x (- z y)) (+ y (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.05) || !(x <= 1.95e-20)) {
tmp = x * (z - y);
} else {
tmp = y + (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 <= (-3.05d0)) .or. (.not. (x <= 1.95d-20))) then
tmp = x * (z - y)
else
tmp = y + (x * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.05) || !(x <= 1.95e-20)) {
tmp = x * (z - y);
} else {
tmp = y + (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.05) or not (x <= 1.95e-20): tmp = x * (z - y) else: tmp = y + (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.05) || !(x <= 1.95e-20)) tmp = Float64(x * Float64(z - y)); else tmp = Float64(y + Float64(x * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.05) || ~((x <= 1.95e-20))) tmp = x * (z - y); else tmp = y + (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.05], N[Not[LessEqual[x, 1.95e-20]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], N[(y + N[(x * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.05 \lor \neg \left(x \leq 1.95 \cdot 10^{-20}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot z\\
\end{array}
\end{array}
if x < -3.0499999999999998 or 1.95000000000000004e-20 < x Initial program 93.9%
fma-def96.2%
Simplified96.2%
Taylor expanded in x around inf 99.1%
mul-1-neg99.1%
unsub-neg99.1%
Simplified99.1%
if -3.0499999999999998 < x < 1.95000000000000004e-20Initial program 100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
neg-sub0100.0%
neg-sub0100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
remove-double-neg100.0%
distribute-rgt-out--100.0%
*-lft-identity100.0%
associate-+l-100.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around 0 99.2%
mul-1-neg99.2%
distribute-rgt-neg-out99.2%
Simplified99.2%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.5e-82) (not (<= x 2.8e-85))) (* x z) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.5e-82) || !(x <= 2.8e-85)) {
tmp = x * z;
} 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 <= (-2.5d-82)) .or. (.not. (x <= 2.8d-85))) then
tmp = x * z
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.5e-82) || !(x <= 2.8e-85)) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.5e-82) or not (x <= 2.8e-85): tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.5e-82) || !(x <= 2.8e-85)) tmp = Float64(x * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.5e-82) || ~((x <= 2.8e-85))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.5e-82], N[Not[LessEqual[x, 2.8e-85]], $MachinePrecision]], N[(x * z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-82} \lor \neg \left(x \leq 2.8 \cdot 10^{-85}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -2.4999999999999999e-82 or 2.80000000000000017e-85 < x Initial program 94.8%
fma-def96.8%
Simplified96.8%
Taylor expanded in y around 0 58.2%
if -2.4999999999999999e-82 < x < 2.80000000000000017e-85Initial program 100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 74.4%
Final simplification64.6%
(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 96.9%
fma-def98.0%
Simplified98.0%
Taylor expanded in x around 0 33.0%
Final simplification33.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 2024027
(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)))