
(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 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 (if (<= z -4.5e+46) z (if (<= z 1.65e-17) (* y x) (if (<= z 1.65e+83) z (* z (- y))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.5e+46) {
tmp = z;
} else if (z <= 1.65e-17) {
tmp = y * x;
} else if (z <= 1.65e+83) {
tmp = z;
} 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 (z <= (-4.5d+46)) then
tmp = z
else if (z <= 1.65d-17) then
tmp = y * x
else if (z <= 1.65d+83) then
tmp = z
else
tmp = z * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -4.5e+46) {
tmp = z;
} else if (z <= 1.65e-17) {
tmp = y * x;
} else if (z <= 1.65e+83) {
tmp = z;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.5e+46: tmp = z elif z <= 1.65e-17: tmp = y * x elif z <= 1.65e+83: tmp = z else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.5e+46) tmp = z; elseif (z <= 1.65e-17) tmp = Float64(y * x); elseif (z <= 1.65e+83) tmp = z; else tmp = Float64(z * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.5e+46) tmp = z; elseif (z <= 1.65e-17) tmp = y * x; elseif (z <= 1.65e+83) tmp = z; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.5e+46], z, If[LessEqual[z, 1.65e-17], N[(y * x), $MachinePrecision], If[LessEqual[z, 1.65e+83], z, N[(z * (-y)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{+46}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.65 \cdot 10^{-17}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;z \leq 1.65 \cdot 10^{+83}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if z < -4.5000000000000001e46 or 1.65e-17 < z < 1.64999999999999992e83Initial program 97.3%
Taylor expanded in y around 0 56.0%
if -4.5000000000000001e46 < z < 1.65e-17Initial program 100.0%
Taylor expanded in x around inf 72.4%
*-commutative72.4%
Simplified72.4%
if 1.64999999999999992e83 < z Initial program 95.9%
Taylor expanded in x around 0 98.1%
Taylor expanded in y around inf 54.2%
mul-1-neg54.2%
distribute-lft-neg-out54.2%
*-commutative54.2%
Simplified54.2%
Final simplification64.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.5e-29) (not (<= y 3.6e-49))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.5e-29) || !(y <= 3.6e-49)) {
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 <= (-6.5d-29)) .or. (.not. (y <= 3.6d-49))) 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 <= -6.5e-29) || !(y <= 3.6e-49)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.5e-29) or not (y <= 3.6e-49): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.5e-29) || !(y <= 3.6e-49)) 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 <= -6.5e-29) || ~((y <= 3.6e-49))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.5e-29], N[Not[LessEqual[y, 3.6e-49]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{-29} \lor \neg \left(y \leq 3.6 \cdot 10^{-49}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -6.5e-29 or 3.5999999999999997e-49 < y Initial program 97.0%
Taylor expanded in y around inf 95.2%
mul-1-neg95.2%
sub-neg95.2%
Simplified95.2%
if -6.5e-29 < y < 3.5999999999999997e-49Initial program 100.0%
Taylor expanded in y around 0 69.4%
Final simplification83.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.6e+29) (not (<= z 6.5e-10))) (* z (- 1.0 y)) (* y (- x z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.6e+29) || !(z <= 6.5e-10)) {
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 <= (-5.6d+29)) .or. (.not. (z <= 6.5d-10))) 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 <= -5.6e+29) || !(z <= 6.5e-10)) {
tmp = z * (1.0 - y);
} else {
tmp = y * (x - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.6e+29) or not (z <= 6.5e-10): tmp = z * (1.0 - y) else: tmp = y * (x - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.6e+29) || !(z <= 6.5e-10)) 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 <= -5.6e+29) || ~((z <= 6.5e-10))) tmp = z * (1.0 - y); else tmp = y * (x - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.6e+29], N[Not[LessEqual[z, 6.5e-10]], $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 -5.6 \cdot 10^{+29} \lor \neg \left(z \leq 6.5 \cdot 10^{-10}\right):\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x - z\right)\\
\end{array}
\end{array}
if z < -5.5999999999999999e29 or 6.5000000000000003e-10 < z Initial program 96.8%
Taylor expanded in x around 0 87.9%
if -5.5999999999999999e29 < z < 6.5000000000000003e-10Initial program 100.0%
Taylor expanded in y around inf 81.6%
mul-1-neg81.6%
sub-neg81.6%
Simplified81.6%
Final simplification84.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 0.0002))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 0.0002)) {
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.0002d0))) 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.0002)) {
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.0002): 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.0002)) 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.0002))) 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.0002]], $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.0002\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -1 or 2.0000000000000001e-4 < y Initial program 96.7%
Taylor expanded in y around inf 98.6%
mul-1-neg98.6%
sub-neg98.6%
Simplified98.6%
if -1 < y < 2.0000000000000001e-4Initial 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 99.6%
mul-1-neg99.6%
distribute-lft-neg-out99.6%
*-commutative99.6%
Simplified99.6%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (if (<= z -1.45e+47) z (if (<= z 1.5e-12) (* y x) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.45e+47) {
tmp = z;
} else if (z <= 1.5e-12) {
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 (z <= (-1.45d+47)) then
tmp = z
else if (z <= 1.5d-12) 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 (z <= -1.45e+47) {
tmp = z;
} else if (z <= 1.5e-12) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.45e+47: tmp = z elif z <= 1.5e-12: tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.45e+47) tmp = z; elseif (z <= 1.5e-12) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.45e+47) tmp = z; elseif (z <= 1.5e-12) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.45e+47], z, If[LessEqual[z, 1.5e-12], N[(y * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.45 \cdot 10^{+47}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{-12}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.4499999999999999e47 or 1.5000000000000001e-12 < z Initial program 96.7%
Taylor expanded in y around 0 52.0%
if -1.4499999999999999e47 < z < 1.5000000000000001e-12Initial program 100.0%
Taylor expanded in x around inf 72.4%
*-commutative72.4%
Simplified72.4%
Final simplification62.6%
(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 35.8%
Final simplification35.8%
(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 2024018
(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))))