
(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 3 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 (+ 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.8%
metadata-eval99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(if (or (<= x -1.02e+30)
(and (not (<= x -1.4e-8)) (or (<= x -5.2e-46) (not (<= x 8.4e+64)))))
(* 0.5 x)
(* (sqrt z) (* 0.5 y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.02e+30) || (!(x <= -1.4e-8) && ((x <= -5.2e-46) || !(x <= 8.4e+64)))) {
tmp = 0.5 * x;
} else {
tmp = sqrt(z) * (0.5 * y);
}
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.02d+30)) .or. (.not. (x <= (-1.4d-8))) .and. (x <= (-5.2d-46)) .or. (.not. (x <= 8.4d+64))) then
tmp = 0.5d0 * x
else
tmp = sqrt(z) * (0.5d0 * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.02e+30) || (!(x <= -1.4e-8) && ((x <= -5.2e-46) || !(x <= 8.4e+64)))) {
tmp = 0.5 * x;
} else {
tmp = Math.sqrt(z) * (0.5 * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.02e+30) or (not (x <= -1.4e-8) and ((x <= -5.2e-46) or not (x <= 8.4e+64))): tmp = 0.5 * x else: tmp = math.sqrt(z) * (0.5 * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.02e+30) || (!(x <= -1.4e-8) && ((x <= -5.2e-46) || !(x <= 8.4e+64)))) tmp = Float64(0.5 * x); else tmp = Float64(sqrt(z) * Float64(0.5 * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.02e+30) || (~((x <= -1.4e-8)) && ((x <= -5.2e-46) || ~((x <= 8.4e+64))))) tmp = 0.5 * x; else tmp = sqrt(z) * (0.5 * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.02e+30], And[N[Not[LessEqual[x, -1.4e-8]], $MachinePrecision], Or[LessEqual[x, -5.2e-46], N[Not[LessEqual[x, 8.4e+64]], $MachinePrecision]]]], N[(0.5 * x), $MachinePrecision], N[(N[Sqrt[z], $MachinePrecision] * N[(0.5 * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.02 \cdot 10^{+30} \lor \neg \left(x \leq -1.4 \cdot 10^{-8}\right) \land \left(x \leq -5.2 \cdot 10^{-46} \lor \neg \left(x \leq 8.4 \cdot 10^{+64}\right)\right):\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\sqrt{z} \cdot \left(0.5 \cdot y\right)\\
\end{array}
\end{array}
if x < -1.02e30 or -1.4e-8 < x < -5.2000000000000004e-46 or 8.4000000000000001e64 < x Initial program 100.0%
metadata-eval100.0%
Simplified100.0%
*-commutative100.0%
add-sqr-sqrt52.0%
sqrt-unprod86.2%
sqrt-prod83.9%
pow283.9%
Applied egg-rr83.9%
Taylor expanded in x around inf 83.7%
if -1.02e30 < x < -1.4e-8 or -5.2000000000000004e-46 < x < 8.4000000000000001e64Initial program 99.7%
metadata-eval99.7%
Simplified99.7%
*-commutative99.7%
add-sqr-sqrt48.6%
sqrt-unprod54.5%
sqrt-prod50.5%
pow250.5%
Applied egg-rr50.5%
flip-+37.9%
add-sqr-sqrt37.8%
div-sub37.8%
pow237.8%
*-commutative37.8%
sqrt-prod37.8%
unpow237.8%
sqrt-prod27.7%
add-sqr-sqrt38.6%
*-commutative38.6%
sqrt-prod38.8%
unpow238.8%
sqrt-prod28.2%
add-sqr-sqrt52.1%
Applied egg-rr52.1%
div-sub52.1%
Simplified52.1%
Taylor expanded in x around 0 35.9%
associate-*r*35.9%
neg-mul-135.9%
*-commutative35.9%
Simplified35.9%
Taylor expanded in y around inf 73.8%
associate-*r*73.8%
Simplified73.8%
Final simplification78.4%
(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.8%
metadata-eval99.8%
Simplified99.8%
*-commutative99.8%
add-sqr-sqrt50.2%
sqrt-unprod69.2%
sqrt-prod66.0%
pow266.0%
Applied egg-rr66.0%
Taylor expanded in x around inf 54.0%
Final simplification54.0%
herbie shell --seed 2024021
(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)))))