
(FPCore (x y z) :precision binary64 (* (/ 1.0 2.0) (+ x (* y (sqrt z)))))
double code(double x, double y, double z) {
return (1.0 / 2.0) * (x + (y * sqrt(z)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (1.0d0 / 2.0d0) * (x + (y * sqrt(z)))
end function
public static double code(double x, double y, double z) {
return (1.0 / 2.0) * (x + (y * Math.sqrt(z)));
}
def code(x, y, z): return (1.0 / 2.0) * (x + (y * math.sqrt(z)))
function code(x, y, z) return Float64(Float64(1.0 / 2.0) * Float64(x + Float64(y * sqrt(z)))) end
function tmp = code(x, y, z) tmp = (1.0 / 2.0) * (x + (y * sqrt(z))); end
code[x_, y_, z_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(x + N[(y * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2} \cdot \left(x + y \cdot \sqrt{z}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* (/ 1.0 2.0) (+ x (* y (sqrt z)))))
double code(double x, double y, double z) {
return (1.0 / 2.0) * (x + (y * sqrt(z)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (1.0d0 / 2.0d0) * (x + (y * sqrt(z)))
end function
public static double code(double x, double y, double z) {
return (1.0 / 2.0) * (x + (y * Math.sqrt(z)));
}
def code(x, y, z): return (1.0 / 2.0) * (x + (y * math.sqrt(z)))
function code(x, y, z) return Float64(Float64(1.0 / 2.0) * Float64(x + Float64(y * sqrt(z)))) end
function tmp = code(x, y, z) tmp = (1.0 / 2.0) * (x + (y * sqrt(z))); end
code[x_, y_, z_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(x + N[(y * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2} \cdot \left(x + y \cdot \sqrt{z}\right)
\end{array}
(FPCore (x y z) :precision binary64 (* 0.5 (fma y (sqrt z) x)))
double code(double x, double y, double z) {
return 0.5 * fma(y, sqrt(z), x);
}
function code(x, y, z) return Float64(0.5 * fma(y, sqrt(z), x)) end
code[x_, y_, z_] := N[(0.5 * N[(y * N[Sqrt[z], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \mathsf{fma}\left(y, \sqrt{z}, x\right)
\end{array}
Initial program 99.5%
metadata-eval99.5%
+-commutative99.5%
fma-def99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x y z)
:precision binary64
(if (<= x -3.8e+47)
(* 0.5 x)
(if (or (<= x -12200.0) (and (not (<= x -9.8e-24)) (<= x 7.5e+72)))
(* y (* 0.5 (sqrt z)))
(* 0.5 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.8e+47) {
tmp = 0.5 * x;
} else if ((x <= -12200.0) || (!(x <= -9.8e-24) && (x <= 7.5e+72))) {
tmp = y * (0.5 * sqrt(z));
} else {
tmp = 0.5 * 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 (x <= (-3.8d+47)) then
tmp = 0.5d0 * x
else if ((x <= (-12200.0d0)) .or. (.not. (x <= (-9.8d-24))) .and. (x <= 7.5d+72)) then
tmp = y * (0.5d0 * sqrt(z))
else
tmp = 0.5d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.8e+47) {
tmp = 0.5 * x;
} else if ((x <= -12200.0) || (!(x <= -9.8e-24) && (x <= 7.5e+72))) {
tmp = y * (0.5 * Math.sqrt(z));
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.8e+47: tmp = 0.5 * x elif (x <= -12200.0) or (not (x <= -9.8e-24) and (x <= 7.5e+72)): tmp = y * (0.5 * math.sqrt(z)) else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.8e+47) tmp = Float64(0.5 * x); elseif ((x <= -12200.0) || (!(x <= -9.8e-24) && (x <= 7.5e+72))) tmp = Float64(y * Float64(0.5 * sqrt(z))); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.8e+47) tmp = 0.5 * x; elseif ((x <= -12200.0) || (~((x <= -9.8e-24)) && (x <= 7.5e+72))) tmp = y * (0.5 * sqrt(z)); else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.8e+47], N[(0.5 * x), $MachinePrecision], If[Or[LessEqual[x, -12200.0], And[N[Not[LessEqual[x, -9.8e-24]], $MachinePrecision], LessEqual[x, 7.5e+72]]], N[(y * N[(0.5 * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{+47}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;x \leq -12200 \lor \neg \left(x \leq -9.8 \cdot 10^{-24}\right) \land x \leq 7.5 \cdot 10^{+72}:\\
\;\;\;\;y \cdot \left(0.5 \cdot \sqrt{z}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if x < -3.8000000000000003e47 or -12200 < x < -9.8000000000000002e-24 or 7.50000000000000027e72 < x Initial program 100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 81.7%
if -3.8000000000000003e47 < x < -12200 or -9.8000000000000002e-24 < x < 7.50000000000000027e72Initial program 99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in x around 0 77.1%
associate-*r*77.7%
*-commutative77.7%
associate-*r*77.7%
Simplified77.7%
Final simplification79.5%
(FPCore (x y z) :precision binary64 (* 0.5 (+ x (* y (sqrt z)))))
double code(double x, double y, double z) {
return 0.5 * (x + (y * sqrt(z)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.5d0 * (x + (y * sqrt(z)))
end function
public static double code(double x, double y, double z) {
return 0.5 * (x + (y * Math.sqrt(z)));
}
def code(x, y, z): return 0.5 * (x + (y * math.sqrt(z)))
function code(x, y, z) return Float64(0.5 * Float64(x + Float64(y * sqrt(z)))) end
function tmp = code(x, y, z) tmp = 0.5 * (x + (y * sqrt(z))); end
code[x_, y_, z_] := N[(0.5 * N[(x + N[(y * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(x + y \cdot \sqrt{z}\right)
\end{array}
Initial program 99.5%
metadata-eval99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (<= y 4.4e+234) (* 0.5 x) (* 0.5 (* z (* y (/ y x))))))
double code(double x, double y, double z) {
double tmp;
if (y <= 4.4e+234) {
tmp = 0.5 * x;
} else {
tmp = 0.5 * (z * (y * (y / 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 (y <= 4.4d+234) then
tmp = 0.5d0 * x
else
tmp = 0.5d0 * (z * (y * (y / x)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 4.4e+234) {
tmp = 0.5 * x;
} else {
tmp = 0.5 * (z * (y * (y / x)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 4.4e+234: tmp = 0.5 * x else: tmp = 0.5 * (z * (y * (y / x))) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 4.4e+234) tmp = Float64(0.5 * x); else tmp = Float64(0.5 * Float64(z * Float64(y * Float64(y / x)))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 4.4e+234) tmp = 0.5 * x; else tmp = 0.5 * (z * (y * (y / x))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 4.4e+234], N[(0.5 * x), $MachinePrecision], N[(0.5 * N[(z * N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.4 \cdot 10^{+234}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(z \cdot \left(y \cdot \frac{y}{x}\right)\right)\\
\end{array}
\end{array}
if y < 4.40000000000000015e234Initial program 99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in x around inf 53.2%
if 4.40000000000000015e234 < y Initial program 100.0%
metadata-eval100.0%
Simplified100.0%
flip-+14.0%
associate-*r/14.0%
*-commutative14.0%
*-commutative14.0%
swap-sqr1.0%
add-sqr-sqrt1.0%
Applied egg-rr1.0%
associate-/l*1.0%
Simplified1.0%
Taylor expanded in x around 0 1.4%
mul-1-neg1.4%
unpow21.4%
associate-*r*13.9%
distribute-rgt-neg-out13.9%
distribute-lft-neg-in13.9%
Simplified13.9%
Taylor expanded in x around inf 27.1%
unpow227.1%
associate-*r*27.2%
associate-/l*27.2%
Simplified27.2%
associate-*r/27.2%
frac-2neg27.2%
metadata-eval27.2%
distribute-lft-neg-in27.2%
*-commutative27.2%
distribute-rgt-neg-in27.2%
metadata-eval27.2%
distribute-neg-frac27.2%
add-sqr-sqrt27.1%
sqrt-unprod54.6%
sqr-neg54.6%
sqrt-unprod41.1%
add-sqr-sqrt41.6%
Applied egg-rr41.6%
distribute-rgt-neg-in41.6%
metadata-eval41.6%
*-commutative41.6%
associate-*r/41.6%
associate-/l*41.5%
associate-*r*41.3%
associate-*l/41.3%
*-commutative41.3%
associate-*r/41.3%
Simplified41.3%
Final simplification52.5%
(FPCore (x y z) :precision binary64 (if (<= y 1.9e+236) (* 0.5 x) (* (* y (/ 0.5 x)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.9e+236) {
tmp = 0.5 * x;
} else {
tmp = (y * (0.5 / 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 (y <= 1.9d+236) then
tmp = 0.5d0 * x
else
tmp = (y * (0.5d0 / x)) * (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.9e+236) {
tmp = 0.5 * x;
} else {
tmp = (y * (0.5 / x)) * (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.9e+236: tmp = 0.5 * x else: tmp = (y * (0.5 / x)) * (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.9e+236) tmp = Float64(0.5 * x); else tmp = Float64(Float64(y * Float64(0.5 / x)) * Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.9e+236) tmp = 0.5 * x; else tmp = (y * (0.5 / x)) * (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.9e+236], N[(0.5 * x), $MachinePrecision], N[(N[(y * N[(0.5 / x), $MachinePrecision]), $MachinePrecision] * N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.9 \cdot 10^{+236}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot \frac{0.5}{x}\right) \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if y < 1.89999999999999993e236Initial program 99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in x around inf 53.2%
if 1.89999999999999993e236 < y Initial program 100.0%
metadata-eval100.0%
Simplified100.0%
flip-+14.0%
associate-*r/14.0%
*-commutative14.0%
*-commutative14.0%
swap-sqr1.0%
add-sqr-sqrt1.0%
Applied egg-rr1.0%
associate-/l*1.0%
Simplified1.0%
Taylor expanded in x around 0 1.4%
mul-1-neg1.4%
unpow21.4%
associate-*r*13.9%
distribute-rgt-neg-out13.9%
distribute-lft-neg-in13.9%
Simplified13.9%
Taylor expanded in x around inf 27.1%
associate-*r/27.1%
neg-mul-127.1%
unpow227.1%
associate-*r*27.2%
Simplified27.2%
associate-/r/27.2%
associate-*r*27.2%
add-sqr-sqrt27.1%
sqrt-unprod54.6%
sqr-neg54.6%
sqrt-unprod41.1%
add-sqr-sqrt41.6%
Applied egg-rr41.6%
Final simplification52.5%
(FPCore (x y z) :precision binary64 (* 0.5 x))
double code(double x, double y, double z) {
return 0.5 * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.5d0 * x
end function
public static double code(double x, double y, double z) {
return 0.5 * x;
}
def code(x, y, z): return 0.5 * x
function code(x, y, z) return Float64(0.5 * x) end
function tmp = code(x, y, z) tmp = 0.5 * x; end
code[x_, y_, z_] := N[(0.5 * x), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot x
\end{array}
Initial program 99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in x around inf 50.6%
Final simplification50.6%
herbie shell --seed 2023275
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quadForm from diagrams-solve-0.1, B"
:precision binary64
(* (/ 1.0 2.0) (+ x (* y (sqrt z)))))