
(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 6 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 (- y z) x z))
double code(double x, double y, double z) {
return fma((y - z), x, z);
}
function code(x, y, z) return fma(Float64(y - z), x, z) end
code[x_, y_, z_] := N[(N[(y - z), $MachinePrecision] * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - z, x, z\right)
\end{array}
Initial program 98.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.8e-29) (not (<= x 7.8e-79))) (* (- y z) x) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.8e-29) || !(x <= 7.8e-79)) {
tmp = (y - z) * x;
} else {
tmp = (1.0 - 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 <= (-9.8d-29)) .or. (.not. (x <= 7.8d-79))) then
tmp = (y - z) * x
else
tmp = (1.0d0 - x) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9.8e-29) || !(x <= 7.8e-79)) {
tmp = (y - z) * x;
} else {
tmp = (1.0 - x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.8e-29) or not (x <= 7.8e-79): tmp = (y - z) * x else: tmp = (1.0 - x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.8e-29) || !(x <= 7.8e-79)) tmp = Float64(Float64(y - z) * x); else tmp = Float64(Float64(1.0 - x) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9.8e-29) || ~((x <= 7.8e-79))) tmp = (y - z) * x; else tmp = (1.0 - x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.8e-29], N[Not[LessEqual[x, 7.8e-79]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.8 \cdot 10^{-29} \lor \neg \left(x \leq 7.8 \cdot 10^{-79}\right):\\
\;\;\;\;\left(y - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot z\\
\end{array}
\end{array}
if x < -9.7999999999999997e-29 or 7.80000000000000011e-79 < x Initial program 96.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6494.0
Applied rewrites94.0%
if -9.7999999999999997e-29 < x < 7.80000000000000011e-79Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6483.8
Applied rewrites83.8%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.9e-133) (not (<= z 6.8e-127))) (* (- 1.0 x) z) (* y x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.9e-133) || !(z <= 6.8e-127)) {
tmp = (1.0 - x) * z;
} else {
tmp = y * 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 ((z <= (-5.9d-133)) .or. (.not. (z <= 6.8d-127))) then
tmp = (1.0d0 - x) * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -5.9e-133) || !(z <= 6.8e-127)) {
tmp = (1.0 - x) * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.9e-133) or not (z <= 6.8e-127): tmp = (1.0 - x) * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.9e-133) || !(z <= 6.8e-127)) tmp = Float64(Float64(1.0 - x) * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.9e-133) || ~((z <= 6.8e-127))) tmp = (1.0 - x) * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.9e-133], N[Not[LessEqual[z, 6.8e-127]], $MachinePrecision]], N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.9 \cdot 10^{-133} \lor \neg \left(z \leq 6.8 \cdot 10^{-127}\right):\\
\;\;\;\;\left(1 - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if z < -5.89999999999999964e-133 or 6.7999999999999997e-127 < z Initial program 97.1%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6485.0
Applied rewrites85.0%
if -5.89999999999999964e-133 < z < 6.7999999999999997e-127Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6427.9
Applied rewrites27.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6473.8
Applied rewrites73.8%
Final simplification81.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.8e-29) (not (<= x 7.8e-79))) (* y x) (* 1.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.8e-29) || !(x <= 7.8e-79)) {
tmp = y * x;
} else {
tmp = 1.0 * 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 <= (-9.8d-29)) .or. (.not. (x <= 7.8d-79))) then
tmp = y * x
else
tmp = 1.0d0 * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9.8e-29) || !(x <= 7.8e-79)) {
tmp = y * x;
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.8e-29) or not (x <= 7.8e-79): tmp = y * x else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.8e-29) || !(x <= 7.8e-79)) tmp = Float64(y * x); else tmp = Float64(1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9.8e-29) || ~((x <= 7.8e-79))) tmp = y * x; else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.8e-29], N[Not[LessEqual[x, 7.8e-79]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.8 \cdot 10^{-29} \lor \neg \left(x \leq 7.8 \cdot 10^{-79}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if x < -9.7999999999999997e-29 or 7.80000000000000011e-79 < x Initial program 96.5%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6452.2
Applied rewrites52.2%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6454.3
Applied rewrites54.3%
if -9.7999999999999997e-29 < x < 7.80000000000000011e-79Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6483.8
Applied rewrites83.8%
Taylor expanded in x around 0
Applied rewrites83.8%
Final simplification67.4%
(FPCore (x y z) :precision binary64 (if (<= x -1.7e-6) (* (- z) x) (if (<= x 7.8e-79) (* 1.0 z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.7e-6) {
tmp = -z * x;
} else if (x <= 7.8e-79) {
tmp = 1.0 * z;
} else {
tmp = y * 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.7d-6)) then
tmp = -z * x
else if (x <= 7.8d-79) then
tmp = 1.0d0 * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.7e-6) {
tmp = -z * x;
} else if (x <= 7.8e-79) {
tmp = 1.0 * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.7e-6: tmp = -z * x elif x <= 7.8e-79: tmp = 1.0 * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.7e-6) tmp = Float64(Float64(-z) * x); elseif (x <= 7.8e-79) tmp = Float64(1.0 * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.7e-6) tmp = -z * x; elseif (x <= 7.8e-79) tmp = 1.0 * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.7e-6], N[((-z) * x), $MachinePrecision], If[LessEqual[x, 7.8e-79], N[(1.0 * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{-6}:\\
\;\;\;\;\left(-z\right) \cdot x\\
\mathbf{elif}\;x \leq 7.8 \cdot 10^{-79}:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -1.70000000000000003e-6Initial program 98.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites58.2%
if -1.70000000000000003e-6 < x < 7.80000000000000011e-79Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6482.2
Applied rewrites82.2%
Taylor expanded in x around 0
Applied rewrites81.6%
if 7.80000000000000011e-79 < x Initial program 94.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6447.7
Applied rewrites47.7%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6457.6
Applied rewrites57.6%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return y * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 98.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6466.2
Applied rewrites66.2%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6438.0
Applied rewrites38.0%
herbie shell --seed 2024339
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))