
(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 98.0%
+-commutative98.0%
+-lft-identity98.0%
cancel-sign-sub98.0%
cancel-sign-sub98.0%
+-lft-identity98.0%
distribute-lft-out--98.0%
*-rgt-identity98.0%
associate-+l-98.0%
distribute-rgt-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.4e-138) (not (<= x 7.9e-72))) (+ z (* y x)) (- z (* z y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.4e-138) || !(x <= 7.9e-72)) {
tmp = z + (y * x);
} 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 ((x <= (-2.4d-138)) .or. (.not. (x <= 7.9d-72))) then
tmp = z + (y * x)
else
tmp = z - (z * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.4e-138) || !(x <= 7.9e-72)) {
tmp = z + (y * x);
} else {
tmp = z - (z * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.4e-138) or not (x <= 7.9e-72): tmp = z + (y * x) else: tmp = z - (z * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.4e-138) || !(x <= 7.9e-72)) tmp = Float64(z + Float64(y * x)); else tmp = Float64(z - Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.4e-138) || ~((x <= 7.9e-72))) tmp = z + (y * x); else tmp = z - (z * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.4e-138], N[Not[LessEqual[x, 7.9e-72]], $MachinePrecision]], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(z - N[(z * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{-138} \lor \neg \left(x \leq 7.9 \cdot 10^{-72}\right):\\
\;\;\;\;z + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z - z \cdot y\\
\end{array}
\end{array}
if x < -2.3999999999999999e-138 or 7.90000000000000005e-72 < x Initial program 97.1%
+-commutative97.1%
+-lft-identity97.1%
cancel-sign-sub97.1%
cancel-sign-sub97.1%
+-lft-identity97.1%
distribute-lft-out--97.1%
*-rgt-identity97.1%
associate-+l-97.1%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 90.6%
mul-1-neg90.6%
distribute-lft-neg-out90.6%
*-commutative90.6%
Simplified90.6%
if -2.3999999999999999e-138 < x < 7.90000000000000005e-72Initial 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 95.6%
Final simplification92.3%
(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 98.0%
+-commutative98.0%
+-lft-identity98.0%
cancel-sign-sub98.0%
cancel-sign-sub98.0%
+-lft-identity98.0%
distribute-lft-out--98.0%
*-rgt-identity98.0%
associate-+l-98.0%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 62.5%
Final simplification62.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 2024101
(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))))