
(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 7 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 (let* ((t_0 (* y (sqrt z)))) (if (or (<= t_0 -1e-85) (not (<= t_0 7e+75))) (* 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-85) || !(t_0 <= 7e+75)) {
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-85)) .or. (.not. (t_0 <= 7d+75))) 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-85) || !(t_0 <= 7e+75)) {
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-85) or not (t_0 <= 7e+75): 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-85) || !(t_0 <= 7e+75)) 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-85) || ~((t_0 <= 7e+75))) 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-85], N[Not[LessEqual[t$95$0, 7e+75]], $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^{-85} \lor \neg \left(t_0 \leq 7 \cdot 10^{+75}\right):\\
\;\;\;\;0.5 \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if (*.f64 y (sqrt.f64 z)) < -9.9999999999999998e-86 or 6.9999999999999997e75 < (*.f64 y (sqrt.f64 z)) Initial program 99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in x around 0 81.8%
if -9.9999999999999998e-86 < (*.f64 y (sqrt.f64 z)) < 6.9999999999999997e75Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 75.7%
Final simplification78.8%
(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 (<= z 5.2e+101) (* 0.5 x) (* 0.5 (+ x (* (* y y) (/ z x))))))
double code(double x, double y, double z) {
double tmp;
if (z <= 5.2e+101) {
tmp = 0.5 * x;
} else {
tmp = 0.5 * (x + ((y * y) * (z / 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 (z <= 5.2d+101) then
tmp = 0.5d0 * x
else
tmp = 0.5d0 * (x + ((y * y) * (z / x)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 5.2e+101) {
tmp = 0.5 * x;
} else {
tmp = 0.5 * (x + ((y * y) * (z / x)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 5.2e+101: tmp = 0.5 * x else: tmp = 0.5 * (x + ((y * y) * (z / x))) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 5.2e+101) tmp = Float64(0.5 * x); else tmp = Float64(0.5 * Float64(x + Float64(Float64(y * y) * Float64(z / x)))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 5.2e+101) tmp = 0.5 * x; else tmp = 0.5 * (x + ((y * y) * (z / x))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 5.2e+101], N[(0.5 * x), $MachinePrecision], N[(0.5 * N[(x + N[(N[(y * y), $MachinePrecision] * N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 5.2 \cdot 10^{+101}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + \left(y \cdot y\right) \cdot \frac{z}{x}\right)\\
\end{array}
\end{array}
if z < 5.2e101Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf 52.2%
if 5.2e101 < z Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
flip-+45.6%
div-inv45.5%
*-commutative45.5%
*-commutative45.5%
swap-sqr41.4%
add-sqr-sqrt41.5%
Applied egg-rr41.5%
Taylor expanded in x around inf 25.9%
add-sqr-sqrt25.9%
sqrt-unprod26.0%
sqr-neg26.0%
sqrt-unprod14.3%
add-sqr-sqrt30.0%
distribute-rgt-neg-out30.0%
Applied egg-rr30.0%
Taylor expanded in x around 0 43.8%
+-commutative43.8%
unpow243.8%
associate-*r/44.1%
Simplified44.1%
Final simplification49.2%
(FPCore (x y z) :precision binary64 (if (<= z 1.08e+17) (* 0.5 x) (* 0.5 (- x (* z (/ (* y y) x))))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.08e+17) {
tmp = 0.5 * x;
} else {
tmp = 0.5 * (x - (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 (z <= 1.08d+17) then
tmp = 0.5d0 * x
else
tmp = 0.5d0 * (x - (z * ((y * y) / x)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1.08e+17) {
tmp = 0.5 * x;
} else {
tmp = 0.5 * (x - (z * ((y * y) / x)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.08e+17: tmp = 0.5 * x else: tmp = 0.5 * (x - (z * ((y * y) / x))) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.08e+17) tmp = Float64(0.5 * x); else tmp = Float64(0.5 * Float64(x - Float64(z * Float64(Float64(y * y) / x)))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.08e+17) tmp = 0.5 * x; else tmp = 0.5 * (x - (z * ((y * y) / x))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.08e+17], N[(0.5 * x), $MachinePrecision], N[(0.5 * N[(x - N[(z * N[(N[(y * y), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.08 \cdot 10^{+17}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x - z \cdot \frac{y \cdot y}{x}\right)\\
\end{array}
\end{array}
if z < 1.08e17Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf 57.0%
if 1.08e17 < z Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
flip-+44.6%
div-inv44.4%
*-commutative44.4%
*-commutative44.4%
swap-sqr41.3%
add-sqr-sqrt41.4%
Applied egg-rr41.4%
Taylor expanded in x around inf 24.4%
Taylor expanded in x around 0 42.1%
+-commutative42.1%
mul-1-neg42.1%
unsub-neg42.1%
unpow242.1%
associate-/l*42.3%
associate-/r/43.5%
Simplified43.5%
Final simplification50.5%
(FPCore (x y z) :precision binary64 (if (<= y -3.2e+218) (* 0.5 (* y (* y (/ z (- x))))) (* 0.5 x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.2e+218) {
tmp = 0.5 * (y * (y * (z / -x)));
} 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 <= (-3.2d+218)) then
tmp = 0.5d0 * (y * (y * (z / -x)))
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 <= -3.2e+218) {
tmp = 0.5 * (y * (y * (z / -x)));
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.2e+218: tmp = 0.5 * (y * (y * (z / -x))) else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.2e+218) tmp = Float64(0.5 * Float64(y * Float64(y * Float64(z / Float64(-x))))); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.2e+218) tmp = 0.5 * (y * (y * (z / -x))); else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.2e+218], N[(0.5 * N[(y * N[(y * N[(z / (-x)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{+218}:\\
\;\;\;\;0.5 \cdot \left(y \cdot \left(y \cdot \frac{z}{-x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if y < -3.19999999999999987e218Initial program 99.7%
metadata-eval99.7%
Simplified99.7%
flip-+10.8%
div-inv10.8%
*-commutative10.8%
*-commutative10.8%
swap-sqr2.5%
add-sqr-sqrt2.5%
Applied egg-rr2.5%
Taylor expanded in x around inf 9.5%
Taylor expanded in x around 0 27.1%
mul-1-neg27.1%
unpow227.1%
associate-/l*26.8%
distribute-neg-frac26.8%
distribute-rgt-neg-in26.8%
Simplified26.8%
Taylor expanded in y around 0 27.1%
associate-*r/27.1%
unpow227.1%
*-commutative27.1%
associate-*l/27.1%
metadata-eval27.1%
associate-/r*27.1%
neg-mul-127.1%
associate-*l*26.8%
associate-/r/26.8%
*-commutative26.8%
associate-*l*27.2%
associate-/r/27.1%
associate-*l/27.1%
*-lft-identity27.1%
Simplified27.1%
if -3.19999999999999987e218 < y Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf 50.7%
Final simplification48.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.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf 46.9%
Final simplification46.9%
herbie shell --seed 2023279
(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)))))