
(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 (- 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 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%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y -4e-15) (* y x) (if (<= y 5.5e-15) z (if (<= y 1.5e+38) (* y x) (* z (- y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4e-15) {
tmp = y * x;
} else if (y <= 5.5e-15) {
tmp = z;
} else if (y <= 1.5e+38) {
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 <= (-4d-15)) then
tmp = y * x
else if (y <= 5.5d-15) then
tmp = z
else if (y <= 1.5d+38) 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 <= -4e-15) {
tmp = y * x;
} else if (y <= 5.5e-15) {
tmp = z;
} else if (y <= 1.5e+38) {
tmp = y * x;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4e-15: tmp = y * x elif y <= 5.5e-15: tmp = z elif y <= 1.5e+38: tmp = y * x else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4e-15) tmp = Float64(y * x); elseif (y <= 5.5e-15) tmp = z; elseif (y <= 1.5e+38) 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 <= -4e-15) tmp = y * x; elseif (y <= 5.5e-15) tmp = z; elseif (y <= 1.5e+38) tmp = y * x; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4e-15], N[(y * x), $MachinePrecision], If[LessEqual[y, 5.5e-15], z, If[LessEqual[y, 1.5e+38], N[(y * x), $MachinePrecision], N[(z * (-y)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{-15}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{-15}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{+38}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if y < -4.0000000000000003e-15 or 5.5000000000000002e-15 < y < 1.5000000000000001e38Initial 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 -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%
if 1.5000000000000001e38 < 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%
*-commutative99.5%
cancel-sign-sub99.5%
+-commutative99.5%
Applied egg-rr99.5%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.5e-11) (not (<= y 3.2e-17))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e-11) || !(y <= 3.2e-17)) {
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 <= (-2.5d-11)) .or. (.not. (y <= 3.2d-17))) 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 <= -2.5e-11) || !(y <= 3.2e-17)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.5e-11) or not (y <= 3.2e-17): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.5e-11) || !(y <= 3.2e-17)) 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 <= -2.5e-11) || ~((y <= 3.2e-17))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.5e-11], N[Not[LessEqual[y, 3.2e-17]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{-11} \lor \neg \left(y \leq 3.2 \cdot 10^{-17}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -2.50000000000000009e-11 or 3.2000000000000002e-17 < 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 -2.50000000000000009e-11 < y < 3.2000000000000002e-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%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.6e-16) (not (<= y 4.6e-17))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.6e-16) || !(y <= 4.6e-17)) {
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 <= (-7.6d-16)) .or. (.not. (y <= 4.6d-17))) 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 <= -7.6e-16) || !(y <= 4.6e-17)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.6e-16) or not (y <= 4.6e-17): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.6e-16) || !(y <= 4.6e-17)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -7.6e-16) || ~((y <= 4.6e-17))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.6e-16], N[Not[LessEqual[y, 4.6e-17]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.6 \cdot 10^{-16} \lor \neg \left(y \leq 4.6 \cdot 10^{-17}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -7.60000000000000024e-16 or 4.60000000000000018e-17 < 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 -7.60000000000000024e-16 < y < 4.60000000000000018e-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%
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 (- 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
(! :herbie-platform default (- z (* (- z x) y)))
(+ (* x y) (* z (- 1.0 y))))