
(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-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -8.4e-17)
(* y x)
(if (<= y -6.4e-32)
z
(if (<= y -1.15e-110)
(* y x)
(if (<= y 1.65e-61)
z
(if (or (<= y 6500000000.0) (not (<= y 2.6e+35)))
(* y x)
(* y (- z))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.4e-17) {
tmp = y * x;
} else if (y <= -6.4e-32) {
tmp = z;
} else if (y <= -1.15e-110) {
tmp = y * x;
} else if (y <= 1.65e-61) {
tmp = z;
} else if ((y <= 6500000000.0) || !(y <= 2.6e+35)) {
tmp = y * x;
} else {
tmp = y * -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-17)) then
tmp = y * x
else if (y <= (-6.4d-32)) then
tmp = z
else if (y <= (-1.15d-110)) then
tmp = y * x
else if (y <= 1.65d-61) then
tmp = z
else if ((y <= 6500000000.0d0) .or. (.not. (y <= 2.6d+35))) then
tmp = y * x
else
tmp = y * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -8.4e-17) {
tmp = y * x;
} else if (y <= -6.4e-32) {
tmp = z;
} else if (y <= -1.15e-110) {
tmp = y * x;
} else if (y <= 1.65e-61) {
tmp = z;
} else if ((y <= 6500000000.0) || !(y <= 2.6e+35)) {
tmp = y * x;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.4e-17: tmp = y * x elif y <= -6.4e-32: tmp = z elif y <= -1.15e-110: tmp = y * x elif y <= 1.65e-61: tmp = z elif (y <= 6500000000.0) or not (y <= 2.6e+35): tmp = y * x else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.4e-17) tmp = Float64(y * x); elseif (y <= -6.4e-32) tmp = z; elseif (y <= -1.15e-110) tmp = Float64(y * x); elseif (y <= 1.65e-61) tmp = z; elseif ((y <= 6500000000.0) || !(y <= 2.6e+35)) tmp = Float64(y * x); else tmp = Float64(y * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.4e-17) tmp = y * x; elseif (y <= -6.4e-32) tmp = z; elseif (y <= -1.15e-110) tmp = y * x; elseif (y <= 1.65e-61) tmp = z; elseif ((y <= 6500000000.0) || ~((y <= 2.6e+35))) tmp = y * x; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.4e-17], N[(y * x), $MachinePrecision], If[LessEqual[y, -6.4e-32], z, If[LessEqual[y, -1.15e-110], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.65e-61], z, If[Or[LessEqual[y, 6500000000.0], N[Not[LessEqual[y, 2.6e+35]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.4 \cdot 10^{-17}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -6.4 \cdot 10^{-32}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -1.15 \cdot 10^{-110}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{-61}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 6500000000 \lor \neg \left(y \leq 2.6 \cdot 10^{+35}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if y < -8.39999999999999968e-17 or -6.4000000000000004e-32 < y < -1.1500000000000001e-110 or 1.64999999999999998e-61 < y < 6.5e9 or 2.60000000000000007e35 < y Initial program 95.6%
Taylor expanded in x around inf 63.7%
*-commutative63.7%
Simplified63.7%
if -8.39999999999999968e-17 < y < -6.4000000000000004e-32 or -1.1500000000000001e-110 < y < 1.64999999999999998e-61Initial program 100.0%
Taylor expanded in y around 0 80.7%
if 6.5e9 < y < 2.60000000000000007e35Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 89.6%
mul-1-neg89.6%
distribute-lft-neg-out89.6%
*-commutative89.6%
Simplified89.6%
Final simplification70.1%
(FPCore (x y z)
:precision binary64
(if (or (<= y -7.4e-17)
(and (not (<= y -5.1e-40))
(or (<= y -8.5e-111) (not (<= y 3.9e-61)))))
(* y (- x z))
z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.4e-17) || (!(y <= -5.1e-40) && ((y <= -8.5e-111) || !(y <= 3.9e-61)))) {
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 <= (-7.4d-17)) .or. (.not. (y <= (-5.1d-40))) .and. (y <= (-8.5d-111)) .or. (.not. (y <= 3.9d-61))) 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 <= -7.4e-17) || (!(y <= -5.1e-40) && ((y <= -8.5e-111) || !(y <= 3.9e-61)))) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.4e-17) or (not (y <= -5.1e-40) and ((y <= -8.5e-111) or not (y <= 3.9e-61))): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.4e-17) || (!(y <= -5.1e-40) && ((y <= -8.5e-111) || !(y <= 3.9e-61)))) 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 <= -7.4e-17) || (~((y <= -5.1e-40)) && ((y <= -8.5e-111) || ~((y <= 3.9e-61))))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.4e-17], And[N[Not[LessEqual[y, -5.1e-40]], $MachinePrecision], Or[LessEqual[y, -8.5e-111], N[Not[LessEqual[y, 3.9e-61]], $MachinePrecision]]]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.4 \cdot 10^{-17} \lor \neg \left(y \leq -5.1 \cdot 10^{-40}\right) \land \left(y \leq -8.5 \cdot 10^{-111} \lor \neg \left(y \leq 3.9 \cdot 10^{-61}\right)\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -7.3999999999999995e-17 or -5.10000000000000037e-40 < y < -8.5000000000000003e-111 or 3.90000000000000033e-61 < y Initial program 95.7%
Taylor expanded in y around inf 92.4%
mul-1-neg92.4%
sub-neg92.4%
Simplified92.4%
if -7.3999999999999995e-17 < y < -5.10000000000000037e-40 or -8.5000000000000003e-111 < y < 3.90000000000000033e-61Initial program 100.0%
Taylor expanded in y around 0 80.7%
Final simplification88.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x z))))
(if (<= y -0.31)
t_0
(if (<= y -8.2e-32)
(* z (- 1.0 y))
(if (or (<= y -1.28e-107) (not (<= y 3.8e-63))) t_0 z)))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -0.31) {
tmp = t_0;
} else if (y <= -8.2e-32) {
tmp = z * (1.0 - y);
} else if ((y <= -1.28e-107) || !(y <= 3.8e-63)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = y * (x - z)
if (y <= (-0.31d0)) then
tmp = t_0
else if (y <= (-8.2d-32)) then
tmp = z * (1.0d0 - y)
else if ((y <= (-1.28d-107)) .or. (.not. (y <= 3.8d-63))) then
tmp = t_0
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -0.31) {
tmp = t_0;
} else if (y <= -8.2e-32) {
tmp = z * (1.0 - y);
} else if ((y <= -1.28e-107) || !(y <= 3.8e-63)) {
tmp = t_0;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x - z) tmp = 0 if y <= -0.31: tmp = t_0 elif y <= -8.2e-32: tmp = z * (1.0 - y) elif (y <= -1.28e-107) or not (y <= 3.8e-63): tmp = t_0 else: tmp = z return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x - z)) tmp = 0.0 if (y <= -0.31) tmp = t_0; elseif (y <= -8.2e-32) tmp = Float64(z * Float64(1.0 - y)); elseif ((y <= -1.28e-107) || !(y <= 3.8e-63)) tmp = t_0; else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x - z); tmp = 0.0; if (y <= -0.31) tmp = t_0; elseif (y <= -8.2e-32) tmp = z * (1.0 - y); elseif ((y <= -1.28e-107) || ~((y <= 3.8e-63))) tmp = t_0; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.31], t$95$0, If[LessEqual[y, -8.2e-32], N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, -1.28e-107], N[Not[LessEqual[y, 3.8e-63]], $MachinePrecision]], t$95$0, z]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -0.31:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -8.2 \cdot 10^{-32}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\mathbf{elif}\;y \leq -1.28 \cdot 10^{-107} \lor \neg \left(y \leq 3.8 \cdot 10^{-63}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -0.309999999999999998 or -8.1999999999999995e-32 < y < -1.28e-107 or 3.80000000000000017e-63 < y Initial program 95.7%
Taylor expanded in y around inf 93.4%
mul-1-neg93.4%
sub-neg93.4%
Simplified93.4%
if -0.309999999999999998 < y < -8.1999999999999995e-32Initial program 100.0%
Taylor expanded in x around 0 82.9%
if -1.28e-107 < y < 3.80000000000000017e-63Initial program 100.0%
Taylor expanded in y around 0 79.5%
Final simplification88.5%
(FPCore (x y z)
:precision binary64
(if (or (<= y -7.8e-17)
(and (not (<= y -5.2e-39))
(or (<= y -2.7e-109) (not (<= y 1.05e-62)))))
(* y x)
z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.8e-17) || (!(y <= -5.2e-39) && ((y <= -2.7e-109) || !(y <= 1.05e-62)))) {
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 <= (-7.8d-17)) .or. (.not. (y <= (-5.2d-39))) .and. (y <= (-2.7d-109)) .or. (.not. (y <= 1.05d-62))) 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 <= -7.8e-17) || (!(y <= -5.2e-39) && ((y <= -2.7e-109) || !(y <= 1.05e-62)))) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.8e-17) or (not (y <= -5.2e-39) and ((y <= -2.7e-109) or not (y <= 1.05e-62))): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.8e-17) || (!(y <= -5.2e-39) && ((y <= -2.7e-109) || !(y <= 1.05e-62)))) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -7.8e-17) || (~((y <= -5.2e-39)) && ((y <= -2.7e-109) || ~((y <= 1.05e-62))))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.8e-17], And[N[Not[LessEqual[y, -5.2e-39]], $MachinePrecision], Or[LessEqual[y, -2.7e-109], N[Not[LessEqual[y, 1.05e-62]], $MachinePrecision]]]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.8 \cdot 10^{-17} \lor \neg \left(y \leq -5.2 \cdot 10^{-39}\right) \land \left(y \leq -2.7 \cdot 10^{-109} \lor \neg \left(y \leq 1.05 \cdot 10^{-62}\right)\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -7.79999999999999979e-17 or -5.2e-39 < y < -2.7e-109 or 1.05e-62 < y Initial program 95.7%
Taylor expanded in x around inf 61.8%
*-commutative61.8%
Simplified61.8%
if -7.79999999999999979e-17 < y < -5.2e-39 or -2.7e-109 < y < 1.05e-62Initial program 100.0%
Taylor expanded in y around 0 80.7%
Final simplification68.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -7e+15) (not (<= y 1.0))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7e+15) || !(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 <= (-7d+15)) .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 <= -7e+15) || !(y <= 1.0)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7e+15) 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 <= -7e+15) || !(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 <= -7e+15) || ~((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, -7e+15], 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 -7 \cdot 10^{+15} \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 < -7e15 or 1 < y Initial program 94.6%
Taylor expanded in y around inf 99.6%
mul-1-neg99.6%
sub-neg99.6%
Simplified99.6%
if -7e15 < y < 1Initial program 100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
associate-+r+100.0%
+-commutative100.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
fma-udef100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 98.4%
*-commutative98.4%
Simplified98.4%
Final simplification99.0%
(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%
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-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
fma-udef100.0%
Applied egg-rr100.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%
Taylor expanded in y around 0 33.3%
Final simplification33.3%
(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 2023318
(FPCore (x y z)
:name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
:precision binary64
:herbie-target
(- z (* (- z x) y))
(+ (* x y) (* z (- 1.0 y))))