
(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 5 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 (or (<= y -7e-95) (not (<= y 1.1e-60))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7e-95) || !(y <= 1.1e-60)) {
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 ((y <= (-7d-95)) .or. (.not. (y <= 1.1d-60))) 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 ((y <= -7e-95) || !(y <= 1.1e-60)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7e-95) or not (y <= 1.1e-60): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7e-95) || !(y <= 1.1e-60)) 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 ((y <= -7e-95) || ~((y <= 1.1e-60))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7e-95], N[Not[LessEqual[y, 1.1e-60]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{-95} \lor \neg \left(y \leq 1.1 \cdot 10^{-60}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -6.9999999999999994e-95 or 1.0999999999999999e-60 < y Initial program 100.0%
Taylor expanded in y around inf 87.8%
if -6.9999999999999994e-95 < y < 1.0999999999999999e-60Initial program 100.0%
Taylor expanded in y around 0 85.7%
neg-mul-185.7%
distribute-neg-frac85.7%
Simplified85.7%
Taylor expanded in x around 0 85.5%
sub-neg85.5%
distribute-rgt-in85.5%
*-lft-identity85.5%
cancel-sign-sub-inv85.5%
associate-*l/85.7%
*-lft-identity85.7%
Simplified85.7%
Final simplification87.0%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) x (if (<= z 1.0) (/ x (- z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x;
} else if (z <= 1.0) {
tmp = x / -z;
} else {
tmp = 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.0d0)) then
tmp = x
else if (z <= 1.0d0) then
tmp = x / -z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x;
} else if (z <= 1.0) {
tmp = x / -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x elif z <= 1.0: tmp = x / -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = x; elseif (z <= 1.0) tmp = Float64(x / Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.0) tmp = x; elseif (z <= 1.0) tmp = x / -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], x, If[LessEqual[z, 1.0], N[(x / (-z)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
Taylor expanded in y around 0 65.1%
neg-mul-165.1%
distribute-neg-frac65.1%
Simplified65.1%
Taylor expanded in z around inf 62.4%
if -1 < z < 1Initial program 100.0%
Taylor expanded in y around 0 47.5%
neg-mul-147.5%
distribute-neg-frac47.5%
Simplified47.5%
Taylor expanded in x around 0 47.4%
sub-neg47.4%
distribute-rgt-in47.4%
*-lft-identity47.4%
cancel-sign-sub-inv47.4%
associate-*l/47.5%
*-lft-identity47.5%
Simplified47.5%
Taylor expanded in z around 0 47.1%
metadata-eval47.1%
times-frac47.1%
*-lft-identity47.1%
neg-mul-147.1%
Simplified47.1%
Final simplification53.4%
(FPCore (x y z) :precision binary64 (if (<= x 1.45e+196) (+ x (/ y z)) (/ x (- z))))
double code(double x, double y, double z) {
double tmp;
if (x <= 1.45e+196) {
tmp = x + (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 <= 1.45d+196) then
tmp = x + (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 <= 1.45e+196) {
tmp = x + (y / z);
} else {
tmp = x / -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 1.45e+196: tmp = x + (y / z) else: tmp = x / -z return tmp
function code(x, y, z) tmp = 0.0 if (x <= 1.45e+196) tmp = Float64(x + 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 <= 1.45e+196) tmp = x + (y / z); else tmp = x / -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 1.45e+196], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.45 \cdot 10^{+196}:\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{-z}\\
\end{array}
\end{array}
if x < 1.45e196Initial program 100.0%
Taylor expanded in y around inf 77.6%
if 1.45e196 < x Initial program 100.0%
Taylor expanded in y around 0 98.4%
neg-mul-198.4%
distribute-neg-frac98.4%
Simplified98.4%
Taylor expanded in x around 0 98.4%
sub-neg98.4%
distribute-rgt-in98.4%
*-lft-identity98.4%
cancel-sign-sub-inv98.4%
associate-*l/98.4%
*-lft-identity98.4%
Simplified98.4%
Taylor expanded in z around 0 65.7%
metadata-eval65.7%
times-frac65.7%
*-lft-identity65.7%
neg-mul-165.7%
Simplified65.7%
Final simplification76.4%
(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%
Taylor expanded in y around 0 54.7%
neg-mul-154.7%
distribute-neg-frac54.7%
Simplified54.7%
Taylor expanded in z around inf 27.4%
Final simplification27.4%
herbie shell --seed 2024011
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))