
(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 8 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 (/ (* y z) (/ x y)))))))
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 - ((y * z) / (x / 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) :: 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 - ((y * z) / (x / y)))
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 - ((y * z) / (x / y)));
}
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 - ((y * z) / (x / y))) 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 * Float64(x - Float64(Float64(y * z) / Float64(x / y)))); 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 - ((y * z) / (x / y))); 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 * N[(x - N[(N[(y * z), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 \left(x - \frac{y \cdot z}{\frac{x}{y}}\right)\\
\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%
flip-+60.3%
div-inv60.1%
*-commutative60.1%
*-commutative60.1%
swap-sqr56.3%
add-sqr-sqrt56.3%
Applied egg-rr56.3%
Taylor expanded in x around inf 42.8%
Taylor expanded in z around 0 42.8%
unpow242.8%
associate-*r*43.6%
Simplified43.6%
Taylor expanded in x around 0 74.3%
mul-1-neg74.3%
unpow274.3%
*-commutative74.3%
rem-3cbrt-lft74.3%
unpow274.3%
associate-*r/74.3%
distribute-lft-neg-in74.3%
cancel-sign-sub-inv74.3%
associate-*r/74.3%
unpow274.3%
rem-3cbrt-lft74.3%
associate-*r/74.3%
associate-/l*75.0%
associate-*r/75.9%
Simplified75.9%
Final simplification78.9%
(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 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%
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 -3e+218) (* 0.5 (* z (/ (- y) (/ x y)))) (* 0.5 x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -3e+218) {
tmp = 0.5 * (z * (-y / (x / 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 <= (-3d+218)) then
tmp = 0.5d0 * (z * (-y / (x / 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 <= -3e+218) {
tmp = 0.5 * (z * (-y / (x / y)));
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3e+218: tmp = 0.5 * (z * (-y / (x / y))) else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3e+218) tmp = Float64(0.5 * Float64(z * Float64(Float64(-y) / Float64(x / y)))); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3e+218) tmp = 0.5 * (z * (-y / (x / y))); else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3e+218], N[(0.5 * N[(z * N[((-y) / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+218}:\\
\;\;\;\;0.5 \cdot \left(z \cdot \frac{-y}{\frac{x}{y}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if y < -3.0000000000000001e218Initial 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%
associate-*r/27.1%
mul-1-neg27.1%
unpow227.1%
*-commutative27.1%
distribute-lft-neg-in27.1%
Simplified27.1%
Taylor expanded in z around 0 27.1%
mul-1-neg27.1%
unpow227.1%
*-commutative27.1%
associate-*r/27.1%
distribute-rgt-neg-in27.1%
associate-/l*27.1%
Simplified27.1%
if -3.0000000000000001e218 < 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 (if (<= y -3.2e+218) (* 0.5 (/ (* y (* z (- y))) x)) (* 0.5 x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.2e+218) {
tmp = 0.5 * ((y * (z * -y)) / 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 * (z * -y)) / 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 * (z * -y)) / x);
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.2e+218: tmp = 0.5 * ((y * (z * -y)) / 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(Float64(y * Float64(z * Float64(-y))) / 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 * (z * -y)) / 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[(N[(y * N[(z * (-y)), $MachinePrecision]), $MachinePrecision] / x), $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 \frac{y \cdot \left(z \cdot \left(-y\right)\right)}{x}\\
\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%
associate-*r/27.1%
mul-1-neg27.1%
unpow227.1%
*-commutative27.1%
distribute-lft-neg-in27.1%
Simplified27.1%
Taylor expanded in z around 0 27.1%
mul-1-neg27.1%
unpow227.1%
associate-*r*27.1%
*-commutative27.1%
distribute-rgt-neg-in27.1%
*-commutative27.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 (/ (* y z) (/ x y)))))
double code(double x, double y, double z) {
return 0.5 * (x - ((y * z) / (x / y)));
}
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 * z) / (x / y)))
end function
public static double code(double x, double y, double z) {
return 0.5 * (x - ((y * z) / (x / y)));
}
def code(x, y, z): return 0.5 * (x - ((y * z) / (x / y)))
function code(x, y, z) return Float64(0.5 * Float64(x - Float64(Float64(y * z) / Float64(x / y)))) end
function tmp = code(x, y, z) tmp = 0.5 * (x - ((y * z) / (x / y))); end
code[x_, y_, z_] := N[(0.5 * N[(x - N[(N[(y * z), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(x - \frac{y \cdot z}{\frac{x}{y}}\right)
\end{array}
Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
flip-+51.1%
div-inv51.0%
*-commutative51.0%
*-commutative51.0%
swap-sqr45.2%
add-sqr-sqrt45.3%
Applied egg-rr45.3%
Taylor expanded in x around inf 26.5%
Taylor expanded in z around 0 26.5%
unpow226.5%
associate-*r*27.4%
Simplified27.4%
Taylor expanded in x around 0 47.1%
mul-1-neg47.1%
unpow247.1%
*-commutative47.1%
rem-3cbrt-lft47.1%
unpow247.1%
associate-*r/47.1%
distribute-lft-neg-in47.1%
cancel-sign-sub-inv47.1%
associate-*r/47.1%
unpow247.1%
rem-3cbrt-lft47.1%
associate-*r/47.8%
associate-/l*49.0%
associate-*r/49.9%
Simplified49.9%
Final simplification49.9%
(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)))))