
(FPCore (x y z) :precision binary64 (+ x (/ (- y x) z)))
double code(double x, double y, double z) {
return x + ((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 = x + ((y - x) / z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) / z);
}
def code(x, y, z): return x + ((y - x) / z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) / z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) / z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y - x}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (/ (- y x) z)))
double code(double x, double y, double z) {
return x + ((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 = x + ((y - x) / z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) / z);
}
def code(x, y, z): return x + ((y - x) / z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) / z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) / z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y - x}{z}
\end{array}
(FPCore (x y z) :precision binary64 (+ x (/ (- y x) z)))
double code(double x, double y, double z) {
return x + ((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 = x + ((y - x) / z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) / z);
}
def code(x, y, z): return x + ((y - x) / z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) / z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) / z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y - x}{z}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= x 3.8e+18) (+ x (/ y z)) (* x (+ (/ -1.0 z) 1.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= 3.8e+18) {
tmp = x + (y / z);
} else {
tmp = x * ((-1.0 / z) + 1.0);
}
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 <= 3.8d+18) then
tmp = x + (y / z)
else
tmp = x * (((-1.0d0) / z) + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 3.8e+18) {
tmp = x + (y / z);
} else {
tmp = x * ((-1.0 / z) + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 3.8e+18: tmp = x + (y / z) else: tmp = x * ((-1.0 / z) + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 3.8e+18) tmp = Float64(x + Float64(y / z)); else tmp = Float64(x * Float64(Float64(-1.0 / z) + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 3.8e+18) tmp = x + (y / z); else tmp = x * ((-1.0 / z) + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 3.8e+18], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(-1.0 / z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.8 \cdot 10^{+18}:\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\frac{-1}{z} + 1\right)\\
\end{array}
\end{array}
if x < 3.8e18Initial program 100.0%
div-sub98.5%
sub-neg98.5%
distribute-frac-neg98.5%
+-commutative98.5%
associate-+r+98.5%
distribute-frac-neg98.5%
sub-neg98.5%
associate--r-98.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 82.8%
neg-mul-182.8%
distribute-neg-frac282.8%
Simplified82.8%
Taylor expanded in x around 0 82.8%
cancel-sign-sub-inv82.8%
metadata-eval82.8%
*-lft-identity82.8%
+-commutative82.8%
Simplified82.8%
if 3.8e18 < x Initial program 100.0%
div-sub95.1%
sub-neg95.1%
distribute-frac-neg95.1%
+-commutative95.1%
associate-+r+95.1%
distribute-frac-neg95.1%
sub-neg95.1%
associate--r-95.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 90.5%
Final simplification84.6%
(FPCore (x y z) :precision binary64 (if (<= x 3.15e+29) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= 3.15e+29) {
tmp = x + (y / z);
} else {
tmp = x - (x / 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 <= 3.15d+29) then
tmp = x + (y / z)
else
tmp = x - (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 3.15e+29) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 3.15e+29: tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 3.15e+29) tmp = Float64(x + Float64(y / z)); else tmp = Float64(x - Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 3.15e+29) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 3.15e+29], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.15 \cdot 10^{+29}:\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if x < 3.1499999999999999e29Initial program 100.0%
div-sub98.5%
sub-neg98.5%
distribute-frac-neg98.5%
+-commutative98.5%
associate-+r+98.5%
distribute-frac-neg98.5%
sub-neg98.5%
associate--r-98.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 82.8%
neg-mul-182.8%
distribute-neg-frac282.8%
Simplified82.8%
Taylor expanded in x around 0 82.8%
cancel-sign-sub-inv82.8%
metadata-eval82.8%
*-lft-identity82.8%
+-commutative82.8%
Simplified82.8%
if 3.1499999999999999e29 < x Initial program 100.0%
div-sub95.1%
sub-neg95.1%
distribute-frac-neg95.1%
+-commutative95.1%
associate-+r+95.1%
distribute-frac-neg95.1%
sub-neg95.1%
associate--r-95.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 90.5%
distribute-rgt-out--90.5%
*-lft-identity90.5%
associate-*l/90.5%
*-lft-identity90.5%
Simplified90.5%
Final simplification84.6%
(FPCore (x y z) :precision binary64 (if (<= x -1.7e+21) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.7e+21) {
tmp = x - (x / 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 (x <= (-1.7d+21)) then
tmp = x - (x / 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 (x <= -1.7e+21) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.7e+21: tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.7e+21) tmp = Float64(x - Float64(x / z)); else tmp = Float64(x + Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.7e+21) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.7e+21], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{+21}:\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -1.7e21Initial program 100.0%
div-sub94.7%
sub-neg94.7%
distribute-frac-neg94.7%
+-commutative94.7%
associate-+r+94.7%
distribute-frac-neg94.7%
sub-neg94.7%
associate--r-94.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 90.6%
distribute-rgt-out--90.6%
*-lft-identity90.6%
associate-*l/90.7%
*-lft-identity90.7%
Simplified90.7%
if -1.7e21 < x Initial program 100.0%
div-sub98.5%
sub-neg98.5%
distribute-frac-neg98.5%
+-commutative98.5%
associate-+r+98.5%
distribute-frac-neg98.5%
sub-neg98.5%
associate--r-98.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 81.0%
neg-mul-181.0%
distribute-neg-frac281.0%
Simplified81.0%
Final simplification83.2%
(FPCore (x y z) :precision binary64 (if (<= x 3.15e+29) (/ y z) (/ x (- z))))
double code(double x, double y, double z) {
double tmp;
if (x <= 3.15e+29) {
tmp = y / z;
} else {
tmp = x / -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 <= 3.15d+29) then
tmp = y / z
else
tmp = x / -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 3.15e+29) {
tmp = y / z;
} else {
tmp = x / -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 3.15e+29: tmp = y / z else: tmp = x / -z return tmp
function code(x, y, z) tmp = 0.0 if (x <= 3.15e+29) tmp = Float64(y / z); else tmp = Float64(x / Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 3.15e+29) tmp = y / z; else tmp = x / -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 3.15e+29], N[(y / z), $MachinePrecision], N[(x / (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.15 \cdot 10^{+29}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{-z}\\
\end{array}
\end{array}
if x < 3.1499999999999999e29Initial program 100.0%
div-sub98.5%
sub-neg98.5%
distribute-frac-neg98.5%
+-commutative98.5%
associate-+r+98.5%
distribute-frac-neg98.5%
sub-neg98.5%
associate--r-98.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 46.3%
if 3.1499999999999999e29 < x Initial program 100.0%
div-sub95.1%
sub-neg95.1%
distribute-frac-neg95.1%
+-commutative95.1%
associate-+r+95.1%
distribute-frac-neg95.1%
sub-neg95.1%
associate--r-95.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 90.5%
distribute-rgt-out--90.5%
*-lft-identity90.5%
associate-*l/90.5%
*-lft-identity90.5%
Simplified90.5%
Taylor expanded in z around 0 44.8%
mul-1-neg44.8%
distribute-neg-frac44.8%
Simplified44.8%
Final simplification45.9%
(FPCore (x y z) :precision binary64 (if (<= x -1400.0) x (/ y z)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1400.0) {
tmp = x;
} else {
tmp = 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 (x <= (-1400.0d0)) then
tmp = x
else
tmp = y / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1400.0) {
tmp = x;
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1400.0: tmp = x else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1400.0) tmp = x; else tmp = Float64(y / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1400.0) tmp = x; else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1400.0], x, N[(y / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1400:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if x < -1400Initial program 100.0%
div-sub94.9%
sub-neg94.9%
distribute-frac-neg94.9%
+-commutative94.9%
associate-+r+94.9%
distribute-frac-neg94.9%
sub-neg94.9%
associate--r-94.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 51.5%
if -1400 < x Initial program 100.0%
div-sub98.5%
sub-neg98.5%
distribute-frac-neg98.5%
+-commutative98.5%
associate-+r+98.5%
distribute-frac-neg98.5%
sub-neg98.5%
associate--r-98.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 45.7%
Final simplification47.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(x + Float64(y / z)) end
function tmp = code(x, y, z) tmp = x + (y / z); end
code[x_, y_, z_] := N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{z}
\end{array}
Initial program 100.0%
div-sub97.6%
sub-neg97.6%
distribute-frac-neg97.6%
+-commutative97.6%
associate-+r+97.6%
distribute-frac-neg97.6%
sub-neg97.6%
associate--r-97.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 77.0%
neg-mul-177.0%
distribute-neg-frac277.0%
Simplified77.0%
Taylor expanded in x around 0 77.0%
cancel-sign-sub-inv77.0%
metadata-eval77.0%
*-lft-identity77.0%
+-commutative77.0%
Simplified77.0%
Final simplification77.0%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
div-sub97.6%
sub-neg97.6%
distribute-frac-neg97.6%
+-commutative97.6%
associate-+r+97.6%
distribute-frac-neg97.6%
sub-neg97.6%
associate--r-97.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 40.5%
Final simplification40.5%
herbie shell --seed 2024066
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))