
(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 4 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 (let* ((t_0 (* y (sqrt z)))) (if (or (<= t_0 -1e+72) (not (<= t_0 1e-147))) (* 0.5 t_0) (* 0.5 x))))
double code(double x, double y, double z) {
double t_0 = y * sqrt(z);
double tmp;
if ((t_0 <= -1e+72) || !(t_0 <= 1e-147)) {
tmp = 0.5 * t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = y * sqrt(z)
if ((t_0 <= (-1d+72)) .or. (.not. (t_0 <= 1d-147))) then
tmp = 0.5d0 * t_0
else
tmp = 0.5d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * Math.sqrt(z);
double tmp;
if ((t_0 <= -1e+72) || !(t_0 <= 1e-147)) {
tmp = 0.5 * t_0;
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): t_0 = y * math.sqrt(z) tmp = 0 if (t_0 <= -1e+72) or not (t_0 <= 1e-147): tmp = 0.5 * t_0 else: tmp = 0.5 * x return tmp
function code(x, y, z) t_0 = Float64(y * sqrt(z)) tmp = 0.0 if ((t_0 <= -1e+72) || !(t_0 <= 1e-147)) tmp = Float64(0.5 * t_0); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * sqrt(z); tmp = 0.0; if ((t_0 <= -1e+72) || ~((t_0 <= 1e-147))) tmp = 0.5 * t_0; else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -1e+72], N[Not[LessEqual[t$95$0, 1e-147]], $MachinePrecision]], N[(0.5 * t$95$0), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \sqrt{z}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{+72} \lor \neg \left(t_0 \leq 10^{-147}\right):\\
\;\;\;\;0.5 \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if (*.f64 y (sqrt.f64 z)) < -9.99999999999999944e71 or 9.9999999999999997e-148 < (*.f64 y (sqrt.f64 z)) Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around 0 77.3%
if -9.99999999999999944e71 < (*.f64 y (sqrt.f64 z)) < 9.9999999999999997e-148Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 80.9%
Final simplification79.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.25e+220) (not (<= y 5.2e+199))) (* (* z (/ y x)) (* 0.5 y)) (* 0.5 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.25e+220) || !(y <= 5.2e+199)) {
tmp = (z * (y / x)) * (0.5 * y);
} 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 ((y <= (-1.25d+220)) .or. (.not. (y <= 5.2d+199))) then
tmp = (z * (y / x)) * (0.5d0 * y)
else
tmp = 0.5d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.25e+220) || !(y <= 5.2e+199)) {
tmp = (z * (y / x)) * (0.5 * y);
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.25e+220) or not (y <= 5.2e+199): tmp = (z * (y / x)) * (0.5 * y) else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.25e+220) || !(y <= 5.2e+199)) tmp = Float64(Float64(z * Float64(y / x)) * Float64(0.5 * y)); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.25e+220) || ~((y <= 5.2e+199))) tmp = (z * (y / x)) * (0.5 * y); else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.25e+220], N[Not[LessEqual[y, 5.2e+199]], $MachinePrecision]], N[(N[(z * N[(y / x), $MachinePrecision]), $MachinePrecision] * N[(0.5 * y), $MachinePrecision]), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.25 \cdot 10^{+220} \lor \neg \left(y \leq 5.2 \cdot 10^{+199}\right):\\
\;\;\;\;\left(z \cdot \frac{y}{x}\right) \cdot \left(0.5 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if y < -1.2500000000000001e220 or 5.2000000000000003e199 < y Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
flip-+10.6%
div-sub10.6%
*-commutative10.6%
*-commutative10.6%
swap-sqr3.1%
add-sqr-sqrt3.1%
Applied egg-rr3.1%
+-rgt-identity3.1%
div-sub3.1%
+-rgt-identity3.1%
*-commutative3.1%
associate-*l*10.6%
Simplified10.6%
Taylor expanded in x around 0 3.6%
mul-1-neg3.6%
unpow23.6%
distribute-rgt-neg-out3.6%
associate-*l*11.1%
Simplified11.1%
Taylor expanded in y around 0 14.5%
*-commutative14.5%
unpow214.5%
associate-/l*14.5%
Simplified14.5%
add-sqr-sqrt8.6%
sqrt-unprod25.7%
*-commutative25.7%
*-commutative25.7%
swap-sqr25.7%
metadata-eval25.7%
metadata-eval25.7%
pow225.7%
add-sqr-sqrt25.7%
sqrt-unprod25.3%
sqr-neg25.3%
sqrt-unprod0.0%
add-sqr-sqrt25.7%
associate-/l*25.9%
*-commutative25.9%
pow225.9%
Applied egg-rr33.9%
associate-/r/33.9%
associate-*l/33.9%
metadata-eval33.9%
distribute-lft-neg-in33.9%
*-commutative33.9%
associate-*r*33.9%
associate-*r*33.9%
distribute-rgt-neg-in33.9%
metadata-eval33.9%
associate-*l/33.9%
associate-*l/34.0%
associate-/l*34.1%
associate-*r/34.0%
associate-*l*34.0%
associate-*r/34.1%
associate-*l/34.1%
*-commutative34.1%
Simplified34.1%
if -1.2500000000000001e220 < y < 5.2000000000000003e199Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf 61.1%
Final simplification57.1%
(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 52.8%
Final simplification52.8%
herbie shell --seed 2023293
(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)))))