
(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.4%
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 (if (<= x -2.25e+117) (* (- z) x) (if (<= x -3.8e-46) (* y x) (if (<= x 3.75e-10) (* 1.0 z) (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.25e+117) {
tmp = -z * x;
} else if (x <= -3.8e-46) {
tmp = y * x;
} else if (x <= 3.75e-10) {
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 <= (-2.25d+117)) then
tmp = -z * x
else if (x <= (-3.8d-46)) then
tmp = y * x
else if (x <= 3.75d-10) 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 <= -2.25e+117) {
tmp = -z * x;
} else if (x <= -3.8e-46) {
tmp = y * x;
} else if (x <= 3.75e-10) {
tmp = 1.0 * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.25e+117: tmp = -z * x elif x <= -3.8e-46: tmp = y * x elif x <= 3.75e-10: tmp = 1.0 * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.25e+117) tmp = Float64(Float64(-z) * x); elseif (x <= -3.8e-46) tmp = Float64(y * x); elseif (x <= 3.75e-10) 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 <= -2.25e+117) tmp = -z * x; elseif (x <= -3.8e-46) tmp = y * x; elseif (x <= 3.75e-10) tmp = 1.0 * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.25e+117], N[((-z) * x), $MachinePrecision], If[LessEqual[x, -3.8e-46], N[(y * x), $MachinePrecision], If[LessEqual[x, 3.75e-10], N[(1.0 * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.25 \cdot 10^{+117}:\\
\;\;\;\;\left(-z\right) \cdot x\\
\mathbf{elif}\;x \leq -3.8 \cdot 10^{-46}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 3.75 \cdot 10^{-10}:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -2.25e117Initial program 94.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--.f64100.0
Applied rewrites100.0%
Taylor expanded in z around inf
Applied rewrites64.7%
if -2.25e117 < x < -3.7999999999999997e-46 or 3.74999999999999998e-10 < x Initial program 98.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6457.4
Applied rewrites57.4%
if -3.7999999999999997e-46 < x < 3.74999999999999998e-10Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6480.9
Applied rewrites80.9%
Taylor expanded in x around 0
Applied rewrites80.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- y z) x))) (if (<= x -3.6e-46) t_0 (if (<= x 5100000000000.0) (* (- 1.0 x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = (y - z) * x;
double tmp;
if (x <= -3.6e-46) {
tmp = t_0;
} else if (x <= 5100000000000.0) {
tmp = (1.0 - x) * 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 = (y - z) * x
if (x <= (-3.6d-46)) then
tmp = t_0
else if (x <= 5100000000000.0d0) then
tmp = (1.0d0 - x) * z
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 tmp;
if (x <= -3.6e-46) {
tmp = t_0;
} else if (x <= 5100000000000.0) {
tmp = (1.0 - x) * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y - z) * x tmp = 0 if x <= -3.6e-46: tmp = t_0 elif x <= 5100000000000.0: 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 <= -3.6e-46) tmp = t_0; elseif (x <= 5100000000000.0) tmp = Float64(Float64(1.0 - x) * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y - z) * x; tmp = 0.0; if (x <= -3.6e-46) tmp = t_0; elseif (x <= 5100000000000.0) tmp = (1.0 - x) * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -3.6e-46], t$95$0, If[LessEqual[x, 5100000000000.0], 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 -3.6 \cdot 10^{-46}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 5100000000000:\\
\;\;\;\;\left(1 - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.6e-46 or 5.1e12 < x Initial program 97.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--.f6496.9
Applied rewrites96.9%
if -3.6e-46 < x < 5.1e12Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6481.1
Applied rewrites81.1%
(FPCore (x y z) :precision binary64 (if (<= y -3.2e+105) (* y x) (if (<= y 7.4e+22) (* (- 1.0 x) z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.2e+105) {
tmp = y * x;
} else if (y <= 7.4e+22) {
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 <= (-3.2d+105)) then
tmp = y * x
else if (y <= 7.4d+22) 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 <= -3.2e+105) {
tmp = y * x;
} else if (y <= 7.4e+22) {
tmp = (1.0 - x) * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.2e+105: tmp = y * x elif y <= 7.4e+22: tmp = (1.0 - x) * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.2e+105) tmp = Float64(y * x); elseif (y <= 7.4e+22) 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 <= -3.2e+105) tmp = y * x; elseif (y <= 7.4e+22) tmp = (1.0 - x) * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.2e+105], N[(y * x), $MachinePrecision], If[LessEqual[y, 7.4e+22], N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{+105}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 7.4 \cdot 10^{+22}:\\
\;\;\;\;\left(1 - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -3.2e105 or 7.3999999999999996e22 < y Initial program 96.7%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6475.5
Applied rewrites75.5%
if -3.2e105 < y < 7.3999999999999996e22Initial program 99.4%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6483.2
Applied rewrites83.2%
(FPCore (x y z) :precision binary64 (if (<= x -3.8e-46) (* y x) (if (<= x 3.75e-10) (* 1.0 z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.8e-46) {
tmp = y * x;
} else if (x <= 3.75e-10) {
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 <= (-3.8d-46)) then
tmp = y * x
else if (x <= 3.75d-10) 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 <= -3.8e-46) {
tmp = y * x;
} else if (x <= 3.75e-10) {
tmp = 1.0 * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.8e-46: tmp = y * x elif x <= 3.75e-10: tmp = 1.0 * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.8e-46) tmp = Float64(y * x); elseif (x <= 3.75e-10) 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 <= -3.8e-46) tmp = y * x; elseif (x <= 3.75e-10) tmp = 1.0 * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.8e-46], N[(y * x), $MachinePrecision], If[LessEqual[x, 3.75e-10], N[(1.0 * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-46}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 3.75 \cdot 10^{-10}:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -3.7999999999999997e-46 or 3.74999999999999998e-10 < x Initial program 97.1%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6451.9
Applied rewrites51.9%
if -3.7999999999999997e-46 < x < 3.74999999999999998e-10Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6480.9
Applied rewrites80.9%
Taylor expanded in x around 0
Applied rewrites80.5%
(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.4%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6438.3
Applied rewrites38.3%
herbie shell --seed 2024257
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))