
(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 8 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 98.4%
sub-neg98.4%
+-commutative98.4%
distribute-lft1-in98.4%
associate-+r+98.4%
+-commutative98.4%
*-commutative98.4%
neg-mul-198.4%
associate-*r*98.4%
*-commutative98.4%
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 -1e-10) (not (<= z 2e-65))) (* z (- 1.0 x)) (* x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1e-10) || !(z <= 2e-65)) {
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 <= (-1d-10)) .or. (.not. (z <= 2d-65))) 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 <= -1e-10) || !(z <= 2e-65)) {
tmp = z * (1.0 - x);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1e-10) or not (z <= 2e-65): tmp = z * (1.0 - x) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1e-10) || !(z <= 2e-65)) 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 <= -1e-10) || ~((z <= 2e-65))) tmp = z * (1.0 - x); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1e-10], N[Not[LessEqual[z, 2e-65]], $MachinePrecision]], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{-10} \lor \neg \left(z \leq 2 \cdot 10^{-65}\right):\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if z < -1.00000000000000004e-10 or 1.99999999999999985e-65 < z Initial program 97.2%
Taylor expanded in y around 0 82.1%
if -1.00000000000000004e-10 < z < 1.99999999999999985e-65Initial program 100.0%
Taylor expanded in y around inf 69.0%
Final simplification76.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.3e-42) (not (<= x 2.4e-12))) (* x (- y z)) (* z (- 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.3e-42) || !(x <= 2.4e-12)) {
tmp = x * (y - z);
} else {
tmp = z * (1.0 - 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-42)) .or. (.not. (x <= 2.4d-12))) then
tmp = x * (y - z)
else
tmp = z * (1.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.3e-42) || !(x <= 2.4e-12)) {
tmp = x * (y - z);
} else {
tmp = z * (1.0 - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.3e-42) or not (x <= 2.4e-12): tmp = x * (y - z) else: tmp = z * (1.0 - x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.3e-42) || !(x <= 2.4e-12)) tmp = Float64(x * Float64(y - z)); else tmp = Float64(z * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.3e-42) || ~((x <= 2.4e-12))) tmp = x * (y - z); else tmp = z * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.3e-42], N[Not[LessEqual[x, 2.4e-12]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{-42} \lor \neg \left(x \leq 2.4 \cdot 10^{-12}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -2.30000000000000004e-42 or 2.39999999999999987e-12 < x Initial program 97.0%
sub-neg97.0%
+-commutative97.0%
distribute-lft1-in97.0%
associate-+r+97.0%
+-commutative97.0%
*-commutative97.0%
neg-mul-197.0%
associate-*r*97.0%
*-commutative97.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 94.6%
if -2.30000000000000004e-42 < x < 2.39999999999999987e-12Initial program 100.0%
Taylor expanded in y around 0 72.5%
Final simplification84.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.1) (not (<= x 7.2e-12))) (* x (- y z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.1) || !(x <= 7.2e-12)) {
tmp = x * (y - z);
} else {
tmp = z + (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.1d0)) .or. (.not. (x <= 7.2d-12))) then
tmp = x * (y - z)
else
tmp = z + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.1) || !(x <= 7.2e-12)) {
tmp = x * (y - z);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.1) or not (x <= 7.2e-12): tmp = x * (y - z) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.1) || !(x <= 7.2e-12)) tmp = Float64(x * Float64(y - z)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.1) || ~((x <= 7.2e-12))) tmp = x * (y - z); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.1], N[Not[LessEqual[x, 7.2e-12]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \lor \neg \left(x \leq 7.2 \cdot 10^{-12}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -2.10000000000000009 or 7.2e-12 < x Initial program 96.6%
sub-neg96.6%
+-commutative96.6%
distribute-lft1-in96.6%
associate-+r+96.6%
+-commutative96.6%
*-commutative96.6%
neg-mul-196.6%
associate-*r*96.6%
*-commutative96.6%
distribute-rgt-out99.9%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 98.8%
if -2.10000000000000009 < x < 7.2e-12Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
distribute-lft1-in100.0%
associate-+r+100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
associate-*r*100.0%
*-commutative100.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 99.4%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (if (<= x -1.15e-42) (* x y) (if (<= x 7.2e-12) z (* x (- z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.15e-42) {
tmp = x * y;
} else if (x <= 7.2e-12) {
tmp = z;
} else {
tmp = 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 <= (-1.15d-42)) then
tmp = x * y
else if (x <= 7.2d-12) then
tmp = z
else
tmp = x * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.15e-42) {
tmp = x * y;
} else if (x <= 7.2e-12) {
tmp = z;
} else {
tmp = x * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.15e-42: tmp = x * y elif x <= 7.2e-12: tmp = z else: tmp = x * -z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.15e-42) tmp = Float64(x * y); elseif (x <= 7.2e-12) tmp = z; else tmp = Float64(x * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.15e-42) tmp = x * y; elseif (x <= 7.2e-12) tmp = z; else tmp = x * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.15e-42], N[(x * y), $MachinePrecision], If[LessEqual[x, 7.2e-12], z, N[(x * (-z)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{-42}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 7.2 \cdot 10^{-12}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\end{array}
\end{array}
if x < -1.15000000000000002e-42Initial program 98.8%
Taylor expanded in y around inf 61.1%
if -1.15000000000000002e-42 < x < 7.2e-12Initial program 100.0%
Taylor expanded in x around 0 72.3%
if 7.2e-12 < x Initial program 94.5%
sub-neg94.5%
+-commutative94.5%
distribute-lft1-in94.5%
associate-+r+94.5%
+-commutative94.5%
*-commutative94.5%
neg-mul-194.5%
associate-*r*94.5%
*-commutative94.5%
distribute-rgt-out99.9%
fma-def99.9%
+-commutative99.9%
*-commutative99.9%
neg-mul-199.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in x around inf 98.8%
Taylor expanded in y around 0 59.5%
mul-1-neg59.5%
distribute-rgt-neg-in59.5%
Simplified59.5%
Final simplification66.0%
(FPCore (x y z) :precision binary64 (if (<= x -5.8e-43) (* x y) (if (<= x 1.65e-12) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.8e-43) {
tmp = x * y;
} else if (x <= 1.65e-12) {
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 <= (-5.8d-43)) then
tmp = x * y
else if (x <= 1.65d-12) 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 <= -5.8e-43) {
tmp = x * y;
} else if (x <= 1.65e-12) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.8e-43: tmp = x * y elif x <= 1.65e-12: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.8e-43) tmp = Float64(x * y); elseif (x <= 1.65e-12) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.8e-43) tmp = x * y; elseif (x <= 1.65e-12) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.8e-43], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.65e-12], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{-43}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.65 \cdot 10^{-12}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5.8000000000000003e-43 or 1.65e-12 < x Initial program 97.0%
Taylor expanded in y around inf 53.8%
if -5.8000000000000003e-43 < x < 1.65e-12Initial program 100.0%
Taylor expanded in x around 0 72.3%
Final simplification62.4%
(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 98.4%
sub-neg98.4%
+-commutative98.4%
distribute-lft1-in98.4%
associate-+r+98.4%
+-commutative98.4%
*-commutative98.4%
neg-mul-198.4%
associate-*r*98.4%
*-commutative98.4%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.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 98.4%
Taylor expanded in x around 0 37.1%
Final simplification37.1%
herbie shell --seed 2023222
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))