
(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 (- 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 97.6%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f64100.0
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- z) x)))
(if (<= x -4.2e+17)
t_0
(if (<= x -8.5e-26) (* y x) (if (<= x 1.0) (* 1.0 z) t_0)))))
double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if (x <= -4.2e+17) {
tmp = t_0;
} else if (x <= -8.5e-26) {
tmp = y * x;
} else if (x <= 1.0) {
tmp = 1.0 * z;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = -z * x
if (x <= (-4.2d+17)) then
tmp = t_0
else if (x <= (-8.5d-26)) then
tmp = y * x
else if (x <= 1.0d0) then
tmp = 1.0d0 * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if (x <= -4.2e+17) {
tmp = t_0;
} else if (x <= -8.5e-26) {
tmp = y * x;
} else if (x <= 1.0) {
tmp = 1.0 * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -z * x tmp = 0 if x <= -4.2e+17: tmp = t_0 elif x <= -8.5e-26: tmp = y * x elif x <= 1.0: tmp = 1.0 * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-z) * x) tmp = 0.0 if (x <= -4.2e+17) tmp = t_0; elseif (x <= -8.5e-26) tmp = Float64(y * x); elseif (x <= 1.0) tmp = Float64(1.0 * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -z * x; tmp = 0.0; if (x <= -4.2e+17) tmp = t_0; elseif (x <= -8.5e-26) tmp = y * x; elseif (x <= 1.0) tmp = 1.0 * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * x), $MachinePrecision]}, If[LessEqual[x, -4.2e+17], t$95$0, If[LessEqual[x, -8.5e-26], N[(y * x), $MachinePrecision], If[LessEqual[x, 1.0], N[(1.0 * z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot x\\
\mathbf{if}\;x \leq -4.2 \cdot 10^{+17}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -8.5 \cdot 10^{-26}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -4.2e17 or 1 < x Initial program 95.0%
Taylor expanded in x around inf
*-commutativeN/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6499.6
Applied rewrites99.6%
Taylor expanded in y around 0
Applied rewrites62.0%
if -4.2e17 < x < -8.50000000000000004e-26Initial program 99.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6435.7
Applied rewrites35.7%
Taylor expanded in x around 0
Applied rewrites12.6%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6467.6
Applied rewrites67.6%
if -8.50000000000000004e-26 < x < 1Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6476.6
Applied rewrites76.6%
Taylor expanded in x around 0
Applied rewrites74.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.5e-26) (not (<= x 0.155))) (* (- y z) x) (fma (- z) x z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.5e-26) || !(x <= 0.155)) {
tmp = (y - z) * x;
} else {
tmp = fma(-z, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -8.5e-26) || !(x <= 0.155)) tmp = Float64(Float64(y - z) * x); else tmp = fma(Float64(-z), x, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.5e-26], N[Not[LessEqual[x, 0.155]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision], N[((-z) * x + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.5 \cdot 10^{-26} \lor \neg \left(x \leq 0.155\right):\\
\;\;\;\;\left(y - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-z, x, z\right)\\
\end{array}
\end{array}
if x < -8.50000000000000004e-26 or 0.154999999999999999 < x Initial program 95.4%
Taylor expanded in x around inf
*-commutativeN/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6497.8
Applied rewrites97.8%
if -8.50000000000000004e-26 < x < 0.154999999999999999Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6477.2
Applied rewrites77.2%
Applied rewrites77.2%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.5e-26) (not (<= x 0.155))) (* (- y z) x) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.5e-26) || !(x <= 0.155)) {
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.5d-26)) .or. (.not. (x <= 0.155d0))) 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.5e-26) || !(x <= 0.155)) {
tmp = (y - z) * x;
} else {
tmp = (1.0 - x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.5e-26) or not (x <= 0.155): tmp = (y - z) * x else: tmp = (1.0 - x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.5e-26) || !(x <= 0.155)) 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.5e-26) || ~((x <= 0.155))) tmp = (y - z) * x; else tmp = (1.0 - x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.5e-26], N[Not[LessEqual[x, 0.155]], $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.5 \cdot 10^{-26} \lor \neg \left(x \leq 0.155\right):\\
\;\;\;\;\left(y - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot z\\
\end{array}
\end{array}
if x < -8.50000000000000004e-26 or 0.154999999999999999 < x Initial program 95.4%
Taylor expanded in x around inf
*-commutativeN/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6497.8
Applied rewrites97.8%
if -8.50000000000000004e-26 < x < 0.154999999999999999Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6477.2
Applied rewrites77.2%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.4e+40) (not (<= y 5e+89))) (* y x) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.4e+40) || !(y <= 5e+89)) {
tmp = y * 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 ((y <= (-3.4d+40)) .or. (.not. (y <= 5d+89))) then
tmp = y * 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 ((y <= -3.4e+40) || !(y <= 5e+89)) {
tmp = y * x;
} else {
tmp = (1.0 - x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.4e+40) or not (y <= 5e+89): tmp = y * x else: tmp = (1.0 - x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.4e+40) || !(y <= 5e+89)) tmp = Float64(y * x); else tmp = Float64(Float64(1.0 - x) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.4e+40) || ~((y <= 5e+89))) tmp = y * x; else tmp = (1.0 - x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.4e+40], N[Not[LessEqual[y, 5e+89]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{+40} \lor \neg \left(y \leq 5 \cdot 10^{+89}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot z\\
\end{array}
\end{array}
if y < -3.39999999999999989e40 or 4.99999999999999983e89 < y Initial program 93.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6435.2
Applied rewrites35.2%
Taylor expanded in x around 0
Applied rewrites24.4%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6473.4
Applied rewrites73.4%
if -3.39999999999999989e40 < y < 4.99999999999999983e89Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6488.3
Applied rewrites88.3%
Final simplification82.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.5e-26) (not (<= x 0.054))) (* y x) (* 1.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.5e-26) || !(x <= 0.054)) {
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 <= (-8.5d-26)) .or. (.not. (x <= 0.054d0))) 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 <= -8.5e-26) || !(x <= 0.054)) {
tmp = y * x;
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.5e-26) or not (x <= 0.054): tmp = y * x else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.5e-26) || !(x <= 0.054)) 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 <= -8.5e-26) || ~((x <= 0.054))) tmp = y * x; else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.5e-26], N[Not[LessEqual[x, 0.054]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.5 \cdot 10^{-26} \lor \neg \left(x \leq 0.054\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if x < -8.50000000000000004e-26 or 0.0539999999999999994 < x Initial program 95.4%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6459.3
Applied rewrites59.3%
Taylor expanded in x around 0
Applied rewrites3.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6447.4
Applied rewrites47.4%
if -8.50000000000000004e-26 < x < 0.0539999999999999994Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6477.2
Applied rewrites77.2%
Taylor expanded in x around 0
Applied rewrites75.3%
Final simplification60.9%
(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 97.6%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6468.0
Applied rewrites68.0%
Taylor expanded in x around 0
Applied rewrites38.5%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6436.3
Applied rewrites36.3%
herbie shell --seed 2024307
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))