
(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 99.2%
sub-neg99.2%
+-commutative99.2%
distribute-lft1-in99.2%
associate-+r+99.2%
+-commutative99.2%
*-commutative99.2%
neg-mul-199.2%
associate-*r*99.2%
*-commutative99.2%
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 (<= x -1.5e+94)
(* x y)
(if (<= x -4.5e+49)
(* x (- z))
(if (<= x -5.8e-18) (* x y) (if (<= x 1.4e-12) z (* x y))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.5e+94) {
tmp = x * y;
} else if (x <= -4.5e+49) {
tmp = x * -z;
} else if (x <= -5.8e-18) {
tmp = x * y;
} else if (x <= 1.4e-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 <= (-1.5d+94)) then
tmp = x * y
else if (x <= (-4.5d+49)) then
tmp = x * -z
else if (x <= (-5.8d-18)) then
tmp = x * y
else if (x <= 1.4d-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 <= -1.5e+94) {
tmp = x * y;
} else if (x <= -4.5e+49) {
tmp = x * -z;
} else if (x <= -5.8e-18) {
tmp = x * y;
} else if (x <= 1.4e-12) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.5e+94: tmp = x * y elif x <= -4.5e+49: tmp = x * -z elif x <= -5.8e-18: tmp = x * y elif x <= 1.4e-12: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.5e+94) tmp = Float64(x * y); elseif (x <= -4.5e+49) tmp = Float64(x * Float64(-z)); elseif (x <= -5.8e-18) tmp = Float64(x * y); elseif (x <= 1.4e-12) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.5e+94) tmp = x * y; elseif (x <= -4.5e+49) tmp = x * -z; elseif (x <= -5.8e-18) tmp = x * y; elseif (x <= 1.4e-12) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.5e+94], N[(x * y), $MachinePrecision], If[LessEqual[x, -4.5e+49], N[(x * (-z)), $MachinePrecision], If[LessEqual[x, -5.8e-18], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.4e-12], z, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+94}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -4.5 \cdot 10^{+49}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{elif}\;x \leq -5.8 \cdot 10^{-18}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{-12}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.5e94 or -4.49999999999999982e49 < x < -5.8e-18 or 1.4000000000000001e-12 < x Initial program 98.3%
Taylor expanded in y around inf 61.6%
if -1.5e94 < x < -4.49999999999999982e49Initial program 100.0%
Taylor expanded in y around 0 80.4%
Taylor expanded in x around inf 80.4%
associate-*r*80.4%
mul-1-neg80.4%
Simplified80.4%
if -5.8e-18 < x < 1.4000000000000001e-12Initial program 100.0%
Taylor expanded in x around 0 79.4%
Final simplification71.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.6e-106) (not (<= z 1.7e-155))) (* z (- 1.0 x)) (* x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.6e-106) || !(z <= 1.7e-155)) {
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 <= (-6.6d-106)) .or. (.not. (z <= 1.7d-155))) 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 <= -6.6e-106) || !(z <= 1.7e-155)) {
tmp = z * (1.0 - x);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.6e-106) or not (z <= 1.7e-155): tmp = z * (1.0 - x) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.6e-106) || !(z <= 1.7e-155)) 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 <= -6.6e-106) || ~((z <= 1.7e-155))) tmp = z * (1.0 - x); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.6e-106], N[Not[LessEqual[z, 1.7e-155]], $MachinePrecision]], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.6 \cdot 10^{-106} \lor \neg \left(z \leq 1.7 \cdot 10^{-155}\right):\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if z < -6.60000000000000031e-106 or 1.7e-155 < z Initial program 98.8%
Taylor expanded in y around 0 80.7%
if -6.60000000000000031e-106 < z < 1.7e-155Initial program 100.0%
Taylor expanded in y around inf 74.0%
Final simplification78.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -3750.0) (not (<= x 0.052))) (* x (- y z)) (* z (- 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3750.0) || !(x <= 0.052)) {
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 <= (-3750.0d0)) .or. (.not. (x <= 0.052d0))) 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 <= -3750.0) || !(x <= 0.052)) {
tmp = x * (y - z);
} else {
tmp = z * (1.0 - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3750.0) or not (x <= 0.052): tmp = x * (y - z) else: tmp = z * (1.0 - x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3750.0) || !(x <= 0.052)) 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 <= -3750.0) || ~((x <= 0.052))) tmp = x * (y - z); else tmp = z * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3750.0], N[Not[LessEqual[x, 0.052]], $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 -3750 \lor \neg \left(x \leq 0.052\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -3750 or 0.0519999999999999976 < x Initial program 98.3%
Taylor expanded in x around inf 99.0%
neg-mul-199.0%
+-commutative99.0%
unsub-neg99.0%
Simplified99.0%
if -3750 < x < 0.0519999999999999976Initial program 100.0%
Taylor expanded in y around 0 78.9%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (<= x -5e-16) (* x y) (if (<= x 1.7e-10) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5e-16) {
tmp = x * y;
} else if (x <= 1.7e-10) {
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 <= (-5d-16)) then
tmp = x * y
else if (x <= 1.7d-10) 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 <= -5e-16) {
tmp = x * y;
} else if (x <= 1.7e-10) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5e-16: tmp = x * y elif x <= 1.7e-10: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5e-16) tmp = Float64(x * y); elseif (x <= 1.7e-10) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5e-16) tmp = x * y; elseif (x <= 1.7e-10) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5e-16], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.7e-10], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-16}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{-10}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5.0000000000000004e-16 or 1.70000000000000007e-10 < x Initial program 98.4%
Taylor expanded in y around inf 58.6%
if -5.0000000000000004e-16 < x < 1.70000000000000007e-10Initial program 100.0%
Taylor expanded in x around 0 79.4%
Final simplification69.0%
(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 99.2%
Taylor expanded in x around 0 100.0%
Taylor expanded in z around 0 99.2%
*-commutative99.2%
neg-mul-199.2%
distribute-lft-in99.2%
*-rgt-identity99.2%
associate-+l+99.2%
+-commutative99.2%
distribute-rgt-neg-out99.2%
unsub-neg99.2%
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 99.2%
Taylor expanded in x around 0 41.2%
Final simplification41.2%
herbie shell --seed 2023257
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))