
(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 97.6%
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 (* z (- y))))
(if (<= y -3.3e+156)
t_0
(if (<= y -8e-98)
(* y x)
(if (<= y 4.3e-7) (fma z y z) (if (<= y 8.5e+96) (* y x) t_0))))))
double code(double x, double y, double z) {
double t_0 = z * -y;
double tmp;
if (y <= -3.3e+156) {
tmp = t_0;
} else if (y <= -8e-98) {
tmp = y * x;
} else if (y <= 4.3e-7) {
tmp = fma(z, y, z);
} else if (y <= 8.5e+96) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * Float64(-y)) tmp = 0.0 if (y <= -3.3e+156) tmp = t_0; elseif (y <= -8e-98) tmp = Float64(y * x); elseif (y <= 4.3e-7) tmp = fma(z, y, z); elseif (y <= 8.5e+96) tmp = Float64(y * x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-y)), $MachinePrecision]}, If[LessEqual[y, -3.3e+156], t$95$0, If[LessEqual[y, -8e-98], N[(y * x), $MachinePrecision], If[LessEqual[y, 4.3e-7], N[(z * y + z), $MachinePrecision], If[LessEqual[y, 8.5e+96], N[(y * x), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -3.3 \cdot 10^{+156}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -8 \cdot 10^{-98}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(z, y, z\right)\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{+96}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.2999999999999999e156 or 8.50000000000000025e96 < y Initial program 92.9%
Taylor expanded in x around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6467.3
Applied rewrites67.3%
Taylor expanded in y around inf
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6467.3
Applied rewrites67.3%
if -3.2999999999999999e156 < y < -7.99999999999999951e-98 or 4.3000000000000001e-7 < y < 8.50000000000000025e96Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6471.0
Applied rewrites71.0%
if -7.99999999999999951e-98 < y < 4.3000000000000001e-7Initial program 100.0%
Taylor expanded in x around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6474.2
Applied rewrites74.2%
lift-*.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6474.2
Applied rewrites74.2%
neg-sub0N/A
flip3--N/A
metadata-evalN/A
sub0-negN/A
cube-negN/A
lift-neg.f64N/A
sqr-powN/A
unpow-prod-downN/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
metadata-evalN/A
+-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
+-lft-identityN/A
pow2N/A
pow-divN/A
metadata-evalN/A
unpow173.8
Applied rewrites73.8%
Final simplification71.0%
(FPCore (x y z) :precision binary64 (if (<= z -2.9e-133) (fma (- z) y z) (if (<= z 6.5e-65) (* y x) (- z (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.9e-133) {
tmp = fma(-z, y, z);
} else if (z <= 6.5e-65) {
tmp = y * x;
} else {
tmp = z - (y * z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -2.9e-133) tmp = fma(Float64(-z), y, z); elseif (z <= 6.5e-65) tmp = Float64(y * x); else tmp = Float64(z - Float64(y * z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -2.9e-133], N[((-z) * y + z), $MachinePrecision], If[LessEqual[z, 6.5e-65], N[(y * x), $MachinePrecision], N[(z - N[(y * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.9 \cdot 10^{-133}:\\
\;\;\;\;\mathsf{fma}\left(-z, y, z\right)\\
\mathbf{elif}\;z \leq 6.5 \cdot 10^{-65}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z - y \cdot z\\
\end{array}
\end{array}
if z < -2.8999999999999998e-133Initial program 96.2%
Taylor expanded in x around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6482.2
Applied rewrites82.2%
lift-*.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6482.2
Applied rewrites82.2%
if -2.8999999999999998e-133 < z < 6.5e-65Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6480.5
Applied rewrites80.5%
if 6.5e-65 < z Initial program 96.6%
Taylor expanded in x around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6485.5
Applied rewrites85.5%
Final simplification82.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- z (* y z)))) (if (<= z -2.9e-133) t_0 (if (<= z 6.5e-65) (* y x) t_0))))
double code(double x, double y, double z) {
double t_0 = z - (y * z);
double tmp;
if (z <= -2.9e-133) {
tmp = t_0;
} else if (z <= 6.5e-65) {
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 = z - (y * z)
if (z <= (-2.9d-133)) then
tmp = t_0
else if (z <= 6.5d-65) 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 = z - (y * z);
double tmp;
if (z <= -2.9e-133) {
tmp = t_0;
} else if (z <= 6.5e-65) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z - (y * z) tmp = 0 if z <= -2.9e-133: tmp = t_0 elif z <= 6.5e-65: tmp = y * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z - Float64(y * z)) tmp = 0.0 if (z <= -2.9e-133) tmp = t_0; elseif (z <= 6.5e-65) tmp = Float64(y * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z - (y * z); tmp = 0.0; if (z <= -2.9e-133) tmp = t_0; elseif (z <= 6.5e-65) tmp = y * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.9e-133], t$95$0, If[LessEqual[z, 6.5e-65], N[(y * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z - y \cdot z\\
\mathbf{if}\;z \leq -2.9 \cdot 10^{-133}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 6.5 \cdot 10^{-65}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.8999999999999998e-133 or 6.5e-65 < z Initial program 96.4%
Taylor expanded in x around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6483.9
Applied rewrites83.9%
if -2.8999999999999998e-133 < z < 6.5e-65Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6480.5
Applied rewrites80.5%
Final simplification82.7%
(FPCore (x y z) :precision binary64 (if (<= y -8e-98) (* y x) (if (<= y 4.3e-7) (fma z y z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8e-98) {
tmp = y * x;
} else if (y <= 4.3e-7) {
tmp = fma(z, y, z);
} else {
tmp = y * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -8e-98) tmp = Float64(y * x); elseif (y <= 4.3e-7) tmp = fma(z, y, z); else tmp = Float64(y * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -8e-98], N[(y * x), $MachinePrecision], If[LessEqual[y, 4.3e-7], N[(z * y + z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{-98}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(z, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -7.99999999999999951e-98 or 4.3000000000000001e-7 < y Initial program 95.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6455.3
Applied rewrites55.3%
if -7.99999999999999951e-98 < y < 4.3000000000000001e-7Initial program 100.0%
Taylor expanded in x around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6474.2
Applied rewrites74.2%
lift-*.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6474.2
Applied rewrites74.2%
neg-sub0N/A
flip3--N/A
metadata-evalN/A
sub0-negN/A
cube-negN/A
lift-neg.f64N/A
sqr-powN/A
unpow-prod-downN/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
metadata-evalN/A
+-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
+-lft-identityN/A
pow2N/A
pow-divN/A
metadata-evalN/A
unpow173.8
Applied rewrites73.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 97.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6442.6
Applied rewrites42.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 2024219
(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))))