
(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 (+ (* y (* (sqrt z) 0.5)) (* 0.5 x)))
double code(double x, double y, double z) {
return (y * (sqrt(z) * 0.5)) + (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 = (y * (sqrt(z) * 0.5d0)) + (0.5d0 * x)
end function
public static double code(double x, double y, double z) {
return (y * (Math.sqrt(z) * 0.5)) + (0.5 * x);
}
def code(x, y, z): return (y * (math.sqrt(z) * 0.5)) + (0.5 * x)
function code(x, y, z) return Float64(Float64(y * Float64(sqrt(z) * 0.5)) + Float64(0.5 * x)) end
function tmp = code(x, y, z) tmp = (y * (sqrt(z) * 0.5)) + (0.5 * x); end
code[x_, y_, z_] := N[(N[(y * N[(N[Sqrt[z], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(\sqrt{z} \cdot 0.5\right) + 0.5 \cdot x
\end{array}
Initial program 99.5%
metadata-eval99.5%
Simplified99.5%
+-commutative99.5%
distribute-lft-in99.5%
*-commutative99.5%
associate-*l*99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (sqrt z)))) (if (or (<= t_0 -0.05) (not (<= t_0 1e+49))) (* 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 <= -0.05) || !(t_0 <= 1e+49)) {
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 <= (-0.05d0)) .or. (.not. (t_0 <= 1d+49))) 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 <= -0.05) || !(t_0 <= 1e+49)) {
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 <= -0.05) or not (t_0 <= 1e+49): 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 <= -0.05) || !(t_0 <= 1e+49)) 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 <= -0.05) || ~((t_0 <= 1e+49))) 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, -0.05], N[Not[LessEqual[t$95$0, 1e+49]], $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 -0.05 \lor \neg \left(t_0 \leq 10^{+49}\right):\\
\;\;\;\;0.5 \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if (*.f64 y (sqrt.f64 z)) < -0.050000000000000003 or 9.99999999999999946e48 < (*.f64 y (sqrt.f64 z)) Initial program 99.0%
metadata-eval99.0%
Simplified99.0%
Taylor expanded in x around 0 85.5%
if -0.050000000000000003 < (*.f64 y (sqrt.f64 z)) < 9.99999999999999946e48Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 83.1%
Final simplification84.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (sqrt z))))
(if (<= t_0 -0.05)
(* (sqrt z) (* y 0.5))
(if (<= t_0 1e+49) (* 0.5 x) (* 0.5 t_0)))))
double code(double x, double y, double z) {
double t_0 = y * sqrt(z);
double tmp;
if (t_0 <= -0.05) {
tmp = sqrt(z) * (y * 0.5);
} else if (t_0 <= 1e+49) {
tmp = 0.5 * x;
} else {
tmp = 0.5 * t_0;
}
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 <= (-0.05d0)) then
tmp = sqrt(z) * (y * 0.5d0)
else if (t_0 <= 1d+49) then
tmp = 0.5d0 * x
else
tmp = 0.5d0 * t_0
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 <= -0.05) {
tmp = Math.sqrt(z) * (y * 0.5);
} else if (t_0 <= 1e+49) {
tmp = 0.5 * x;
} else {
tmp = 0.5 * t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * math.sqrt(z) tmp = 0 if t_0 <= -0.05: tmp = math.sqrt(z) * (y * 0.5) elif t_0 <= 1e+49: tmp = 0.5 * x else: tmp = 0.5 * t_0 return tmp
function code(x, y, z) t_0 = Float64(y * sqrt(z)) tmp = 0.0 if (t_0 <= -0.05) tmp = Float64(sqrt(z) * Float64(y * 0.5)); elseif (t_0 <= 1e+49) tmp = Float64(0.5 * x); else tmp = Float64(0.5 * t_0); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * sqrt(z); tmp = 0.0; if (t_0 <= -0.05) tmp = sqrt(z) * (y * 0.5); elseif (t_0 <= 1e+49) tmp = 0.5 * x; else tmp = 0.5 * t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.05], N[(N[Sqrt[z], $MachinePrecision] * N[(y * 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+49], N[(0.5 * x), $MachinePrecision], N[(0.5 * t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \sqrt{z}\\
\mathbf{if}\;t_0 \leq -0.05:\\
\;\;\;\;\sqrt{z} \cdot \left(y \cdot 0.5\right)\\
\mathbf{elif}\;t_0 \leq 10^{+49}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot t_0\\
\end{array}
\end{array}
if (*.f64 y (sqrt.f64 z)) < -0.050000000000000003Initial program 98.3%
metadata-eval98.3%
Simplified98.3%
*-commutative98.3%
flip-+37.7%
associate-*l/37.7%
*-commutative37.7%
*-commutative37.7%
swap-sqr27.3%
add-sqr-sqrt27.2%
Applied egg-rr27.2%
Taylor expanded in x around 0 25.3%
unpow225.3%
associate-*r*25.3%
neg-mul-125.3%
distribute-rgt-neg-out25.3%
associate-*r*35.4%
Simplified35.4%
Taylor expanded in y around inf 82.9%
associate-*r*84.3%
*-commutative84.3%
Simplified84.3%
if -0.050000000000000003 < (*.f64 y (sqrt.f64 z)) < 9.99999999999999946e48Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 83.1%
if 9.99999999999999946e48 < (*.f64 y (sqrt.f64 z)) Initial program 99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in x around 0 87.9%
Final simplification84.5%
(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.5%
metadata-eval99.5%
Simplified99.5%
Final simplification99.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.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in x around inf 52.5%
Final simplification52.5%
herbie shell --seed 2023215
(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)))))