
(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 5 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 96.5%
*-commutative96.5%
sub-neg96.5%
distribute-rgt-in96.5%
metadata-eval96.5%
neg-mul-196.5%
associate-+r+96.5%
unsub-neg96.5%
+-commutative96.5%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.25e+52) (not (<= z 1.3e+59))) (- (* x z) z) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.25e+52) || !(z <= 1.3e+59)) {
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 <= (-2.25d+52)) .or. (.not. (z <= 1.3d+59))) 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 <= -2.25e+52) || !(z <= 1.3e+59)) {
tmp = (x * z) - z;
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.25e+52) or not (z <= 1.3e+59): tmp = (x * z) - z else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.25e+52) || !(z <= 1.3e+59)) 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 <= -2.25e+52) || ~((z <= 1.3e+59))) tmp = (x * z) - z; else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.25e+52], N[Not[LessEqual[z, 1.3e+59]], $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 -2.25 \cdot 10^{+52} \lor \neg \left(z \leq 1.3 \cdot 10^{+59}\right):\\
\;\;\;\;x \cdot z - z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if z < -2.25e52 or 1.3e59 < z Initial program 91.7%
*-commutative91.7%
sub-neg91.7%
distribute-rgt-in91.8%
metadata-eval91.8%
neg-mul-191.8%
associate-+r+91.8%
unsub-neg91.8%
+-commutative91.8%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 93.0%
if -2.25e52 < z < 1.3e59Initial program 99.4%
*-commutative99.4%
sub-neg99.4%
distribute-rgt-in99.4%
metadata-eval99.4%
neg-mul-199.4%
associate-+r+99.4%
unsub-neg99.4%
+-commutative99.4%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 86.0%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -6e-30) (not (<= x 1.2e-13))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6e-30) || !(x <= 1.2e-13)) {
tmp = x * y;
} 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 ((x <= (-6d-30)) .or. (.not. (x <= 1.2d-13))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6e-30) || !(x <= 1.2e-13)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6e-30) or not (x <= 1.2e-13): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6e-30) || !(x <= 1.2e-13)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6e-30) || ~((x <= 1.2e-13))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6e-30], N[Not[LessEqual[x, 1.2e-13]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-30} \lor \neg \left(x \leq 1.2 \cdot 10^{-13}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -5.9999999999999998e-30 or 1.1999999999999999e-13 < x Initial program 93.6%
*-commutative93.6%
sub-neg93.6%
distribute-rgt-in93.6%
metadata-eval93.6%
neg-mul-193.6%
associate-+r+93.6%
unsub-neg93.6%
+-commutative93.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 52.8%
Taylor expanded in x around inf 51.7%
if -5.9999999999999998e-30 < x < 1.1999999999999999e-13Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 73.4%
neg-mul-173.4%
Simplified73.4%
Final simplification61.4%
(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 96.5%
*-commutative96.5%
sub-neg96.5%
distribute-rgt-in96.5%
metadata-eval96.5%
neg-mul-196.5%
associate-+r+96.5%
unsub-neg96.5%
+-commutative96.5%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 74.0%
Final simplification74.0%
(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 Float64(-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%
sub-neg96.5%
distribute-rgt-in96.5%
metadata-eval96.5%
neg-mul-196.5%
associate-+r+96.5%
unsub-neg96.5%
+-commutative96.5%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 35.1%
neg-mul-135.1%
Simplified35.1%
Final simplification35.1%
herbie shell --seed 2024055
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))