
(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 (fma (- z y) x y))
double code(double x, double y, double z) {
return fma((z - y), x, y);
}
function code(x, y, z) return fma(Float64(z - y), x, y) end
code[x_, y_, z_] := N[(N[(z - y), $MachinePrecision] * x + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z - y, x, y\right)
\end{array}
Initial program 98.4%
*-commutative98.4%
distribute-rgt-out--98.4%
*-lft-identity98.4%
associate-+l-98.4%
distribute-lft-out--100.0%
Simplified100.0%
sub-neg100.0%
+-commutative100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
fma-define100.0%
Applied egg-rr100.0%
neg-sub0100.0%
associate--r-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- z y) x)))
(if (<= x -1e-9)
t_0
(if (<= x -2.2e-40)
(- y (* y x))
(if (or (<= x -1.9e-137) (not (<= x 2.6e-74))) t_0 y)))))
double code(double x, double y, double z) {
double t_0 = (z - y) * x;
double tmp;
if (x <= -1e-9) {
tmp = t_0;
} else if (x <= -2.2e-40) {
tmp = y - (y * x);
} else if ((x <= -1.9e-137) || !(x <= 2.6e-74)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = (z - y) * x
if (x <= (-1d-9)) then
tmp = t_0
else if (x <= (-2.2d-40)) then
tmp = y - (y * x)
else if ((x <= (-1.9d-137)) .or. (.not. (x <= 2.6d-74))) then
tmp = t_0
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (z - y) * x;
double tmp;
if (x <= -1e-9) {
tmp = t_0;
} else if (x <= -2.2e-40) {
tmp = y - (y * x);
} else if ((x <= -1.9e-137) || !(x <= 2.6e-74)) {
tmp = t_0;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): t_0 = (z - y) * x tmp = 0 if x <= -1e-9: tmp = t_0 elif x <= -2.2e-40: tmp = y - (y * x) elif (x <= -1.9e-137) or not (x <= 2.6e-74): tmp = t_0 else: tmp = y return tmp
function code(x, y, z) t_0 = Float64(Float64(z - y) * x) tmp = 0.0 if (x <= -1e-9) tmp = t_0; elseif (x <= -2.2e-40) tmp = Float64(y - Float64(y * x)); elseif ((x <= -1.9e-137) || !(x <= 2.6e-74)) tmp = t_0; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z - y) * x; tmp = 0.0; if (x <= -1e-9) tmp = t_0; elseif (x <= -2.2e-40) tmp = y - (y * x); elseif ((x <= -1.9e-137) || ~((x <= 2.6e-74))) tmp = t_0; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z - y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1e-9], t$95$0, If[LessEqual[x, -2.2e-40], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, -1.9e-137], N[Not[LessEqual[x, 2.6e-74]], $MachinePrecision]], t$95$0, y]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z - y\right) \cdot x\\
\mathbf{if}\;x \leq -1 \cdot 10^{-9}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -2.2 \cdot 10^{-40}:\\
\;\;\;\;y - y \cdot x\\
\mathbf{elif}\;x \leq -1.9 \cdot 10^{-137} \lor \neg \left(x \leq 2.6 \cdot 10^{-74}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.00000000000000006e-9 or -2.20000000000000009e-40 < x < -1.89999999999999999e-137 or 2.6000000000000001e-74 < x Initial program 97.6%
*-commutative97.6%
distribute-rgt-out--97.6%
*-lft-identity97.6%
associate-+l-97.6%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around inf 90.2%
if -1.00000000000000006e-9 < x < -2.20000000000000009e-40Initial program 99.6%
*-commutative99.6%
distribute-rgt-out--100.0%
*-lft-identity100.0%
associate-+l-100.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 75.5%
if -1.89999999999999999e-137 < x < 2.6000000000000001e-74Initial program 100.0%
*-commutative100.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 0 87.0%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.9e-137) (not (<= x 1.75e-75))) (* (- z y) x) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.9e-137) || !(x <= 1.75e-75)) {
tmp = (z - y) * x;
} 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.9d-137)) .or. (.not. (x <= 1.75d-75))) then
tmp = (z - y) * x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.9e-137) || !(x <= 1.75e-75)) {
tmp = (z - y) * x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.9e-137) or not (x <= 1.75e-75): tmp = (z - y) * x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.9e-137) || !(x <= 1.75e-75)) tmp = Float64(Float64(z - y) * x); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.9e-137) || ~((x <= 1.75e-75))) tmp = (z - y) * x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.9e-137], N[Not[LessEqual[x, 1.75e-75]], $MachinePrecision]], N[(N[(z - y), $MachinePrecision] * x), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{-137} \lor \neg \left(x \leq 1.75 \cdot 10^{-75}\right):\\
\;\;\;\;\left(z - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.89999999999999999e-137 or 1.74999999999999993e-75 < x Initial program 97.7%
*-commutative97.7%
distribute-rgt-out--97.7%
*-lft-identity97.7%
associate-+l-97.7%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around inf 87.2%
if -1.89999999999999999e-137 < x < 1.74999999999999993e-75Initial program 100.0%
*-commutative100.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 0 87.0%
Final simplification87.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.05e-9) (not (<= x 1.7e-74))) (* z x) y))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.05e-9) || !(x <= 1.7e-74)) {
tmp = z * x;
} 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.05d-9)) .or. (.not. (x <= 1.7d-74))) then
tmp = z * x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.05e-9) || !(x <= 1.7e-74)) {
tmp = z * x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.05e-9) or not (x <= 1.7e-74): tmp = z * x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.05e-9) || !(x <= 1.7e-74)) tmp = Float64(z * x); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.05e-9) || ~((x <= 1.7e-74))) tmp = z * x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.05e-9], N[Not[LessEqual[x, 1.7e-74]], $MachinePrecision]], N[(z * x), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{-9} \lor \neg \left(x \leq 1.7 \cdot 10^{-74}\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.0500000000000001e-9 or 1.7e-74 < x Initial program 97.2%
*-commutative97.2%
distribute-rgt-out--97.2%
*-lft-identity97.2%
associate-+l-97.2%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around 0 51.1%
if -1.0500000000000001e-9 < x < 1.7e-74Initial program 100.0%
*-commutative100.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 0 77.5%
Final simplification62.4%
(FPCore (x y z) :precision binary64 (+ y (* (- z y) x)))
double code(double x, double y, double z) {
return y + ((z - y) * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y + ((z - y) * x)
end function
public static double code(double x, double y, double z) {
return y + ((z - y) * x);
}
def code(x, y, z): return y + ((z - y) * x)
function code(x, y, z) return Float64(y + Float64(Float64(z - y) * x)) end
function tmp = code(x, y, z) tmp = y + ((z - y) * x); end
code[x_, y_, z_] := N[(y + N[(N[(z - y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + \left(z - y\right) \cdot x
\end{array}
Initial program 98.4%
*-commutative98.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%
*-commutative98.4%
distribute-rgt-out--98.4%
*-lft-identity98.4%
associate-+l-98.4%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around 0 37.7%
Final simplification37.7%
(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 2024048
(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)))