
(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 (- z x))))
double code(double x, double y, double z) {
return z - (y * (z - x));
}
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 * (z - x))
end function
public static double code(double x, double y, double z) {
return z - (y * (z - x));
}
def code(x, y, z): return z - (y * (z - x))
function code(x, y, z) return Float64(z - Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = z - (y * (z - x)); end
code[x_, y_, z_] := N[(z - N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - y \cdot \left(z - x\right)
\end{array}
Initial program 99.2%
+-commutative99.2%
distribute-lft-out--99.2%
*-rgt-identity99.2%
associate-+l-99.2%
distribute-rgt-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -6e-61)
(* y x)
(if (<= y 2.25e-98)
z
(if (or (<= y 1.55e+69) (not (<= y 7.8e+213))) (* y x) (* z (- y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6e-61) {
tmp = y * x;
} else if (y <= 2.25e-98) {
tmp = z;
} else if ((y <= 1.55e+69) || !(y <= 7.8e+213)) {
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 <= (-6d-61)) then
tmp = y * x
else if (y <= 2.25d-98) then
tmp = z
else if ((y <= 1.55d+69) .or. (.not. (y <= 7.8d+213))) 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 <= -6e-61) {
tmp = y * x;
} else if (y <= 2.25e-98) {
tmp = z;
} else if ((y <= 1.55e+69) || !(y <= 7.8e+213)) {
tmp = y * x;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6e-61: tmp = y * x elif y <= 2.25e-98: tmp = z elif (y <= 1.55e+69) or not (y <= 7.8e+213): tmp = y * x else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6e-61) tmp = Float64(y * x); elseif (y <= 2.25e-98) tmp = z; elseif ((y <= 1.55e+69) || !(y <= 7.8e+213)) 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 <= -6e-61) tmp = y * x; elseif (y <= 2.25e-98) tmp = z; elseif ((y <= 1.55e+69) || ~((y <= 7.8e+213))) tmp = y * x; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6e-61], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.25e-98], z, If[Or[LessEqual[y, 1.55e+69], N[Not[LessEqual[y, 7.8e+213]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(z * (-y)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{-61}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 2.25 \cdot 10^{-98}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{+69} \lor \neg \left(y \leq 7.8 \cdot 10^{+213}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if y < -6.00000000000000024e-61 or 2.24999999999999998e-98 < y < 1.5499999999999999e69 or 7.8000000000000003e213 < y Initial program 98.5%
Taylor expanded in x around inf 62.1%
*-commutative62.1%
Simplified62.1%
if -6.00000000000000024e-61 < y < 2.24999999999999998e-98Initial program 100.0%
Taylor expanded in y around 0 73.5%
if 1.5499999999999999e69 < y < 7.8000000000000003e213Initial program 100.0%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 83.8%
mul-1-neg83.8%
*-commutative83.8%
distribute-rgt-neg-in83.8%
Simplified83.8%
Final simplification68.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.35e-58) (not (<= y 4.5e-98))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e-58) || !(y <= 4.5e-98)) {
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 <= (-1.35d-58)) .or. (.not. (y <= 4.5d-98))) 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 <= -1.35e-58) || !(y <= 4.5e-98)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.35e-58) or not (y <= 4.5e-98): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.35e-58) || !(y <= 4.5e-98)) 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 <= -1.35e-58) || ~((y <= 4.5e-98))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.35e-58], N[Not[LessEqual[y, 4.5e-98]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-58} \lor \neg \left(y \leq 4.5 \cdot 10^{-98}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.3499999999999999e-58 or 4.49999999999999997e-98 < y Initial program 98.8%
Taylor expanded in y around inf 91.5%
mul-1-neg91.5%
sub-neg91.5%
Simplified91.5%
if -1.3499999999999999e-58 < y < 4.49999999999999997e-98Initial program 100.0%
Taylor expanded in y around 0 73.5%
Final simplification85.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.3e+52) (not (<= z 6.2e+30))) (* z (- 1.0 y)) (* y (- x z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.3e+52) || !(z <= 6.2e+30)) {
tmp = z * (1.0 - y);
} else {
tmp = y * (x - 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 ((z <= (-3.3d+52)) .or. (.not. (z <= 6.2d+30))) then
tmp = z * (1.0d0 - y)
else
tmp = y * (x - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.3e+52) || !(z <= 6.2e+30)) {
tmp = z * (1.0 - y);
} else {
tmp = y * (x - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.3e+52) or not (z <= 6.2e+30): tmp = z * (1.0 - y) else: tmp = y * (x - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.3e+52) || !(z <= 6.2e+30)) tmp = Float64(z * Float64(1.0 - y)); else tmp = Float64(y * Float64(x - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.3e+52) || ~((z <= 6.2e+30))) tmp = z * (1.0 - y); else tmp = y * (x - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.3e+52], N[Not[LessEqual[z, 6.2e+30]], $MachinePrecision]], N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{+52} \lor \neg \left(z \leq 6.2 \cdot 10^{+30}\right):\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x - z\right)\\
\end{array}
\end{array}
if z < -3.3e52 or 6.1999999999999995e30 < z Initial program 97.9%
Taylor expanded in x around 0 96.9%
if -3.3e52 < z < 6.1999999999999995e30Initial program 100.0%
Taylor expanded in y around inf 78.2%
mul-1-neg78.2%
sub-neg78.2%
Simplified78.2%
Final simplification85.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -19.0) (not (<= y 0.00029))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -19.0) || !(y <= 0.00029)) {
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 <= (-19.0d0)) .or. (.not. (y <= 0.00029d0))) 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 <= -19.0) || !(y <= 0.00029)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -19.0) or not (y <= 0.00029): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -19.0) || !(y <= 0.00029)) 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 <= -19.0) || ~((y <= 0.00029))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -19.0], N[Not[LessEqual[y, 0.00029]], $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 -19 \lor \neg \left(y \leq 0.00029\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -19 or 2.9e-4 < y Initial program 98.5%
Taylor expanded in y around inf 98.2%
mul-1-neg98.2%
sub-neg98.2%
Simplified98.2%
if -19 < y < 2.9e-4Initial program 100.0%
+-commutative100.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 98.7%
mul-1-neg98.7%
distribute-lft-neg-out98.7%
*-commutative98.7%
Simplified98.7%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.35e-59) (not (<= y 2.3e-96))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e-59) || !(y <= 2.3e-96)) {
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.35d-59)) .or. (.not. (y <= 2.3d-96))) 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.35e-59) || !(y <= 2.3e-96)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.35e-59) or not (y <= 2.3e-96): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.35e-59) || !(y <= 2.3e-96)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.35e-59) || ~((y <= 2.3e-96))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.35e-59], N[Not[LessEqual[y, 2.3e-96]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-59} \lor \neg \left(y \leq 2.3 \cdot 10^{-96}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.3499999999999999e-59 or 2.3e-96 < y Initial program 98.8%
Taylor expanded in x around inf 54.8%
*-commutative54.8%
Simplified54.8%
if -1.3499999999999999e-59 < y < 2.3e-96Initial program 100.0%
Taylor expanded in y around 0 73.5%
Final simplification61.5%
(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 99.2%
Taylor expanded in y around 0 32.2%
Final simplification32.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 2024034
(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))))