
(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.4%
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
Simplified100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- y z)))) (if (<= x -1.8e-5) t_0 (if (<= x 7.2e-69) (- z (* x z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -1.8e-5) {
tmp = t_0;
} else if (x <= 7.2e-69) {
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 <= (-1.8d-5)) then
tmp = t_0
else if (x <= 7.2d-69) 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 <= -1.8e-5) {
tmp = t_0;
} else if (x <= 7.2e-69) {
tmp = z - (x * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y - z) tmp = 0 if x <= -1.8e-5: tmp = t_0 elif x <= 7.2e-69: 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 <= -1.8e-5) tmp = t_0; elseif (x <= 7.2e-69) 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 <= -1.8e-5) tmp = t_0; elseif (x <= 7.2e-69) 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, -1.8e-5], t$95$0, If[LessEqual[x, 7.2e-69], 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 -1.8 \cdot 10^{-5}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 7.2 \cdot 10^{-69}:\\
\;\;\;\;z - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.80000000000000005e-5 or 7.20000000000000035e-69 < x Initial program 97.3%
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--.f6496.2
Simplified96.2%
if -1.80000000000000005e-5 < x < 7.20000000000000035e-69Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6479.1
Simplified79.1%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- z)))) (if (<= z -3.8e+24) t_0 (if (<= z 1.25e+26) (* x y) t_0))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -3.8e+24) {
tmp = t_0;
} else if (z <= 1.25e+26) {
tmp = x * y;
} 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 * -z
if (z <= (-3.8d+24)) then
tmp = t_0
else if (z <= 1.25d+26) then
tmp = x * y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -3.8e+24) {
tmp = t_0;
} else if (z <= 1.25e+26) {
tmp = x * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -3.8e+24: tmp = t_0 elif z <= 1.25e+26: tmp = x * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -3.8e+24) tmp = t_0; elseif (z <= 1.25e+26) tmp = Float64(x * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -3.8e+24) tmp = t_0; elseif (z <= 1.25e+26) tmp = x * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -3.8e+24], t$95$0, If[LessEqual[z, 1.25e+26], N[(x * y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -3.8 \cdot 10^{+24}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.25 \cdot 10^{+26}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.80000000000000015e24 or 1.25e26 < z Initial program 96.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--.f6458.8
Simplified58.8%
Taylor expanded in y around 0
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6453.1
Simplified53.1%
if -3.80000000000000015e24 < z < 1.25e26Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6463.7
Simplified63.7%
Final simplification58.8%
(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.4%
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--.f6466.2
Simplified66.2%
(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.4%
Taylor expanded in y around inf
lower-*.f6440.0
Simplified40.0%
herbie shell --seed 2024215
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))