
(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 (- 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.5%
+-commutative96.5%
+-lft-identity96.5%
cancel-sign-sub96.5%
cancel-sign-sub96.5%
+-lft-identity96.5%
distribute-lft-out--96.5%
*-rgt-identity96.5%
associate-+l-96.5%
distribute-rgt-out--100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= y -2.25e-11) (* y x) (if (<= y 1.05e-17) z (if (<= y 5e+41) (* y x) (* y (- z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.25e-11) {
tmp = y * x;
} else if (y <= 1.05e-17) {
tmp = z;
} else if (y <= 5e+41) {
tmp = y * x;
} else {
tmp = y * -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.25d-11)) then
tmp = y * x
else if (y <= 1.05d-17) then
tmp = z
else if (y <= 5d+41) then
tmp = y * x
else
tmp = y * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.25e-11) {
tmp = y * x;
} else if (y <= 1.05e-17) {
tmp = z;
} else if (y <= 5e+41) {
tmp = y * x;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.25e-11: tmp = y * x elif y <= 1.05e-17: tmp = z elif y <= 5e+41: tmp = y * x else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.25e-11) tmp = Float64(y * x); elseif (y <= 1.05e-17) tmp = z; elseif (y <= 5e+41) tmp = Float64(y * x); else tmp = Float64(y * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.25e-11) tmp = y * x; elseif (y <= 1.05e-17) tmp = z; elseif (y <= 5e+41) tmp = y * x; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.25e-11], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.05e-17], z, If[LessEqual[y, 5e+41], N[(y * x), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.25 \cdot 10^{-11}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{-17}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 5 \cdot 10^{+41}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if y < -2.25e-11 or 1.04999999999999996e-17 < y < 5.00000000000000022e41Initial program 90.7%
+-commutative90.7%
+-lft-identity90.7%
cancel-sign-sub90.7%
cancel-sign-sub90.7%
+-lft-identity90.7%
distribute-lft-out--90.7%
*-rgt-identity90.7%
associate-+l-90.7%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 60.2%
if -2.25e-11 < y < 1.04999999999999996e-17Initial 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 inf 77.2%
Taylor expanded in y around 0 77.2%
if 5.00000000000000022e41 < y Initial program 97.0%
+-commutative97.0%
+-lft-identity97.0%
cancel-sign-sub97.0%
cancel-sign-sub97.0%
+-lft-identity97.0%
distribute-lft-out--97.0%
*-rgt-identity97.0%
associate-+l-97.0%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around 0 60.4%
associate-*r*60.4%
neg-mul-160.4%
Simplified60.4%
Final simplification67.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -22000.0) (not (<= y 0.96))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -22000.0) || !(y <= 0.96)) {
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 <= (-22000.0d0)) .or. (.not. (y <= 0.96d0))) 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 <= -22000.0) || !(y <= 0.96)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -22000.0) or not (y <= 0.96): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -22000.0) || !(y <= 0.96)) 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 <= -22000.0) || ~((y <= 0.96))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -22000.0], N[Not[LessEqual[y, 0.96]], $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 -22000 \lor \neg \left(y \leq 0.96\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -22000 or 0.95999999999999996 < y Initial program 93.3%
+-commutative93.3%
+-lft-identity93.3%
cancel-sign-sub93.3%
cancel-sign-sub93.3%
+-lft-identity93.3%
distribute-lft-out--93.3%
*-rgt-identity93.3%
associate-+l-93.3%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 99.4%
if -22000 < y < 0.95999999999999996Initial 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.5%
mul-1-neg99.5%
distribute-lft-neg-out99.5%
*-commutative99.5%
Simplified99.5%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.5e-11) (not (<= y 0.00105))) (* y (- x z)) (- z (* z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e-11) || !(y <= 0.00105)) {
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 <= (-2.5d-11)) .or. (.not. (y <= 0.00105d0))) 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 <= -2.5e-11) || !(y <= 0.00105)) {
tmp = y * (x - z);
} else {
tmp = z - (z * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.5e-11) or not (y <= 0.00105): tmp = y * (x - z) else: tmp = z - (z * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.5e-11) || !(y <= 0.00105)) 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 <= -2.5e-11) || ~((y <= 0.00105))) tmp = y * (x - z); else tmp = z - (z * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.5e-11], N[Not[LessEqual[y, 0.00105]], $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 -2.5 \cdot 10^{-11} \lor \neg \left(y \leq 0.00105\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z - z \cdot y\\
\end{array}
\end{array}
if y < -2.50000000000000009e-11 or 0.00104999999999999994 < y Initial program 93.5%
+-commutative93.5%
+-lft-identity93.5%
cancel-sign-sub93.5%
cancel-sign-sub93.5%
+-lft-identity93.5%
distribute-lft-out--93.5%
*-rgt-identity93.5%
associate-+l-93.5%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 99.4%
if -2.50000000000000009e-11 < y < 0.00104999999999999994Initial 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 inf 76.8%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -4e-15) (not (<= y 5.5e-15))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4e-15) || !(y <= 5.5e-15)) {
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 <= (-4d-15)) .or. (.not. (y <= 5.5d-15))) 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 <= -4e-15) || !(y <= 5.5e-15)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4e-15) or not (y <= 5.5e-15): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4e-15) || !(y <= 5.5e-15)) 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 <= -4e-15) || ~((y <= 5.5e-15))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4e-15], N[Not[LessEqual[y, 5.5e-15]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{-15} \lor \neg \left(y \leq 5.5 \cdot 10^{-15}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -4.0000000000000003e-15 or 5.5000000000000002e-15 < y Initial program 93.6%
+-commutative93.6%
+-lft-identity93.6%
cancel-sign-sub93.6%
cancel-sign-sub93.6%
+-lft-identity93.6%
distribute-lft-out--93.6%
*-rgt-identity93.6%
associate-+l-93.6%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 98.7%
if -4.0000000000000003e-15 < y < 5.5000000000000002e-15Initial 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 inf 77.2%
Taylor expanded in y around 0 77.2%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.2e-12) (not (<= y 7e-15))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.2e-12) || !(y <= 7e-15)) {
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 <= (-9.2d-12)) .or. (.not. (y <= 7d-15))) 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 <= -9.2e-12) || !(y <= 7e-15)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.2e-12) or not (y <= 7e-15): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.2e-12) || !(y <= 7e-15)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -9.2e-12) || ~((y <= 7e-15))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.2e-12], N[Not[LessEqual[y, 7e-15]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.2 \cdot 10^{-12} \lor \neg \left(y \leq 7 \cdot 10^{-15}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -9.19999999999999957e-12 or 7.0000000000000001e-15 < y Initial program 93.6%
+-commutative93.6%
+-lft-identity93.6%
cancel-sign-sub93.6%
cancel-sign-sub93.6%
+-lft-identity93.6%
distribute-lft-out--93.6%
*-rgt-identity93.6%
associate-+l-93.6%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 54.7%
if -9.19999999999999957e-12 < y < 7.0000000000000001e-15Initial 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 inf 77.2%
Taylor expanded in y around 0 77.2%
Final simplification64.8%
(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.5%
+-commutative96.5%
+-lft-identity96.5%
cancel-sign-sub96.5%
cancel-sign-sub96.5%
+-lft-identity96.5%
distribute-lft-out--96.5%
*-rgt-identity96.5%
associate-+l-96.5%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 63.4%
Taylor expanded in y around 0 36.3%
(FPCore (x y z) :precision binary64 0.0)
double code(double x, double y, double z) {
return 0.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.0d0
end function
public static double code(double x, double y, double z) {
return 0.0;
}
def code(x, y, z): return 0.0
function code(x, y, z) return 0.0 end
function tmp = code(x, y, z) tmp = 0.0; end
code[x_, y_, z_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 96.5%
+-commutative96.5%
+-lft-identity96.5%
cancel-sign-sub96.5%
cancel-sign-sub96.5%
+-lft-identity96.5%
distribute-lft-out--96.5%
*-rgt-identity96.5%
associate-+l-96.5%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 65.9%
Taylor expanded in x around 0 29.8%
associate-*r*29.8%
neg-mul-129.8%
Simplified29.8%
Applied egg-rr2.5%
Taylor expanded in z around 0 2.5%
(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 2024111
(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))))