
(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 z (- 1.0 y) (* y x)))
double code(double x, double y, double z) {
return fma(z, (1.0 - y), (y * x));
}
function code(x, y, z) return fma(z, Float64(1.0 - y), Float64(y * x)) end
code[x_, y_, z_] := N[(z * N[(1.0 - y), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, 1 - y, y \cdot x\right)
\end{array}
Initial program 98.4%
+-commutative98.4%
fma-define100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -5.5e+102)
(* y x)
(if (<= y -1.9e+93)
(* z (- y))
(if (or (<= y -5.1e-62) (not (<= y 3e-32))) (* y x) z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.5e+102) {
tmp = y * x;
} else if (y <= -1.9e+93) {
tmp = z * -y;
} else if ((y <= -5.1e-62) || !(y <= 3e-32)) {
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 <= (-5.5d+102)) then
tmp = y * x
else if (y <= (-1.9d+93)) then
tmp = z * -y
else if ((y <= (-5.1d-62)) .or. (.not. (y <= 3d-32))) 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 <= -5.5e+102) {
tmp = y * x;
} else if (y <= -1.9e+93) {
tmp = z * -y;
} else if ((y <= -5.1e-62) || !(y <= 3e-32)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.5e+102: tmp = y * x elif y <= -1.9e+93: tmp = z * -y elif (y <= -5.1e-62) or not (y <= 3e-32): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.5e+102) tmp = Float64(y * x); elseif (y <= -1.9e+93) tmp = Float64(z * Float64(-y)); elseif ((y <= -5.1e-62) || !(y <= 3e-32)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.5e+102) tmp = y * x; elseif (y <= -1.9e+93) tmp = z * -y; elseif ((y <= -5.1e-62) || ~((y <= 3e-32))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.5e+102], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.9e+93], N[(z * (-y)), $MachinePrecision], If[Or[LessEqual[y, -5.1e-62], N[Not[LessEqual[y, 3e-32]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{+102}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -1.9 \cdot 10^{+93}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{elif}\;y \leq -5.1 \cdot 10^{-62} \lor \neg \left(y \leq 3 \cdot 10^{-32}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -5.49999999999999981e102 or -1.8999999999999999e93 < y < -5.1e-62 or 3e-32 < y Initial program 97.2%
Taylor expanded in x around inf 66.5%
*-commutative66.5%
Simplified66.5%
if -5.49999999999999981e102 < y < -1.8999999999999999e93Initial program 99.7%
Taylor expanded in x around 0 87.6%
Taylor expanded in y around inf 87.6%
mul-1-neg87.6%
distribute-lft-neg-out87.6%
*-commutative87.6%
Simplified87.6%
if -5.1e-62 < y < 3e-32Initial program 100.0%
Taylor expanded in y around 0 70.4%
Final simplification68.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.4e-18))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.4e-18)) {
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.4d-18))) 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.4e-18)) {
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.4e-18): 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.4e-18)) 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.4e-18))) 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.4e-18]], $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.4 \cdot 10^{-18}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -1 or 1.40000000000000006e-18 < y Initial program 96.9%
Taylor expanded in y around inf 99.6%
mul-1-neg99.6%
sub-neg99.6%
Simplified99.6%
if -1 < y < 1.40000000000000006e-18Initial program 100.0%
+-commutative100.0%
+-lft-identity100.0%
cancel-sign-sub100.0%
cancel-sign-sub100.0%
+-lft-identity100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
associate-+l-100.0%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 99.9%
mul-1-neg99.9%
distribute-lft-neg-out99.9%
*-commutative99.9%
Simplified99.9%
*-commutative99.9%
cancel-sign-sub99.9%
*-commutative99.9%
+-commutative99.9%
Applied egg-rr99.9%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.8e-62) (not (<= y 3.2e-30))) (* y (- x z)) (* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.8e-62) || !(y <= 3.2e-30)) {
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 <= (-4.8d-62)) .or. (.not. (y <= 3.2d-30))) 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 <= -4.8e-62) || !(y <= 3.2e-30)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.8e-62) or not (y <= 3.2e-30): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.8e-62) || !(y <= 3.2e-30)) 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 <= -4.8e-62) || ~((y <= 3.2e-30))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.8e-62], N[Not[LessEqual[y, 3.2e-30]], $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 -4.8 \cdot 10^{-62} \lor \neg \left(y \leq 3.2 \cdot 10^{-30}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -4.79999999999999967e-62 or 3.2e-30 < y Initial program 97.3%
Taylor expanded in y around inf 96.4%
mul-1-neg96.4%
sub-neg96.4%
Simplified96.4%
if -4.79999999999999967e-62 < y < 3.2e-30Initial program 100.0%
Taylor expanded in x around 0 70.4%
Final simplification85.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -8.4e-63) (not (<= y 6e-33))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.4e-63) || !(y <= 6e-33)) {
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 <= (-8.4d-63)) .or. (.not. (y <= 6d-33))) 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 <= -8.4e-63) || !(y <= 6e-33)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.4e-63) or not (y <= 6e-33): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.4e-63) || !(y <= 6e-33)) 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 <= -8.4e-63) || ~((y <= 6e-33))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.4e-63], N[Not[LessEqual[y, 6e-33]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.4 \cdot 10^{-63} \lor \neg \left(y \leq 6 \cdot 10^{-33}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -8.4e-63 or 6.0000000000000003e-33 < y Initial program 97.3%
Taylor expanded in y around inf 96.4%
mul-1-neg96.4%
sub-neg96.4%
Simplified96.4%
if -8.4e-63 < y < 6.0000000000000003e-33Initial program 100.0%
Taylor expanded in y around 0 70.4%
Final simplification85.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.25e-61) (not (<= y 4e-35))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.25e-61) || !(y <= 4e-35)) {
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.25d-61)) .or. (.not. (y <= 4d-35))) 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.25e-61) || !(y <= 4e-35)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.25e-61) or not (y <= 4e-35): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.25e-61) || !(y <= 4e-35)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.25e-61) || ~((y <= 4e-35))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.25e-61], N[Not[LessEqual[y, 4e-35]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.25 \cdot 10^{-61} \lor \neg \left(y \leq 4 \cdot 10^{-35}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.25e-61 or 4.00000000000000003e-35 < y Initial program 97.3%
Taylor expanded in x around inf 64.3%
*-commutative64.3%
Simplified64.3%
if -1.25e-61 < y < 4.00000000000000003e-35Initial program 100.0%
Taylor expanded in y around 0 70.4%
Final simplification66.8%
(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 98.4%
+-commutative98.4%
+-lft-identity98.4%
cancel-sign-sub98.4%
cancel-sign-sub98.4%
+-lft-identity98.4%
distribute-lft-out--98.4%
*-rgt-identity98.4%
associate-+l-98.4%
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 98.4%
Taylor expanded in y around 0 32.9%
(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 2024100
(FPCore (x y z)
:name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
:precision binary64
:alt
(- z (* (- z x) y))
(+ (* x y) (* z (- 1.0 y))))