
(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 (+ 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 -2.5e-11) (* 0.5 x) (if (<= x 2.1e+62) (* 0.5 (* y (sqrt z))) (* 0.5 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.5e-11) {
tmp = 0.5 * x;
} else if (x <= 2.1e+62) {
tmp = 0.5 * (y * sqrt(z));
} 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 (x <= (-2.5d-11)) then
tmp = 0.5d0 * x
else if (x <= 2.1d+62) then
tmp = 0.5d0 * (y * sqrt(z))
else
tmp = 0.5d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.5e-11) {
tmp = 0.5 * x;
} else if (x <= 2.1e+62) {
tmp = 0.5 * (y * Math.sqrt(z));
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.5e-11: tmp = 0.5 * x elif x <= 2.1e+62: tmp = 0.5 * (y * math.sqrt(z)) else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.5e-11) tmp = Float64(0.5 * x); elseif (x <= 2.1e+62) tmp = Float64(0.5 * Float64(y * sqrt(z))); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.5e-11) tmp = 0.5 * x; elseif (x <= 2.1e+62) tmp = 0.5 * (y * sqrt(z)); else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.5e-11], N[(0.5 * x), $MachinePrecision], If[LessEqual[x, 2.1e+62], N[(0.5 * N[(y * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-11}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{+62}:\\
\;\;\;\;0.5 \cdot \left(y \cdot \sqrt{z}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if x < -2.50000000000000009e-11 or 2.1e62 < x Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 83.0%
if -2.50000000000000009e-11 < x < 2.1e62Initial program 99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in x around 0 82.2%
Final simplification82.6%
(FPCore (x y z) :precision binary64 (if (<= y -6.5e+192) (* 0.5 (* y (* y (/ z x)))) (* 0.5 x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.5e+192) {
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 <= (-6.5d+192)) 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 <= -6.5e+192) {
tmp = 0.5 * (y * (y * (z / x)));
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.5e+192: tmp = 0.5 * (y * (y * (z / x))) else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.5e+192) tmp = Float64(0.5 * Float64(y * Float64(y * Float64(z / x)))); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.5e+192) tmp = 0.5 * (y * (y * (z / x))); else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.5e+192], 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 -6.5 \cdot 10^{+192}:\\
\;\;\;\;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 < -6.50000000000000033e192Initial program 99.7%
metadata-eval99.7%
Simplified99.7%
flip-+16.4%
div-sub16.4%
*-commutative16.4%
*-commutative16.4%
swap-sqr3.2%
add-sqr-sqrt3.2%
Applied egg-rr3.2%
+-rgt-identity3.2%
div-sub3.2%
+-rgt-identity3.2%
*-commutative3.2%
associate-*l*16.4%
Simplified16.4%
Taylor expanded in x around 0 4.1%
mul-1-neg4.1%
unpow24.1%
associate-*r*16.8%
*-commutative16.8%
distribute-rgt-neg-out16.8%
associate-*l*16.8%
Simplified16.8%
Taylor expanded in y around 0 15.1%
associate-*r/15.1%
mul-1-neg15.1%
unpow215.1%
*-commutative15.1%
distribute-rgt-neg-in15.1%
associate-/l*15.1%
Simplified15.1%
associate-/r/15.1%
distribute-rgt-neg-in15.1%
associate-*r*15.3%
add-sqr-sqrt15.3%
sqrt-unprod15.1%
sqr-neg15.1%
sqrt-prod0.0%
add-sqr-sqrt22.6%
Applied egg-rr22.6%
if -6.50000000000000033e192 < y Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf 52.5%
Final simplification49.0%
(FPCore (x y z) :precision binary64 (if (<= y -1.85e+193) (* 0.5 (* z (/ y (/ x y)))) (* 0.5 x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.85e+193) {
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 <= (-1.85d+193)) 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 <= -1.85e+193) {
tmp = 0.5 * (z * (y / (x / y)));
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.85e+193: tmp = 0.5 * (z * (y / (x / y))) else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.85e+193) tmp = Float64(0.5 * Float64(z * 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 <= -1.85e+193) tmp = 0.5 * (z * (y / (x / y))); else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.85e+193], 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 -1.85 \cdot 10^{+193}:\\
\;\;\;\;0.5 \cdot \left(z \cdot \frac{y}{\frac{x}{y}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if y < -1.8500000000000001e193Initial program 99.7%
metadata-eval99.7%
Simplified99.7%
flip-+16.4%
div-sub16.4%
*-commutative16.4%
*-commutative16.4%
swap-sqr3.2%
add-sqr-sqrt3.2%
Applied egg-rr3.2%
+-rgt-identity3.2%
div-sub3.2%
+-rgt-identity3.2%
*-commutative3.2%
associate-*l*16.4%
Simplified16.4%
Taylor expanded in x around 0 4.1%
mul-1-neg4.1%
unpow24.1%
associate-*r*16.8%
*-commutative16.8%
distribute-rgt-neg-out16.8%
associate-*l*16.8%
Simplified16.8%
Taylor expanded in y around 0 15.1%
associate-*r/15.1%
mul-1-neg15.1%
unpow215.1%
*-commutative15.1%
distribute-rgt-neg-in15.1%
associate-/l*15.1%
Simplified15.1%
clear-num15.1%
associate-/r/15.1%
clear-num15.1%
distribute-lft-neg-in15.1%
associate-/l*15.3%
add-sqr-sqrt15.3%
sqrt-unprod15.1%
sqr-neg15.1%
sqrt-prod0.0%
add-sqr-sqrt22.8%
Applied egg-rr22.8%
if -1.8500000000000001e193 < y Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf 52.5%
Final simplification49.1%
(FPCore (x y z) :precision binary64 (if (<= y -1.85e+193) (* 0.5 (* y (/ (* y z) x))) (* 0.5 x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.85e+193) {
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 <= (-1.85d+193)) 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 <= -1.85e+193) {
tmp = 0.5 * (y * ((y * z) / x));
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.85e+193: tmp = 0.5 * (y * ((y * z) / x)) else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.85e+193) tmp = Float64(0.5 * 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 <= -1.85e+193) tmp = 0.5 * (y * ((y * z) / x)); else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.85e+193], 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 -1.85 \cdot 10^{+193}:\\
\;\;\;\;0.5 \cdot \left(y \cdot \frac{y \cdot z}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if y < -1.8500000000000001e193Initial program 99.7%
metadata-eval99.7%
Simplified99.7%
flip-+16.4%
div-sub16.4%
*-commutative16.4%
*-commutative16.4%
swap-sqr3.2%
add-sqr-sqrt3.2%
Applied egg-rr3.2%
+-rgt-identity3.2%
div-sub3.2%
+-rgt-identity3.2%
*-commutative3.2%
associate-*l*16.4%
Simplified16.4%
Taylor expanded in x around 0 4.1%
mul-1-neg4.1%
unpow24.1%
associate-*r*16.8%
*-commutative16.8%
distribute-rgt-neg-out16.8%
associate-*l*16.8%
Simplified16.8%
add-sqr-sqrt16.7%
times-frac50.8%
add-sqr-sqrt50.6%
sqrt-unprod4.1%
sqr-neg4.1%
sqrt-unprod0.0%
add-sqr-sqrt0.4%
*-commutative0.4%
times-frac0.3%
add-sqr-sqrt0.5%
associate-*l/0.6%
*-commutative0.6%
associate-*r*1.1%
Applied egg-rr59.7%
Taylor expanded in y around 0 22.9%
if -1.8500000000000001e193 < y Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf 52.5%
Final simplification49.1%
(FPCore (x y z) :precision binary64 (if (<= y -1.3e+193) (* 0.5 (/ z (/ x (* y y)))) (* 0.5 x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.3e+193) {
tmp = 0.5 * (z / (x / (y * 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 <= (-1.3d+193)) then
tmp = 0.5d0 * (z / (x / (y * 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 <= -1.3e+193) {
tmp = 0.5 * (z / (x / (y * y)));
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.3e+193: tmp = 0.5 * (z / (x / (y * y))) else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.3e+193) tmp = Float64(0.5 * Float64(z / Float64(x / Float64(y * y)))); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.3e+193) tmp = 0.5 * (z / (x / (y * y))); else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.3e+193], N[(0.5 * N[(z / N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.3 \cdot 10^{+193}:\\
\;\;\;\;0.5 \cdot \frac{z}{\frac{x}{y \cdot y}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if y < -1.30000000000000007e193Initial program 99.7%
metadata-eval99.7%
Simplified99.7%
flip-+16.4%
div-sub16.4%
*-commutative16.4%
*-commutative16.4%
swap-sqr3.2%
add-sqr-sqrt3.2%
Applied egg-rr3.2%
+-rgt-identity3.2%
div-sub3.2%
+-rgt-identity3.2%
*-commutative3.2%
associate-*l*16.4%
Simplified16.4%
Taylor expanded in x around 0 4.1%
mul-1-neg4.1%
unpow24.1%
associate-*r*16.8%
*-commutative16.8%
distribute-rgt-neg-out16.8%
associate-*l*16.8%
Simplified16.8%
Taylor expanded in y around 0 15.1%
associate-*r/15.1%
mul-1-neg15.1%
unpow215.1%
*-commutative15.1%
distribute-rgt-neg-in15.1%
associate-/l*15.1%
Simplified15.1%
expm1-log1p-u15.1%
expm1-udef0.5%
distribute-rgt-neg-in0.5%
distribute-rgt-neg-in0.5%
add-sqr-sqrt0.0%
sqrt-unprod0.5%
sqr-neg0.5%
sqrt-unprod0.5%
add-sqr-sqrt0.5%
Applied egg-rr0.5%
expm1-def23.1%
expm1-log1p23.1%
Simplified23.1%
if -1.30000000000000007e193 < y Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf 52.5%
Final simplification49.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.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf 47.5%
Final simplification47.5%
herbie shell --seed 2023297
(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)))))