
(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 97.2%
distribute-lft-out--97.2%
*-rgt-identity97.2%
cancel-sign-sub-inv97.2%
+-commutative97.2%
associate-+r+97.2%
+-commutative97.2%
distribute-rgt-out100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -3000000.0) (not (<= y 1.0))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3000000.0) || !(y <= 1.0)) {
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 <= (-3000000.0d0)) .or. (.not. (y <= 1.0d0))) 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 <= -3000000.0) || !(y <= 1.0)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3000000.0) or not (y <= 1.0): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3000000.0) || !(y <= 1.0)) 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 <= -3000000.0) || ~((y <= 1.0))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3000000.0], N[Not[LessEqual[y, 1.0]], $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 -3000000 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -3e6 or 1 < y Initial program 95.0%
Taylor expanded in y around inf 98.5%
neg-mul-198.5%
sub-neg98.5%
Simplified98.5%
if -3e6 < y < 1Initial program 100.0%
Taylor expanded in y around 0 99.3%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -8.5e-23) (not (<= y 60000000000000.0))) (* y (- x z)) (* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.5e-23) || !(y <= 60000000000000.0)) {
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 <= (-8.5d-23)) .or. (.not. (y <= 60000000000000.0d0))) 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 <= -8.5e-23) || !(y <= 60000000000000.0)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.5e-23) or not (y <= 60000000000000.0): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.5e-23) || !(y <= 60000000000000.0)) 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 <= -8.5e-23) || ~((y <= 60000000000000.0))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.5e-23], N[Not[LessEqual[y, 60000000000000.0]], $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 -8.5 \cdot 10^{-23} \lor \neg \left(y \leq 60000000000000\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -8.4999999999999996e-23 or 6e13 < y Initial program 95.1%
Taylor expanded in y around inf 98.3%
neg-mul-198.3%
sub-neg98.3%
Simplified98.3%
if -8.4999999999999996e-23 < y < 6e13Initial program 100.0%
+-commutative100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
+-commutative100.0%
associate-+l+100.0%
distribute-lft-neg-out100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
distribute-neg-out100.0%
sub-neg100.0%
distribute-rgt-neg-out100.0%
sub-neg100.0%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 78.3%
Taylor expanded in x around 0 59.1%
sub-neg59.1%
distribute-rgt-in59.1%
*-rgt-identity59.1%
associate-*l/59.1%
associate-*r/58.9%
associate-*l*80.7%
lft-mult-inverse80.9%
distribute-lft-neg-in80.9%
distribute-rgt-neg-out80.9%
distribute-lft-in80.9%
sub-neg80.9%
Simplified80.9%
Final simplification90.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.8e-22) (not (<= y 8e-25))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.8e-22) || !(y <= 8e-25)) {
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 <= (-3.8d-22)) .or. (.not. (y <= 8d-25))) 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 <= -3.8e-22) || !(y <= 8e-25)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.8e-22) or not (y <= 8e-25): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.8e-22) || !(y <= 8e-25)) 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 <= -3.8e-22) || ~((y <= 8e-25))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.8e-22], N[Not[LessEqual[y, 8e-25]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{-22} \lor \neg \left(y \leq 8 \cdot 10^{-25}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -3.80000000000000023e-22 or 8.00000000000000031e-25 < y Initial program 95.3%
Taylor expanded in y around inf 96.8%
neg-mul-196.8%
sub-neg96.8%
Simplified96.8%
if -3.80000000000000023e-22 < y < 8.00000000000000031e-25Initial program 100.0%
+-commutative100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
+-commutative100.0%
associate-+l+100.0%
distribute-lft-neg-out100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
distribute-neg-out100.0%
sub-neg100.0%
distribute-rgt-neg-out100.0%
sub-neg100.0%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 77.0%
Taylor expanded in y around 0 81.6%
Final simplification90.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* z (- y)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = z * -y;
} 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.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = z * -y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = z * -y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = z * -y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(z * Float64(-y)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = z * -y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(z * (-y)), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 95.0%
Taylor expanded in y around inf 98.5%
neg-mul-198.5%
sub-neg98.5%
Simplified98.5%
Taylor expanded in x around 0 58.4%
associate-*r*58.4%
neg-mul-158.4%
*-commutative58.4%
Simplified58.4%
if -1 < y < 1Initial program 100.0%
+-commutative100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
+-commutative100.0%
associate-+l+100.0%
distribute-lft-neg-out100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
distribute-neg-out100.0%
sub-neg100.0%
distribute-rgt-neg-out100.0%
sub-neg100.0%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 78.6%
Taylor expanded in y around 0 77.1%
Final simplification66.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.8e-21) (not (<= y 7.8e-25))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.8e-21) || !(y <= 7.8e-25)) {
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 <= (-4.8d-21)) .or. (.not. (y <= 7.8d-25))) 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 <= -4.8e-21) || !(y <= 7.8e-25)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.8e-21) or not (y <= 7.8e-25): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.8e-21) || !(y <= 7.8e-25)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.8e-21) || ~((y <= 7.8e-25))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.8e-21], N[Not[LessEqual[y, 7.8e-25]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{-21} \lor \neg \left(y \leq 7.8 \cdot 10^{-25}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -4.7999999999999999e-21 or 7.8e-25 < y Initial program 95.3%
Taylor expanded in x around inf 46.7%
*-commutative46.7%
Simplified46.7%
if -4.7999999999999999e-21 < y < 7.8e-25Initial program 100.0%
+-commutative100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
+-commutative100.0%
associate-+l+100.0%
distribute-lft-neg-out100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
distribute-neg-out100.0%
sub-neg100.0%
distribute-rgt-neg-out100.0%
sub-neg100.0%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 77.0%
Taylor expanded in y around 0 81.6%
Final simplification61.2%
(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 97.2%
+-commutative97.2%
distribute-lft-out--97.2%
*-rgt-identity97.2%
cancel-sign-sub-inv97.2%
+-commutative97.2%
+-commutative97.2%
associate-+l+97.2%
distribute-lft-neg-out97.2%
remove-double-neg97.2%
distribute-rgt-neg-out97.2%
distribute-neg-out97.2%
sub-neg97.2%
distribute-rgt-neg-out97.2%
sub-neg97.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 97.2%
+-commutative97.2%
distribute-lft-out--97.2%
*-rgt-identity97.2%
cancel-sign-sub-inv97.2%
+-commutative97.2%
+-commutative97.2%
associate-+l+97.2%
distribute-lft-neg-out97.2%
remove-double-neg97.2%
distribute-rgt-neg-out97.2%
distribute-neg-out97.2%
sub-neg97.2%
distribute-rgt-neg-out97.2%
sub-neg97.2%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 90.5%
Taylor expanded in y around 0 36.2%
(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 2024157
(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))))