
(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 7 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
(if (<= y -1.3e-25)
(* y x)
(if (<= y -4.8e-77)
z
(if (<= y -8.4e-123)
(* y x)
(if (<= y 5.4e-24) z (if (<= y 1.4e+117) (* y x) (* z (- y))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.3e-25) {
tmp = y * x;
} else if (y <= -4.8e-77) {
tmp = z;
} else if (y <= -8.4e-123) {
tmp = y * x;
} else if (y <= 5.4e-24) {
tmp = z;
} else if (y <= 1.4e+117) {
tmp = y * x;
} else {
tmp = 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 <= (-1.3d-25)) then
tmp = y * x
else if (y <= (-4.8d-77)) then
tmp = z
else if (y <= (-8.4d-123)) then
tmp = y * x
else if (y <= 5.4d-24) then
tmp = z
else if (y <= 1.4d+117) then
tmp = y * x
else
tmp = z * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.3e-25) {
tmp = y * x;
} else if (y <= -4.8e-77) {
tmp = z;
} else if (y <= -8.4e-123) {
tmp = y * x;
} else if (y <= 5.4e-24) {
tmp = z;
} else if (y <= 1.4e+117) {
tmp = y * x;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.3e-25: tmp = y * x elif y <= -4.8e-77: tmp = z elif y <= -8.4e-123: tmp = y * x elif y <= 5.4e-24: tmp = z elif y <= 1.4e+117: tmp = y * x else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.3e-25) tmp = Float64(y * x); elseif (y <= -4.8e-77) tmp = z; elseif (y <= -8.4e-123) tmp = Float64(y * x); elseif (y <= 5.4e-24) tmp = z; elseif (y <= 1.4e+117) tmp = Float64(y * x); else tmp = Float64(z * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.3e-25) tmp = y * x; elseif (y <= -4.8e-77) tmp = z; elseif (y <= -8.4e-123) tmp = y * x; elseif (y <= 5.4e-24) tmp = z; elseif (y <= 1.4e+117) tmp = y * x; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.3e-25], N[(y * x), $MachinePrecision], If[LessEqual[y, -4.8e-77], z, If[LessEqual[y, -8.4e-123], N[(y * x), $MachinePrecision], If[LessEqual[y, 5.4e-24], z, If[LessEqual[y, 1.4e+117], N[(y * x), $MachinePrecision], N[(z * (-y)), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.3 \cdot 10^{-25}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -4.8 \cdot 10^{-77}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -8.4 \cdot 10^{-123}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 5.4 \cdot 10^{-24}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{+117}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if y < -1.3e-25 or -4.7999999999999998e-77 < y < -8.3999999999999997e-123 or 5.40000000000000014e-24 < y < 1.39999999999999999e117Initial program 96.9%
Taylor expanded in x around inf 65.0%
*-commutative65.0%
Simplified65.0%
if -1.3e-25 < y < -4.7999999999999998e-77 or -8.3999999999999997e-123 < y < 5.40000000000000014e-24Initial program 100.0%
Taylor expanded in y around 0 73.3%
if 1.39999999999999999e117 < y Initial program 95.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.4%
associate-*r*62.4%
neg-mul-162.4%
*-commutative62.4%
Simplified62.4%
Final simplification68.2%
(FPCore (x y z)
:precision binary64
(if (or (<= y -5e-22)
(not (or (<= y -3.9e-76) (and (not (<= y -1e-122)) (<= y 4e-23)))))
(* y (- x z))
z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5e-22) || !((y <= -3.9e-76) || (!(y <= -1e-122) && (y <= 4e-23)))) {
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 <= (-5d-22)) .or. (.not. (y <= (-3.9d-76)) .or. (.not. (y <= (-1d-122))) .and. (y <= 4d-23))) 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 <= -5e-22) || !((y <= -3.9e-76) || (!(y <= -1e-122) && (y <= 4e-23)))) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5e-22) or not ((y <= -3.9e-76) or (not (y <= -1e-122) and (y <= 4e-23))): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5e-22) || !((y <= -3.9e-76) || (!(y <= -1e-122) && (y <= 4e-23)))) 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 <= -5e-22) || ~(((y <= -3.9e-76) || (~((y <= -1e-122)) && (y <= 4e-23))))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5e-22], N[Not[Or[LessEqual[y, -3.9e-76], And[N[Not[LessEqual[y, -1e-122]], $MachinePrecision], LessEqual[y, 4e-23]]]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{-22} \lor \neg \left(y \leq -3.9 \cdot 10^{-76} \lor \neg \left(y \leq -1 \cdot 10^{-122}\right) \land y \leq 4 \cdot 10^{-23}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -4.99999999999999954e-22 or -3.90000000000000025e-76 < y < -1.00000000000000006e-122 or 3.99999999999999984e-23 < y Initial program 96.5%
Taylor expanded in y around inf 95.3%
mul-1-neg95.3%
sub-neg95.3%
Simplified95.3%
if -4.99999999999999954e-22 < y < -3.90000000000000025e-76 or -1.00000000000000006e-122 < y < 3.99999999999999984e-23Initial program 100.0%
Taylor expanded in y around 0 73.3%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.95e+28) (not (<= x 6.5e-59))) (* y (- x z)) (* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.95e+28) || !(x <= 6.5e-59)) {
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 ((x <= (-1.95d+28)) .or. (.not. (x <= 6.5d-59))) 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 ((x <= -1.95e+28) || !(x <= 6.5e-59)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.95e+28) or not (x <= 6.5e-59): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.95e+28) || !(x <= 6.5e-59)) 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 ((x <= -1.95e+28) || ~((x <= 6.5e-59))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.95e+28], N[Not[LessEqual[x, 6.5e-59]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{+28} \lor \neg \left(x \leq 6.5 \cdot 10^{-59}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if x < -1.9499999999999999e28 or 6.50000000000000017e-59 < x Initial program 96.4%
Taylor expanded in y around inf 80.6%
mul-1-neg80.6%
sub-neg80.6%
Simplified80.6%
if -1.9499999999999999e28 < x < 6.50000000000000017e-59Initial program 100.0%
Taylor expanded in x around 0 89.5%
Final simplification84.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -4e+14) (not (<= y 1.0))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4e+14) || !(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 <= (-4d+14)) .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 <= -4e+14) || !(y <= 1.0)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4e+14) 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 <= -4e+14) || !(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 <= -4e+14) || ~((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, -4e+14], 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 -4 \cdot 10^{+14} \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 < -4e14 or 1 < y Initial program 95.8%
Taylor expanded in y around inf 99.1%
mul-1-neg99.1%
sub-neg99.1%
Simplified99.1%
if -4e14 < 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 z around 0 99.1%
mul-1-neg99.1%
distribute-lft-neg-out99.1%
*-commutative99.1%
Simplified99.1%
sub-neg99.1%
+-commutative99.1%
distribute-rgt-neg-out99.1%
remove-double-neg99.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.3e+28) (not (<= x 4.8e-51))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.3e+28) || !(x <= 4.8e-51)) {
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 ((x <= (-2.3d+28)) .or. (.not. (x <= 4.8d-51))) 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 ((x <= -2.3e+28) || !(x <= 4.8e-51)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.3e+28) or not (x <= 4.8e-51): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.3e+28) || !(x <= 4.8e-51)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.3e+28) || ~((x <= 4.8e-51))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.3e+28], N[Not[LessEqual[x, 4.8e-51]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{+28} \lor \neg \left(x \leq 4.8 \cdot 10^{-51}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -2.29999999999999984e28 or 4.8e-51 < x Initial program 96.3%
Taylor expanded in x around inf 73.4%
*-commutative73.4%
Simplified73.4%
if -2.29999999999999984e28 < x < 4.8e-51Initial program 100.0%
Taylor expanded in y around 0 52.6%
Final simplification63.7%
(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 35.3%
Final simplification35.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 2024076
(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))))