
(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 8 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%
distribute-lft-out--99.2%
*-rgt-identity99.2%
cancel-sign-sub-inv99.2%
+-commutative99.2%
associate-+r+99.2%
distribute-rgt-out100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.35e-13))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.35e-13)) {
tmp = y * (x - z);
} else {
tmp = z + (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 <= (-1.0d0)) .or. (.not. (y <= 1.35d-13))) then
tmp = y * (x - z)
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.35e-13)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.35e-13): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.35e-13)) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.35e-13))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.35e-13]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1.35 \cdot 10^{-13}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -1 or 1.35000000000000005e-13 < y Initial program 98.5%
Taylor expanded in y around inf 98.5%
neg-mul-198.5%
sub-neg98.5%
Simplified98.5%
if -1 < y < 1.35000000000000005e-13Initial program 99.9%
distribute-lft-out--100.0%
*-rgt-identity100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-rgt-out100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 98.7%
fma-undefine98.7%
Applied egg-rr98.7%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -4700000.0) (not (<= y 4e-52))) (* y (- x z)) (* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4700000.0) || !(y <= 4e-52)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - 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 ((y <= (-4700000.0d0)) .or. (.not. (y <= 4d-52))) then
tmp = y * (x - z)
else
tmp = z * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4700000.0) || !(y <= 4e-52)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4700000.0) or not (y <= 4e-52): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4700000.0) || !(y <= 4e-52)) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4700000.0) || ~((y <= 4e-52))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4700000.0], N[Not[LessEqual[y, 4e-52]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4700000 \lor \neg \left(y \leq 4 \cdot 10^{-52}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -4.7e6 or 4e-52 < y Initial program 98.6%
Taylor expanded in y around inf 96.3%
neg-mul-196.3%
sub-neg96.3%
Simplified96.3%
if -4.7e6 < y < 4e-52Initial program 100.0%
Taylor expanded in x around 0 73.2%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.8e-94) (not (<= y 1.36e-52))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.8e-94) || !(y <= 1.36e-52)) {
tmp = y * (x - z);
} else {
tmp = z;
}
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 <= (-6.8d-94)) .or. (.not. (y <= 1.36d-52))) then
tmp = y * (x - z)
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6.8e-94) || !(y <= 1.36e-52)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.8e-94) or not (y <= 1.36e-52): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.8e-94) || !(y <= 1.36e-52)) tmp = Float64(y * Float64(x - z)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.8e-94) || ~((y <= 1.36e-52))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.8e-94], N[Not[LessEqual[y, 1.36e-52]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{-94} \lor \neg \left(y \leq 1.36 \cdot 10^{-52}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -6.7999999999999996e-94 or 1.36e-52 < y Initial program 98.8%
Taylor expanded in y around inf 89.8%
neg-mul-189.8%
sub-neg89.8%
Simplified89.8%
if -6.7999999999999996e-94 < y < 1.36e-52Initial program 100.0%
Taylor expanded in y around 0 77.0%
Final simplification85.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.5e-47) (not (<= y 1.25e-59))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.5e-47) || !(y <= 1.25e-59)) {
tmp = y * x;
} else {
tmp = z;
}
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 <= (-1.5d-47)) .or. (.not. (y <= 1.25d-59))) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.5e-47) || !(y <= 1.25e-59)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.5e-47) or not (y <= 1.25e-59): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.5e-47) || !(y <= 1.25e-59)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.5e-47) || ~((y <= 1.25e-59))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.5e-47], N[Not[LessEqual[y, 1.25e-59]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{-47} \lor \neg \left(y \leq 1.25 \cdot 10^{-59}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.50000000000000008e-47 or 1.25e-59 < y Initial program 98.7%
Taylor expanded in x around inf 51.6%
*-commutative51.6%
Simplified51.6%
if -1.50000000000000008e-47 < y < 1.25e-59Initial program 100.0%
Taylor expanded in y around 0 74.9%
Final simplification60.3%
(FPCore (x y z) :precision binary64 (if (<= y -1.0) (* z (- y)) (if (<= y 1.25e-59) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.0) {
tmp = z * -y;
} else if (y <= 1.25e-59) {
tmp = 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 <= (-1.0d0)) then
tmp = z * -y
else if (y <= 1.25d-59) then
tmp = 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 <= -1.0) {
tmp = z * -y;
} else if (y <= 1.25e-59) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.0: tmp = z * -y elif y <= 1.25e-59: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.0) tmp = Float64(z * Float64(-y)); elseif (y <= 1.25e-59) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.0) tmp = z * -y; elseif (y <= 1.25e-59) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.0], N[(z * (-y)), $MachinePrecision], If[LessEqual[y, 1.25e-59], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{-59}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1Initial program 98.6%
Taylor expanded in y around inf 97.6%
neg-mul-197.6%
sub-neg97.6%
Simplified97.6%
Taylor expanded in x around 0 55.9%
neg-mul-155.9%
*-commutative55.9%
distribute-rgt-neg-in55.9%
Simplified55.9%
if -1 < y < 1.25e-59Initial program 100.0%
Taylor expanded in y around 0 71.6%
if 1.25e-59 < y Initial program 98.7%
Taylor expanded in x around inf 58.9%
*-commutative58.9%
Simplified58.9%
(FPCore (x y z) :precision binary64 (+ z (* y (- x z))))
double code(double x, double y, double z) {
return z + (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 = z + (y * (x - z))
end function
public static double code(double x, double y, double z) {
return z + (y * (x - z));
}
def code(x, y, z): return z + (y * (x - z))
function code(x, y, z) return Float64(z + Float64(y * Float64(x - z))) end
function tmp = code(x, y, z) tmp = z + (y * (x - z)); end
code[x_, y_, z_] := N[(z + N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + y \cdot \left(x - z\right)
\end{array}
Initial program 99.2%
+-commutative99.2%
+-lft-identity99.2%
cancel-sign-sub99.2%
cancel-sign-sub99.2%
+-lft-identity99.2%
distribute-lft-out--99.2%
*-rgt-identity99.2%
associate-+l-99.2%
distribute-rgt-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.2%
Taylor expanded in y around 0 33.7%
(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 2024114
(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))))