
(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.8%
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 -3e+188)
t_0
(if (<= x -9e-31)
(* y x)
(if (<= x 2.4e-143) (* 1.0 z) (if (<= x 2.65e+19) (* y x) t_0))))))
double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if (x <= -3e+188) {
tmp = t_0;
} else if (x <= -9e-31) {
tmp = y * x;
} else if (x <= 2.4e-143) {
tmp = 1.0 * z;
} else if (x <= 2.65e+19) {
tmp = y * x;
} 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 <= (-3d+188)) then
tmp = t_0
else if (x <= (-9d-31)) then
tmp = y * x
else if (x <= 2.4d-143) then
tmp = 1.0d0 * z
else if (x <= 2.65d+19) then
tmp = y * x
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 <= -3e+188) {
tmp = t_0;
} else if (x <= -9e-31) {
tmp = y * x;
} else if (x <= 2.4e-143) {
tmp = 1.0 * z;
} else if (x <= 2.65e+19) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -z * x tmp = 0 if x <= -3e+188: tmp = t_0 elif x <= -9e-31: tmp = y * x elif x <= 2.4e-143: tmp = 1.0 * z elif x <= 2.65e+19: tmp = y * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-z) * x) tmp = 0.0 if (x <= -3e+188) tmp = t_0; elseif (x <= -9e-31) tmp = Float64(y * x); elseif (x <= 2.4e-143) tmp = Float64(1.0 * z); elseif (x <= 2.65e+19) tmp = Float64(y * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -z * x; tmp = 0.0; if (x <= -3e+188) tmp = t_0; elseif (x <= -9e-31) tmp = y * x; elseif (x <= 2.4e-143) tmp = 1.0 * z; elseif (x <= 2.65e+19) tmp = y * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * x), $MachinePrecision]}, If[LessEqual[x, -3e+188], t$95$0, If[LessEqual[x, -9e-31], N[(y * x), $MachinePrecision], If[LessEqual[x, 2.4e-143], N[(1.0 * z), $MachinePrecision], If[LessEqual[x, 2.65e+19], N[(y * x), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot x\\
\mathbf{if}\;x \leq -3 \cdot 10^{+188}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -9 \cdot 10^{-31}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 2.4 \cdot 10^{-143}:\\
\;\;\;\;1 \cdot z\\
\mathbf{elif}\;x \leq 2.65 \cdot 10^{+19}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.0000000000000001e188 or 2.65e19 < x Initial program 96.2%
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--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites72.4%
if -3.0000000000000001e188 < x < -9.0000000000000008e-31 or 2.3999999999999999e-143 < x < 2.65e19Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6439.8
Applied rewrites39.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6462.7
Applied rewrites62.7%
if -9.0000000000000008e-31 < x < 2.3999999999999999e-143Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6477.9
Applied rewrites77.9%
Taylor expanded in x around 0
Applied rewrites77.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -9e-31) (not (<= x 2.4e-143))) (* (- y z) x) (* 1.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9e-31) || !(x <= 2.4e-143)) {
tmp = (y - 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 <= (-9d-31)) .or. (.not. (x <= 2.4d-143))) then
tmp = (y - 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 <= -9e-31) || !(x <= 2.4e-143)) {
tmp = (y - z) * x;
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9e-31) or not (x <= 2.4e-143): tmp = (y - z) * x else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9e-31) || !(x <= 2.4e-143)) tmp = Float64(Float64(y - z) * x); else tmp = Float64(1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9e-31) || ~((x <= 2.4e-143))) tmp = (y - z) * x; else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9e-31], N[Not[LessEqual[x, 2.4e-143]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{-31} \lor \neg \left(x \leq 2.4 \cdot 10^{-143}\right):\\
\;\;\;\;\left(y - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if x < -9.0000000000000008e-31 or 2.3999999999999999e-143 < x Initial program 98.1%
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--.f6490.4
Applied rewrites90.4%
if -9.0000000000000008e-31 < x < 2.3999999999999999e-143Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6477.9
Applied rewrites77.9%
Taylor expanded in x around 0
Applied rewrites77.9%
Final simplification85.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.7e+172) (not (<= y 5.5e+35))) (* y x) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.7e+172) || !(y <= 5.5e+35)) {
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.7d+172)) .or. (.not. (y <= 5.5d+35))) 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.7e+172) || !(y <= 5.5e+35)) {
tmp = y * x;
} else {
tmp = (1.0 - x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.7e+172) or not (y <= 5.5e+35): tmp = y * x else: tmp = (1.0 - x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.7e+172) || !(y <= 5.5e+35)) 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.7e+172) || ~((y <= 5.5e+35))) tmp = y * x; else tmp = (1.0 - x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.7e+172], N[Not[LessEqual[y, 5.5e+35]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{+172} \lor \neg \left(y \leq 5.5 \cdot 10^{+35}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot z\\
\end{array}
\end{array}
if y < -3.69999999999999972e172 or 5.50000000000000001e35 < y Initial program 97.7%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6428.5
Applied rewrites28.5%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6478.0
Applied rewrites78.0%
if -3.69999999999999972e172 < y < 5.50000000000000001e35Initial program 99.4%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6482.5
Applied rewrites82.5%
Final simplification80.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -9e-31) (not (<= x 2.4e-143))) (* y x) (* 1.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9e-31) || !(x <= 2.4e-143)) {
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 <= (-9d-31)) .or. (.not. (x <= 2.4d-143))) 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 <= -9e-31) || !(x <= 2.4e-143)) {
tmp = y * x;
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9e-31) or not (x <= 2.4e-143): tmp = y * x else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9e-31) || !(x <= 2.4e-143)) 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 <= -9e-31) || ~((x <= 2.4e-143))) tmp = y * x; else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9e-31], N[Not[LessEqual[x, 2.4e-143]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{-31} \lor \neg \left(x \leq 2.4 \cdot 10^{-143}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if x < -9.0000000000000008e-31 or 2.3999999999999999e-143 < x Initial program 98.1%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6455.6
Applied rewrites55.6%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6451.2
Applied rewrites51.2%
if -9.0000000000000008e-31 < x < 2.3999999999999999e-143Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6477.9
Applied rewrites77.9%
Taylor expanded in x around 0
Applied rewrites77.9%
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 98.8%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6463.7
Applied rewrites63.7%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6440.9
Applied rewrites40.9%
herbie shell --seed 2024302
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))