
(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 99.6%
+-commutative99.6%
remove-double-neg99.6%
distribute-rgt-neg-out99.6%
neg-sub099.6%
neg-sub099.6%
*-commutative99.6%
distribute-lft-neg-in99.6%
remove-double-neg99.6%
distribute-rgt-out--99.6%
*-lft-identity99.6%
associate-+l-99.6%
distribute-lft-out--100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* x (- y z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
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.0d0))) 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.0)) {
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.0): 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.0)) 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.0))) 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.0]], $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\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 99.2%
Taylor expanded in x around inf 98.7%
neg-mul-198.7%
sub-neg98.7%
Simplified98.7%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 98.4%
Final simplification98.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.12e-39) (not (<= x 0.185))) (* x (- y z)) (* z (- 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.12e-39) || !(x <= 0.185)) {
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 <= (-1.12d-39)) .or. (.not. (x <= 0.185d0))) 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 <= -1.12e-39) || !(x <= 0.185)) {
tmp = x * (y - z);
} else {
tmp = z * (1.0 - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.12e-39) or not (x <= 0.185): tmp = x * (y - z) else: tmp = z * (1.0 - x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.12e-39) || !(x <= 0.185)) 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 <= -1.12e-39) || ~((x <= 0.185))) tmp = x * (y - z); else tmp = z * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.12e-39], N[Not[LessEqual[x, 0.185]], $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 -1.12 \cdot 10^{-39} \lor \neg \left(x \leq 0.185\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -1.12e-39 or 0.185 < x Initial program 99.2%
Taylor expanded in x around inf 96.7%
neg-mul-196.7%
sub-neg96.7%
Simplified96.7%
if -1.12e-39 < x < 0.185Initial 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 75.3%
*-commutative75.3%
Simplified75.3%
Taylor expanded in z around 0 75.3%
Final simplification86.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.4e-43) (not (<= x 1.7e-6))) (* x (- y z)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.4e-43) || !(x <= 1.7e-6)) {
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.4d-43)) .or. (.not. (x <= 1.7d-6))) 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.4e-43) || !(x <= 1.7e-6)) {
tmp = x * (y - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.4e-43) or not (x <= 1.7e-6): tmp = x * (y - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.4e-43) || !(x <= 1.7e-6)) 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.4e-43) || ~((x <= 1.7e-6))) tmp = x * (y - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.4e-43], N[Not[LessEqual[x, 1.7e-6]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{-43} \lor \neg \left(x \leq 1.7 \cdot 10^{-6}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -5.39999999999999982e-43 or 1.70000000000000003e-6 < x Initial program 99.2%
Taylor expanded in x around inf 96.0%
neg-mul-196.0%
sub-neg96.0%
Simplified96.0%
if -5.39999999999999982e-43 < x < 1.70000000000000003e-6Initial program 100.0%
Taylor expanded in x around 0 99.0%
Taylor expanded in x around 0 74.7%
Final simplification86.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 26000000.0))) (* z (- x)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 26000000.0)) {
tmp = z * -x;
} 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.0d0)) .or. (.not. (x <= 26000000.0d0))) then
tmp = z * -x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 26000000.0)) {
tmp = z * -x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 26000000.0): tmp = z * -x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 26000000.0)) tmp = Float64(z * Float64(-x)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.0) || ~((x <= 26000000.0))) tmp = z * -x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 26000000.0]], $MachinePrecision]], N[(z * (-x)), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 26000000\right):\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1 or 2.6e7 < x Initial program 99.2%
Taylor expanded in x around inf 98.6%
neg-mul-198.6%
sub-neg98.6%
Simplified98.6%
Taylor expanded in y around 0 60.6%
neg-mul-160.6%
*-commutative60.6%
distribute-rgt-neg-in60.6%
Simplified60.6%
if -1 < x < 2.6e7Initial program 100.0%
Taylor expanded in x around 0 98.4%
Taylor expanded in x around 0 70.5%
Final simplification65.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.2e-39) (not (<= x 3.4e-7))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.2e-39) || !(x <= 3.4e-7)) {
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.2d-39)) .or. (.not. (x <= 3.4d-7))) 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.2e-39) || !(x <= 3.4e-7)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.2e-39) or not (x <= 3.4e-7): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.2e-39) || !(x <= 3.4e-7)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.2e-39) || ~((x <= 3.4e-7))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.2e-39], N[Not[LessEqual[x, 3.4e-7]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{-39} \lor \neg \left(x \leq 3.4 \cdot 10^{-7}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.20000000000000008e-39 or 3.39999999999999974e-7 < x Initial program 99.2%
Taylor expanded in y around inf 44.0%
if -1.20000000000000008e-39 < x < 3.39999999999999974e-7Initial program 100.0%
Taylor expanded in x around 0 99.0%
Taylor expanded in x around 0 74.7%
Final simplification58.5%
(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.6%
Taylor expanded in x around 0 71.4%
Taylor expanded in x around 0 38.1%
herbie shell --seed 2024182
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))