
(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 5 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.4%
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 -8.4e-36) (not (<= x 2.2e-92))) (* (- y z) x) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.4e-36) || !(x <= 2.2e-92)) {
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 <= (-8.4d-36)) .or. (.not. (x <= 2.2d-92))) 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 <= -8.4e-36) || !(x <= 2.2e-92)) {
tmp = (y - z) * x;
} else {
tmp = (1.0 - x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.4e-36) or not (x <= 2.2e-92): tmp = (y - z) * x else: tmp = (1.0 - x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.4e-36) || !(x <= 2.2e-92)) 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 <= -8.4e-36) || ~((x <= 2.2e-92))) tmp = (y - z) * x; else tmp = (1.0 - x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.4e-36], N[Not[LessEqual[x, 2.2e-92]], $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 -8.4 \cdot 10^{-36} \lor \neg \left(x \leq 2.2 \cdot 10^{-92}\right):\\
\;\;\;\;\left(y - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot z\\
\end{array}
\end{array}
if x < -8.39999999999999964e-36 or 2.19999999999999987e-92 < x Initial program 97.4%
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.7
Applied rewrites94.7%
if -8.39999999999999964e-36 < x < 2.19999999999999987e-92Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6477.5
Applied rewrites77.5%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* (- z) x) (* 1.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -z * 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 <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = -z * 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 <= -1.0) || !(x <= 1.0)) {
tmp = -z * x;
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = -z * x else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(Float64(-z) * x); else tmp = Float64(1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = -z * x; else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[((-z) * x), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\left(-z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 97.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6499.4
Applied rewrites99.4%
Taylor expanded in y around 0
Applied rewrites56.7%
if -1 < x < 1Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6471.3
Applied rewrites71.3%
Taylor expanded in x around 0
Applied rewrites70.5%
Final simplification63.4%
(FPCore (x y z) :precision binary64 (* (- 1.0 x) z))
double code(double x, double y, double z) {
return (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 = (1.0d0 - x) * z
end function
public static double code(double x, double y, double z) {
return (1.0 - x) * z;
}
def code(x, y, z): return (1.0 - x) * z
function code(x, y, z) return Float64(Float64(1.0 - x) * z) end
function tmp = code(x, y, z) tmp = (1.0 - x) * z; end
code[x_, y_, z_] := N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) \cdot z
\end{array}
Initial program 98.4%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6464.0
Applied rewrites64.0%
(FPCore (x y z) :precision binary64 (* 1.0 z))
double code(double x, double y, double z) {
return 1.0 * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 * z
end function
public static double code(double x, double y, double z) {
return 1.0 * z;
}
def code(x, y, z): return 1.0 * z
function code(x, y, z) return Float64(1.0 * z) end
function tmp = code(x, y, z) tmp = 1.0 * z; end
code[x_, y_, z_] := N[(1.0 * z), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot z
\end{array}
Initial program 98.4%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6464.0
Applied rewrites64.0%
Taylor expanded in x around 0
Applied rewrites35.8%
herbie shell --seed 2024332
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))