
(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 97.6%
*-commutative97.6%
distribute-lft-out--97.7%
*-rgt-identity97.7%
cancel-sign-sub-inv97.7%
associate-+l+97.7%
+-commutative97.7%
*-commutative97.7%
distribute-rgt-out100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.95e+59) (* x (- y)) (if (or (<= x -9.5e-20) (not (<= x 6.8e-31))) (* x z) y)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.95e+59) {
tmp = x * -y;
} else if ((x <= -9.5e-20) || !(x <= 6.8e-31)) {
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 <= (-1.95d+59)) then
tmp = x * -y
else if ((x <= (-9.5d-20)) .or. (.not. (x <= 6.8d-31))) 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 <= -1.95e+59) {
tmp = x * -y;
} else if ((x <= -9.5e-20) || !(x <= 6.8e-31)) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.95e+59: tmp = x * -y elif (x <= -9.5e-20) or not (x <= 6.8e-31): tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.95e+59) tmp = Float64(x * Float64(-y)); elseif ((x <= -9.5e-20) || !(x <= 6.8e-31)) tmp = Float64(x * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.95e+59) tmp = x * -y; elseif ((x <= -9.5e-20) || ~((x <= 6.8e-31))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.95e+59], N[(x * (-y)), $MachinePrecision], If[Or[LessEqual[x, -9.5e-20], N[Not[LessEqual[x, 6.8e-31]], $MachinePrecision]], N[(x * z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{+59}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{elif}\;x \leq -9.5 \cdot 10^{-20} \lor \neg \left(x \leq 6.8 \cdot 10^{-31}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.95000000000000011e59Initial program 95.5%
remove-double-neg95.5%
distribute-rgt-neg-out95.5%
neg-sub095.5%
neg-sub095.5%
*-commutative95.5%
distribute-lft-neg-in95.5%
remove-double-neg95.5%
distribute-rgt-out--95.5%
*-lft-identity95.5%
associate-+l-95.5%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 65.7%
Taylor expanded in x around inf 65.7%
mul-1-neg65.7%
*-commutative65.7%
distribute-rgt-neg-in65.7%
Simplified65.7%
if -1.95000000000000011e59 < x < -9.5e-20 or 6.8000000000000002e-31 < x Initial program 96.4%
remove-double-neg96.4%
distribute-rgt-neg-out96.4%
neg-sub096.4%
neg-sub096.4%
*-commutative96.4%
distribute-lft-neg-in96.4%
remove-double-neg96.4%
distribute-rgt-out--96.5%
*-lft-identity96.5%
associate-+l-96.5%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around 0 64.7%
if -9.5e-20 < x < 6.8000000000000002e-31Initial 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 x around inf 68.4%
Taylor expanded in x around 0 73.2%
Final simplification68.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -230000000.0) (not (<= x 0.0027))) (* x (- z y)) (+ y (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -230000000.0) || !(x <= 0.0027)) {
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 <= (-230000000.0d0)) .or. (.not. (x <= 0.0027d0))) 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 <= -230000000.0) || !(x <= 0.0027)) {
tmp = x * (z - y);
} else {
tmp = y + (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -230000000.0) or not (x <= 0.0027): tmp = x * (z - y) else: tmp = y + (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -230000000.0) || !(x <= 0.0027)) 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 <= -230000000.0) || ~((x <= 0.0027))) tmp = x * (z - y); else tmp = y + (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -230000000.0], N[Not[LessEqual[x, 0.0027]], $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 -230000000 \lor \neg \left(x \leq 0.0027\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot z\\
\end{array}
\end{array}
if x < -2.3e8 or 0.0027000000000000001 < x Initial program 95.8%
remove-double-neg95.8%
distribute-rgt-neg-out95.8%
neg-sub095.8%
neg-sub095.8%
*-commutative95.8%
distribute-lft-neg-in95.8%
remove-double-neg95.8%
distribute-rgt-out--95.8%
*-lft-identity95.8%
associate-+l-95.8%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in z around inf 100.0%
if -2.3e8 < x < 0.0027000000000000001Initial 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%
*-commutative99.2%
cancel-sign-sub99.2%
*-commutative99.2%
+-commutative99.2%
Applied egg-rr99.2%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.05e-16) (not (<= x 5.5e-31))) (* x (- z y)) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.05e-16) || !(x <= 5.5e-31)) {
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.05d-16)) .or. (.not. (x <= 5.5d-31))) 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.05e-16) || !(x <= 5.5e-31)) {
tmp = x * (z - y);
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.05e-16) or not (x <= 5.5e-31): tmp = x * (z - y) else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.05e-16) || !(x <= 5.5e-31)) 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.05e-16) || ~((x <= 5.5e-31))) tmp = x * (z - y); else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.05e-16], N[Not[LessEqual[x, 5.5e-31]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{-16} \lor \neg \left(x \leq 5.5 \cdot 10^{-31}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.0500000000000001e-16 or 5.49999999999999958e-31 < x Initial program 96.0%
remove-double-neg96.0%
distribute-rgt-neg-out96.0%
neg-sub096.0%
neg-sub096.0%
*-commutative96.0%
distribute-lft-neg-in96.0%
remove-double-neg96.0%
distribute-rgt-out--96.0%
*-lft-identity96.0%
associate-+l-96.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in z around inf 98.7%
if -1.0500000000000001e-16 < x < 5.49999999999999958e-31Initial 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 x around inf 68.4%
Taylor expanded in x around 0 73.2%
Final simplification88.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.05e-19) (not (<= x 7.5e-31))) (* x z) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.05e-19) || !(x <= 7.5e-31)) {
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 <= (-1.05d-19)) .or. (.not. (x <= 7.5d-31))) 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 <= -1.05e-19) || !(x <= 7.5e-31)) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.05e-19) or not (x <= 7.5e-31): tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.05e-19) || !(x <= 7.5e-31)) tmp = Float64(x * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.05e-19) || ~((x <= 7.5e-31))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.05e-19], N[Not[LessEqual[x, 7.5e-31]], $MachinePrecision]], N[(x * z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{-19} \lor \neg \left(x \leq 7.5 \cdot 10^{-31}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.0499999999999999e-19 or 7.49999999999999975e-31 < x Initial program 96.0%
remove-double-neg96.0%
distribute-rgt-neg-out96.0%
neg-sub096.0%
neg-sub096.0%
*-commutative96.0%
distribute-lft-neg-in96.0%
remove-double-neg96.0%
distribute-rgt-out--96.0%
*-lft-identity96.0%
associate-+l-96.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around 0 52.1%
if -1.0499999999999999e-19 < x < 7.49999999999999975e-31Initial 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 x around inf 68.4%
Taylor expanded in x around 0 73.2%
Final simplification60.8%
(FPCore (x y z) :precision binary64 (+ y (* x (- z y))))
double code(double x, double y, double z) {
return y + (x * (z - 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 + (x * (z - y))
end function
public static double code(double x, double y, double z) {
return y + (x * (z - y));
}
def code(x, y, z): return y + (x * (z - y))
function code(x, y, z) return Float64(y + Float64(x * Float64(z - y))) end
function tmp = code(x, y, z) tmp = y + (x * (z - y)); end
code[x_, y_, z_] := N[(y + N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + x \cdot \left(z - y\right)
\end{array}
Initial program 97.6%
remove-double-neg97.6%
distribute-rgt-neg-out97.6%
neg-sub097.6%
neg-sub097.6%
*-commutative97.6%
distribute-lft-neg-in97.6%
remove-double-neg97.6%
distribute-rgt-out--97.7%
*-lft-identity97.7%
associate-+l-97.7%
distribute-lft-out--100.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 97.6%
remove-double-neg97.6%
distribute-rgt-neg-out97.6%
neg-sub097.6%
neg-sub097.6%
*-commutative97.6%
distribute-lft-neg-in97.6%
remove-double-neg97.6%
distribute-rgt-out--97.7%
*-lft-identity97.7%
associate-+l-97.7%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around inf 87.1%
Taylor expanded in x around 0 32.3%
(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 2024144
(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)))