
(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 x (- y z) z))
double code(double x, double y, double z) {
return fma(x, (y - z), z);
}
function code(x, y, z) return fma(x, Float64(y - z), z) end
code[x_, y_, z_] := N[(x * N[(y - z), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y - z, z\right)
\end{array}
Initial program 98.8%
Taylor expanded in x around 0
+-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 (* x (- y z)))) (if (<= x -5.5e+26) t_0 (if (<= x 2.8e-54) (- z (* x z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -5.5e+26) {
tmp = t_0;
} else if (x <= 2.8e-54) {
tmp = z - (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 = x * (y - z)
if (x <= (-5.5d+26)) then
tmp = t_0
else if (x <= 2.8d-54) then
tmp = z - (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 = x * (y - z);
double tmp;
if (x <= -5.5e+26) {
tmp = t_0;
} else if (x <= 2.8e-54) {
tmp = z - (x * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y - z) tmp = 0 if x <= -5.5e+26: tmp = t_0 elif x <= 2.8e-54: tmp = z - (x * z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y - z)) tmp = 0.0 if (x <= -5.5e+26) tmp = t_0; elseif (x <= 2.8e-54) tmp = Float64(z - Float64(x * z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y - z); tmp = 0.0; if (x <= -5.5e+26) tmp = t_0; elseif (x <= 2.8e-54) tmp = z - (x * z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -5.5e+26], t$95$0, If[LessEqual[x, 2.8e-54], N[(z - N[(x * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - z\right)\\
\mathbf{if}\;x \leq -5.5 \cdot 10^{+26}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{-54}:\\
\;\;\;\;z - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -5.4999999999999997e26 or 2.8000000000000002e-54 < x Initial program 97.6%
Taylor expanded in x around inf
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.0
Applied rewrites97.0%
if -5.4999999999999997e26 < x < 2.8000000000000002e-54Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6480.1
Applied rewrites80.1%
Final simplification88.2%
(FPCore (x y z) :precision binary64 (if (<= y -1.18e-51) (* x y) (if (<= y 4.6e-52) (* x (- z)) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.18e-51) {
tmp = x * y;
} else if (y <= 4.6e-52) {
tmp = x * -z;
} else {
tmp = x * y;
}
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 <= (-1.18d-51)) then
tmp = x * y
else if (y <= 4.6d-52) then
tmp = x * -z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.18e-51) {
tmp = x * y;
} else if (y <= 4.6e-52) {
tmp = x * -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.18e-51: tmp = x * y elif y <= 4.6e-52: tmp = x * -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.18e-51) tmp = Float64(x * y); elseif (y <= 4.6e-52) tmp = Float64(x * Float64(-z)); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.18e-51) tmp = x * y; elseif (y <= 4.6e-52) tmp = x * -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.18e-51], N[(x * y), $MachinePrecision], If[LessEqual[y, 4.6e-52], N[(x * (-z)), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.18 \cdot 10^{-51}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 4.6 \cdot 10^{-52}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.18000000000000004e-51 or 4.59999999999999989e-52 < y Initial program 97.9%
Taylor expanded in y around inf
lower-*.f6464.6
Applied rewrites64.6%
if -1.18000000000000004e-51 < y < 4.59999999999999989e-52Initial program 100.0%
Taylor expanded in x around inf
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--.f6448.1
Applied rewrites48.1%
Taylor expanded in y around 0
Applied rewrites39.9%
(FPCore (x y z) :precision binary64 (* x (- y z)))
double code(double x, double y, double z) {
return x * (y - 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 - z)
end function
public static double code(double x, double y, double z) {
return x * (y - z);
}
def code(x, y, z): return x * (y - z)
function code(x, y, z) return Float64(x * Float64(y - z)) end
function tmp = code(x, y, z) tmp = x * (y - z); end
code[x_, y_, z_] := N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y - z\right)
\end{array}
Initial program 98.8%
Taylor expanded in x around inf
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--.f6459.9
Applied rewrites59.9%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * y;
}
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
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 98.8%
Taylor expanded in y around inf
lower-*.f6441.1
Applied rewrites41.1%
herbie shell --seed 2024221
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))