
(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.4%
*-commutative98.4%
distribute-lft-out--98.4%
*-rgt-identity98.4%
cancel-sign-sub-inv98.4%
associate-+l+98.4%
+-commutative98.4%
*-commutative98.4%
distribute-rgt-out100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- y))))
(if (<= x -9.5e+224)
t_0
(if (<= x -5.4e+63)
(* x z)
(if (<= x -1.3e+43)
t_0
(if (<= x -1.36e-14)
(* x z)
(if (<= x -7e-38)
y
(if (<= x -3e-61)
(* x z)
(if (<= x 1.0)
y
(if (or (<= x 6.5e+57)
(and (not (<= x 3.7e+142)) (<= x 2.1e+232)))
t_0
(* x z)))))))))))
double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (x <= -9.5e+224) {
tmp = t_0;
} else if (x <= -5.4e+63) {
tmp = x * z;
} else if (x <= -1.3e+43) {
tmp = t_0;
} else if (x <= -1.36e-14) {
tmp = x * z;
} else if (x <= -7e-38) {
tmp = y;
} else if (x <= -3e-61) {
tmp = x * z;
} else if (x <= 1.0) {
tmp = y;
} else if ((x <= 6.5e+57) || (!(x <= 3.7e+142) && (x <= 2.1e+232))) {
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 = x * -y
if (x <= (-9.5d+224)) then
tmp = t_0
else if (x <= (-5.4d+63)) then
tmp = x * z
else if (x <= (-1.3d+43)) then
tmp = t_0
else if (x <= (-1.36d-14)) then
tmp = x * z
else if (x <= (-7d-38)) then
tmp = y
else if (x <= (-3d-61)) then
tmp = x * z
else if (x <= 1.0d0) then
tmp = y
else if ((x <= 6.5d+57) .or. (.not. (x <= 3.7d+142)) .and. (x <= 2.1d+232)) 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 = x * -y;
double tmp;
if (x <= -9.5e+224) {
tmp = t_0;
} else if (x <= -5.4e+63) {
tmp = x * z;
} else if (x <= -1.3e+43) {
tmp = t_0;
} else if (x <= -1.36e-14) {
tmp = x * z;
} else if (x <= -7e-38) {
tmp = y;
} else if (x <= -3e-61) {
tmp = x * z;
} else if (x <= 1.0) {
tmp = y;
} else if ((x <= 6.5e+57) || (!(x <= 3.7e+142) && (x <= 2.1e+232))) {
tmp = t_0;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * -y tmp = 0 if x <= -9.5e+224: tmp = t_0 elif x <= -5.4e+63: tmp = x * z elif x <= -1.3e+43: tmp = t_0 elif x <= -1.36e-14: tmp = x * z elif x <= -7e-38: tmp = y elif x <= -3e-61: tmp = x * z elif x <= 1.0: tmp = y elif (x <= 6.5e+57) or (not (x <= 3.7e+142) and (x <= 2.1e+232)): tmp = t_0 else: tmp = x * z return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-y)) tmp = 0.0 if (x <= -9.5e+224) tmp = t_0; elseif (x <= -5.4e+63) tmp = Float64(x * z); elseif (x <= -1.3e+43) tmp = t_0; elseif (x <= -1.36e-14) tmp = Float64(x * z); elseif (x <= -7e-38) tmp = y; elseif (x <= -3e-61) tmp = Float64(x * z); elseif (x <= 1.0) tmp = y; elseif ((x <= 6.5e+57) || (!(x <= 3.7e+142) && (x <= 2.1e+232))) tmp = t_0; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -y; tmp = 0.0; if (x <= -9.5e+224) tmp = t_0; elseif (x <= -5.4e+63) tmp = x * z; elseif (x <= -1.3e+43) tmp = t_0; elseif (x <= -1.36e-14) tmp = x * z; elseif (x <= -7e-38) tmp = y; elseif (x <= -3e-61) tmp = x * z; elseif (x <= 1.0) tmp = y; elseif ((x <= 6.5e+57) || (~((x <= 3.7e+142)) && (x <= 2.1e+232))) tmp = t_0; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[x, -9.5e+224], t$95$0, If[LessEqual[x, -5.4e+63], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.3e+43], t$95$0, If[LessEqual[x, -1.36e-14], N[(x * z), $MachinePrecision], If[LessEqual[x, -7e-38], y, If[LessEqual[x, -3e-61], N[(x * z), $MachinePrecision], If[LessEqual[x, 1.0], y, If[Or[LessEqual[x, 6.5e+57], And[N[Not[LessEqual[x, 3.7e+142]], $MachinePrecision], LessEqual[x, 2.1e+232]]], t$95$0, N[(x * z), $MachinePrecision]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;x \leq -9.5 \cdot 10^{+224}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -5.4 \cdot 10^{+63}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.3 \cdot 10^{+43}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -1.36 \cdot 10^{-14}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -7 \cdot 10^{-38}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -3 \cdot 10^{-61}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 6.5 \cdot 10^{+57} \lor \neg \left(x \leq 3.7 \cdot 10^{+142}\right) \land x \leq 2.1 \cdot 10^{+232}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -9.5000000000000002e224 or -5.40000000000000035e63 < x < -1.3000000000000001e43 or 1 < x < 6.4999999999999997e57 or 3.6999999999999997e142 < x < 2.09999999999999991e232Initial program 98.2%
Taylor expanded in x around inf 98.0%
mul-1-neg98.0%
sub-neg98.0%
Simplified98.0%
Taylor expanded in z around 0 71.8%
mul-1-neg71.8%
distribute-rgt-neg-out71.8%
Simplified71.8%
if -9.5000000000000002e224 < x < -5.40000000000000035e63 or -1.3000000000000001e43 < x < -1.36e-14 or -7.0000000000000003e-38 < x < -3.00000000000000012e-61 or 6.4999999999999997e57 < x < 3.6999999999999997e142 or 2.09999999999999991e232 < x Initial program 96.3%
Taylor expanded in y around 0 70.0%
if -1.36e-14 < x < -7.0000000000000003e-38 or -3.00000000000000012e-61 < x < 1Initial program 100.0%
Taylor expanded in x around 0 79.4%
Final simplification74.8%
(FPCore (x y z)
:precision binary64
(if (or (<= x -6e-14)
(not (or (<= x -9.5e-36) (and (not (<= x -1e-60)) (<= x 2.7e-41)))))
(* x (- z y))
y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6e-14) || !((x <= -9.5e-36) || (!(x <= -1e-60) && (x <= 2.7e-41)))) {
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 <= (-6d-14)) .or. (.not. (x <= (-9.5d-36)) .or. (.not. (x <= (-1d-60))) .and. (x <= 2.7d-41))) 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 <= -6e-14) || !((x <= -9.5e-36) || (!(x <= -1e-60) && (x <= 2.7e-41)))) {
tmp = x * (z - y);
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6e-14) or not ((x <= -9.5e-36) or (not (x <= -1e-60) and (x <= 2.7e-41))): tmp = x * (z - y) else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6e-14) || !((x <= -9.5e-36) || (!(x <= -1e-60) && (x <= 2.7e-41)))) 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 <= -6e-14) || ~(((x <= -9.5e-36) || (~((x <= -1e-60)) && (x <= 2.7e-41))))) tmp = x * (z - y); else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6e-14], N[Not[Or[LessEqual[x, -9.5e-36], And[N[Not[LessEqual[x, -1e-60]], $MachinePrecision], LessEqual[x, 2.7e-41]]]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-14} \lor \neg \left(x \leq -9.5 \cdot 10^{-36} \lor \neg \left(x \leq -1 \cdot 10^{-60}\right) \land x \leq 2.7 \cdot 10^{-41}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -5.9999999999999997e-14 or -9.5000000000000003e-36 < x < -9.9999999999999997e-61 or 2.7e-41 < x Initial program 97.1%
Taylor expanded in x around inf 98.1%
mul-1-neg98.1%
sub-neg98.1%
Simplified98.1%
if -5.9999999999999997e-14 < x < -9.5000000000000003e-36 or -9.9999999999999997e-61 < x < 2.7e-41Initial program 100.0%
Taylor expanded in x around 0 81.7%
Final simplification90.7%
(FPCore (x y z)
:precision binary64
(if (or (<= x -4.8e-17)
(not (or (<= x -1.9e-38) (and (not (<= x -3.5e-63)) (<= x 3.1e-41)))))
(* x z)
y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.8e-17) || !((x <= -1.9e-38) || (!(x <= -3.5e-63) && (x <= 3.1e-41)))) {
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 <= (-4.8d-17)) .or. (.not. (x <= (-1.9d-38)) .or. (.not. (x <= (-3.5d-63))) .and. (x <= 3.1d-41))) 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 <= -4.8e-17) || !((x <= -1.9e-38) || (!(x <= -3.5e-63) && (x <= 3.1e-41)))) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.8e-17) or not ((x <= -1.9e-38) or (not (x <= -3.5e-63) and (x <= 3.1e-41))): tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.8e-17) || !((x <= -1.9e-38) || (!(x <= -3.5e-63) && (x <= 3.1e-41)))) tmp = Float64(x * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.8e-17) || ~(((x <= -1.9e-38) || (~((x <= -3.5e-63)) && (x <= 3.1e-41))))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.8e-17], N[Not[Or[LessEqual[x, -1.9e-38], And[N[Not[LessEqual[x, -3.5e-63]], $MachinePrecision], LessEqual[x, 3.1e-41]]]], $MachinePrecision]], N[(x * z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{-17} \lor \neg \left(x \leq -1.9 \cdot 10^{-38} \lor \neg \left(x \leq -3.5 \cdot 10^{-63}\right) \land x \leq 3.1 \cdot 10^{-41}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -4.79999999999999973e-17 or -1.9e-38 < x < -3.50000000000000003e-63 or 3.10000000000000001e-41 < x Initial program 97.1%
Taylor expanded in y around 0 54.8%
if -4.79999999999999973e-17 < x < -1.9e-38 or -3.50000000000000003e-63 < x < 3.10000000000000001e-41Initial program 100.0%
Taylor expanded in x around 0 81.7%
Final simplification67.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -70000000000000.0) (not (<= x 1.0))) (* x (- z y)) (+ y (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -70000000000000.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 <= (-70000000000000.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 <= -70000000000000.0) || !(x <= 1.0)) {
tmp = x * (z - y);
} else {
tmp = y + (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -70000000000000.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 <= -70000000000000.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 <= -70000000000000.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, -70000000000000.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 -70000000000000 \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 < -7e13 or 1 < x Initial program 96.8%
Taylor expanded in x around inf 99.1%
mul-1-neg99.1%
sub-neg99.1%
Simplified99.1%
if -7e13 < 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 99.6%
neg-mul-199.6%
*-commutative99.6%
distribute-rgt-neg-in99.6%
Simplified99.6%
sub-neg99.6%
+-commutative99.6%
distribute-rgt-neg-out99.6%
remove-double-neg99.6%
Applied egg-rr99.6%
Final simplification99.3%
(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 98.4%
remove-double-neg98.4%
distribute-rgt-neg-out98.4%
neg-sub098.4%
neg-sub098.4%
*-commutative98.4%
distribute-lft-neg-in98.4%
remove-double-neg98.4%
distribute-rgt-out--98.4%
*-lft-identity98.4%
associate-+l-98.4%
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 98.4%
Taylor expanded in x around 0 38.8%
Final simplification38.8%
(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 2024044
(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)))