
(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 7 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 96.8%
sub-neg96.8%
+-commutative96.8%
distribute-lft1-in96.8%
associate-+r+96.8%
+-commutative96.8%
*-commutative96.8%
neg-mul-196.8%
associate-*r*96.8%
*-commutative96.8%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.5e-69) (not (<= z 9.8e-107))) (* z (- 1.0 x)) (* x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.5e-69) || !(z <= 9.8e-107)) {
tmp = z * (1.0 - x);
} else {
tmp = x * 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 ((z <= (-2.5d-69)) .or. (.not. (z <= 9.8d-107))) then
tmp = z * (1.0d0 - x)
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.5e-69) || !(z <= 9.8e-107)) {
tmp = z * (1.0 - x);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.5e-69) or not (z <= 9.8e-107): tmp = z * (1.0 - x) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.5e-69) || !(z <= 9.8e-107)) tmp = Float64(z * Float64(1.0 - x)); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.5e-69) || ~((z <= 9.8e-107))) tmp = z * (1.0 - x); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.5e-69], N[Not[LessEqual[z, 9.8e-107]], $MachinePrecision]], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.5 \cdot 10^{-69} \lor \neg \left(z \leq 9.8 \cdot 10^{-107}\right):\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if z < -2.50000000000000017e-69 or 9.79999999999999959e-107 < z Initial program 94.7%
Taylor expanded in y around 0 83.3%
if -2.50000000000000017e-69 < z < 9.79999999999999959e-107Initial program 100.0%
Taylor expanded in y around inf 68.8%
Final simplification77.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.2e-108) (not (<= x 2.8e-32))) (* x (- y z)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.2e-108) || !(x <= 2.8e-32)) {
tmp = x * (y - z);
} 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 <= (-5.2d-108)) .or. (.not. (x <= 2.8d-32))) then
tmp = x * (y - z)
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.2e-108) || !(x <= 2.8e-32)) {
tmp = x * (y - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.2e-108) or not (x <= 2.8e-32): tmp = x * (y - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.2e-108) || !(x <= 2.8e-32)) tmp = Float64(x * Float64(y - z)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.2e-108) || ~((x <= 2.8e-32))) tmp = x * (y - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.2e-108], N[Not[LessEqual[x, 2.8e-32]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{-108} \lor \neg \left(x \leq 2.8 \cdot 10^{-32}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -5.19999999999999968e-108 or 2.7999999999999999e-32 < x Initial program 94.3%
Taylor expanded in x around inf 92.3%
neg-mul-192.3%
+-commutative92.3%
unsub-neg92.3%
Simplified92.3%
if -5.19999999999999968e-108 < x < 2.7999999999999999e-32Initial program 100.0%
Taylor expanded in x around 0 74.3%
Final simplification84.3%
(FPCore (x y z) :precision binary64 (if (<= x -2.6e-81) (* x y) (if (<= x 3.5e-33) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.6e-81) {
tmp = x * y;
} else if (x <= 3.5e-33) {
tmp = z;
} else {
tmp = x * 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 <= (-2.6d-81)) then
tmp = x * y
else if (x <= 3.5d-33) then
tmp = z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.6e-81) {
tmp = x * y;
} else if (x <= 3.5e-33) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.6e-81: tmp = x * y elif x <= 3.5e-33: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.6e-81) tmp = Float64(x * y); elseif (x <= 3.5e-33) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.6e-81) tmp = x * y; elseif (x <= 3.5e-33) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.6e-81], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.5e-33], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{-81}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{-33}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -2.5999999999999999e-81 or 3.4999999999999999e-33 < x Initial program 94.1%
Taylor expanded in y around inf 48.9%
if -2.5999999999999999e-81 < x < 3.4999999999999999e-33Initial program 100.0%
Taylor expanded in x around 0 73.6%
Final simplification60.4%
(FPCore (x y z) :precision binary64 (if (<= x -1.0) (* x (- z)) (if (<= x 6.1e-33) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.0) {
tmp = x * -z;
} else if (x <= 6.1e-33) {
tmp = z;
} else {
tmp = x * 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.0d0)) then
tmp = x * -z
else if (x <= 6.1d-33) then
tmp = z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.0) {
tmp = x * -z;
} else if (x <= 6.1e-33) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.0: tmp = x * -z elif x <= 6.1e-33: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.0) tmp = Float64(x * Float64(-z)); elseif (x <= 6.1e-33) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.0) tmp = x * -z; elseif (x <= 6.1e-33) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.0], N[(x * (-z)), $MachinePrecision], If[LessEqual[x, 6.1e-33], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{elif}\;x \leq 6.1 \cdot 10^{-33}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1Initial program 89.7%
Taylor expanded in y around 0 65.1%
Taylor expanded in x around inf 63.4%
associate-*r*63.4%
mul-1-neg63.4%
Simplified63.4%
if -1 < x < 6.1000000000000001e-33Initial program 100.0%
Taylor expanded in x around 0 69.1%
if 6.1000000000000001e-33 < x Initial program 96.7%
Taylor expanded in y around inf 60.6%
Final simplification65.8%
(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 96.8%
Taylor expanded in x around 0 100.0%
Taylor expanded in z around 0 96.8%
*-commutative96.8%
neg-mul-196.8%
distribute-lft-in96.8%
*-rgt-identity96.8%
associate-+l+96.8%
+-commutative96.8%
distribute-rgt-neg-out96.8%
unsub-neg96.8%
distribute-rgt-out--100.0%
Simplified100.0%
Final simplification100.0%
(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 96.8%
Taylor expanded in x around 0 38.5%
Final simplification38.5%
herbie shell --seed 2023185
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))