
(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 98.8%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
distribute-lft1-inN/A
associate-*r*N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
distribute-lft-out--N/A
unsub-negN/A
mul-1-negN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- y z) x)))
(if (<= x -1500.0)
t_0
(if (<= x 2.05e-240)
(fma (- z) x z)
(if (<= x 5e-88) (* y x) (if (<= x 1.45e-45) (* (- 1.0 x) z) t_0))))))
double code(double x, double y, double z) {
double t_0 = (y - z) * x;
double tmp;
if (x <= -1500.0) {
tmp = t_0;
} else if (x <= 2.05e-240) {
tmp = fma(-z, x, z);
} else if (x <= 5e-88) {
tmp = y * x;
} else if (x <= 1.45e-45) {
tmp = (1.0 - x) * z;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(y - z) * x) tmp = 0.0 if (x <= -1500.0) tmp = t_0; elseif (x <= 2.05e-240) tmp = fma(Float64(-z), x, z); elseif (x <= 5e-88) tmp = Float64(y * x); elseif (x <= 1.45e-45) tmp = Float64(Float64(1.0 - x) * z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1500.0], t$95$0, If[LessEqual[x, 2.05e-240], N[((-z) * x + z), $MachinePrecision], If[LessEqual[x, 5e-88], N[(y * x), $MachinePrecision], If[LessEqual[x, 1.45e-45], N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - z\right) \cdot x\\
\mathbf{if}\;x \leq -1500:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.05 \cdot 10^{-240}:\\
\;\;\;\;\mathsf{fma}\left(-z, x, z\right)\\
\mathbf{elif}\;x \leq 5 \cdot 10^{-88}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{-45}:\\
\;\;\;\;\left(1 - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1500 or 1.45e-45 < x Initial program 97.7%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6493.6
Applied rewrites93.6%
if -1500 < x < 2.0500000000000001e-240Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6483.1
Applied rewrites83.1%
Applied rewrites83.2%
if 2.0500000000000001e-240 < x < 5.00000000000000009e-88Initial program 99.9%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6468.5
Applied rewrites68.5%
if 5.00000000000000009e-88 < x < 1.45e-45Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6479.9
Applied rewrites79.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- y z) x)) (t_1 (* (- 1.0 x) z)))
(if (<= x -1500.0)
t_0
(if (<= x 2.05e-240)
t_1
(if (<= x 5e-88) (* y x) (if (<= x 1.45e-45) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = (y - z) * x;
double t_1 = (1.0 - x) * z;
double tmp;
if (x <= -1500.0) {
tmp = t_0;
} else if (x <= 2.05e-240) {
tmp = t_1;
} else if (x <= 5e-88) {
tmp = y * x;
} else if (x <= 1.45e-45) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = (y - z) * x
t_1 = (1.0d0 - x) * z
if (x <= (-1500.0d0)) then
tmp = t_0
else if (x <= 2.05d-240) then
tmp = t_1
else if (x <= 5d-88) then
tmp = y * x
else if (x <= 1.45d-45) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y - z) * x;
double t_1 = (1.0 - x) * z;
double tmp;
if (x <= -1500.0) {
tmp = t_0;
} else if (x <= 2.05e-240) {
tmp = t_1;
} else if (x <= 5e-88) {
tmp = y * x;
} else if (x <= 1.45e-45) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y - z) * x t_1 = (1.0 - x) * z tmp = 0 if x <= -1500.0: tmp = t_0 elif x <= 2.05e-240: tmp = t_1 elif x <= 5e-88: tmp = y * x elif x <= 1.45e-45: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y - z) * x) t_1 = Float64(Float64(1.0 - x) * z) tmp = 0.0 if (x <= -1500.0) tmp = t_0; elseif (x <= 2.05e-240) tmp = t_1; elseif (x <= 5e-88) tmp = Float64(y * x); elseif (x <= 1.45e-45) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y - z) * x; t_1 = (1.0 - x) * z; tmp = 0.0; if (x <= -1500.0) tmp = t_0; elseif (x <= 2.05e-240) tmp = t_1; elseif (x <= 5e-88) tmp = y * x; elseif (x <= 1.45e-45) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$1 = N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[x, -1500.0], t$95$0, If[LessEqual[x, 2.05e-240], t$95$1, If[LessEqual[x, 5e-88], N[(y * x), $MachinePrecision], If[LessEqual[x, 1.45e-45], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - z\right) \cdot x\\
t_1 := \left(1 - x\right) \cdot z\\
\mathbf{if}\;x \leq -1500:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.05 \cdot 10^{-240}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 5 \cdot 10^{-88}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{-45}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1500 or 1.45e-45 < x Initial program 97.7%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6493.6
Applied rewrites93.6%
if -1500 < x < 2.0500000000000001e-240 or 5.00000000000000009e-88 < x < 1.45e-45Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6482.7
Applied rewrites82.7%
if 2.0500000000000001e-240 < x < 5.00000000000000009e-88Initial program 99.9%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6468.5
Applied rewrites68.5%
(FPCore (x y z) :precision binary64 (if (<= x -1.46e-8) (* y x) (if (<= x 2.05e-240) (* 1.0 z) (if (<= x 1.32e+139) (* y x) (* (- z) x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.46e-8) {
tmp = y * x;
} else if (x <= 2.05e-240) {
tmp = 1.0 * z;
} else if (x <= 1.32e+139) {
tmp = y * x;
} else {
tmp = -z * 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.46d-8)) then
tmp = y * x
else if (x <= 2.05d-240) then
tmp = 1.0d0 * z
else if (x <= 1.32d+139) then
tmp = y * x
else
tmp = -z * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.46e-8) {
tmp = y * x;
} else if (x <= 2.05e-240) {
tmp = 1.0 * z;
} else if (x <= 1.32e+139) {
tmp = y * x;
} else {
tmp = -z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.46e-8: tmp = y * x elif x <= 2.05e-240: tmp = 1.0 * z elif x <= 1.32e+139: tmp = y * x else: tmp = -z * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.46e-8) tmp = Float64(y * x); elseif (x <= 2.05e-240) tmp = Float64(1.0 * z); elseif (x <= 1.32e+139) tmp = Float64(y * x); else tmp = Float64(Float64(-z) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.46e-8) tmp = y * x; elseif (x <= 2.05e-240) tmp = 1.0 * z; elseif (x <= 1.32e+139) tmp = y * x; else tmp = -z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.46e-8], N[(y * x), $MachinePrecision], If[LessEqual[x, 2.05e-240], N[(1.0 * z), $MachinePrecision], If[LessEqual[x, 1.32e+139], N[(y * x), $MachinePrecision], N[((-z) * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.46 \cdot 10^{-8}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 2.05 \cdot 10^{-240}:\\
\;\;\;\;1 \cdot z\\
\mathbf{elif}\;x \leq 1.32 \cdot 10^{+139}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) \cdot x\\
\end{array}
\end{array}
if x < -1.46e-8 or 2.0500000000000001e-240 < x < 1.31999999999999991e139Initial program 99.3%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6457.2
Applied rewrites57.2%
if -1.46e-8 < x < 2.0500000000000001e-240Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6483.7
Applied rewrites83.7%
Taylor expanded in x around 0
Applied rewrites82.8%
if 1.31999999999999991e139 < x Initial program 93.1%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/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 z around inf
Applied rewrites72.9%
(FPCore (x y z) :precision binary64 (if (<= y -86000000000000.0) (* y x) (if (<= y 5e+70) (* (- 1.0 x) z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -86000000000000.0) {
tmp = y * x;
} else if (y <= 5e+70) {
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 (y <= (-86000000000000.0d0)) then
tmp = y * x
else if (y <= 5d+70) 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 (y <= -86000000000000.0) {
tmp = y * x;
} else if (y <= 5e+70) {
tmp = (1.0 - x) * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -86000000000000.0: tmp = y * x elif y <= 5e+70: tmp = (1.0 - x) * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -86000000000000.0) tmp = Float64(y * x); elseif (y <= 5e+70) 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 (y <= -86000000000000.0) tmp = y * x; elseif (y <= 5e+70) tmp = (1.0 - x) * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -86000000000000.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 5e+70], N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -86000000000000:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 5 \cdot 10^{+70}:\\
\;\;\;\;\left(1 - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -8.6e13 or 5.0000000000000002e70 < y Initial program 98.4%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6470.9
Applied rewrites70.9%
if -8.6e13 < y < 5.0000000000000002e70Initial program 99.2%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6488.5
Applied rewrites88.5%
(FPCore (x y z) :precision binary64 (if (<= x -1.46e-8) (* y x) (if (<= x 2.05e-240) (* 1.0 z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.46e-8) {
tmp = y * x;
} else if (x <= 2.05e-240) {
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.46d-8)) then
tmp = y * x
else if (x <= 2.05d-240) 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.46e-8) {
tmp = y * x;
} else if (x <= 2.05e-240) {
tmp = 1.0 * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.46e-8: tmp = y * x elif x <= 2.05e-240: tmp = 1.0 * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.46e-8) tmp = Float64(y * x); elseif (x <= 2.05e-240) 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.46e-8) tmp = y * x; elseif (x <= 2.05e-240) tmp = 1.0 * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.46e-8], N[(y * x), $MachinePrecision], If[LessEqual[x, 2.05e-240], N[(1.0 * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.46 \cdot 10^{-8}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 2.05 \cdot 10^{-240}:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -1.46e-8 or 2.0500000000000001e-240 < x Initial program 98.3%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6454.1
Applied rewrites54.1%
if -1.46e-8 < x < 2.0500000000000001e-240Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6483.7
Applied rewrites83.7%
Taylor expanded in x around 0
Applied rewrites82.8%
(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 z around 0
*-commutativeN/A
lower-*.f6442.7
Applied rewrites42.7%
herbie shell --seed 2024268
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))