
(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 5 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.8%
metadata-eval99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(if (<= x -1.35e+24)
(* 0.5 x)
(if (or (<= x 2e-50) (and (not (<= x 29500000000.0)) (<= x 2.3e+45)))
(* 0.5 (/ y (pow z -0.5)))
(* 0.5 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.35e+24) {
tmp = 0.5 * x;
} else if ((x <= 2e-50) || (!(x <= 29500000000.0) && (x <= 2.3e+45))) {
tmp = 0.5 * (y / pow(z, -0.5));
} 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 <= (-1.35d+24)) then
tmp = 0.5d0 * x
else if ((x <= 2d-50) .or. (.not. (x <= 29500000000.0d0)) .and. (x <= 2.3d+45)) then
tmp = 0.5d0 * (y / (z ** (-0.5d0)))
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 <= -1.35e+24) {
tmp = 0.5 * x;
} else if ((x <= 2e-50) || (!(x <= 29500000000.0) && (x <= 2.3e+45))) {
tmp = 0.5 * (y / Math.pow(z, -0.5));
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.35e+24: tmp = 0.5 * x elif (x <= 2e-50) or (not (x <= 29500000000.0) and (x <= 2.3e+45)): tmp = 0.5 * (y / math.pow(z, -0.5)) else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.35e+24) tmp = Float64(0.5 * x); elseif ((x <= 2e-50) || (!(x <= 29500000000.0) && (x <= 2.3e+45))) tmp = Float64(0.5 * Float64(y / (z ^ -0.5))); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.35e+24) tmp = 0.5 * x; elseif ((x <= 2e-50) || (~((x <= 29500000000.0)) && (x <= 2.3e+45))) tmp = 0.5 * (y / (z ^ -0.5)); else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.35e+24], N[(0.5 * x), $MachinePrecision], If[Or[LessEqual[x, 2e-50], And[N[Not[LessEqual[x, 29500000000.0]], $MachinePrecision], LessEqual[x, 2.3e+45]]], N[(0.5 * N[(y / N[Power[z, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.35 \cdot 10^{+24}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;x \leq 2 \cdot 10^{-50} \lor \neg \left(x \leq 29500000000\right) \land x \leq 2.3 \cdot 10^{+45}:\\
\;\;\;\;0.5 \cdot \frac{y}{{z}^{-0.5}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if x < -1.35e24 or 2.00000000000000002e-50 < x < 2.95e10 or 2.30000000000000012e45 < x Initial program 100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 77.5%
if -1.35e24 < x < 2.00000000000000002e-50 or 2.95e10 < x < 2.30000000000000012e45Initial program 99.6%
metadata-eval99.6%
Simplified99.6%
+-commutative99.6%
*-commutative99.6%
add-sqr-sqrt99.2%
associate-*l*99.3%
fma-def99.2%
pow1/299.2%
sqrt-pow199.4%
metadata-eval99.4%
pow1/299.4%
sqrt-pow199.3%
metadata-eval99.3%
Applied egg-rr99.3%
Applied egg-rr99.5%
Taylor expanded in y around inf 79.1%
expm1-log1p-u52.9%
expm1-udef29.8%
associate-*l/29.8%
*-un-lft-identity29.8%
clear-num29.8%
inv-pow29.8%
sqrt-pow129.8%
metadata-eval29.8%
Applied egg-rr29.8%
expm1-def53.0%
expm1-log1p79.3%
Simplified79.3%
Final simplification78.4%
(FPCore (x y z)
:precision binary64
(if (<= x -8.4e+83)
(* 0.5 x)
(if (or (<= x 1.95e-56) (and (not (<= x 33000000000.0)) (<= x 2.6e+40)))
(* 0.5 (* y (sqrt z)))
(* 0.5 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -8.4e+83) {
tmp = 0.5 * x;
} else if ((x <= 1.95e-56) || (!(x <= 33000000000.0) && (x <= 2.6e+40))) {
tmp = 0.5 * (y * 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 <= (-8.4d+83)) then
tmp = 0.5d0 * x
else if ((x <= 1.95d-56) .or. (.not. (x <= 33000000000.0d0)) .and. (x <= 2.6d+40)) then
tmp = 0.5d0 * (y * 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 <= -8.4e+83) {
tmp = 0.5 * x;
} else if ((x <= 1.95e-56) || (!(x <= 33000000000.0) && (x <= 2.6e+40))) {
tmp = 0.5 * (y * Math.sqrt(z));
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -8.4e+83: tmp = 0.5 * x elif (x <= 1.95e-56) or (not (x <= 33000000000.0) and (x <= 2.6e+40)): tmp = 0.5 * (y * math.sqrt(z)) else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -8.4e+83) tmp = Float64(0.5 * x); elseif ((x <= 1.95e-56) || (!(x <= 33000000000.0) && (x <= 2.6e+40))) tmp = Float64(0.5 * Float64(y * sqrt(z))); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -8.4e+83) tmp = 0.5 * x; elseif ((x <= 1.95e-56) || (~((x <= 33000000000.0)) && (x <= 2.6e+40))) tmp = 0.5 * (y * sqrt(z)); else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -8.4e+83], N[(0.5 * x), $MachinePrecision], If[Or[LessEqual[x, 1.95e-56], And[N[Not[LessEqual[x, 33000000000.0]], $MachinePrecision], LessEqual[x, 2.6e+40]]], N[(0.5 * N[(y * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.4 \cdot 10^{+83}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;x \leq 1.95 \cdot 10^{-56} \lor \neg \left(x \leq 33000000000\right) \land x \leq 2.6 \cdot 10^{+40}:\\
\;\;\;\;0.5 \cdot \left(y \cdot \sqrt{z}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if x < -8.4000000000000001e83 or 1.95e-56 < x < 3.3e10 or 2.6000000000000001e40 < x Initial program 100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 80.5%
if -8.4000000000000001e83 < x < 1.95e-56 or 3.3e10 < x < 2.6000000000000001e40Initial program 99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in x around 0 76.5%
Final simplification78.3%
(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 (* 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%
Taylor expanded in x around inf 49.9%
Final simplification49.9%
herbie shell --seed 2023214
(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)))))