
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (- (* x (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (z + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 98.0%
*-commutative98.0%
sub-neg98.0%
distribute-rgt-in98.0%
metadata-eval98.0%
neg-mul-198.0%
associate-+r+98.0%
unsub-neg98.0%
+-commutative98.0%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1e+89) (not (<= z 2.7e+26))) (- (* x z) z) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1e+89) || !(z <= 2.7e+26)) {
tmp = (x * z) - z;
} else {
tmp = (x * 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 ((z <= (-1d+89)) .or. (.not. (z <= 2.7d+26))) then
tmp = (x * z) - z
else
tmp = (x * y) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1e+89) || !(z <= 2.7e+26)) {
tmp = (x * z) - z;
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1e+89) or not (z <= 2.7e+26): tmp = (x * z) - z else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1e+89) || !(z <= 2.7e+26)) tmp = Float64(Float64(x * z) - z); else tmp = Float64(Float64(x * y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1e+89) || ~((z <= 2.7e+26))) tmp = (x * z) - z; else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1e+89], N[Not[LessEqual[z, 2.7e+26]], $MachinePrecision]], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{+89} \lor \neg \left(z \leq 2.7 \cdot 10^{+26}\right):\\
\;\;\;\;x \cdot z - z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if z < -9.99999999999999995e88 or 2.7e26 < z Initial program 96.3%
*-commutative96.3%
sub-neg96.3%
distribute-rgt-in96.3%
metadata-eval96.3%
neg-mul-196.3%
associate-+r+96.3%
unsub-neg96.3%
+-commutative96.3%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 94.2%
if -9.99999999999999995e88 < z < 2.7e26Initial program 99.3%
*-commutative99.3%
sub-neg99.3%
distribute-rgt-in99.3%
metadata-eval99.3%
neg-mul-199.3%
associate-+r+99.3%
unsub-neg99.3%
+-commutative99.3%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 90.6%
Final simplification92.1%
(FPCore (x y z) :precision binary64 (- (* x y) z))
double code(double x, double y, double z) {
return (x * y) - z;
}
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
end function
public static double code(double x, double y, double z) {
return (x * y) - z;
}
def code(x, y, z): return (x * y) - z
function code(x, y, z) return Float64(Float64(x * y) - z) end
function tmp = code(x, y, z) tmp = (x * y) - z; end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y - z
\end{array}
Initial program 98.0%
*-commutative98.0%
sub-neg98.0%
distribute-rgt-in98.0%
metadata-eval98.0%
neg-mul-198.0%
associate-+r+98.0%
unsub-neg98.0%
+-commutative98.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 76.8%
herbie shell --seed 2024086
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))