
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / 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)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / 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)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (+ x (/ x (/ z y))))
double code(double x, double y, double z) {
return x + (x / (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 = x + (x / (z / y))
end function
public static double code(double x, double y, double z) {
return x + (x / (z / y));
}
def code(x, y, z): return x + (x / (z / y))
function code(x, y, z) return Float64(x + Float64(x / Float64(z / y))) end
function tmp = code(x, y, z) tmp = x + (x / (z / y)); end
code[x_, y_, z_] := N[(x + N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{x}{\frac{z}{y}}
\end{array}
Initial program 83.7%
associate-*l/84.2%
div-inv84.1%
associate-*l*97.5%
Applied egg-rr97.5%
distribute-rgt-in97.5%
div-inv97.5%
rgt-mult-inverse97.7%
distribute-rgt-in97.7%
*-commutative97.7%
*-un-lft-identity97.7%
Applied egg-rr97.7%
clear-num97.6%
un-div-inv97.7%
Applied egg-rr97.7%
Final simplification97.7%
(FPCore (x y z)
:precision binary64
(if (<= z -9e-7)
x
(if (or (<= z 1.15e-91) (and (not (<= z 1.1e+155)) (<= z 1.4e+174)))
(* x (/ y z))
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -9e-7) {
tmp = x;
} else if ((z <= 1.15e-91) || (!(z <= 1.1e+155) && (z <= 1.4e+174))) {
tmp = x * (y / 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 <= (-9d-7)) then
tmp = x
else if ((z <= 1.15d-91) .or. (.not. (z <= 1.1d+155)) .and. (z <= 1.4d+174)) then
tmp = x * (y / z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -9e-7) {
tmp = x;
} else if ((z <= 1.15e-91) || (!(z <= 1.1e+155) && (z <= 1.4e+174))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9e-7: tmp = x elif (z <= 1.15e-91) or (not (z <= 1.1e+155) and (z <= 1.4e+174)): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9e-7) tmp = x; elseif ((z <= 1.15e-91) || (!(z <= 1.1e+155) && (z <= 1.4e+174))) tmp = Float64(x * Float64(y / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9e-7) tmp = x; elseif ((z <= 1.15e-91) || (~((z <= 1.1e+155)) && (z <= 1.4e+174))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9e-7], x, If[Or[LessEqual[z, 1.15e-91], And[N[Not[LessEqual[z, 1.1e+155]], $MachinePrecision], LessEqual[z, 1.4e+174]]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{-7}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{-91} \lor \neg \left(z \leq 1.1 \cdot 10^{+155}\right) \land z \leq 1.4 \cdot 10^{+174}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.99999999999999959e-7 or 1.14999999999999998e-91 < z < 1.1000000000000001e155 or 1.4e174 < z Initial program 79.4%
associate-/l*99.3%
remove-double-neg99.3%
distribute-frac-neg299.3%
neg-sub099.3%
remove-double-neg99.3%
unsub-neg99.3%
div-sub99.3%
*-inverses99.3%
metadata-eval99.3%
associate--r-99.3%
neg-sub099.3%
distribute-frac-neg299.3%
remove-double-neg99.3%
sub-neg99.3%
Simplified99.3%
Taylor expanded in y around 0 77.3%
if -8.99999999999999959e-7 < z < 1.14999999999999998e-91 or 1.1000000000000001e155 < z < 1.4e174Initial program 89.5%
associate-/l*95.5%
remove-double-neg95.5%
distribute-frac-neg295.5%
neg-sub095.5%
remove-double-neg95.5%
unsub-neg95.5%
div-sub95.5%
*-inverses95.5%
metadata-eval95.5%
associate--r-95.5%
neg-sub095.5%
distribute-frac-neg295.5%
remove-double-neg95.5%
sub-neg95.5%
Simplified95.5%
Taylor expanded in y around inf 76.7%
associate-*r/81.0%
Simplified81.0%
Final simplification78.9%
(FPCore (x y z)
:precision binary64
(if (<= z -0.00098)
x
(if (<= z 1.52e-87)
(/ y (/ z x))
(if (<= z 1.1e+155) x (if (<= z 1.4e+174) (* x (/ y z)) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.00098) {
tmp = x;
} else if (z <= 1.52e-87) {
tmp = y / (z / x);
} else if (z <= 1.1e+155) {
tmp = x;
} else if (z <= 1.4e+174) {
tmp = x * (y / 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 <= (-0.00098d0)) then
tmp = x
else if (z <= 1.52d-87) then
tmp = y / (z / x)
else if (z <= 1.1d+155) then
tmp = x
else if (z <= 1.4d+174) then
tmp = x * (y / z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -0.00098) {
tmp = x;
} else if (z <= 1.52e-87) {
tmp = y / (z / x);
} else if (z <= 1.1e+155) {
tmp = x;
} else if (z <= 1.4e+174) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -0.00098: tmp = x elif z <= 1.52e-87: tmp = y / (z / x) elif z <= 1.1e+155: tmp = x elif z <= 1.4e+174: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -0.00098) tmp = x; elseif (z <= 1.52e-87) tmp = Float64(y / Float64(z / x)); elseif (z <= 1.1e+155) tmp = x; elseif (z <= 1.4e+174) tmp = Float64(x * Float64(y / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -0.00098) tmp = x; elseif (z <= 1.52e-87) tmp = y / (z / x); elseif (z <= 1.1e+155) tmp = x; elseif (z <= 1.4e+174) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -0.00098], x, If[LessEqual[z, 1.52e-87], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.1e+155], x, If[LessEqual[z, 1.4e+174], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.00098:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.52 \cdot 10^{-87}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{elif}\;z \leq 1.1 \cdot 10^{+155}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{+174}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.7999999999999997e-4 or 1.52000000000000004e-87 < z < 1.1000000000000001e155 or 1.4e174 < z Initial program 79.1%
associate-/l*99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
neg-sub099.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
*-inverses99.9%
metadata-eval99.9%
associate--r-99.9%
neg-sub099.9%
distribute-frac-neg299.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 77.7%
if -9.7999999999999997e-4 < z < 1.52000000000000004e-87Initial program 90.7%
associate-/l*94.4%
remove-double-neg94.4%
distribute-frac-neg294.4%
neg-sub094.4%
remove-double-neg94.4%
unsub-neg94.4%
div-sub94.4%
*-inverses94.4%
metadata-eval94.4%
associate--r-94.4%
neg-sub094.4%
distribute-frac-neg294.4%
remove-double-neg94.4%
sub-neg94.4%
Simplified94.4%
Taylor expanded in y around inf 77.4%
associate-*r/79.3%
Simplified79.3%
associate-*r/77.4%
*-commutative77.4%
associate-*r/82.2%
clear-num82.2%
un-div-inv83.4%
Applied egg-rr83.4%
if 1.1000000000000001e155 < z < 1.4e174Initial program 76.4%
associate-/l*99.6%
remove-double-neg99.6%
distribute-frac-neg299.6%
neg-sub099.6%
remove-double-neg99.6%
unsub-neg99.6%
div-sub99.6%
*-inverses99.6%
metadata-eval99.6%
associate--r-99.6%
neg-sub099.6%
distribute-frac-neg299.6%
remove-double-neg99.6%
sub-neg99.6%
Simplified99.6%
Taylor expanded in y around inf 61.8%
associate-*r/84.6%
Simplified84.6%
(FPCore (x y z)
:precision binary64
(if (<= z -2.2e-9)
x
(if (<= z 2.65e-86)
(* y (/ x z))
(if (<= z 4.5e+154) x (if (<= z 1.4e+174) (* x (/ y z)) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e-9) {
tmp = x;
} else if (z <= 2.65e-86) {
tmp = y * (x / z);
} else if (z <= 4.5e+154) {
tmp = x;
} else if (z <= 1.4e+174) {
tmp = x * (y / 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 <= (-2.2d-9)) then
tmp = x
else if (z <= 2.65d-86) then
tmp = y * (x / z)
else if (z <= 4.5d+154) then
tmp = x
else if (z <= 1.4d+174) then
tmp = x * (y / z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e-9) {
tmp = x;
} else if (z <= 2.65e-86) {
tmp = y * (x / z);
} else if (z <= 4.5e+154) {
tmp = x;
} else if (z <= 1.4e+174) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.2e-9: tmp = x elif z <= 2.65e-86: tmp = y * (x / z) elif z <= 4.5e+154: tmp = x elif z <= 1.4e+174: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.2e-9) tmp = x; elseif (z <= 2.65e-86) tmp = Float64(y * Float64(x / z)); elseif (z <= 4.5e+154) tmp = x; elseif (z <= 1.4e+174) tmp = Float64(x * Float64(y / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.2e-9) tmp = x; elseif (z <= 2.65e-86) tmp = y * (x / z); elseif (z <= 4.5e+154) tmp = x; elseif (z <= 1.4e+174) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.2e-9], x, If[LessEqual[z, 2.65e-86], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 4.5e+154], x, If[LessEqual[z, 1.4e+174], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{-9}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.65 \cdot 10^{-86}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{+154}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{+174}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.1999999999999998e-9 or 2.6499999999999998e-86 < z < 4.50000000000000009e154 or 1.4e174 < z Initial program 79.1%
associate-/l*99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
neg-sub099.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
*-inverses99.9%
metadata-eval99.9%
associate--r-99.9%
neg-sub099.9%
distribute-frac-neg299.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 77.7%
if -2.1999999999999998e-9 < z < 2.6499999999999998e-86Initial program 90.7%
associate-/l*94.4%
remove-double-neg94.4%
distribute-frac-neg294.4%
neg-sub094.4%
remove-double-neg94.4%
unsub-neg94.4%
div-sub94.4%
*-inverses94.4%
metadata-eval94.4%
associate--r-94.4%
neg-sub094.4%
distribute-frac-neg294.4%
remove-double-neg94.4%
sub-neg94.4%
Simplified94.4%
Taylor expanded in y around inf 77.4%
associate-*l/82.2%
*-commutative82.2%
Simplified82.2%
if 4.50000000000000009e154 < z < 1.4e174Initial program 76.4%
associate-/l*99.6%
remove-double-neg99.6%
distribute-frac-neg299.6%
neg-sub099.6%
remove-double-neg99.6%
unsub-neg99.6%
div-sub99.6%
*-inverses99.6%
metadata-eval99.6%
associate--r-99.6%
neg-sub099.6%
distribute-frac-neg299.6%
remove-double-neg99.6%
sub-neg99.6%
Simplified99.6%
Taylor expanded in y around inf 61.8%
associate-*r/84.6%
Simplified84.6%
(FPCore (x y z) :precision binary64 (* x (- (/ y z) -1.0)))
double code(double x, double y, double z) {
return x * ((y / z) - -1.0);
}
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))
end function
public static double code(double x, double y, double z) {
return x * ((y / z) - -1.0);
}
def code(x, y, z): return x * ((y / z) - -1.0)
function code(x, y, z) return Float64(x * Float64(Float64(y / z) - -1.0)) end
function tmp = code(x, y, z) tmp = x * ((y / z) - -1.0); end
code[x_, y_, z_] := N[(x * N[(N[(y / z), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(\frac{y}{z} - -1\right)
\end{array}
Initial program 83.7%
associate-/l*97.7%
remove-double-neg97.7%
distribute-frac-neg297.7%
neg-sub097.7%
remove-double-neg97.7%
unsub-neg97.7%
div-sub97.7%
*-inverses97.7%
metadata-eval97.7%
associate--r-97.7%
neg-sub097.7%
distribute-frac-neg297.7%
remove-double-neg97.7%
sub-neg97.7%
Simplified97.7%
(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 83.7%
associate-/l*97.7%
remove-double-neg97.7%
distribute-frac-neg297.7%
neg-sub097.7%
remove-double-neg97.7%
unsub-neg97.7%
div-sub97.7%
*-inverses97.7%
metadata-eval97.7%
associate--r-97.7%
neg-sub097.7%
distribute-frac-neg297.7%
remove-double-neg97.7%
sub-neg97.7%
Simplified97.7%
Taylor expanded in y around 0 51.5%
(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(x / Float64(z / Float64(y + z))) end
function tmp = code(x, y, z) tmp = x / (z / (y + z)); end
code[x_, y_, z_] := N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{z}{y + z}}
\end{array}
herbie shell --seed 2024100
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:alt
(/ x (/ z (+ y z)))
(/ (* x (+ y z)) z))