
(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 6 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.9%
metadata-eval99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (sqrt z))))
(if (or (<= t_0 -2e+144)
(and (not (<= t_0 -1e+93))
(or (<= t_0 -4e-23) (not (<= t_0 1e+34)))))
(* 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 <= -2e+144) || (!(t_0 <= -1e+93) && ((t_0 <= -4e-23) || !(t_0 <= 1e+34)))) {
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 <= (-2d+144)) .or. (.not. (t_0 <= (-1d+93))) .and. (t_0 <= (-4d-23)) .or. (.not. (t_0 <= 1d+34))) 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 <= -2e+144) || (!(t_0 <= -1e+93) && ((t_0 <= -4e-23) || !(t_0 <= 1e+34)))) {
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 <= -2e+144) or (not (t_0 <= -1e+93) and ((t_0 <= -4e-23) or not (t_0 <= 1e+34))): 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 <= -2e+144) || (!(t_0 <= -1e+93) && ((t_0 <= -4e-23) || !(t_0 <= 1e+34)))) 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 <= -2e+144) || (~((t_0 <= -1e+93)) && ((t_0 <= -4e-23) || ~((t_0 <= 1e+34))))) 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, -2e+144], And[N[Not[LessEqual[t$95$0, -1e+93]], $MachinePrecision], Or[LessEqual[t$95$0, -4e-23], N[Not[LessEqual[t$95$0, 1e+34]], $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 -2 \cdot 10^{+144} \lor \neg \left(t_0 \leq -1 \cdot 10^{+93}\right) \land \left(t_0 \leq -4 \cdot 10^{-23} \lor \neg \left(t_0 \leq 10^{+34}\right)\right):\\
\;\;\;\;0.5 \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if (*.f64 y (sqrt.f64 z)) < -2.00000000000000005e144 or -1.00000000000000004e93 < (*.f64 y (sqrt.f64 z)) < -3.99999999999999984e-23 or 9.99999999999999946e33 < (*.f64 y (sqrt.f64 z)) Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around 0 82.3%
if -2.00000000000000005e144 < (*.f64 y (sqrt.f64 z)) < -1.00000000000000004e93 or -3.99999999999999984e-23 < (*.f64 y (sqrt.f64 z)) < 9.99999999999999946e33Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 79.7%
Final simplification80.8%
(FPCore (x y z) :precision binary64 (if (<= y 3e+164) (* 0.5 x) (* -0.5 (* z (/ y (/ x y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= 3e+164) {
tmp = 0.5 * x;
} else {
tmp = -0.5 * (z * (y / (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) :: tmp
if (y <= 3d+164) then
tmp = 0.5d0 * x
else
tmp = (-0.5d0) * (z * (y / (x / y)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 3e+164) {
tmp = 0.5 * x;
} else {
tmp = -0.5 * (z * (y / (x / y)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 3e+164: tmp = 0.5 * x else: tmp = -0.5 * (z * (y / (x / y))) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 3e+164) tmp = Float64(0.5 * x); else tmp = Float64(-0.5 * Float64(z * Float64(y / Float64(x / y)))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 3e+164) tmp = 0.5 * x; else tmp = -0.5 * (z * (y / (x / y))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 3e+164], N[(0.5 * x), $MachinePrecision], N[(-0.5 * N[(z * N[(y / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{+164}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(z \cdot \frac{y}{\frac{x}{y}}\right)\\
\end{array}
\end{array}
if y < 3.00000000000000001e164Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 59.2%
if 3.00000000000000001e164 < y Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
flip-+20.9%
div-sub20.9%
*-commutative20.9%
*-commutative20.9%
swap-sqr3.5%
add-sqr-sqrt3.5%
Applied egg-rr3.5%
+-rgt-identity3.5%
div-sub3.5%
+-rgt-identity3.5%
*-commutative3.5%
associate-*l*20.9%
Simplified20.9%
Taylor expanded in x around 0 4.2%
mul-1-neg4.2%
unpow24.2%
associate-*r*21.2%
*-commutative21.2%
distribute-rgt-neg-out21.2%
associate-*l*21.2%
Simplified21.2%
Taylor expanded in y around 0 21.4%
*-commutative21.4%
unpow221.4%
*-commutative21.4%
associate-*r*21.4%
*-commutative21.4%
Simplified21.4%
Taylor expanded in y around 0 21.4%
unpow221.4%
*-commutative21.4%
associate-*r*21.4%
associate-/l*21.4%
*-commutative21.4%
associate-*l/21.4%
*-commutative21.4%
Simplified21.4%
Final simplification55.1%
(FPCore (x y z) :precision binary64 (if (<= y 3e+164) (* 0.5 x) (* -0.5 (* (* y z) (/ y x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 3e+164) {
tmp = 0.5 * x;
} else {
tmp = -0.5 * ((y * z) * (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 (y <= 3d+164) then
tmp = 0.5d0 * x
else
tmp = (-0.5d0) * ((y * z) * (y / x))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 3e+164) {
tmp = 0.5 * x;
} else {
tmp = -0.5 * ((y * z) * (y / x));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 3e+164: tmp = 0.5 * x else: tmp = -0.5 * ((y * z) * (y / x)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 3e+164) tmp = Float64(0.5 * x); else tmp = Float64(-0.5 * Float64(Float64(y * z) * Float64(y / x))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 3e+164) tmp = 0.5 * x; else tmp = -0.5 * ((y * z) * (y / x)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 3e+164], N[(0.5 * x), $MachinePrecision], N[(-0.5 * N[(N[(y * z), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{+164}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\left(y \cdot z\right) \cdot \frac{y}{x}\right)\\
\end{array}
\end{array}
if y < 3.00000000000000001e164Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 59.2%
if 3.00000000000000001e164 < y Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
flip-+20.9%
div-sub20.9%
*-commutative20.9%
*-commutative20.9%
swap-sqr3.5%
add-sqr-sqrt3.5%
Applied egg-rr3.5%
+-rgt-identity3.5%
div-sub3.5%
+-rgt-identity3.5%
*-commutative3.5%
associate-*l*20.9%
Simplified20.9%
Taylor expanded in x around 0 4.2%
mul-1-neg4.2%
unpow24.2%
associate-*r*21.2%
*-commutative21.2%
distribute-rgt-neg-out21.2%
associate-*l*21.2%
Simplified21.2%
Taylor expanded in y around 0 21.4%
*-commutative21.4%
unpow221.4%
*-commutative21.4%
associate-*r*21.4%
*-commutative21.4%
Simplified21.4%
Taylor expanded in y around 0 21.4%
unpow221.4%
*-commutative21.4%
associate-*r*21.4%
associate-*r/21.4%
*-commutative21.4%
Simplified21.4%
Final simplification55.1%
(FPCore (x y z) :precision binary64 (if (<= y 3e+164) (* 0.5 x) (* (* y (/ (* y z) x)) -0.5)))
double code(double x, double y, double z) {
double tmp;
if (y <= 3e+164) {
tmp = 0.5 * x;
} else {
tmp = (y * ((y * z) / x)) * -0.5;
}
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+164) then
tmp = 0.5d0 * x
else
tmp = (y * ((y * z) / x)) * (-0.5d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 3e+164) {
tmp = 0.5 * x;
} else {
tmp = (y * ((y * z) / x)) * -0.5;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 3e+164: tmp = 0.5 * x else: tmp = (y * ((y * z) / x)) * -0.5 return tmp
function code(x, y, z) tmp = 0.0 if (y <= 3e+164) tmp = Float64(0.5 * x); else tmp = Float64(Float64(y * Float64(Float64(y * z) / x)) * -0.5); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 3e+164) tmp = 0.5 * x; else tmp = (y * ((y * z) / x)) * -0.5; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 3e+164], N[(0.5 * x), $MachinePrecision], N[(N[(y * N[(N[(y * z), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{+164}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot \frac{y \cdot z}{x}\right) \cdot -0.5\\
\end{array}
\end{array}
if y < 3.00000000000000001e164Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 59.2%
if 3.00000000000000001e164 < y Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
flip-+20.9%
div-sub20.9%
*-commutative20.9%
*-commutative20.9%
swap-sqr3.5%
add-sqr-sqrt3.5%
Applied egg-rr3.5%
+-rgt-identity3.5%
div-sub3.5%
+-rgt-identity3.5%
*-commutative3.5%
associate-*l*20.9%
Simplified20.9%
Taylor expanded in x around 0 4.2%
mul-1-neg4.2%
unpow24.2%
associate-*r*21.2%
*-commutative21.2%
distribute-rgt-neg-out21.2%
associate-*l*21.2%
Simplified21.2%
Taylor expanded in y around 0 21.4%
*-commutative21.4%
unpow221.4%
*-commutative21.4%
associate-*r*21.4%
*-commutative21.4%
Simplified21.4%
associate-/l*21.4%
associate-/r/21.4%
*-commutative21.4%
Applied egg-rr21.4%
Final simplification55.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.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 53.3%
Final simplification53.3%
herbie shell --seed 2023271
(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)))))