
(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 5 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 97.6%
remove-double-neg97.6%
distribute-rgt-neg-out97.6%
neg-sub097.6%
neg-sub097.6%
*-commutative97.6%
distribute-lft-neg-in97.6%
remove-double-neg97.6%
distribute-rgt-out--97.6%
*-lft-identity97.6%
associate-+l-97.6%
distribute-lft-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.2e+54) (not (<= y 2.25e+141))) (- y (* y x)) (+ y (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.2e+54) || !(y <= 2.25e+141)) {
tmp = y - (y * x);
} 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 ((y <= (-7.2d+54)) .or. (.not. (y <= 2.25d+141))) then
tmp = y - (y * x)
else
tmp = y + (x * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -7.2e+54) || !(y <= 2.25e+141)) {
tmp = y - (y * x);
} else {
tmp = y + (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.2e+54) or not (y <= 2.25e+141): tmp = y - (y * x) else: tmp = y + (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.2e+54) || !(y <= 2.25e+141)) tmp = Float64(y - Float64(y * x)); else tmp = Float64(y + Float64(x * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -7.2e+54) || ~((y <= 2.25e+141))) tmp = y - (y * x); else tmp = y + (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.2e+54], N[Not[LessEqual[y, 2.25e+141]], $MachinePrecision]], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision], N[(y + N[(x * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{+54} \lor \neg \left(y \leq 2.25 \cdot 10^{+141}\right):\\
\;\;\;\;y - y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot z\\
\end{array}
\end{array}
if y < -7.2000000000000003e54 or 2.2500000000000001e141 < y Initial program 94.7%
remove-double-neg94.7%
distribute-rgt-neg-out94.7%
neg-sub094.7%
neg-sub094.7%
*-commutative94.7%
distribute-lft-neg-in94.7%
remove-double-neg94.7%
distribute-rgt-out--94.7%
*-lft-identity94.7%
associate-+l-94.7%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 94.8%
if -7.2000000000000003e54 < y < 2.2500000000000001e141Initial program 99.4%
remove-double-neg99.4%
distribute-rgt-neg-out99.4%
neg-sub099.4%
neg-sub099.4%
*-commutative99.4%
distribute-lft-neg-in99.4%
remove-double-neg99.4%
distribute-rgt-out--99.4%
*-lft-identity99.4%
associate-+l-99.4%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around 0 86.0%
mul-1-neg86.0%
distribute-rgt-neg-out86.0%
Simplified86.0%
*-commutative86.0%
cancel-sign-sub86.0%
*-commutative86.0%
+-commutative86.0%
Applied egg-rr86.0%
Final simplification89.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.8e-32) (not (<= x 1.3e-12))) (* x z) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.8e-32) || !(x <= 1.3e-12)) {
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-32)) .or. (.not. (x <= 1.3d-12))) 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-32) || !(x <= 1.3e-12)) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.8e-32) or not (x <= 1.3e-12): tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.8e-32) || !(x <= 1.3e-12)) 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-32) || ~((x <= 1.3e-12))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.8e-32], N[Not[LessEqual[x, 1.3e-12]], $MachinePrecision]], N[(x * z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{-32} \lor \neg \left(x \leq 1.3 \cdot 10^{-12}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -4.8000000000000003e-32 or 1.29999999999999991e-12 < x Initial program 95.0%
remove-double-neg95.0%
distribute-rgt-neg-out95.0%
neg-sub095.0%
neg-sub095.0%
*-commutative95.0%
distribute-lft-neg-in95.0%
remove-double-neg95.0%
distribute-rgt-out--95.0%
*-lft-identity95.0%
associate-+l-95.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around 0 46.0%
if -4.8000000000000003e-32 < x < 1.29999999999999991e-12Initial 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 z around inf 90.0%
sub-neg90.0%
+-commutative90.0%
neg-mul-190.0%
distribute-neg-in90.0%
remove-double-neg90.0%
mul-1-neg90.0%
associate-+r+90.0%
distribute-lft-in90.0%
+-commutative90.0%
mul-1-neg90.0%
sub-neg90.0%
div-sub90.0%
sub-neg90.0%
mul-1-neg90.0%
Simplified90.0%
Taylor expanded in x around 0 74.5%
Final simplification61.0%
(FPCore (x y z) :precision binary64 (+ y (* x z)))
double code(double x, double y, double z) {
return 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 = y + (x * z)
end function
public static double code(double x, double y, double z) {
return y + (x * z);
}
def code(x, y, z): return y + (x * z)
function code(x, y, z) return Float64(y + Float64(x * z)) end
function tmp = code(x, y, z) tmp = y + (x * z); end
code[x_, y_, z_] := N[(y + N[(x * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + x \cdot z
\end{array}
Initial program 97.6%
remove-double-neg97.6%
distribute-rgt-neg-out97.6%
neg-sub097.6%
neg-sub097.6%
*-commutative97.6%
distribute-lft-neg-in97.6%
remove-double-neg97.6%
distribute-rgt-out--97.6%
*-lft-identity97.6%
associate-+l-97.6%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around 0 74.7%
mul-1-neg74.7%
distribute-rgt-neg-out74.7%
Simplified74.7%
*-commutative74.7%
cancel-sign-sub74.7%
*-commutative74.7%
+-commutative74.7%
Applied egg-rr74.7%
Final simplification74.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 97.6%
remove-double-neg97.6%
distribute-rgt-neg-out97.6%
neg-sub097.6%
neg-sub097.6%
*-commutative97.6%
distribute-lft-neg-in97.6%
remove-double-neg97.6%
distribute-rgt-out--97.6%
*-lft-identity97.6%
associate-+l-97.6%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 86.1%
sub-neg86.1%
+-commutative86.1%
neg-mul-186.1%
distribute-neg-in86.1%
remove-double-neg86.1%
mul-1-neg86.1%
associate-+r+86.1%
distribute-lft-in84.5%
+-commutative84.5%
mul-1-neg84.5%
sub-neg84.5%
div-sub86.9%
sub-neg86.9%
mul-1-neg86.9%
Simplified88.5%
Taylor expanded in x around 0 40.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 2024130
(FPCore (x y z)
:name "Diagrams.Color.HSV:lerp from diagrams-contrib-1.3.0.5"
:precision binary64
:alt
(! :herbie-platform default (- y (* x (- y z))))
(+ (* (- 1.0 x) y) (* x z)))