
(FPCore (x y z) :precision binary64 (+ (* x y) (* z (- 1.0 y))))
double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - 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) + (z * (1.0d0 - y))
end function
public static double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
def code(x, y, z): return (x * y) + (z * (1.0 - y))
function code(x, y, z) return Float64(Float64(x * y) + Float64(z * Float64(1.0 - y))) end
function tmp = code(x, y, z) tmp = (x * y) + (z * (1.0 - y)); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + z \cdot \left(1 - y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* z (- 1.0 y))))
double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - 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) + (z * (1.0d0 - y))
end function
public static double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
def code(x, y, z): return (x * y) + (z * (1.0 - y))
function code(x, y, z) return Float64(Float64(x * y) + Float64(z * Float64(1.0 - y))) end
function tmp = code(x, y, z) tmp = (x * y) + (z * (1.0 - y)); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + z \cdot \left(1 - y\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma (- x z) y z))
double code(double x, double y, double z) {
return fma((x - z), y, z);
}
function code(x, y, z) return fma(Float64(x - z), y, z) end
code[x_, y_, z_] := N[(N[(x - z), $MachinePrecision] * y + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x - z, y, z\right)
\end{array}
Initial program 97.6%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-out--N/A
unsub-negN/A
*-lft-identityN/A
mul-1-negN/A
+-commutativeN/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
*-commutativeN/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 (* (- x z) y))) (if (<= y -6.5e-131) t_0 (if (<= y 8.5e-7) (* (- 1.0 y) z) t_0))))
double code(double x, double y, double z) {
double t_0 = (x - z) * y;
double tmp;
if (y <= -6.5e-131) {
tmp = t_0;
} else if (y <= 8.5e-7) {
tmp = (1.0 - y) * 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 - z) * y
if (y <= (-6.5d-131)) then
tmp = t_0
else if (y <= 8.5d-7) then
tmp = (1.0d0 - y) * 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 - z) * y;
double tmp;
if (y <= -6.5e-131) {
tmp = t_0;
} else if (y <= 8.5e-7) {
tmp = (1.0 - y) * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x - z) * y tmp = 0 if y <= -6.5e-131: tmp = t_0 elif y <= 8.5e-7: tmp = (1.0 - y) * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x - z) * y) tmp = 0.0 if (y <= -6.5e-131) tmp = t_0; elseif (y <= 8.5e-7) tmp = Float64(Float64(1.0 - y) * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x - z) * y; tmp = 0.0; if (y <= -6.5e-131) tmp = t_0; elseif (y <= 8.5e-7) tmp = (1.0 - y) * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x - z), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -6.5e-131], t$95$0, If[LessEqual[y, 8.5e-7], N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x - z\right) \cdot y\\
\mathbf{if}\;y \leq -6.5 \cdot 10^{-131}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{-7}:\\
\;\;\;\;\left(1 - y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -6.5000000000000002e-131 or 8.50000000000000014e-7 < y Initial program 96.4%
Taylor expanded in y around inf
*-commutativeN/A
remove-double-negN/A
mul-1-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--.f6494.6
Applied rewrites94.6%
if -6.5000000000000002e-131 < y < 8.50000000000000014e-7Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6473.0
Applied rewrites73.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z) y))) (if (<= y -1.45e-6) t_0 (if (<= y 1.0) (* 1.0 z) t_0))))
double code(double x, double y, double z) {
double t_0 = -z * y;
double tmp;
if (y <= -1.45e-6) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = 1.0 * 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 = -z * y
if (y <= (-1.45d-6)) then
tmp = t_0
else if (y <= 1.0d0) then
tmp = 1.0d0 * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -z * y;
double tmp;
if (y <= -1.45e-6) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = 1.0 * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -z * y tmp = 0 if y <= -1.45e-6: tmp = t_0 elif y <= 1.0: tmp = 1.0 * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-z) * y) tmp = 0.0 if (y <= -1.45e-6) tmp = t_0; elseif (y <= 1.0) tmp = Float64(1.0 * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -z * y; tmp = 0.0; if (y <= -1.45e-6) tmp = t_0; elseif (y <= 1.0) tmp = 1.0 * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * y), $MachinePrecision]}, If[LessEqual[y, -1.45e-6], t$95$0, If[LessEqual[y, 1.0], N[(1.0 * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot y\\
\mathbf{if}\;y \leq -1.45 \cdot 10^{-6}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.4500000000000001e-6 or 1 < y Initial program 95.7%
Taylor expanded in y around inf
*-commutativeN/A
remove-double-negN/A
mul-1-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--.f6498.9
Applied rewrites98.9%
Taylor expanded in x around 0
Applied rewrites48.4%
if -1.4500000000000001e-6 < y < 1Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6463.9
Applied rewrites63.9%
Taylor expanded in y around 0
Applied rewrites63.4%
(FPCore (x y z) :precision binary64 (* (- 1.0 y) z))
double code(double x, double y, double z) {
return (1.0 - 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 = (1.0d0 - y) * z
end function
public static double code(double x, double y, double z) {
return (1.0 - y) * z;
}
def code(x, y, z): return (1.0 - y) * z
function code(x, y, z) return Float64(Float64(1.0 - y) * z) end
function tmp = code(x, y, z) tmp = (1.0 - y) * z; end
code[x_, y_, z_] := N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - y\right) \cdot z
\end{array}
Initial program 97.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6456.0
Applied rewrites56.0%
(FPCore (x y z) :precision binary64 (* 1.0 z))
double code(double x, double y, double z) {
return 1.0 * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 * z
end function
public static double code(double x, double y, double z) {
return 1.0 * z;
}
def code(x, y, z): return 1.0 * z
function code(x, y, z) return Float64(1.0 * z) end
function tmp = code(x, y, z) tmp = 1.0 * z; end
code[x_, y_, z_] := N[(1.0 * z), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot z
\end{array}
Initial program 97.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6456.0
Applied rewrites56.0%
Taylor expanded in y around 0
Applied rewrites30.0%
(FPCore (x y z) :precision binary64 (- z (* (- z x) y)))
double code(double x, double y, double z) {
return z - ((z - 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 = z - ((z - x) * y)
end function
public static double code(double x, double y, double z) {
return z - ((z - x) * y);
}
def code(x, y, z): return z - ((z - x) * y)
function code(x, y, z) return Float64(z - Float64(Float64(z - x) * y)) end
function tmp = code(x, y, z) tmp = z - ((z - x) * y); end
code[x_, y_, z_] := N[(z - N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - \left(z - x\right) \cdot y
\end{array}
herbie shell --seed 2024327
(FPCore (x y z)
:name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
:precision binary64
:alt
(! :herbie-platform default (- z (* (- z x) y)))
(+ (* x y) (* z (- 1.0 y))))