
(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 3 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 (fma (/ y z) x x))
double code(double x, double y, double z) {
return fma((y / z), x, x);
}
function code(x, y, z) return fma(Float64(y / z), x, x) end
code[x_, y_, z_] := N[(N[(y / z), $MachinePrecision] * x + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{z}, x, x\right)
\end{array}
Initial program 84.4%
Taylor expanded in x around 0
*-commutativeN/A
associate-*l/N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-/.f6497.3
Applied rewrites97.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (/ (* x (+ y z)) z))) (if (or (<= t_0 0.0) (not (<= t_0 5e+184))) (* (/ y z) x) (/ (* z x) z))))
double code(double x, double y, double z) {
double t_0 = (x * (y + z)) / z;
double tmp;
if ((t_0 <= 0.0) || !(t_0 <= 5e+184)) {
tmp = (y / z) * x;
} else {
tmp = (z * 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) :: t_0
real(8) :: tmp
t_0 = (x * (y + z)) / z
if ((t_0 <= 0.0d0) .or. (.not. (t_0 <= 5d+184))) then
tmp = (y / z) * x
else
tmp = (z * x) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * (y + z)) / z;
double tmp;
if ((t_0 <= 0.0) || !(t_0 <= 5e+184)) {
tmp = (y / z) * x;
} else {
tmp = (z * x) / z;
}
return tmp;
}
def code(x, y, z): t_0 = (x * (y + z)) / z tmp = 0 if (t_0 <= 0.0) or not (t_0 <= 5e+184): tmp = (y / z) * x else: tmp = (z * x) / z return tmp
function code(x, y, z) t_0 = Float64(Float64(x * Float64(y + z)) / z) tmp = 0.0 if ((t_0 <= 0.0) || !(t_0 <= 5e+184)) tmp = Float64(Float64(y / z) * x); else tmp = Float64(Float64(z * x) / z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * (y + z)) / z; tmp = 0.0; if ((t_0 <= 0.0) || ~((t_0 <= 5e+184))) tmp = (y / z) * x; else tmp = (z * x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, If[Or[LessEqual[t$95$0, 0.0], N[Not[LessEqual[t$95$0, 5e+184]], $MachinePrecision]], N[(N[(y / z), $MachinePrecision] * x), $MachinePrecision], N[(N[(z * x), $MachinePrecision] / z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(y + z\right)}{z}\\
\mathbf{if}\;t\_0 \leq 0 \lor \neg \left(t\_0 \leq 5 \cdot 10^{+184}\right):\\
\;\;\;\;\frac{y}{z} \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{z \cdot x}{z}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 y z)) z) < -0.0 or 4.9999999999999999e184 < (/.f64 (*.f64 x (+.f64 y z)) z) Initial program 76.8%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6485.5
lift-+.f64N/A
+-commutativeN/A
lower-+.f6485.5
Applied rewrites85.5%
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
lift-*.f64N/A
frac-addN/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-/.f6454.1
Applied rewrites54.7%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6434.0
Applied rewrites34.0%
Taylor expanded in y around inf
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f6451.0
Applied rewrites51.0%
if -0.0 < (/.f64 (*.f64 x (+.f64 y z)) z) < 4.9999999999999999e184Initial program 99.7%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f6472.1
Applied rewrites72.1%
Final simplification58.0%
(FPCore (x y z) :precision binary64 (* (/ y z) x))
double code(double x, double y, double z) {
return (y / z) * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y / z) * x
end function
public static double code(double x, double y, double z) {
return (y / z) * x;
}
def code(x, y, z): return (y / z) * x
function code(x, y, z) return Float64(Float64(y / z) * x) end
function tmp = code(x, y, z) tmp = (y / z) * x; end
code[x_, y_, z_] := N[(N[(y / z), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{z} \cdot x
\end{array}
Initial program 84.4%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6480.8
lift-+.f64N/A
+-commutativeN/A
lower-+.f6480.8
Applied rewrites80.8%
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
lift-*.f64N/A
frac-addN/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-/.f6451.6
Applied rewrites52.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6427.1
Applied rewrites27.1%
Taylor expanded in y around inf
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f6444.1
Applied rewrites44.1%
Final simplification44.1%
(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 2024326
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:alt
(! :herbie-platform default (/ x (/ z (+ y z))))
(/ (* x (+ y z)) z))