
(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 6 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 y (- x z) z))
double code(double x, double y, double z) {
return fma(y, (x - z), z);
}
function code(x, y, z) return fma(y, Float64(x - z), z) end
code[x_, y_, z_] := N[(y * N[(x - z), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x - z, z\right)
\end{array}
Initial program 99.2%
Taylor expanded in x around 0
distribute-rgt-out--N/A
unsub-negN/A
*-lft-identityN/A
mul-1-negN/A
+-commutativeN/A
associate-+l+N/A
*-commutativeN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
distribute-lft-inN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-fma.f64N/A
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- x z)))) (if (<= y -14500.0) t_0 (if (<= y 7e-9) (fma (- z) y z) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -14500.0) {
tmp = t_0;
} else if (y <= 7e-9) {
tmp = fma(-z, y, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y * Float64(x - z)) tmp = 0.0 if (y <= -14500.0) tmp = t_0; elseif (y <= 7e-9) tmp = fma(Float64(-z), y, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -14500.0], t$95$0, If[LessEqual[y, 7e-9], N[((-z) * y + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -14500:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 7 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(-z, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -14500 or 6.9999999999999998e-9 < y Initial program 98.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
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6499.1
Applied rewrites99.1%
if -14500 < y < 6.9999999999999998e-9Initial program 100.0%
Taylor expanded in x around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6479.2
Applied rewrites79.2%
Applied rewrites79.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- x z)))) (if (<= y -14500.0) t_0 (if (<= y 7e-9) (- z (* y z)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -14500.0) {
tmp = t_0;
} else if (y <= 7e-9) {
tmp = z - (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 = y * (x - z)
if (y <= (-14500.0d0)) then
tmp = t_0
else if (y <= 7d-9) then
tmp = z - (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 = y * (x - z);
double tmp;
if (y <= -14500.0) {
tmp = t_0;
} else if (y <= 7e-9) {
tmp = z - (y * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x - z) tmp = 0 if y <= -14500.0: tmp = t_0 elif y <= 7e-9: tmp = z - (y * z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x - z)) tmp = 0.0 if (y <= -14500.0) tmp = t_0; elseif (y <= 7e-9) tmp = Float64(z - Float64(y * z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x - z); tmp = 0.0; if (y <= -14500.0) tmp = t_0; elseif (y <= 7e-9) tmp = z - (y * z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -14500.0], t$95$0, If[LessEqual[y, 7e-9], N[(z - N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -14500:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 7 \cdot 10^{-9}:\\
\;\;\;\;z - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -14500 or 6.9999999999999998e-9 < y Initial program 98.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
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6499.1
Applied rewrites99.1%
if -14500 < y < 6.9999999999999998e-9Initial program 100.0%
Taylor expanded in x around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6479.2
Applied rewrites79.2%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (<= x -8.8e-38) (* x y) (if (<= x 5000000000.0) (* y (- z)) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -8.8e-38) {
tmp = x * y;
} else if (x <= 5000000000.0) {
tmp = y * -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 (x <= (-8.8d-38)) then
tmp = x * y
else if (x <= 5000000000.0d0) then
tmp = y * -z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -8.8e-38) {
tmp = x * y;
} else if (x <= 5000000000.0) {
tmp = y * -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -8.8e-38: tmp = x * y elif x <= 5000000000.0: tmp = y * -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -8.8e-38) tmp = Float64(x * y); elseif (x <= 5000000000.0) tmp = Float64(y * Float64(-z)); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -8.8e-38) tmp = x * y; elseif (x <= 5000000000.0) tmp = y * -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -8.8e-38], N[(x * y), $MachinePrecision], If[LessEqual[x, 5000000000.0], N[(y * (-z)), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.8 \cdot 10^{-38}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 5000000000:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -8.80000000000000029e-38 or 5e9 < x Initial program 98.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6466.5
Applied rewrites66.5%
if -8.80000000000000029e-38 < x < 5e9Initial program 100.0%
Taylor expanded in y around inf
+-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--.f6449.9
Applied rewrites49.9%
Taylor expanded in x around 0
Applied rewrites35.4%
Final simplification49.8%
(FPCore (x y z) :precision binary64 (* y (- x z)))
double code(double x, double y, double z) {
return y * (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 = y * (x - z)
end function
public static double code(double x, double y, double z) {
return y * (x - z);
}
def code(x, y, z): return y * (x - z)
function code(x, y, z) return Float64(y * Float64(x - z)) end
function tmp = code(x, y, z) tmp = y * (x - z); end
code[x_, y_, z_] := N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(x - z\right)
\end{array}
Initial program 99.2%
Taylor expanded in y around inf
+-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--.f6460.5
Applied rewrites60.5%
(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 99.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6439.5
Applied rewrites39.5%
Final simplification39.5%
(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 2024238
(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))))