
(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.3%
*-commutative97.3%
distribute-lft-out--97.3%
*-rgt-identity97.3%
cancel-sign-sub-inv97.3%
associate-+l+97.3%
+-commutative97.3%
*-commutative97.3%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- y))))
(if (<= x -1.7e+227)
(* x z)
(if (<= x -9.5e+54)
t_0
(if (<= x -1.7e-13)
(* x z)
(if (<= x 1.75e-59)
y
(if (or (<= x 7.2e+162) (not (<= x 6e+256))) (* x z) t_0)))))))
double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (x <= -1.7e+227) {
tmp = x * z;
} else if (x <= -9.5e+54) {
tmp = t_0;
} else if (x <= -1.7e-13) {
tmp = x * z;
} else if (x <= 1.75e-59) {
tmp = y;
} else if ((x <= 7.2e+162) || !(x <= 6e+256)) {
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 = x * -y
if (x <= (-1.7d+227)) then
tmp = x * z
else if (x <= (-9.5d+54)) then
tmp = t_0
else if (x <= (-1.7d-13)) then
tmp = x * z
else if (x <= 1.75d-59) then
tmp = y
else if ((x <= 7.2d+162) .or. (.not. (x <= 6d+256))) 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 = x * -y;
double tmp;
if (x <= -1.7e+227) {
tmp = x * z;
} else if (x <= -9.5e+54) {
tmp = t_0;
} else if (x <= -1.7e-13) {
tmp = x * z;
} else if (x <= 1.75e-59) {
tmp = y;
} else if ((x <= 7.2e+162) || !(x <= 6e+256)) {
tmp = x * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -y tmp = 0 if x <= -1.7e+227: tmp = x * z elif x <= -9.5e+54: tmp = t_0 elif x <= -1.7e-13: tmp = x * z elif x <= 1.75e-59: tmp = y elif (x <= 7.2e+162) or not (x <= 6e+256): tmp = x * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-y)) tmp = 0.0 if (x <= -1.7e+227) tmp = Float64(x * z); elseif (x <= -9.5e+54) tmp = t_0; elseif (x <= -1.7e-13) tmp = Float64(x * z); elseif (x <= 1.75e-59) tmp = y; elseif ((x <= 7.2e+162) || !(x <= 6e+256)) tmp = Float64(x * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -y; tmp = 0.0; if (x <= -1.7e+227) tmp = x * z; elseif (x <= -9.5e+54) tmp = t_0; elseif (x <= -1.7e-13) tmp = x * z; elseif (x <= 1.75e-59) tmp = y; elseif ((x <= 7.2e+162) || ~((x <= 6e+256))) tmp = x * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[x, -1.7e+227], N[(x * z), $MachinePrecision], If[LessEqual[x, -9.5e+54], t$95$0, If[LessEqual[x, -1.7e-13], N[(x * z), $MachinePrecision], If[LessEqual[x, 1.75e-59], y, If[Or[LessEqual[x, 7.2e+162], N[Not[LessEqual[x, 6e+256]], $MachinePrecision]], N[(x * z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;x \leq -1.7 \cdot 10^{+227}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -9.5 \cdot 10^{+54}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -1.7 \cdot 10^{-13}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 1.75 \cdot 10^{-59}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 7.2 \cdot 10^{+162} \lor \neg \left(x \leq 6 \cdot 10^{+256}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -1.69999999999999995e227 or -9.4999999999999999e54 < x < -1.70000000000000008e-13 or 1.75e-59 < x < 7.19999999999999987e162 or 6.0000000000000002e256 < x Initial program 96.6%
remove-double-neg96.6%
distribute-rgt-neg-out96.6%
neg-sub096.6%
neg-sub096.6%
*-commutative96.6%
distribute-lft-neg-in96.6%
remove-double-neg96.6%
distribute-rgt-out--96.6%
*-lft-identity96.6%
associate-+l-96.6%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around 0 68.2%
if -1.69999999999999995e227 < x < -9.4999999999999999e54 or 7.19999999999999987e162 < x < 6.0000000000000002e256Initial program 93.4%
remove-double-neg93.4%
distribute-rgt-neg-out93.4%
neg-sub093.4%
neg-sub093.4%
*-commutative93.4%
distribute-lft-neg-in93.4%
remove-double-neg93.4%
distribute-rgt-out--93.4%
*-lft-identity93.4%
associate-+l-93.4%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in z around 0 68.3%
associate-*r*68.3%
neg-mul-168.3%
*-commutative68.3%
Simplified68.3%
if -1.70000000000000008e-13 < x < 1.75e-59Initial 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 0 81.3%
Final simplification73.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.8e-13) (not (<= x 3.8e-58))) (* x (- z y)) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e-13) || !(x <= 3.8e-58)) {
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-13)) .or. (.not. (x <= 3.8d-58))) 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-13) || !(x <= 3.8e-58)) {
tmp = x * (z - y);
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.8e-13) or not (x <= 3.8e-58): tmp = x * (z - y) else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.8e-13) || !(x <= 3.8e-58)) 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-13) || ~((x <= 3.8e-58))) tmp = x * (z - y); else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.8e-13], N[Not[LessEqual[x, 3.8e-58]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-13} \lor \neg \left(x \leq 3.8 \cdot 10^{-58}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -3.8e-13 or 3.7999999999999997e-58 < x Initial program 95.3%
remove-double-neg95.3%
distribute-rgt-neg-out95.3%
neg-sub095.3%
neg-sub095.3%
*-commutative95.3%
distribute-lft-neg-in95.3%
remove-double-neg95.3%
distribute-rgt-out--95.3%
*-lft-identity95.3%
associate-+l-95.3%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around inf 97.2%
if -3.8e-13 < x < 3.7999999999999997e-58Initial 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 0 81.3%
Final simplification90.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.5e+17) (not (<= x 3.5e-13))) (* x (- z y)) (+ y (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e+17) || !(x <= 3.5e-13)) {
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 <= (-5.5d+17)) .or. (.not. (x <= 3.5d-13))) 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 <= -5.5e+17) || !(x <= 3.5e-13)) {
tmp = x * (z - y);
} else {
tmp = y + (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.5e+17) or not (x <= 3.5e-13): tmp = x * (z - y) else: tmp = y + (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.5e+17) || !(x <= 3.5e-13)) 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 <= -5.5e+17) || ~((x <= 3.5e-13))) tmp = x * (z - y); else tmp = y + (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.5e+17], N[Not[LessEqual[x, 3.5e-13]], $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 -5.5 \cdot 10^{+17} \lor \neg \left(x \leq 3.5 \cdot 10^{-13}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot z\\
\end{array}
\end{array}
if x < -5.5e17 or 3.5000000000000002e-13 < x Initial program 94.8%
remove-double-neg94.8%
distribute-rgt-neg-out94.8%
neg-sub094.8%
neg-sub094.8%
*-commutative94.8%
distribute-lft-neg-in94.8%
remove-double-neg94.8%
distribute-rgt-out--94.8%
*-lft-identity94.8%
associate-+l-94.8%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around inf 99.7%
if -5.5e17 < x < 3.5000000000000002e-13Initial 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.9%
associate-*r*99.9%
neg-mul-199.9%
Simplified99.9%
cancel-sign-sub99.9%
+-commutative99.9%
Applied egg-rr99.9%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.5e-14) (not (<= x 3.3e-59))) (* x z) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.5e-14) || !(x <= 3.3e-59)) {
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-14)) .or. (.not. (x <= 3.3d-59))) 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-14) || !(x <= 3.3e-59)) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.5e-14) or not (x <= 3.3e-59): tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.5e-14) || !(x <= 3.3e-59)) 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-14) || ~((x <= 3.3e-59))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.5e-14], N[Not[LessEqual[x, 3.3e-59]], $MachinePrecision]], N[(x * z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-14} \lor \neg \left(x \leq 3.3 \cdot 10^{-59}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -2.5000000000000001e-14 or 3.29999999999999982e-59 < x Initial program 95.3%
remove-double-neg95.3%
distribute-rgt-neg-out95.3%
neg-sub095.3%
neg-sub095.3%
*-commutative95.3%
distribute-lft-neg-in95.3%
remove-double-neg95.3%
distribute-rgt-out--95.3%
*-lft-identity95.3%
associate-+l-95.3%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around 0 55.7%
if -2.5000000000000001e-14 < x < 3.29999999999999982e-59Initial 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 0 81.3%
Final simplification66.4%
(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.3%
remove-double-neg97.3%
distribute-rgt-neg-out97.3%
neg-sub097.3%
neg-sub097.3%
*-commutative97.3%
distribute-lft-neg-in97.3%
remove-double-neg97.3%
distribute-rgt-out--97.3%
*-lft-identity97.3%
associate-+l-97.3%
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.3%
remove-double-neg97.3%
distribute-rgt-neg-out97.3%
neg-sub097.3%
neg-sub097.3%
*-commutative97.3%
distribute-lft-neg-in97.3%
remove-double-neg97.3%
distribute-rgt-out--97.3%
*-lft-identity97.3%
associate-+l-97.3%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around 0 36.9%
Final simplification36.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 2024011
(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)))