
(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.0%
*-commutative98.0%
distribute-rgt-out--98.0%
*-lft-identity98.0%
associate-+l-98.0%
distribute-lft-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= x -5e+191)
(* x z)
(if (<= x -1.9e+113)
t_0
(if (<= x -6.6e+80)
(* x z)
(if (<= x -2.45e+19)
t_0
(if (<= x -4.8e-51)
(* x z)
(if (<= x 3.2e-95) y (if (<= x 6.5e+143) (* x z) t_0)))))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (x <= -5e+191) {
tmp = x * z;
} else if (x <= -1.9e+113) {
tmp = t_0;
} else if (x <= -6.6e+80) {
tmp = x * z;
} else if (x <= -2.45e+19) {
tmp = t_0;
} else if (x <= -4.8e-51) {
tmp = x * z;
} else if (x <= 3.2e-95) {
tmp = y;
} else if (x <= 6.5e+143) {
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 <= (-5d+191)) then
tmp = x * z
else if (x <= (-1.9d+113)) then
tmp = t_0
else if (x <= (-6.6d+80)) then
tmp = x * z
else if (x <= (-2.45d+19)) then
tmp = t_0
else if (x <= (-4.8d-51)) then
tmp = x * z
else if (x <= 3.2d-95) then
tmp = y
else if (x <= 6.5d+143) 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 <= -5e+191) {
tmp = x * z;
} else if (x <= -1.9e+113) {
tmp = t_0;
} else if (x <= -6.6e+80) {
tmp = x * z;
} else if (x <= -2.45e+19) {
tmp = t_0;
} else if (x <= -4.8e-51) {
tmp = x * z;
} else if (x <= 3.2e-95) {
tmp = y;
} else if (x <= 6.5e+143) {
tmp = x * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if x <= -5e+191: tmp = x * z elif x <= -1.9e+113: tmp = t_0 elif x <= -6.6e+80: tmp = x * z elif x <= -2.45e+19: tmp = t_0 elif x <= -4.8e-51: tmp = x * z elif x <= 3.2e-95: tmp = y elif x <= 6.5e+143: 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 <= -5e+191) tmp = Float64(x * z); elseif (x <= -1.9e+113) tmp = t_0; elseif (x <= -6.6e+80) tmp = Float64(x * z); elseif (x <= -2.45e+19) tmp = t_0; elseif (x <= -4.8e-51) tmp = Float64(x * z); elseif (x <= 3.2e-95) tmp = y; elseif (x <= 6.5e+143) 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 <= -5e+191) tmp = x * z; elseif (x <= -1.9e+113) tmp = t_0; elseif (x <= -6.6e+80) tmp = x * z; elseif (x <= -2.45e+19) tmp = t_0; elseif (x <= -4.8e-51) tmp = x * z; elseif (x <= 3.2e-95) tmp = y; elseif (x <= 6.5e+143) 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, -5e+191], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.9e+113], t$95$0, If[LessEqual[x, -6.6e+80], N[(x * z), $MachinePrecision], If[LessEqual[x, -2.45e+19], t$95$0, If[LessEqual[x, -4.8e-51], N[(x * z), $MachinePrecision], If[LessEqual[x, 3.2e-95], y, If[LessEqual[x, 6.5e+143], N[(x * z), $MachinePrecision], t$95$0]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -5 \cdot 10^{+191}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.9 \cdot 10^{+113}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -6.6 \cdot 10^{+80}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -2.45 \cdot 10^{+19}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -4.8 \cdot 10^{-51}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{-95}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 6.5 \cdot 10^{+143}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -5.0000000000000002e191 or -1.9000000000000002e113 < x < -6.59999999999999982e80 or -2.45e19 < x < -4.8e-51 or 3.1999999999999997e-95 < x < 6.4999999999999997e143Initial program 98.1%
Taylor expanded in y around 0 62.2%
if -5.0000000000000002e191 < x < -1.9000000000000002e113 or -6.59999999999999982e80 < x < -2.45e19 or 6.4999999999999997e143 < x Initial program 95.2%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in z around 0 78.1%
mul-1-neg78.1%
distribute-rgt-neg-out78.1%
Simplified78.1%
if -4.8e-51 < x < 3.1999999999999997e-95Initial program 100.0%
Taylor expanded in x around 0 78.1%
Final simplification71.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -2e-59) (not (<= x 4.7e-91))) (* x (- z y)) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2e-59) || !(x <= 4.7e-91)) {
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 <= (-2d-59)) .or. (.not. (x <= 4.7d-91))) 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 <= -2e-59) || !(x <= 4.7e-91)) {
tmp = x * (z - y);
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2e-59) or not (x <= 4.7e-91): tmp = x * (z - y) else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2e-59) || !(x <= 4.7e-91)) 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 <= -2e-59) || ~((x <= 4.7e-91))) tmp = x * (z - y); else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2e-59], N[Not[LessEqual[x, 4.7e-91]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-59} \lor \neg \left(x \leq 4.7 \cdot 10^{-91}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -2.0000000000000001e-59 or 4.70000000000000006e-91 < x Initial program 97.1%
Taylor expanded in x around inf 91.7%
mul-1-neg91.7%
sub-neg91.7%
Simplified91.7%
if -2.0000000000000001e-59 < x < 4.70000000000000006e-91Initial program 100.0%
Taylor expanded in x around 0 78.7%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.55e-23) (not (<= y 6e+74))) (* y (- 1.0 x)) (* x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.55e-23) || !(y <= 6e+74)) {
tmp = y * (1.0 - 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 <= (-2.55d-23)) .or. (.not. (y <= 6d+74))) then
tmp = y * (1.0d0 - 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 <= -2.55e-23) || !(y <= 6e+74)) {
tmp = y * (1.0 - x);
} else {
tmp = x * (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.55e-23) or not (y <= 6e+74): tmp = y * (1.0 - x) else: tmp = x * (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.55e-23) || !(y <= 6e+74)) tmp = Float64(y * Float64(1.0 - x)); else tmp = Float64(x * Float64(z - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.55e-23) || ~((y <= 6e+74))) tmp = y * (1.0 - x); else tmp = x * (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.55e-23], N[Not[LessEqual[y, 6e+74]], $MachinePrecision]], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.55 \cdot 10^{-23} \lor \neg \left(y \leq 6 \cdot 10^{+74}\right):\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z - y\right)\\
\end{array}
\end{array}
if y < -2.55000000000000005e-23 or 6e74 < y Initial program 95.9%
Taylor expanded in y around inf 88.2%
if -2.55000000000000005e-23 < y < 6e74Initial program 100.0%
Taylor expanded in x around inf 86.2%
mul-1-neg86.2%
sub-neg86.2%
Simplified86.2%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (<= y -2.55e-23) (* y (- 1.0 x)) (if (<= y 2.25e+74) (* x (- z y)) (- y (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.55e-23) {
tmp = y * (1.0 - x);
} else if (y <= 2.25e+74) {
tmp = x * (z - y);
} else {
tmp = y - (y * x);
}
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 <= (-2.55d-23)) then
tmp = y * (1.0d0 - x)
else if (y <= 2.25d+74) then
tmp = x * (z - y)
else
tmp = y - (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.55e-23) {
tmp = y * (1.0 - x);
} else if (y <= 2.25e+74) {
tmp = x * (z - y);
} else {
tmp = y - (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.55e-23: tmp = y * (1.0 - x) elif y <= 2.25e+74: tmp = x * (z - y) else: tmp = y - (y * x) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.55e-23) tmp = Float64(y * Float64(1.0 - x)); elseif (y <= 2.25e+74) tmp = Float64(x * Float64(z - y)); else tmp = Float64(y - Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.55e-23) tmp = y * (1.0 - x); elseif (y <= 2.25e+74) tmp = x * (z - y); else tmp = y - (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.55e-23], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.25e+74], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.55 \cdot 10^{-23}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\mathbf{elif}\;y \leq 2.25 \cdot 10^{+74}:\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot x\\
\end{array}
\end{array}
if y < -2.55000000000000005e-23Initial program 97.2%
Taylor expanded in y around inf 87.9%
if -2.55000000000000005e-23 < y < 2.25e74Initial program 100.0%
Taylor expanded in x around inf 86.2%
mul-1-neg86.2%
sub-neg86.2%
Simplified86.2%
if 2.25e74 < y Initial program 94.1%
*-commutative94.1%
distribute-rgt-out--94.1%
*-lft-identity94.1%
associate-+l-94.1%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 88.7%
*-commutative88.7%
Simplified88.7%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.8e-50) (not (<= x 3.8e-93))) (* x z) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.8e-50) || !(x <= 3.8e-93)) {
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.8d-50)) .or. (.not. (x <= 3.8d-93))) 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.8e-50) || !(x <= 3.8e-93)) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.8e-50) or not (x <= 3.8e-93): tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.8e-50) || !(x <= 3.8e-93)) tmp = Float64(x * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.8e-50) || ~((x <= 3.8e-93))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.8e-50], N[Not[LessEqual[x, 3.8e-93]], $MachinePrecision]], N[(x * z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{-50} \lor \neg \left(x \leq 3.8 \cdot 10^{-93}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.7999999999999999e-50 or 3.7999999999999999e-93 < x Initial program 97.0%
Taylor expanded in y around 0 50.3%
if -1.7999999999999999e-50 < x < 3.7999999999999999e-93Initial program 100.0%
Taylor expanded in x around 0 78.1%
Final simplification59.7%
(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.0%
Taylor expanded in x around 0 31.6%
Final simplification31.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 2024109
(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)))