
(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 (+ 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.0%
+-commutative98.0%
distribute-lft-out--98.0%
*-rgt-identity98.0%
cancel-sign-sub-inv98.0%
+-commutative98.0%
+-commutative98.0%
associate-+l+98.0%
distribute-lft-neg-out98.0%
remove-double-neg98.0%
distribute-rgt-neg-out98.0%
distribute-neg-out98.0%
sub-neg98.0%
distribute-rgt-neg-out98.0%
sub-neg98.0%
distribute-rgt-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- y))))
(if (<= y -5.5e+278)
t_0
(if (<= y -2.6e+118)
(* y x)
(if (<= y -5.5e+31)
t_0
(if (or (<= y -1.4e-50) (not (<= y 5e-8))) (* y x) z))))))
double code(double x, double y, double z) {
double t_0 = z * -y;
double tmp;
if (y <= -5.5e+278) {
tmp = t_0;
} else if (y <= -2.6e+118) {
tmp = y * x;
} else if (y <= -5.5e+31) {
tmp = t_0;
} else if ((y <= -1.4e-50) || !(y <= 5e-8)) {
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) :: t_0
real(8) :: tmp
t_0 = z * -y
if (y <= (-5.5d+278)) then
tmp = t_0
else if (y <= (-2.6d+118)) then
tmp = y * x
else if (y <= (-5.5d+31)) then
tmp = t_0
else if ((y <= (-1.4d-50)) .or. (.not. (y <= 5d-8))) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * -y;
double tmp;
if (y <= -5.5e+278) {
tmp = t_0;
} else if (y <= -2.6e+118) {
tmp = y * x;
} else if (y <= -5.5e+31) {
tmp = t_0;
} else if ((y <= -1.4e-50) || !(y <= 5e-8)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): t_0 = z * -y tmp = 0 if y <= -5.5e+278: tmp = t_0 elif y <= -2.6e+118: tmp = y * x elif y <= -5.5e+31: tmp = t_0 elif (y <= -1.4e-50) or not (y <= 5e-8): tmp = y * x else: tmp = z return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-y)) tmp = 0.0 if (y <= -5.5e+278) tmp = t_0; elseif (y <= -2.6e+118) tmp = Float64(y * x); elseif (y <= -5.5e+31) tmp = t_0; elseif ((y <= -1.4e-50) || !(y <= 5e-8)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -y; tmp = 0.0; if (y <= -5.5e+278) tmp = t_0; elseif (y <= -2.6e+118) tmp = y * x; elseif (y <= -5.5e+31) tmp = t_0; elseif ((y <= -1.4e-50) || ~((y <= 5e-8))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-y)), $MachinePrecision]}, If[LessEqual[y, -5.5e+278], t$95$0, If[LessEqual[y, -2.6e+118], N[(y * x), $MachinePrecision], If[LessEqual[y, -5.5e+31], t$95$0, If[Or[LessEqual[y, -1.4e-50], N[Not[LessEqual[y, 5e-8]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -5.5 \cdot 10^{+278}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -2.6 \cdot 10^{+118}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -5.5 \cdot 10^{+31}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.4 \cdot 10^{-50} \lor \neg \left(y \leq 5 \cdot 10^{-8}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -5.4999999999999999e278 or -2.60000000000000016e118 < y < -5.50000000000000002e31Initial program 99.9%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 75.9%
associate-*r*75.9%
neg-mul-175.9%
Simplified75.9%
if -5.4999999999999999e278 < y < -2.60000000000000016e118 or -5.50000000000000002e31 < y < -1.3999999999999999e-50 or 4.9999999999999998e-8 < y Initial program 96.0%
Taylor expanded in x around inf 58.9%
*-commutative58.9%
Simplified58.9%
if -1.3999999999999999e-50 < y < 4.9999999999999998e-8Initial program 100.0%
Taylor expanded in y around 0 76.8%
Final simplification67.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.05e-52) (not (<= y 4.5e-8))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.05e-52) || !(y <= 4.5e-8)) {
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.05d-52)) .or. (.not. (y <= 4.5d-8))) 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.05e-52) || !(y <= 4.5e-8)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.05e-52) or not (y <= 4.5e-8): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.05e-52) || !(y <= 4.5e-8)) 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.05e-52) || ~((y <= 4.5e-8))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.05e-52], N[Not[LessEqual[y, 4.5e-8]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.05 \cdot 10^{-52} \lor \neg \left(y \leq 4.5 \cdot 10^{-8}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -3.04999999999999995e-52 or 4.49999999999999993e-8 < y Initial program 96.7%
Taylor expanded in y around inf 96.3%
mul-1-neg96.3%
sub-neg96.3%
Simplified96.3%
if -3.04999999999999995e-52 < y < 4.49999999999999993e-8Initial program 100.0%
Taylor expanded in y around 0 76.8%
Final simplification88.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.3e-53) (not (<= y 3e-5))) (* y (- x z)) (* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.3e-53) || !(y <= 3e-5)) {
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 <= (-3.3d-53)) .or. (.not. (y <= 3d-5))) 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 <= -3.3e-53) || !(y <= 3e-5)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.3e-53) or not (y <= 3e-5): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.3e-53) || !(y <= 3e-5)) 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 <= -3.3e-53) || ~((y <= 3e-5))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.3e-53], N[Not[LessEqual[y, 3e-5]], $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 -3.3 \cdot 10^{-53} \lor \neg \left(y \leq 3 \cdot 10^{-5}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -3.30000000000000004e-53 or 3.00000000000000008e-5 < y Initial program 96.7%
Taylor expanded in y around inf 96.3%
mul-1-neg96.3%
sub-neg96.3%
Simplified96.3%
if -3.30000000000000004e-53 < y < 3.00000000000000008e-5Initial program 100.0%
Taylor expanded in x around 0 77.4%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.2e-50) (not (<= y 0.00142))) (* y (- x z)) (- z (* z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.2e-50) || !(y <= 0.00142)) {
tmp = y * (x - z);
} else {
tmp = z - (z * 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 <= (-6.2d-50)) .or. (.not. (y <= 0.00142d0))) then
tmp = y * (x - z)
else
tmp = z - (z * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6.2e-50) || !(y <= 0.00142)) {
tmp = y * (x - z);
} else {
tmp = z - (z * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.2e-50) or not (y <= 0.00142): tmp = y * (x - z) else: tmp = z - (z * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.2e-50) || !(y <= 0.00142)) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z - Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.2e-50) || ~((y <= 0.00142))) tmp = y * (x - z); else tmp = z - (z * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.2e-50], N[Not[LessEqual[y, 0.00142]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z - N[(z * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.2 \cdot 10^{-50} \lor \neg \left(y \leq 0.00142\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z - z \cdot y\\
\end{array}
\end{array}
if y < -6.2000000000000004e-50 or 0.00142000000000000004 < y Initial program 96.7%
Taylor expanded in y around inf 96.3%
mul-1-neg96.3%
sub-neg96.3%
Simplified96.3%
if -6.2000000000000004e-50 < y < 0.00142000000000000004Initial 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 z around inf 77.4%
*-commutative77.4%
Simplified77.4%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 0.0069))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 0.0069)) {
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 <= 0.0069d0))) 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 <= 0.0069)) {
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 <= 0.0069): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 0.0069)) 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 <= 0.0069))) 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, 0.0069]], $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 0.0069\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -1 or 0.0068999999999999999 < y Initial program 96.5%
Taylor expanded in y around inf 98.0%
mul-1-neg98.0%
sub-neg98.0%
Simplified98.0%
if -1 < y < 0.0068999999999999999Initial 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 z around 0 98.9%
mul-1-neg98.9%
distribute-lft-neg-out98.9%
*-commutative98.9%
Simplified98.9%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.35e-51) (not (<= y 4.8e-8))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.35e-51) || !(y <= 4.8e-8)) {
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 <= (-2.35d-51)) .or. (.not. (y <= 4.8d-8))) 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 <= -2.35e-51) || !(y <= 4.8e-8)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.35e-51) or not (y <= 4.8e-8): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.35e-51) || !(y <= 4.8e-8)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.35e-51) || ~((y <= 4.8e-8))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.35e-51], N[Not[LessEqual[y, 4.8e-8]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.35 \cdot 10^{-51} \lor \neg \left(y \leq 4.8 \cdot 10^{-8}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -2.3499999999999999e-51 or 4.79999999999999997e-8 < y Initial program 96.7%
Taylor expanded in x around inf 53.6%
*-commutative53.6%
Simplified53.6%
if -2.3499999999999999e-51 < y < 4.79999999999999997e-8Initial program 100.0%
Taylor expanded in y around 0 76.8%
Final simplification63.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.0%
Taylor expanded in y around 0 33.9%
Final simplification33.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 2024089
(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))))