
(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 6 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 96.9%
+-commutative96.9%
distribute-lft-out--96.9%
*-rgt-identity96.9%
cancel-sign-sub-inv96.9%
+-commutative96.9%
+-commutative96.9%
associate-+l+96.9%
distribute-lft-neg-out96.9%
remove-double-neg96.9%
distribute-rgt-neg-out96.9%
distribute-neg-out96.9%
sub-neg96.9%
distribute-rgt-neg-out96.9%
sub-neg96.9%
distribute-rgt-out--100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= y -4.8e+63) (* z (- y)) (if (or (<= y -1.75e-25) (not (<= y 5.2e-23))) (* y x) z)))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.8e+63) {
tmp = z * -y;
} else if ((y <= -1.75e-25) || !(y <= 5.2e-23)) {
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 <= (-4.8d+63)) then
tmp = z * -y
else if ((y <= (-1.75d-25)) .or. (.not. (y <= 5.2d-23))) 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 <= -4.8e+63) {
tmp = z * -y;
} else if ((y <= -1.75e-25) || !(y <= 5.2e-23)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.8e+63: tmp = z * -y elif (y <= -1.75e-25) or not (y <= 5.2e-23): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.8e+63) tmp = Float64(z * Float64(-y)); elseif ((y <= -1.75e-25) || !(y <= 5.2e-23)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.8e+63) tmp = z * -y; elseif ((y <= -1.75e-25) || ~((y <= 5.2e-23))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.8e+63], N[(z * (-y)), $MachinePrecision], If[Or[LessEqual[y, -1.75e-25], N[Not[LessEqual[y, 5.2e-23]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{+63}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{elif}\;y \leq -1.75 \cdot 10^{-25} \lor \neg \left(y \leq 5.2 \cdot 10^{-23}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -4.8e63Initial program 86.5%
+-commutative86.5%
distribute-lft-out--86.5%
*-rgt-identity86.5%
cancel-sign-sub-inv86.5%
+-commutative86.5%
+-commutative86.5%
associate-+l+86.5%
distribute-lft-neg-out86.5%
remove-double-neg86.5%
distribute-rgt-neg-out86.5%
distribute-neg-out86.5%
sub-neg86.5%
distribute-rgt-neg-out86.5%
sub-neg86.5%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around 0 64.2%
associate-*r*64.2%
neg-mul-164.2%
Simplified64.2%
if -4.8e63 < y < -1.7500000000000001e-25 or 5.2e-23 < y Initial program 98.8%
+-commutative98.8%
distribute-lft-out--98.8%
*-rgt-identity98.8%
cancel-sign-sub-inv98.8%
+-commutative98.8%
+-commutative98.8%
associate-+l+98.8%
distribute-lft-neg-out98.8%
remove-double-neg98.8%
distribute-rgt-neg-out98.8%
distribute-neg-out98.8%
sub-neg98.8%
distribute-rgt-neg-out98.8%
sub-neg98.8%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 66.5%
if -1.7500000000000001e-25 < y < 5.2e-23Initial 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 73.5%
Taylor expanded in y around 0 73.5%
Final simplification69.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -19000.0) (not (<= y 0.000105))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -19000.0) || !(y <= 0.000105)) {
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 <= (-19000.0d0)) .or. (.not. (y <= 0.000105d0))) 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 <= -19000.0) || !(y <= 0.000105)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -19000.0) or not (y <= 0.000105): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -19000.0) || !(y <= 0.000105)) 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 <= -19000.0) || ~((y <= 0.000105))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -19000.0], N[Not[LessEqual[y, 0.000105]], $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 -19000 \lor \neg \left(y \leq 0.000105\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -19000 or 1.05e-4 < y Initial program 93.8%
+-commutative93.8%
distribute-lft-out--93.8%
*-rgt-identity93.8%
cancel-sign-sub-inv93.8%
+-commutative93.8%
+-commutative93.8%
associate-+l+93.8%
distribute-lft-neg-out93.8%
remove-double-neg93.8%
distribute-rgt-neg-out93.8%
distribute-neg-out93.8%
sub-neg93.8%
distribute-rgt-neg-out93.8%
sub-neg93.8%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 99.3%
if -19000 < y < 1.05e-4Initial 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.6%
mul-1-neg99.6%
distribute-lft-neg-out99.6%
*-commutative99.6%
Simplified99.6%
*-commutative99.6%
cancel-sign-sub99.6%
+-commutative99.6%
Applied egg-rr99.6%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -5e-29) (not (<= y 8.4e-19))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5e-29) || !(y <= 8.4e-19)) {
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-29)) .or. (.not. (y <= 8.4d-19))) 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-29) || !(y <= 8.4e-19)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5e-29) or not (y <= 8.4e-19): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5e-29) || !(y <= 8.4e-19)) 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-29) || ~((y <= 8.4e-19))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5e-29], N[Not[LessEqual[y, 8.4e-19]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{-29} \lor \neg \left(y \leq 8.4 \cdot 10^{-19}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -4.99999999999999986e-29 or 8.3999999999999996e-19 < y Initial program 94.2%
+-commutative94.2%
distribute-lft-out--94.2%
*-rgt-identity94.2%
cancel-sign-sub-inv94.2%
+-commutative94.2%
+-commutative94.2%
associate-+l+94.2%
distribute-lft-neg-out94.2%
remove-double-neg94.2%
distribute-rgt-neg-out94.2%
distribute-neg-out94.2%
sub-neg94.2%
distribute-rgt-neg-out94.2%
sub-neg94.2%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 98.0%
if -4.99999999999999986e-29 < y < 8.3999999999999996e-19Initial 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 73.5%
Taylor expanded in y around 0 73.5%
Final simplification86.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.75e-29) (not (<= y 4.8e-23))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.75e-29) || !(y <= 4.8e-23)) {
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.75d-29)) .or. (.not. (y <= 4.8d-23))) 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.75e-29) || !(y <= 4.8e-23)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.75e-29) or not (y <= 4.8e-23): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.75e-29) || !(y <= 4.8e-23)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.75e-29) || ~((y <= 4.8e-23))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.75e-29], N[Not[LessEqual[y, 4.8e-23]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.75 \cdot 10^{-29} \lor \neg \left(y \leq 4.8 \cdot 10^{-23}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.7499999999999999e-29 or 4.79999999999999993e-23 < y Initial program 94.2%
+-commutative94.2%
distribute-lft-out--94.2%
*-rgt-identity94.2%
cancel-sign-sub-inv94.2%
+-commutative94.2%
+-commutative94.2%
associate-+l+94.2%
distribute-lft-neg-out94.2%
remove-double-neg94.2%
distribute-rgt-neg-out94.2%
distribute-neg-out94.2%
sub-neg94.2%
distribute-rgt-neg-out94.2%
sub-neg94.2%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 58.0%
if -1.7499999999999999e-29 < y < 4.79999999999999993e-23Initial 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 73.5%
Taylor expanded in y around 0 73.5%
Final simplification65.2%
(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 96.9%
+-commutative96.9%
distribute-lft-out--96.9%
*-rgt-identity96.9%
cancel-sign-sub-inv96.9%
+-commutative96.9%
+-commutative96.9%
associate-+l+96.9%
distribute-lft-neg-out96.9%
remove-double-neg96.9%
distribute-rgt-neg-out96.9%
distribute-neg-out96.9%
sub-neg96.9%
distribute-rgt-neg-out96.9%
sub-neg96.9%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 60.1%
Taylor expanded in y around 0 36.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 2024156
(FPCore (x y z)
:name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
:precision binary64
:alt
(! :herbie-platform default (- z (* (- z x) y)))
(+ (* x y) (* z (- 1.0 y))))