
(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 6 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.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
(if (<= x -2.3e-13)
(* x z)
(if (<= x 6.8e-40)
y
(if (or (<= x 25000000000000.0) (not (<= x 1.9e+132)))
(* x z)
(* y (- x))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.3e-13) {
tmp = x * z;
} else if (x <= 6.8e-40) {
tmp = y;
} else if ((x <= 25000000000000.0) || !(x <= 1.9e+132)) {
tmp = x * z;
} else {
tmp = 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 (x <= (-2.3d-13)) then
tmp = x * z
else if (x <= 6.8d-40) then
tmp = y
else if ((x <= 25000000000000.0d0) .or. (.not. (x <= 1.9d+132))) then
tmp = x * z
else
tmp = y * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.3e-13) {
tmp = x * z;
} else if (x <= 6.8e-40) {
tmp = y;
} else if ((x <= 25000000000000.0) || !(x <= 1.9e+132)) {
tmp = x * z;
} else {
tmp = y * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.3e-13: tmp = x * z elif x <= 6.8e-40: tmp = y elif (x <= 25000000000000.0) or not (x <= 1.9e+132): tmp = x * z else: tmp = y * -x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.3e-13) tmp = Float64(x * z); elseif (x <= 6.8e-40) tmp = y; elseif ((x <= 25000000000000.0) || !(x <= 1.9e+132)) tmp = Float64(x * z); else tmp = Float64(y * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.3e-13) tmp = x * z; elseif (x <= 6.8e-40) tmp = y; elseif ((x <= 25000000000000.0) || ~((x <= 1.9e+132))) tmp = x * z; else tmp = y * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.3e-13], N[(x * z), $MachinePrecision], If[LessEqual[x, 6.8e-40], y, If[Or[LessEqual[x, 25000000000000.0], N[Not[LessEqual[x, 1.9e+132]], $MachinePrecision]], N[(x * z), $MachinePrecision], N[(y * (-x)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{-13}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 6.8 \cdot 10^{-40}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 25000000000000 \lor \neg \left(x \leq 1.9 \cdot 10^{+132}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\end{array}
\end{array}
if x < -2.29999999999999979e-13 or 6.79999999999999968e-40 < x < 2.5e13 or 1.90000000000000003e132 < x Initial program 96.6%
remove-double-neg96.6%
distribute-rgt-neg-out96.6%
neg-sub096.6%
neg-sub096.6%
*-commutative96.6%
distribute-lft-neg-in96.6%
remove-double-neg96.6%
distribute-rgt-out--96.6%
*-lft-identity96.6%
associate-+l-96.6%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around 0 61.3%
if -2.29999999999999979e-13 < x < 6.79999999999999968e-40Initial 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 inf 72.6%
Taylor expanded in x around 0 72.5%
if 2.5e13 < x < 1.90000000000000003e132Initial 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 x around inf 99.8%
Taylor expanded in z around 0 67.0%
associate-*r*67.0%
neg-mul-167.0%
Simplified67.0%
Final simplification66.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -450000000000.0) (not (<= x 4.2e-11))) (* x (- z y)) (+ y (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -450000000000.0) || !(x <= 4.2e-11)) {
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 <= (-450000000000.0d0)) .or. (.not. (x <= 4.2d-11))) 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 <= -450000000000.0) || !(x <= 4.2e-11)) {
tmp = x * (z - y);
} else {
tmp = y + (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -450000000000.0) or not (x <= 4.2e-11): tmp = x * (z - y) else: tmp = y + (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -450000000000.0) || !(x <= 4.2e-11)) 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 <= -450000000000.0) || ~((x <= 4.2e-11))) tmp = x * (z - y); else tmp = y + (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -450000000000.0], N[Not[LessEqual[x, 4.2e-11]], $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 -450000000000 \lor \neg \left(x \leq 4.2 \cdot 10^{-11}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot z\\
\end{array}
\end{array}
if x < -4.5e11 or 4.1999999999999997e-11 < x Initial program 97.1%
remove-double-neg97.1%
distribute-rgt-neg-out97.1%
neg-sub097.1%
neg-sub097.1%
*-commutative97.1%
distribute-lft-neg-in97.1%
remove-double-neg97.1%
distribute-rgt-out--97.1%
*-lft-identity97.1%
associate-+l-97.1%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around inf 99.6%
if -4.5e11 < x < 4.1999999999999997e-11Initial 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.3%
mul-1-neg99.3%
distribute-rgt-neg-out99.3%
Simplified99.3%
*-commutative99.3%
cancel-sign-sub99.3%
*-commutative99.3%
+-commutative99.3%
Applied egg-rr99.3%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.5e-13) (not (<= x 9.6e-12))) (* x (- z y)) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.5e-13) || !(x <= 9.6e-12)) {
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 <= (-1.5d-13)) .or. (.not. (x <= 9.6d-12))) 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 <= -1.5e-13) || !(x <= 9.6e-12)) {
tmp = x * (z - y);
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.5e-13) or not (x <= 9.6e-12): tmp = x * (z - y) else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.5e-13) || !(x <= 9.6e-12)) 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 <= -1.5e-13) || ~((x <= 9.6e-12))) tmp = x * (z - y); else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.5e-13], N[Not[LessEqual[x, 9.6e-12]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{-13} \lor \neg \left(x \leq 9.6 \cdot 10^{-12}\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.49999999999999992e-13 or 9.59999999999999948e-12 < x Initial program 97.2%
remove-double-neg97.2%
distribute-rgt-neg-out97.2%
neg-sub097.2%
neg-sub097.2%
*-commutative97.2%
distribute-lft-neg-in97.2%
remove-double-neg97.2%
distribute-rgt-out--97.2%
*-lft-identity97.2%
associate-+l-97.2%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around inf 99.0%
if -1.49999999999999992e-13 < x < 9.59999999999999948e-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 y around inf 71.5%
Taylor expanded in x around 0 71.4%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.4e-14) (not (<= x 9e-40))) (* x z) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.4e-14) || !(x <= 9e-40)) {
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 <= (-9.4d-14)) .or. (.not. (x <= 9d-40))) 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 <= -9.4e-14) || !(x <= 9e-40)) {
tmp = x * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.4e-14) or not (x <= 9e-40): tmp = x * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.4e-14) || !(x <= 9e-40)) tmp = Float64(x * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9.4e-14) || ~((x <= 9e-40))) tmp = x * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.4e-14], N[Not[LessEqual[x, 9e-40]], $MachinePrecision]], N[(x * z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.4 \cdot 10^{-14} \lor \neg \left(x \leq 9 \cdot 10^{-40}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -9.4000000000000003e-14 or 9.0000000000000002e-40 < x Initial program 97.3%
remove-double-neg97.3%
distribute-rgt-neg-out97.3%
neg-sub097.3%
neg-sub097.3%
*-commutative97.3%
distribute-lft-neg-in97.3%
remove-double-neg97.3%
distribute-rgt-out--97.3%
*-lft-identity97.3%
associate-+l-97.3%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around 0 56.2%
if -9.4000000000000003e-14 < x < 9.0000000000000002e-40Initial 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 inf 72.6%
Taylor expanded in x around 0 72.5%
Final simplification63.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%
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%
Taylor expanded in y around inf 60.2%
Taylor expanded in x around 0 33.1%
(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 2024137
(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)))