
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
return (x * y) + ((1.0 - 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 = (x * y) + ((1.0d0 - x) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
def code(x, y, z): return (x * y) + ((1.0 - x) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(1.0 - x) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((1.0 - x) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(1 - x\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
return (x * y) + ((1.0 - 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 = (x * y) + ((1.0d0 - x) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
def code(x, y, z): return (x * y) + ((1.0 - x) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(1.0 - x) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((1.0 - x) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(1 - x\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma x (- y z) z))
double code(double x, double y, double z) {
return fma(x, (y - z), z);
}
function code(x, y, z) return fma(x, Float64(y - z), z) end
code[x_, y_, z_] := N[(x * N[(y - z), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y - z, z\right)
\end{array}
Initial program 97.6%
*-commutative97.6%
distribute-lft-out--97.6%
*-rgt-identity97.6%
cancel-sign-sub-inv97.6%
+-commutative97.6%
associate-+r+97.6%
+-commutative97.6%
*-commutative97.6%
distribute-rgt-out100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.8e-187) (not (<= y 7.3e-93))) (+ z (* x y)) (- z (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.8e-187) || !(y <= 7.3e-93)) {
tmp = z + (x * y);
} else {
tmp = z - (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 <= (-1.8d-187)) .or. (.not. (y <= 7.3d-93))) then
tmp = z + (x * y)
else
tmp = z - (x * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.8e-187) || !(y <= 7.3e-93)) {
tmp = z + (x * y);
} else {
tmp = z - (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.8e-187) or not (y <= 7.3e-93): tmp = z + (x * y) else: tmp = z - (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.8e-187) || !(y <= 7.3e-93)) tmp = Float64(z + Float64(x * y)); else tmp = Float64(z - Float64(x * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.8e-187) || ~((y <= 7.3e-93))) tmp = z + (x * y); else tmp = z - (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.8e-187], N[Not[LessEqual[y, 7.3e-93]], $MachinePrecision]], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(z - N[(x * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{-187} \lor \neg \left(y \leq 7.3 \cdot 10^{-93}\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot z\\
\end{array}
\end{array}
if y < -1.79999999999999997e-187 or 7.29999999999999976e-93 < y Initial program 96.8%
+-commutative96.8%
remove-double-neg96.8%
distribute-rgt-neg-out96.8%
neg-sub096.8%
neg-sub096.8%
*-commutative96.8%
distribute-lft-neg-in96.8%
remove-double-neg96.8%
distribute-rgt-out--96.9%
*-lft-identity96.9%
associate-+l-96.9%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 88.9%
mul-1-neg88.9%
distribute-rgt-neg-out88.9%
Simplified88.9%
*-commutative88.9%
cancel-sign-sub88.9%
*-commutative88.9%
+-commutative88.9%
Applied egg-rr88.9%
if -1.79999999999999997e-187 < y < 7.29999999999999976e-93Initial program 100.0%
+-commutative100.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.6%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.2e-9) (not (<= x 2.8e-60))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.2e-9) || !(x <= 2.8e-60)) {
tmp = x * y;
} else {
tmp = 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 <= (-2.2d-9)) .or. (.not. (x <= 2.8d-60))) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.2e-9) || !(x <= 2.8e-60)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.2e-9) or not (x <= 2.8e-60): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.2e-9) || !(x <= 2.8e-60)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.2e-9) || ~((x <= 2.8e-60))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.2e-9], N[Not[LessEqual[x, 2.8e-60]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.2 \cdot 10^{-9} \lor \neg \left(x \leq 2.8 \cdot 10^{-60}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -2.1999999999999998e-9 or 2.8000000000000002e-60 < x Initial program 95.2%
+-commutative95.2%
remove-double-neg95.2%
distribute-rgt-neg-out95.2%
neg-sub095.2%
neg-sub095.2%
*-commutative95.2%
distribute-lft-neg-in95.2%
remove-double-neg95.2%
distribute-rgt-out--95.2%
*-lft-identity95.2%
associate-+l-95.2%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 59.8%
if -2.1999999999999998e-9 < x < 2.8000000000000002e-60Initial program 100.0%
+-commutative100.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 87.5%
sub-neg87.5%
+-commutative87.5%
neg-mul-187.5%
distribute-neg-in87.5%
remove-double-neg87.5%
mul-1-neg87.5%
associate-+r+87.5%
distribute-lft-in87.5%
+-commutative87.5%
mul-1-neg87.5%
sub-neg87.5%
div-sub87.6%
sub-neg87.6%
mul-1-neg87.6%
Simplified87.6%
Taylor expanded in x around 0 77.0%
Final simplification68.5%
(FPCore (x y z) :precision binary64 (+ z (* x (- y z))))
double code(double x, double y, double z) {
return z + (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 = z + (x * (y - z))
end function
public static double code(double x, double y, double z) {
return z + (x * (y - z));
}
def code(x, y, z): return z + (x * (y - z))
function code(x, y, z) return Float64(z + Float64(x * Float64(y - z))) end
function tmp = code(x, y, z) tmp = z + (x * (y - z)); end
code[x_, y_, z_] := N[(z + N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot \left(y - z\right)
\end{array}
Initial program 97.6%
+-commutative97.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 (+ z (* x y)))
double code(double x, double y, double z) {
return z + (x * y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (x * y)
end function
public static double code(double x, double y, double z) {
return z + (x * y);
}
def code(x, y, z): return z + (x * y)
function code(x, y, z) return Float64(z + Float64(x * y)) end
function tmp = code(x, y, z) tmp = z + (x * y); end
code[x_, y_, z_] := N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot y
\end{array}
Initial program 97.6%
+-commutative97.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 0 81.1%
mul-1-neg81.1%
distribute-rgt-neg-out81.1%
Simplified81.1%
*-commutative81.1%
cancel-sign-sub81.1%
*-commutative81.1%
+-commutative81.1%
Applied egg-rr81.1%
Final simplification81.1%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 97.6%
+-commutative97.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 inf 86.0%
sub-neg86.0%
+-commutative86.0%
neg-mul-186.0%
distribute-neg-in86.0%
remove-double-neg86.0%
mul-1-neg86.0%
associate-+r+86.0%
distribute-lft-in85.2%
+-commutative85.2%
mul-1-neg85.2%
sub-neg85.2%
div-sub86.6%
sub-neg86.6%
mul-1-neg86.6%
Simplified87.4%
Taylor expanded in x around 0 41.5%
herbie shell --seed 2024130
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))