
(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 98.8%
remove-double-neg98.8%
distribute-rgt-neg-out98.8%
neg-sub098.8%
neg-sub098.8%
*-commutative98.8%
distribute-lft-neg-in98.8%
remove-double-neg98.8%
distribute-rgt-out--98.8%
*-lft-identity98.8%
associate-+l-98.8%
distribute-lft-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= x -8.8e+210)
(* x z)
(if (<= x -1.3e+41)
t_0
(if (<= x -2.05e-33)
(* x z)
(if (<= x 1.7e-81)
y
(if (or (<= x 5.2e+36) (not (<= x 5.8e+86))) (* x z) t_0)))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (x <= -8.8e+210) {
tmp = x * z;
} else if (x <= -1.3e+41) {
tmp = t_0;
} else if (x <= -2.05e-33) {
tmp = x * z;
} else if (x <= 1.7e-81) {
tmp = y;
} else if ((x <= 5.2e+36) || !(x <= 5.8e+86)) {
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 <= (-8.8d+210)) then
tmp = x * z
else if (x <= (-1.3d+41)) then
tmp = t_0
else if (x <= (-2.05d-33)) then
tmp = x * z
else if (x <= 1.7d-81) then
tmp = y
else if ((x <= 5.2d+36) .or. (.not. (x <= 5.8d+86))) 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 <= -8.8e+210) {
tmp = x * z;
} else if (x <= -1.3e+41) {
tmp = t_0;
} else if (x <= -2.05e-33) {
tmp = x * z;
} else if (x <= 1.7e-81) {
tmp = y;
} else if ((x <= 5.2e+36) || !(x <= 5.8e+86)) {
tmp = x * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if x <= -8.8e+210: tmp = x * z elif x <= -1.3e+41: tmp = t_0 elif x <= -2.05e-33: tmp = x * z elif x <= 1.7e-81: tmp = y elif (x <= 5.2e+36) or not (x <= 5.8e+86): 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 <= -8.8e+210) tmp = Float64(x * z); elseif (x <= -1.3e+41) tmp = t_0; elseif (x <= -2.05e-33) tmp = Float64(x * z); elseif (x <= 1.7e-81) tmp = y; elseif ((x <= 5.2e+36) || !(x <= 5.8e+86)) 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 <= -8.8e+210) tmp = x * z; elseif (x <= -1.3e+41) tmp = t_0; elseif (x <= -2.05e-33) tmp = x * z; elseif (x <= 1.7e-81) tmp = y; elseif ((x <= 5.2e+36) || ~((x <= 5.8e+86))) 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, -8.8e+210], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.3e+41], t$95$0, If[LessEqual[x, -2.05e-33], N[(x * z), $MachinePrecision], If[LessEqual[x, 1.7e-81], y, If[Or[LessEqual[x, 5.2e+36], N[Not[LessEqual[x, 5.8e+86]], $MachinePrecision]], N[(x * z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -8.8 \cdot 10^{+210}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.3 \cdot 10^{+41}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -2.05 \cdot 10^{-33}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{-81}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{+36} \lor \neg \left(x \leq 5.8 \cdot 10^{+86}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -8.79999999999999948e210 or -1.3e41 < x < -2.05e-33 or 1.6999999999999999e-81 < x < 5.2000000000000003e36 or 5.79999999999999981e86 < x Initial program 97.4%
Taylor expanded in y around 0 67.1%
if -8.79999999999999948e210 < x < -1.3e41 or 5.2000000000000003e36 < x < 5.79999999999999981e86Initial program 100.0%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in z around 0 68.2%
mul-1-neg68.2%
distribute-rgt-neg-out68.2%
Simplified68.2%
if -2.05e-33 < x < 1.6999999999999999e-81Initial program 100.0%
Taylor expanded in x around 0 71.6%
Final simplification69.0%
(FPCore (x y z)
:precision binary64
(if (or (<= y -6.6e+101)
(not
(or (<= y -5.4e+46) (and (not (<= y -1.8e-149)) (<= y 3.3e-53)))))
(- y (* y x))
(* x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.6e+101) || !((y <= -5.4e+46) || (!(y <= -1.8e-149) && (y <= 3.3e-53)))) {
tmp = y - (y * x);
} else {
tmp = x * (z - 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 ((y <= (-6.6d+101)) .or. (.not. (y <= (-5.4d+46)) .or. (.not. (y <= (-1.8d-149))) .and. (y <= 3.3d-53))) then
tmp = y - (y * x)
else
tmp = x * (z - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6.6e+101) || !((y <= -5.4e+46) || (!(y <= -1.8e-149) && (y <= 3.3e-53)))) {
tmp = y - (y * x);
} else {
tmp = x * (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.6e+101) or not ((y <= -5.4e+46) or (not (y <= -1.8e-149) and (y <= 3.3e-53))): tmp = y - (y * x) else: tmp = x * (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.6e+101) || !((y <= -5.4e+46) || (!(y <= -1.8e-149) && (y <= 3.3e-53)))) tmp = Float64(y - Float64(y * x)); else tmp = Float64(x * Float64(z - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.6e+101) || ~(((y <= -5.4e+46) || (~((y <= -1.8e-149)) && (y <= 3.3e-53))))) tmp = y - (y * x); else tmp = x * (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.6e+101], N[Not[Or[LessEqual[y, -5.4e+46], And[N[Not[LessEqual[y, -1.8e-149]], $MachinePrecision], LessEqual[y, 3.3e-53]]]], $MachinePrecision]], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.6 \cdot 10^{+101} \lor \neg \left(y \leq -5.4 \cdot 10^{+46} \lor \neg \left(y \leq -1.8 \cdot 10^{-149}\right) \land y \leq 3.3 \cdot 10^{-53}\right):\\
\;\;\;\;y - y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z - y\right)\\
\end{array}
\end{array}
if y < -6.60000000000000022e101 or -5.4000000000000003e46 < y < -1.8000000000000001e-149 or 3.30000000000000004e-53 < y Initial program 98.0%
remove-double-neg98.0%
distribute-rgt-neg-out98.0%
neg-sub098.0%
neg-sub098.0%
*-commutative98.0%
distribute-lft-neg-in98.0%
remove-double-neg98.0%
distribute-rgt-out--98.0%
*-lft-identity98.0%
associate-+l-98.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 83.5%
*-commutative83.5%
Simplified83.5%
if -6.60000000000000022e101 < y < -5.4000000000000003e46 or -1.8000000000000001e-149 < y < 3.30000000000000004e-53Initial program 99.9%
Taylor expanded in x around inf 91.8%
mul-1-neg91.8%
unsub-neg91.8%
Simplified91.8%
Final simplification86.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z y))))
(if (<= x -1.65e-32)
t_0
(if (<= x 3.1e-82)
y
(if (<= x 3.7e-54) (* x z) (if (<= x 5.5e-26) y t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (z - y);
double tmp;
if (x <= -1.65e-32) {
tmp = t_0;
} else if (x <= 3.1e-82) {
tmp = y;
} else if (x <= 3.7e-54) {
tmp = x * z;
} else if (x <= 5.5e-26) {
tmp = y;
} 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.65d-32)) then
tmp = t_0
else if (x <= 3.1d-82) then
tmp = y
else if (x <= 3.7d-54) then
tmp = x * z
else if (x <= 5.5d-26) then
tmp = y
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.65e-32) {
tmp = t_0;
} else if (x <= 3.1e-82) {
tmp = y;
} else if (x <= 3.7e-54) {
tmp = x * z;
} else if (x <= 5.5e-26) {
tmp = y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z - y) tmp = 0 if x <= -1.65e-32: tmp = t_0 elif x <= 3.1e-82: tmp = y elif x <= 3.7e-54: tmp = x * z elif x <= 5.5e-26: tmp = y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z - y)) tmp = 0.0 if (x <= -1.65e-32) tmp = t_0; elseif (x <= 3.1e-82) tmp = y; elseif (x <= 3.7e-54) tmp = Float64(x * z); elseif (x <= 5.5e-26) tmp = y; 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.65e-32) tmp = t_0; elseif (x <= 3.1e-82) tmp = y; elseif (x <= 3.7e-54) tmp = x * z; elseif (x <= 5.5e-26) tmp = y; 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.65e-32], t$95$0, If[LessEqual[x, 3.1e-82], y, If[LessEqual[x, 3.7e-54], N[(x * z), $MachinePrecision], If[LessEqual[x, 5.5e-26], y, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z - y\right)\\
\mathbf{if}\;x \leq -1.65 \cdot 10^{-32}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3.1 \cdot 10^{-82}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{-54}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 5.5 \cdot 10^{-26}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.65000000000000013e-32 or 5.5000000000000005e-26 < x Initial program 97.9%
Taylor expanded in x around inf 93.6%
mul-1-neg93.6%
unsub-neg93.6%
Simplified93.6%
if -1.65000000000000013e-32 < x < 3.1e-82 or 3.7000000000000003e-54 < x < 5.5000000000000005e-26Initial program 100.0%
Taylor expanded in x around 0 72.3%
if 3.1e-82 < x < 3.7000000000000003e-54Initial program 100.0%
Taylor expanded in y around 0 89.4%
Final simplification85.1%
(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 97.6%
Taylor expanded in x around inf 99.0%
mul-1-neg99.0%
unsub-neg99.0%
Simplified99.0%
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.2%
neg-mul-198.2%
distribute-rgt-neg-in98.2%
Simplified98.2%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.6e-33) (not (<= x 7.2e-87))) (* x z) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.6e-33) || !(x <= 7.2e-87)) {
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.6d-33)) .or. (.not. (x <= 7.2d-87))) 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.6e-33) || !(x <= 7.2e-87)) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.6e-33) or not (x <= 7.2e-87): tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.6e-33) || !(x <= 7.2e-87)) tmp = Float64(x * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.6e-33) || ~((x <= 7.2e-87))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.6e-33], N[Not[LessEqual[x, 7.2e-87]], $MachinePrecision]], N[(x * z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{-33} \lor \neg \left(x \leq 7.2 \cdot 10^{-87}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.59999999999999988e-33 or 7.19999999999999986e-87 < x Initial program 98.1%
Taylor expanded in y around 0 59.5%
if -1.59999999999999988e-33 < x < 7.19999999999999986e-87Initial program 100.0%
Taylor expanded in x around 0 71.6%
Final simplification63.9%
(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.8%
Taylor expanded in x around 0 32.5%
Final simplification32.5%
(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 2024096
(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)))