
(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 3 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 (or (<= z -1.14e+192) (not (<= z 1.8e-5))) (- z (* z y)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.14e+192) || !(z <= 1.8e-5)) {
tmp = z - (z * y);
} 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 ((z <= (-1.14d+192)) .or. (.not. (z <= 1.8d-5))) then
tmp = z - (z * y)
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.14e+192) || !(z <= 1.8e-5)) {
tmp = z - (z * y);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.14e+192) or not (z <= 1.8e-5): tmp = z - (z * y) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.14e+192) || !(z <= 1.8e-5)) tmp = Float64(z - Float64(z * y)); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.14e+192) || ~((z <= 1.8e-5))) tmp = z - (z * y); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.14e+192], N[Not[LessEqual[z, 1.8e-5]], $MachinePrecision]], N[(z - N[(z * y), $MachinePrecision]), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.14 \cdot 10^{+192} \lor \neg \left(z \leq 1.8 \cdot 10^{-5}\right):\\
\;\;\;\;z - z \cdot y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if z < -1.14e192 or 1.80000000000000005e-5 < z Initial program 90.5%
+-commutative90.5%
+-lft-identity90.5%
cancel-sign-sub90.5%
cancel-sign-sub90.5%
+-lft-identity90.5%
distribute-lft-out--90.5%
*-rgt-identity90.5%
associate-+l-90.5%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 89.7%
if -1.14e192 < z < 1.80000000000000005e-5Initial 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 88.0%
mul-1-neg88.0%
distribute-lft-neg-out88.0%
*-commutative88.0%
Simplified88.0%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (- z (* z y)))
double code(double x, double y, double z) {
return z - (z * 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 * y)
end function
public static double code(double x, double y, double z) {
return z - (z * y);
}
def code(x, y, z): return z - (z * y)
function code(x, y, z) return Float64(z - Float64(z * y)) end
function tmp = code(x, y, z) tmp = z - (z * y); end
code[x_, y_, z_] := N[(z - N[(z * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - z \cdot y
\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 59.8%
Final simplification59.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 2024039
(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))))