
(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 98.4%
distribute-lft-out--98.4%
*-rgt-identity98.4%
cancel-sign-sub-inv98.4%
+-commutative98.4%
associate-+r+98.4%
distribute-rgt-out100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- z))))
(if (<= y -3.2e+91)
(* y x)
(if (<= y -1.0)
t_0
(if (<= y 9.6e-26) z (if (<= y 6.5e+39) (* y x) t_0))))))
double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (y <= -3.2e+91) {
tmp = y * x;
} else if (y <= -1.0) {
tmp = t_0;
} else if (y <= 9.6e-26) {
tmp = z;
} else if (y <= 6.5e+39) {
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 = y * -z
if (y <= (-3.2d+91)) then
tmp = y * x
else if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 9.6d-26) then
tmp = z
else if (y <= 6.5d+39) 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 = y * -z;
double tmp;
if (y <= -3.2e+91) {
tmp = y * x;
} else if (y <= -1.0) {
tmp = t_0;
} else if (y <= 9.6e-26) {
tmp = z;
} else if (y <= 6.5e+39) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -z tmp = 0 if y <= -3.2e+91: tmp = y * x elif y <= -1.0: tmp = t_0 elif y <= 9.6e-26: tmp = z elif y <= 6.5e+39: tmp = y * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-z)) tmp = 0.0 if (y <= -3.2e+91) tmp = Float64(y * x); elseif (y <= -1.0) tmp = t_0; elseif (y <= 9.6e-26) tmp = z; elseif (y <= 6.5e+39) tmp = Float64(y * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -z; tmp = 0.0; if (y <= -3.2e+91) tmp = y * x; elseif (y <= -1.0) tmp = t_0; elseif (y <= 9.6e-26) tmp = z; elseif (y <= 6.5e+39) tmp = y * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-z)), $MachinePrecision]}, If[LessEqual[y, -3.2e+91], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 9.6e-26], z, If[LessEqual[y, 6.5e+39], N[(y * x), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-z\right)\\
\mathbf{if}\;y \leq -3.2 \cdot 10^{+91}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 9.6 \cdot 10^{-26}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{+39}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.19999999999999989e91 or 9.6000000000000004e-26 < y < 6.5000000000000001e39Initial program 100.0%
Taylor expanded in x around inf 65.7%
*-commutative65.7%
Simplified65.7%
if -3.19999999999999989e91 < y < -1 or 6.5000000000000001e39 < y Initial program 94.6%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 62.7%
mul-1-neg62.7%
*-commutative62.7%
distribute-rgt-neg-in62.7%
Simplified62.7%
if -1 < y < 9.6000000000000004e-26Initial program 100.0%
Taylor expanded in y around 0 75.8%
Final simplification69.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -114000.0) (not (<= y 3.35e-12))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -114000.0) || !(y <= 3.35e-12)) {
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 <= (-114000.0d0)) .or. (.not. (y <= 3.35d-12))) 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 <= -114000.0) || !(y <= 3.35e-12)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -114000.0) or not (y <= 3.35e-12): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -114000.0) || !(y <= 3.35e-12)) 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 <= -114000.0) || ~((y <= 3.35e-12))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -114000.0], N[Not[LessEqual[y, 3.35e-12]], $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 -114000 \lor \neg \left(y \leq 3.35 \cdot 10^{-12}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -114000 or 3.3500000000000001e-12 < y Initial program 97.0%
Taylor expanded in y around inf 99.4%
mul-1-neg99.4%
sub-neg99.4%
Simplified99.4%
if -114000 < y < 3.3500000000000001e-12Initial 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 100.0%
mul-1-neg100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
Simplified100.0%
*-commutative100.0%
cancel-sign-sub100.0%
*-commutative100.0%
+-commutative100.0%
Applied egg-rr100.0%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -6e-32) (not (<= y 5.5e-27))) (* y (- x z)) (* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6e-32) || !(y <= 5.5e-27)) {
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 <= (-6d-32)) .or. (.not. (y <= 5.5d-27))) 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 <= -6e-32) || !(y <= 5.5e-27)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6e-32) or not (y <= 5.5e-27): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6e-32) || !(y <= 5.5e-27)) 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 <= -6e-32) || ~((y <= 5.5e-27))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6e-32], N[Not[LessEqual[y, 5.5e-27]], $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 -6 \cdot 10^{-32} \lor \neg \left(y \leq 5.5 \cdot 10^{-27}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -6.0000000000000001e-32 or 5.5000000000000002e-27 < y Initial program 97.1%
Taylor expanded in y around inf 98.1%
mul-1-neg98.1%
sub-neg98.1%
Simplified98.1%
if -6.0000000000000001e-32 < y < 5.5000000000000002e-27Initial program 100.0%
Taylor expanded in x around 0 76.8%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1e-30) (not (<= y 2.2e-27))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1e-30) || !(y <= 2.2e-27)) {
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 <= (-1d-30)) .or. (.not. (y <= 2.2d-27))) 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 <= -1e-30) || !(y <= 2.2e-27)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1e-30) or not (y <= 2.2e-27): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1e-30) || !(y <= 2.2e-27)) 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 <= -1e-30) || ~((y <= 2.2e-27))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1e-30], N[Not[LessEqual[y, 2.2e-27]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{-30} \lor \neg \left(y \leq 2.2 \cdot 10^{-27}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1e-30 or 2.19999999999999987e-27 < y Initial program 97.1%
Taylor expanded in y around inf 98.1%
mul-1-neg98.1%
sub-neg98.1%
Simplified98.1%
if -1e-30 < y < 2.19999999999999987e-27Initial program 100.0%
Taylor expanded in y around 0 76.8%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.8e-20) (not (<= y 2.9e-27))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.8e-20) || !(y <= 2.9e-27)) {
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 <= (-6.8d-20)) .or. (.not. (y <= 2.9d-27))) 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 <= -6.8e-20) || !(y <= 2.9e-27)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.8e-20) or not (y <= 2.9e-27): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.8e-20) || !(y <= 2.9e-27)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.8e-20) || ~((y <= 2.9e-27))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.8e-20], N[Not[LessEqual[y, 2.9e-27]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{-20} \lor \neg \left(y \leq 2.9 \cdot 10^{-27}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -6.7999999999999994e-20 or 2.90000000000000004e-27 < y Initial program 97.1%
Taylor expanded in x around inf 53.3%
*-commutative53.3%
Simplified53.3%
if -6.7999999999999994e-20 < y < 2.90000000000000004e-27Initial program 100.0%
Taylor expanded in y around 0 76.4%
Final simplification63.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 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 37.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 2024108
(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))))