
(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 7 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 98.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
distribute-rgt-out--N/A
*-lft-identityN/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
+-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 (* (- z) y)))
(if (<= y -8.2e+226)
t_0
(if (<= y -10000000.0)
(* y x)
(if (<= y 1.0) (* 1.0 z) (if (<= y 9.5e+137) t_0 (* y x)))))))
double code(double x, double y, double z) {
double t_0 = -z * y;
double tmp;
if (y <= -8.2e+226) {
tmp = t_0;
} else if (y <= -10000000.0) {
tmp = y * x;
} else if (y <= 1.0) {
tmp = 1.0 * z;
} else if (y <= 9.5e+137) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = -z * y
if (y <= (-8.2d+226)) then
tmp = t_0
else if (y <= (-10000000.0d0)) then
tmp = y * x
else if (y <= 1.0d0) then
tmp = 1.0d0 * z
else if (y <= 9.5d+137) then
tmp = t_0
else
tmp = y * x
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 <= -8.2e+226) {
tmp = t_0;
} else if (y <= -10000000.0) {
tmp = y * x;
} else if (y <= 1.0) {
tmp = 1.0 * z;
} else if (y <= 9.5e+137) {
tmp = t_0;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): t_0 = -z * y tmp = 0 if y <= -8.2e+226: tmp = t_0 elif y <= -10000000.0: tmp = y * x elif y <= 1.0: tmp = 1.0 * z elif y <= 9.5e+137: tmp = t_0 else: tmp = y * x return tmp
function code(x, y, z) t_0 = Float64(Float64(-z) * y) tmp = 0.0 if (y <= -8.2e+226) tmp = t_0; elseif (y <= -10000000.0) tmp = Float64(y * x); elseif (y <= 1.0) tmp = Float64(1.0 * z); elseif (y <= 9.5e+137) tmp = t_0; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) t_0 = -z * y; tmp = 0.0; if (y <= -8.2e+226) tmp = t_0; elseif (y <= -10000000.0) tmp = y * x; elseif (y <= 1.0) tmp = 1.0 * z; elseif (y <= 9.5e+137) tmp = t_0; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * y), $MachinePrecision]}, If[LessEqual[y, -8.2e+226], t$95$0, If[LessEqual[y, -10000000.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.0], N[(1.0 * z), $MachinePrecision], If[LessEqual[y, 9.5e+137], t$95$0, N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot y\\
\mathbf{if}\;y \leq -8.2 \cdot 10^{+226}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -10000000:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;1 \cdot z\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{+137}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -8.19999999999999971e226 or 1 < y < 9.50000000000000031e137Initial program 95.2%
Taylor expanded in y 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--.f6495.8
Applied rewrites95.8%
Taylor expanded in z around inf
Applied rewrites72.2%
if -8.19999999999999971e226 < y < -1e7 or 9.50000000000000031e137 < y Initial program 96.2%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6462.9
Applied rewrites62.9%
if -1e7 < y < 1Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6474.4
Applied rewrites74.4%
Taylor expanded in y around 0
Applied rewrites71.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- x z) y))) (if (<= y -10000000.0) t_0 (if (<= y 1350000.0) (fma (- z) y z) t_0))))
double code(double x, double y, double z) {
double t_0 = (x - z) * y;
double tmp;
if (y <= -10000000.0) {
tmp = t_0;
} else if (y <= 1350000.0) {
tmp = fma(-z, 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 <= -10000000.0) tmp = t_0; elseif (y <= 1350000.0) tmp = fma(Float64(-z), y, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x - z), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -10000000.0], t$95$0, If[LessEqual[y, 1350000.0], N[((-z) * y + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x - z\right) \cdot y\\
\mathbf{if}\;y \leq -10000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1350000:\\
\;\;\;\;\mathsf{fma}\left(-z, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1e7 or 1.35e6 < y Initial program 95.8%
Taylor expanded in y 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%
if -1e7 < y < 1.35e6Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6475.0
Applied rewrites75.0%
Applied rewrites75.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- x z) y))) (if (<= y -10000000.0) t_0 (if (<= y 1350000.0) (* (- 1.0 y) z) t_0))))
double code(double x, double y, double z) {
double t_0 = (x - z) * y;
double tmp;
if (y <= -10000000.0) {
tmp = t_0;
} else if (y <= 1350000.0) {
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 <= (-10000000.0d0)) then
tmp = t_0
else if (y <= 1350000.0d0) 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 <= -10000000.0) {
tmp = t_0;
} else if (y <= 1350000.0) {
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 <= -10000000.0: tmp = t_0 elif y <= 1350000.0: 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 <= -10000000.0) tmp = t_0; elseif (y <= 1350000.0) 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 <= -10000000.0) tmp = t_0; elseif (y <= 1350000.0) 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, -10000000.0], t$95$0, If[LessEqual[y, 1350000.0], 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 -10000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1350000:\\
\;\;\;\;\left(1 - y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1e7 or 1.35e6 < y Initial program 95.8%
Taylor expanded in y 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%
if -1e7 < y < 1.35e6Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6475.0
Applied rewrites75.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- 1.0 y) z))) (if (<= z -5.5e-86) t_0 (if (<= z 1.12e-145) (* y x) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 - y) * z;
double tmp;
if (z <= -5.5e-86) {
tmp = t_0;
} else if (z <= 1.12e-145) {
tmp = y * x;
} 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 = (1.0d0 - y) * z
if (z <= (-5.5d-86)) then
tmp = t_0
else if (z <= 1.12d-145) then
tmp = y * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (1.0 - y) * z;
double tmp;
if (z <= -5.5e-86) {
tmp = t_0;
} else if (z <= 1.12e-145) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 - y) * z tmp = 0 if z <= -5.5e-86: tmp = t_0 elif z <= 1.12e-145: tmp = y * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 - y) * z) tmp = 0.0 if (z <= -5.5e-86) tmp = t_0; elseif (z <= 1.12e-145) tmp = Float64(y * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 - y) * z; tmp = 0.0; if (z <= -5.5e-86) tmp = t_0; elseif (z <= 1.12e-145) tmp = y * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -5.5e-86], t$95$0, If[LessEqual[z, 1.12e-145], N[(y * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - y\right) \cdot z\\
\mathbf{if}\;z \leq -5.5 \cdot 10^{-86}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.12 \cdot 10^{-145}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.5e-86 or 1.12000000000000001e-145 < z Initial program 97.2%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6480.6
Applied rewrites80.6%
if -5.5e-86 < z < 1.12000000000000001e-145Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6474.7
Applied rewrites74.7%
(FPCore (x y z) :precision binary64 (if (<= y -10000000.0) (* y x) (if (<= y 1.35e-63) (* 1.0 z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -10000000.0) {
tmp = y * x;
} else if (y <= 1.35e-63) {
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 (y <= (-10000000.0d0)) then
tmp = y * x
else if (y <= 1.35d-63) 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 (y <= -10000000.0) {
tmp = y * x;
} else if (y <= 1.35e-63) {
tmp = 1.0 * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -10000000.0: tmp = y * x elif y <= 1.35e-63: tmp = 1.0 * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -10000000.0) tmp = Float64(y * x); elseif (y <= 1.35e-63) 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 (y <= -10000000.0) tmp = y * x; elseif (y <= 1.35e-63) tmp = 1.0 * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -10000000.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.35e-63], N[(1.0 * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -10000000:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{-63}:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1e7 or 1.3500000000000001e-63 < y Initial program 96.2%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6450.9
Applied rewrites50.9%
if -1e7 < y < 1.3500000000000001e-63Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6476.7
Applied rewrites76.7%
Taylor expanded in y around 0
Applied rewrites74.8%
(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.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6438.6
Applied rewrites38.6%
(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 2024254
(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))))