
(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 (- z (* x (- z y))))
double code(double x, double y, double z) {
return z - (x * (z - 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 * (z - y))
end function
public static double code(double x, double y, double z) {
return z - (x * (z - y));
}
def code(x, y, z): return z - (x * (z - y))
function code(x, y, z) return Float64(z - Float64(x * Float64(z - y))) end
function tmp = code(x, y, z) tmp = z - (x * (z - y)); end
code[x_, y_, z_] := N[(z - N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - x \cdot \left(z - y\right)
\end{array}
Initial program 97.2%
+-commutative97.2%
remove-double-neg97.2%
distribute-rgt-neg-out97.2%
neg-sub097.2%
neg-sub097.2%
*-commutative97.2%
distribute-lft-neg-in97.2%
remove-double-neg97.2%
distribute-rgt-out--97.3%
*-lft-identity97.3%
associate-+l-97.3%
distribute-lft-out--100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.85e-21)
(* x y)
(if (<= x 8.2e-131)
z
(if (or (<= x 1.4e+102) (not (<= x 3.5e+214))) (* x y) (* z (- x))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.85e-21) {
tmp = x * y;
} else if (x <= 8.2e-131) {
tmp = z;
} else if ((x <= 1.4e+102) || !(x <= 3.5e+214)) {
tmp = x * y;
} else {
tmp = z * -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 <= (-1.85d-21)) then
tmp = x * y
else if (x <= 8.2d-131) then
tmp = z
else if ((x <= 1.4d+102) .or. (.not. (x <= 3.5d+214))) then
tmp = x * y
else
tmp = z * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.85e-21) {
tmp = x * y;
} else if (x <= 8.2e-131) {
tmp = z;
} else if ((x <= 1.4e+102) || !(x <= 3.5e+214)) {
tmp = x * y;
} else {
tmp = z * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.85e-21: tmp = x * y elif x <= 8.2e-131: tmp = z elif (x <= 1.4e+102) or not (x <= 3.5e+214): tmp = x * y else: tmp = z * -x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.85e-21) tmp = Float64(x * y); elseif (x <= 8.2e-131) tmp = z; elseif ((x <= 1.4e+102) || !(x <= 3.5e+214)) tmp = Float64(x * y); else tmp = Float64(z * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.85e-21) tmp = x * y; elseif (x <= 8.2e-131) tmp = z; elseif ((x <= 1.4e+102) || ~((x <= 3.5e+214))) tmp = x * y; else tmp = z * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.85e-21], N[(x * y), $MachinePrecision], If[LessEqual[x, 8.2e-131], z, If[Or[LessEqual[x, 1.4e+102], N[Not[LessEqual[x, 3.5e+214]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(z * (-x)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.85 \cdot 10^{-21}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 8.2 \cdot 10^{-131}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{+102} \lor \neg \left(x \leq 3.5 \cdot 10^{+214}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\end{array}
\end{array}
if x < -1.8500000000000001e-21 or 8.2000000000000004e-131 < x < 1.40000000000000009e102 or 3.5e214 < x Initial program 94.9%
Taylor expanded in y around inf 59.7%
if -1.8500000000000001e-21 < x < 8.2000000000000004e-131Initial program 100.0%
Taylor expanded in x around 0 80.8%
if 1.40000000000000009e102 < x < 3.5e214Initial program 99.9%
Taylor expanded in x around inf 99.9%
mul-1-neg99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 63.2%
mul-1-neg63.2%
*-commutative63.2%
distribute-rgt-neg-in63.2%
Simplified63.2%
Final simplification67.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.2e-17))) (* x (- y z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1.2e-17)) {
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 <= (-1.0d0)) .or. (.not. (x <= 1.2d-17))) 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 <= -1.0) || !(x <= 1.2e-17)) {
tmp = x * (y - z);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 1.2e-17): tmp = x * (y - z) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.2e-17)) 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 <= -1.0) || ~((x <= 1.2e-17))) tmp = x * (y - z); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.2e-17]], $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 -1 \lor \neg \left(x \leq 1.2 \cdot 10^{-17}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -1 or 1.19999999999999993e-17 < x Initial program 94.6%
Taylor expanded in x around inf 99.6%
mul-1-neg99.6%
unsub-neg99.6%
Simplified99.6%
if -1 < x < 1.19999999999999993e-17Initial 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 0 98.5%
mul-1-neg98.5%
*-commutative98.5%
distribute-rgt-neg-in98.5%
Simplified98.5%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.6e+28) (not (<= x 7.8e-131))) (* x (- y z)) (- z (* z x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.6e+28) || !(x <= 7.8e-131)) {
tmp = x * (y - z);
} else {
tmp = z - (z * 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 <= (-7.6d+28)) .or. (.not. (x <= 7.8d-131))) then
tmp = x * (y - z)
else
tmp = z - (z * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7.6e+28) || !(x <= 7.8e-131)) {
tmp = x * (y - z);
} else {
tmp = z - (z * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.6e+28) or not (x <= 7.8e-131): tmp = x * (y - z) else: tmp = z - (z * x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.6e+28) || !(x <= 7.8e-131)) tmp = Float64(x * Float64(y - z)); else tmp = Float64(z - Float64(z * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.6e+28) || ~((x <= 7.8e-131))) tmp = x * (y - z); else tmp = z - (z * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.6e+28], N[Not[LessEqual[x, 7.8e-131]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], N[(z - N[(z * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.6 \cdot 10^{+28} \lor \neg \left(x \leq 7.8 \cdot 10^{-131}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z - z \cdot x\\
\end{array}
\end{array}
if x < -7.5999999999999998e28 or 7.80000000000000039e-131 < x Initial program 95.5%
Taylor expanded in x around inf 92.7%
mul-1-neg92.7%
unsub-neg92.7%
Simplified92.7%
if -7.5999999999999998e28 < x < 7.80000000000000039e-131Initial 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 79.6%
*-commutative79.6%
Simplified79.6%
Final simplification87.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.9e-22) (not (<= x 8.2e-131))) (* x (- y z)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.9e-22) || !(x <= 8.2e-131)) {
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 <= (-1.9d-22)) .or. (.not. (x <= 8.2d-131))) 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 <= -1.9e-22) || !(x <= 8.2e-131)) {
tmp = x * (y - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.9e-22) or not (x <= 8.2e-131): tmp = x * (y - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.9e-22) || !(x <= 8.2e-131)) 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 <= -1.9e-22) || ~((x <= 8.2e-131))) tmp = x * (y - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.9e-22], N[Not[LessEqual[x, 8.2e-131]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{-22} \lor \neg \left(x \leq 8.2 \cdot 10^{-131}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.90000000000000012e-22 or 8.2000000000000004e-131 < x Initial program 95.7%
Taylor expanded in x around inf 91.0%
mul-1-neg91.0%
unsub-neg91.0%
Simplified91.0%
if -1.90000000000000012e-22 < x < 8.2000000000000004e-131Initial program 100.0%
Taylor expanded in x around 0 80.8%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.36e-21) (not (<= x 3.5e-131))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.36e-21) || !(x <= 3.5e-131)) {
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 <= (-1.36d-21)) .or. (.not. (x <= 3.5d-131))) 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 <= -1.36e-21) || !(x <= 3.5e-131)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.36e-21) or not (x <= 3.5e-131): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.36e-21) || !(x <= 3.5e-131)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.36e-21) || ~((x <= 3.5e-131))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.36e-21], N[Not[LessEqual[x, 3.5e-131]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.36 \cdot 10^{-21} \lor \neg \left(x \leq 3.5 \cdot 10^{-131}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.3599999999999999e-21 or 3.5000000000000002e-131 < x Initial program 95.7%
Taylor expanded in y around inf 56.0%
if -1.3599999999999999e-21 < x < 3.5000000000000002e-131Initial program 100.0%
Taylor expanded in x around 0 80.8%
Final simplification64.7%
(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.2%
Taylor expanded in x around 0 35.4%
herbie shell --seed 2024086
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))