
(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.8%
metadata-eval99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (<= x -1.9e-11) (* 0.5 x) (if (<= x 4.9e-18) (* 0.5 (* y (sqrt z))) (* 0.5 (fabs x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.9e-11) {
tmp = 0.5 * x;
} else if (x <= 4.9e-18) {
tmp = 0.5 * (y * sqrt(z));
} else {
tmp = 0.5 * fabs(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 (x <= (-1.9d-11)) then
tmp = 0.5d0 * x
else if (x <= 4.9d-18) then
tmp = 0.5d0 * (y * sqrt(z))
else
tmp = 0.5d0 * abs(x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.9e-11) {
tmp = 0.5 * x;
} else if (x <= 4.9e-18) {
tmp = 0.5 * (y * Math.sqrt(z));
} else {
tmp = 0.5 * Math.abs(x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.9e-11: tmp = 0.5 * x elif x <= 4.9e-18: tmp = 0.5 * (y * math.sqrt(z)) else: tmp = 0.5 * math.fabs(x) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.9e-11) tmp = Float64(0.5 * x); elseif (x <= 4.9e-18) tmp = Float64(0.5 * Float64(y * sqrt(z))); else tmp = Float64(0.5 * abs(x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.9e-11) tmp = 0.5 * x; elseif (x <= 4.9e-18) tmp = 0.5 * (y * sqrt(z)); else tmp = 0.5 * abs(x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.9e-11], N[(0.5 * x), $MachinePrecision], If[LessEqual[x, 4.9e-18], N[(0.5 * N[(y * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Abs[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{-11}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;x \leq 4.9 \cdot 10^{-18}:\\
\;\;\;\;0.5 \cdot \left(y \cdot \sqrt{z}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left|x\right|\\
\end{array}
\end{array}
if x < -1.8999999999999999e-11Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 76.0%
if -1.8999999999999999e-11 < x < 4.9000000000000001e-18Initial program 99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in x around 0 78.8%
if 4.9000000000000001e-18 < x Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
flip-+48.0%
div-inv47.9%
*-commutative47.9%
*-commutative47.9%
swap-sqr45.9%
add-sqr-sqrt45.9%
Applied egg-rr45.9%
Taylor expanded in x around inf 44.5%
Taylor expanded in x around inf 42.6%
unpow242.6%
Simplified42.6%
pow242.6%
inv-pow42.6%
pow-prod-up73.6%
metadata-eval73.6%
pow173.6%
add-sqr-sqrt73.0%
sqrt-prod42.7%
rem-sqrt-square73.6%
Applied egg-rr73.6%
Final simplification76.8%
(FPCore (x y z) :precision binary64 (if (<= z 2.9e-55) (* 0.5 x) (* 0.5 (- x (* z (/ (* y y) x))))))
double code(double x, double y, double z) {
double tmp;
if (z <= 2.9e-55) {
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 <= 2.9d-55) 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 <= 2.9e-55) {
tmp = 0.5 * x;
} else {
tmp = 0.5 * (x - (z * ((y * y) / x)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 2.9e-55: 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 <= 2.9e-55) 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 <= 2.9e-55) 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, 2.9e-55], 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 2.9 \cdot 10^{-55}:\\
\;\;\;\;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 < 2.9e-55Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf 57.3%
if 2.9e-55 < z Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
flip-+45.3%
div-inv45.2%
*-commutative45.2%
*-commutative45.2%
swap-sqr41.1%
add-sqr-sqrt41.1%
Applied egg-rr41.1%
Taylor expanded in x around inf 28.5%
Taylor expanded in x around 0 41.5%
+-commutative41.5%
mul-1-neg41.5%
unsub-neg41.5%
unpow241.5%
associate-/l*46.6%
associate-/r/47.0%
Simplified47.0%
Final simplification51.4%
(FPCore (x y z) :precision binary64 (if (<= y -2.4e+218) (* 0.5 (* (- y) (/ (* y z) x))) (* 0.5 x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.4e+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 <= (-2.4d+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 <= -2.4e+218) {
tmp = 0.5 * (-y * ((y * z) / x));
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.4e+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 <= -2.4e+218) tmp = Float64(0.5 * Float64(Float64(-y) * Float64(Float64(y * z) / x))); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.4e+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, -2.4e+218], N[(0.5 * N[((-y) * N[(N[(y * z), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{+218}:\\
\;\;\;\;0.5 \cdot \left(\left(-y\right) \cdot \frac{y \cdot z}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if y < -2.39999999999999981e218Initial program 99.6%
metadata-eval99.6%
Simplified99.6%
flip-+16.9%
div-inv16.9%
*-commutative16.9%
*-commutative16.9%
swap-sqr3.1%
add-sqr-sqrt3.1%
Applied egg-rr3.1%
Taylor expanded in x around inf 25.7%
Taylor expanded in x around 0 26.2%
associate-*r/26.2%
mul-1-neg26.2%
unpow226.2%
*-commutative26.2%
distribute-lft-neg-in26.2%
Simplified26.2%
Taylor expanded in z around 0 26.2%
mul-1-neg26.2%
unpow226.2%
associate-*r*26.2%
*-rgt-identity26.2%
associate-*r/26.2%
associate-*l*26.2%
distribute-lft-neg-in26.2%
associate-*r/26.2%
*-rgt-identity26.2%
Simplified26.2%
if -2.39999999999999981e218 < y Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf 51.6%
Final simplification49.5%
(FPCore (x y z) :precision binary64 (if (<= y -1.95e+218) (* -0.5 (/ (* z (* y y)) x)) (* 0.5 x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.95e+218) {
tmp = -0.5 * ((z * (y * 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 <= (-1.95d+218)) then
tmp = (-0.5d0) * ((z * (y * 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 <= -1.95e+218) {
tmp = -0.5 * ((z * (y * y)) / x);
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.95e+218: tmp = -0.5 * ((z * (y * y)) / x) else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.95e+218) tmp = Float64(-0.5 * Float64(Float64(z * Float64(y * y)) / x)); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.95e+218) tmp = -0.5 * ((z * (y * y)) / x); else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.95e+218], N[(-0.5 * N[(N[(z * N[(y * y), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{+218}:\\
\;\;\;\;-0.5 \cdot \frac{z \cdot \left(y \cdot y\right)}{x}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if y < -1.9500000000000001e218Initial program 99.6%
metadata-eval99.6%
Simplified99.6%
flip-+16.9%
div-inv16.9%
*-commutative16.9%
*-commutative16.9%
swap-sqr3.1%
add-sqr-sqrt3.1%
Applied egg-rr3.1%
Taylor expanded in x around inf 25.7%
Taylor expanded in x around 0 26.2%
associate-*r/26.2%
mul-1-neg26.2%
unpow226.2%
*-commutative26.2%
distribute-lft-neg-in26.2%
Simplified26.2%
Taylor expanded in z around 0 26.2%
unpow226.2%
*-commutative26.2%
Simplified26.2%
if -1.9500000000000001e218 < y Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf 51.6%
Final simplification49.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 47.9%
Final simplification47.9%
herbie shell --seed 2023224
(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)))))