
(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 (- 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 96.1%
remove-double-neg96.1%
distribute-rgt-neg-out96.1%
neg-sub096.1%
neg-sub096.1%
*-commutative96.1%
distribute-lft-neg-in96.1%
remove-double-neg96.1%
distribute-rgt-out--96.1%
*-lft-identity96.1%
associate-+l-96.1%
distribute-lft-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= x -9e+269)
t_0
(if (<= x -6e+160)
(* x z)
(if (<= x -5.8e+117)
t_0
(if (<= x -5.4e+88)
(* x z)
(if (<= x -36000000000.0)
t_0
(if (or (<= x -2.6e-21) (not (<= x 1.8e-111))) (* x z) y))))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (x <= -9e+269) {
tmp = t_0;
} else if (x <= -6e+160) {
tmp = x * z;
} else if (x <= -5.8e+117) {
tmp = t_0;
} else if (x <= -5.4e+88) {
tmp = x * z;
} else if (x <= -36000000000.0) {
tmp = t_0;
} else if ((x <= -2.6e-21) || !(x <= 1.8e-111)) {
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) :: t_0
real(8) :: tmp
t_0 = y * -x
if (x <= (-9d+269)) then
tmp = t_0
else if (x <= (-6d+160)) then
tmp = x * z
else if (x <= (-5.8d+117)) then
tmp = t_0
else if (x <= (-5.4d+88)) then
tmp = x * z
else if (x <= (-36000000000.0d0)) then
tmp = t_0
else if ((x <= (-2.6d-21)) .or. (.not. (x <= 1.8d-111))) then
tmp = x * z
else
tmp = y
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 <= -9e+269) {
tmp = t_0;
} else if (x <= -6e+160) {
tmp = x * z;
} else if (x <= -5.8e+117) {
tmp = t_0;
} else if (x <= -5.4e+88) {
tmp = x * z;
} else if (x <= -36000000000.0) {
tmp = t_0;
} else if ((x <= -2.6e-21) || !(x <= 1.8e-111)) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if x <= -9e+269: tmp = t_0 elif x <= -6e+160: tmp = x * z elif x <= -5.8e+117: tmp = t_0 elif x <= -5.4e+88: tmp = x * z elif x <= -36000000000.0: tmp = t_0 elif (x <= -2.6e-21) or not (x <= 1.8e-111): tmp = x * z else: tmp = y return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (x <= -9e+269) tmp = t_0; elseif (x <= -6e+160) tmp = Float64(x * z); elseif (x <= -5.8e+117) tmp = t_0; elseif (x <= -5.4e+88) tmp = Float64(x * z); elseif (x <= -36000000000.0) tmp = t_0; elseif ((x <= -2.6e-21) || !(x <= 1.8e-111)) tmp = Float64(x * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -x; tmp = 0.0; if (x <= -9e+269) tmp = t_0; elseif (x <= -6e+160) tmp = x * z; elseif (x <= -5.8e+117) tmp = t_0; elseif (x <= -5.4e+88) tmp = x * z; elseif (x <= -36000000000.0) tmp = t_0; elseif ((x <= -2.6e-21) || ~((x <= 1.8e-111))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[x, -9e+269], t$95$0, If[LessEqual[x, -6e+160], N[(x * z), $MachinePrecision], If[LessEqual[x, -5.8e+117], t$95$0, If[LessEqual[x, -5.4e+88], N[(x * z), $MachinePrecision], If[LessEqual[x, -36000000000.0], t$95$0, If[Or[LessEqual[x, -2.6e-21], N[Not[LessEqual[x, 1.8e-111]], $MachinePrecision]], N[(x * z), $MachinePrecision], y]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -9 \cdot 10^{+269}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -6 \cdot 10^{+160}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -5.8 \cdot 10^{+117}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -5.4 \cdot 10^{+88}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -36000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -2.6 \cdot 10^{-21} \lor \neg \left(x \leq 1.8 \cdot 10^{-111}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -9.0000000000000004e269 or -5.9999999999999997e160 < x < -5.80000000000000055e117 or -5.40000000000000031e88 < x < -3.6e10Initial program 95.0%
Taylor expanded in x around inf 99.1%
mul-1-neg99.1%
sub-neg99.1%
Simplified99.1%
Taylor expanded in z around 0 67.6%
mul-1-neg67.6%
distribute-rgt-neg-out67.6%
Simplified67.6%
if -9.0000000000000004e269 < x < -5.9999999999999997e160 or -5.80000000000000055e117 < x < -5.40000000000000031e88 or -3.6e10 < x < -2.60000000000000017e-21 or 1.80000000000000005e-111 < x Initial program 93.7%
Taylor expanded in y around 0 61.1%
if -2.60000000000000017e-21 < x < 1.80000000000000005e-111Initial program 100.0%
Taylor expanded in x around 0 78.0%
Final simplification67.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z y))))
(if (<= x -1.1e-63)
t_0
(if (<= x 3.6e-111)
y
(if (<= x 4e-55) (* x z) (if (<= x 72.0) (* y (- 1.0 x)) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (z - y);
double tmp;
if (x <= -1.1e-63) {
tmp = t_0;
} else if (x <= 3.6e-111) {
tmp = y;
} else if (x <= 4e-55) {
tmp = x * z;
} else if (x <= 72.0) {
tmp = y * (1.0 - 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 = x * (z - y)
if (x <= (-1.1d-63)) then
tmp = t_0
else if (x <= 3.6d-111) then
tmp = y
else if (x <= 4d-55) then
tmp = x * z
else if (x <= 72.0d0) then
tmp = y * (1.0d0 - x)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (z - y);
double tmp;
if (x <= -1.1e-63) {
tmp = t_0;
} else if (x <= 3.6e-111) {
tmp = y;
} else if (x <= 4e-55) {
tmp = x * z;
} else if (x <= 72.0) {
tmp = y * (1.0 - x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z - y) tmp = 0 if x <= -1.1e-63: tmp = t_0 elif x <= 3.6e-111: tmp = y elif x <= 4e-55: tmp = x * z elif x <= 72.0: tmp = y * (1.0 - x) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z - y)) tmp = 0.0 if (x <= -1.1e-63) tmp = t_0; elseif (x <= 3.6e-111) tmp = y; elseif (x <= 4e-55) tmp = Float64(x * z); elseif (x <= 72.0) tmp = Float64(y * Float64(1.0 - x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (z - y); tmp = 0.0; if (x <= -1.1e-63) tmp = t_0; elseif (x <= 3.6e-111) tmp = y; elseif (x <= 4e-55) tmp = x * z; elseif (x <= 72.0) tmp = y * (1.0 - x); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.1e-63], t$95$0, If[LessEqual[x, 3.6e-111], y, If[LessEqual[x, 4e-55], N[(x * z), $MachinePrecision], If[LessEqual[x, 72.0], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z - y\right)\\
\mathbf{if}\;x \leq -1.1 \cdot 10^{-63}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3.6 \cdot 10^{-111}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 4 \cdot 10^{-55}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 72:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.1e-63 or 72 < x Initial program 93.2%
Taylor expanded in x around inf 98.5%
mul-1-neg98.5%
sub-neg98.5%
Simplified98.5%
if -1.1e-63 < x < 3.6000000000000001e-111Initial program 100.0%
Taylor expanded in x around 0 79.2%
if 3.6000000000000001e-111 < x < 3.99999999999999998e-55Initial program 100.0%
Taylor expanded in y around 0 70.4%
if 3.99999999999999998e-55 < x < 72Initial program 100.0%
Taylor expanded in y around inf 75.7%
Final simplification89.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.8e-50) (not (<= x 3.1e-111))) (* x (- z y)) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.8e-50) || !(x <= 3.1e-111)) {
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 <= (-4.8d-50)) .or. (.not. (x <= 3.1d-111))) 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 <= -4.8e-50) || !(x <= 3.1e-111)) {
tmp = x * (z - y);
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.8e-50) or not (x <= 3.1e-111): tmp = x * (z - y) else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.8e-50) || !(x <= 3.1e-111)) 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 <= -4.8e-50) || ~((x <= 3.1e-111))) tmp = x * (z - y); else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.8e-50], N[Not[LessEqual[x, 3.1e-111]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{-50} \lor \neg \left(x \leq 3.1 \cdot 10^{-111}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -4.80000000000000004e-50 or 3.10000000000000014e-111 < x Initial program 94.1%
Taylor expanded in x around inf 91.4%
mul-1-neg91.4%
sub-neg91.4%
Simplified91.4%
if -4.80000000000000004e-50 < x < 3.10000000000000014e-111Initial program 100.0%
Taylor expanded in x around 0 79.2%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* x (- z y)) (+ y (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
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 <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) 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 <= -1.0) || !(x <= 1.0)) {
tmp = x * (z - y);
} else {
tmp = y + (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = x * (z - y) else: tmp = y + (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) 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 <= -1.0) || ~((x <= 1.0))) tmp = x * (z - y); else tmp = y + (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $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 -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot z\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 92.9%
Taylor expanded in x around inf 99.2%
mul-1-neg99.2%
sub-neg99.2%
Simplified99.2%
if -1 < x < 1Initial 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 98.3%
mul-1-neg98.3%
distribute-lft-neg-out98.3%
*-commutative98.3%
Simplified98.3%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.1e-25) (not (<= x 1.8e-111))) (* x z) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.1e-25) || !(x <= 1.8e-111)) {
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 <= (-3.1d-25)) .or. (.not. (x <= 1.8d-111))) 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 <= -3.1e-25) || !(x <= 1.8e-111)) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.1e-25) or not (x <= 1.8e-111): tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.1e-25) || !(x <= 1.8e-111)) tmp = Float64(x * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.1e-25) || ~((x <= 1.8e-111))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.1e-25], N[Not[LessEqual[x, 1.8e-111]], $MachinePrecision]], N[(x * z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{-25} \lor \neg \left(x \leq 1.8 \cdot 10^{-111}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -3.09999999999999995e-25 or 1.80000000000000005e-111 < x Initial program 94.0%
Taylor expanded in y around 0 53.7%
if -3.09999999999999995e-25 < x < 1.80000000000000005e-111Initial program 100.0%
Taylor expanded in x around 0 78.0%
Final simplification62.1%
(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.1%
Taylor expanded in x around 0 32.6%
Final simplification32.6%
(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 2024071
(FPCore (x y z)
:name "Diagrams.Color.HSV:lerp from diagrams-contrib-1.3.0.5"
:precision binary64
:alt
(- y (* x (- y z)))
(+ (* (- 1.0 x) y) (* x z)))