
(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 (+ (* (sqrt z) (* y 0.5)) (* 0.5 x)))
double code(double x, double y, double z) {
return (sqrt(z) * (y * 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 = (sqrt(z) * (y * 0.5d0)) + (0.5d0 * x)
end function
public static double code(double x, double y, double z) {
return (Math.sqrt(z) * (y * 0.5)) + (0.5 * x);
}
def code(x, y, z): return (math.sqrt(z) * (y * 0.5)) + (0.5 * x)
function code(x, y, z) return Float64(Float64(sqrt(z) * Float64(y * 0.5)) + Float64(0.5 * x)) end
function tmp = code(x, y, z) tmp = (sqrt(z) * (y * 0.5)) + (0.5 * x); end
code[x_, y_, z_] := N[(N[(N[Sqrt[z], $MachinePrecision] * N[(y * 0.5), $MachinePrecision]), $MachinePrecision] + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{z} \cdot \left(y \cdot 0.5\right) + 0.5 \cdot x
\end{array}
Initial program 99.5%
metadata-eval99.5%
Simplified99.5%
distribute-rgt-in99.5%
+-commutative99.5%
*-commutative99.5%
associate-*l*99.9%
*-commutative99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (<= x -1.8e+59)
(* 0.5 x)
(if (or (<= x -1.25e+33) (and (not (<= x -2e-16)) (<= x 5e-31)))
(* 0.5 (* (sqrt z) y))
(* 0.5 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.8e+59) {
tmp = 0.5 * x;
} else if ((x <= -1.25e+33) || (!(x <= -2e-16) && (x <= 5e-31))) {
tmp = 0.5 * (sqrt(z) * 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 (x <= (-1.8d+59)) then
tmp = 0.5d0 * x
else if ((x <= (-1.25d+33)) .or. (.not. (x <= (-2d-16))) .and. (x <= 5d-31)) then
tmp = 0.5d0 * (sqrt(z) * 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 (x <= -1.8e+59) {
tmp = 0.5 * x;
} else if ((x <= -1.25e+33) || (!(x <= -2e-16) && (x <= 5e-31))) {
tmp = 0.5 * (Math.sqrt(z) * y);
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.8e+59: tmp = 0.5 * x elif (x <= -1.25e+33) or (not (x <= -2e-16) and (x <= 5e-31)): tmp = 0.5 * (math.sqrt(z) * y) else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.8e+59) tmp = Float64(0.5 * x); elseif ((x <= -1.25e+33) || (!(x <= -2e-16) && (x <= 5e-31))) tmp = Float64(0.5 * Float64(sqrt(z) * y)); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.8e+59) tmp = 0.5 * x; elseif ((x <= -1.25e+33) || (~((x <= -2e-16)) && (x <= 5e-31))) tmp = 0.5 * (sqrt(z) * y); else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.8e+59], N[(0.5 * x), $MachinePrecision], If[Or[LessEqual[x, -1.25e+33], And[N[Not[LessEqual[x, -2e-16]], $MachinePrecision], LessEqual[x, 5e-31]]], N[(0.5 * N[(N[Sqrt[z], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{+59}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;x \leq -1.25 \cdot 10^{+33} \lor \neg \left(x \leq -2 \cdot 10^{-16}\right) \land x \leq 5 \cdot 10^{-31}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{z} \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if x < -1.7999999999999999e59 or -1.24999999999999993e33 < x < -2e-16 or 5e-31 < x Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 82.3%
if -1.7999999999999999e59 < x < -1.24999999999999993e33 or -2e-16 < x < 5e-31Initial program 99.1%
metadata-eval99.1%
Simplified99.1%
Taylor expanded in x around 0 82.0%
Final simplification82.1%
(FPCore (x y z)
:precision binary64
(if (<= x -1.3e+59)
(* 0.5 x)
(if (<= x -9e+34)
(* 0.5 (* (sqrt z) y))
(if (<= x -4.1e-16)
(* 0.5 x)
(if (<= x 5.5e-35) (* (sqrt z) (* y 0.5)) (* 0.5 x))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.3e+59) {
tmp = 0.5 * x;
} else if (x <= -9e+34) {
tmp = 0.5 * (sqrt(z) * y);
} else if (x <= -4.1e-16) {
tmp = 0.5 * x;
} else if (x <= 5.5e-35) {
tmp = sqrt(z) * (y * 0.5);
} 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 <= (-1.3d+59)) then
tmp = 0.5d0 * x
else if (x <= (-9d+34)) then
tmp = 0.5d0 * (sqrt(z) * y)
else if (x <= (-4.1d-16)) then
tmp = 0.5d0 * x
else if (x <= 5.5d-35) then
tmp = sqrt(z) * (y * 0.5d0)
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 <= -1.3e+59) {
tmp = 0.5 * x;
} else if (x <= -9e+34) {
tmp = 0.5 * (Math.sqrt(z) * y);
} else if (x <= -4.1e-16) {
tmp = 0.5 * x;
} else if (x <= 5.5e-35) {
tmp = Math.sqrt(z) * (y * 0.5);
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.3e+59: tmp = 0.5 * x elif x <= -9e+34: tmp = 0.5 * (math.sqrt(z) * y) elif x <= -4.1e-16: tmp = 0.5 * x elif x <= 5.5e-35: tmp = math.sqrt(z) * (y * 0.5) else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.3e+59) tmp = Float64(0.5 * x); elseif (x <= -9e+34) tmp = Float64(0.5 * Float64(sqrt(z) * y)); elseif (x <= -4.1e-16) tmp = Float64(0.5 * x); elseif (x <= 5.5e-35) tmp = Float64(sqrt(z) * Float64(y * 0.5)); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.3e+59) tmp = 0.5 * x; elseif (x <= -9e+34) tmp = 0.5 * (sqrt(z) * y); elseif (x <= -4.1e-16) tmp = 0.5 * x; elseif (x <= 5.5e-35) tmp = sqrt(z) * (y * 0.5); else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.3e+59], N[(0.5 * x), $MachinePrecision], If[LessEqual[x, -9e+34], N[(0.5 * N[(N[Sqrt[z], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -4.1e-16], N[(0.5 * x), $MachinePrecision], If[LessEqual[x, 5.5e-35], N[(N[Sqrt[z], $MachinePrecision] * N[(y * 0.5), $MachinePrecision]), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{+59}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;x \leq -9 \cdot 10^{+34}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{z} \cdot y\right)\\
\mathbf{elif}\;x \leq -4.1 \cdot 10^{-16}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;x \leq 5.5 \cdot 10^{-35}:\\
\;\;\;\;\sqrt{z} \cdot \left(y \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if x < -1.3e59 or -9.0000000000000001e34 < x < -4.10000000000000006e-16 or 5.4999999999999997e-35 < x Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 82.3%
if -1.3e59 < x < -9.0000000000000001e34Initial program 99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in x around 0 83.3%
if -4.10000000000000006e-16 < x < 5.4999999999999997e-35Initial program 99.1%
metadata-eval99.1%
Simplified99.1%
flip-+62.0%
associate-*r/62.0%
*-commutative62.0%
*-commutative62.0%
swap-sqr52.4%
add-sqr-sqrt52.5%
Applied egg-rr52.5%
*-commutative52.5%
associate-/l*52.6%
Simplified52.6%
Taylor expanded in x around 0 40.4%
mul-1-neg40.4%
unpow240.4%
distribute-rgt-neg-in40.4%
Simplified40.4%
Taylor expanded in y around inf 81.9%
associate-*r*82.6%
Simplified82.6%
Final simplification82.5%
(FPCore (x y z) :precision binary64 (* 0.5 (+ x (* (sqrt z) y))))
double code(double x, double y, double z) {
return 0.5 * (x + (sqrt(z) * 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 + (sqrt(z) * y))
end function
public static double code(double x, double y, double z) {
return 0.5 * (x + (Math.sqrt(z) * y));
}
def code(x, y, z): return 0.5 * (x + (math.sqrt(z) * y))
function code(x, y, z) return Float64(0.5 * Float64(x + Float64(sqrt(z) * y))) end
function tmp = code(x, y, z) tmp = 0.5 * (x + (sqrt(z) * y)); end
code[x_, y_, z_] := N[(0.5 * N[(x + N[(N[Sqrt[z], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(x + \sqrt{z} \cdot y\right)
\end{array}
Initial program 99.5%
metadata-eval99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (<= y -7.5e+203) (* -0.5 (* z (* y (/ y x)))) (* 0.5 x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.5e+203) {
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 <= (-7.5d+203)) 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 <= -7.5e+203) {
tmp = -0.5 * (z * (y * (y / x)));
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7.5e+203: tmp = -0.5 * (z * (y * (y / x))) else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7.5e+203) tmp = Float64(-0.5 * Float64(z * Float64(y * 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 <= -7.5e+203) tmp = -0.5 * (z * (y * (y / x))); else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7.5e+203], N[(-0.5 * N[(z * N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{+203}:\\
\;\;\;\;-0.5 \cdot \left(z \cdot \left(y \cdot \frac{y}{x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if y < -7.49999999999999957e203Initial program 97.0%
metadata-eval97.0%
Simplified97.0%
flip-+9.3%
associate-*r/9.3%
*-commutative9.3%
*-commutative9.3%
swap-sqr2.3%
add-sqr-sqrt2.3%
Applied egg-rr2.3%
*-commutative2.3%
associate-/l*2.3%
Simplified2.3%
Taylor expanded in x around 0 3.0%
mul-1-neg3.0%
unpow23.0%
distribute-rgt-neg-in3.0%
Simplified3.0%
Taylor expanded in y around 0 34.2%
unpow234.2%
associate-*r*34.2%
associate-/l*34.5%
associate-/r*34.5%
Simplified34.5%
associate-/r/34.4%
div-inv34.4%
clear-num34.4%
Applied egg-rr34.4%
if -7.49999999999999957e203 < y Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 58.5%
Final simplification55.9%
(FPCore (x y z) :precision binary64 (if (<= y -7e+203) (* -0.5 (/ y (/ (/ x y) z))) (* 0.5 x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -7e+203) {
tmp = -0.5 * (y / ((x / y) / 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 (y <= (-7d+203)) then
tmp = (-0.5d0) * (y / ((x / y) / 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 (y <= -7e+203) {
tmp = -0.5 * (y / ((x / y) / z));
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7e+203: tmp = -0.5 * (y / ((x / y) / z)) else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7e+203) tmp = Float64(-0.5 * Float64(y / Float64(Float64(x / y) / z))); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -7e+203) tmp = -0.5 * (y / ((x / y) / z)); else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7e+203], N[(-0.5 * N[(y / N[(N[(x / y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{+203}:\\
\;\;\;\;-0.5 \cdot \frac{y}{\frac{\frac{x}{y}}{z}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if y < -7.00000000000000062e203Initial program 97.0%
metadata-eval97.0%
Simplified97.0%
flip-+9.3%
associate-*r/9.3%
*-commutative9.3%
*-commutative9.3%
swap-sqr2.3%
add-sqr-sqrt2.3%
Applied egg-rr2.3%
*-commutative2.3%
associate-/l*2.3%
Simplified2.3%
Taylor expanded in x around 0 3.0%
mul-1-neg3.0%
unpow23.0%
distribute-rgt-neg-in3.0%
Simplified3.0%
Taylor expanded in y around 0 34.2%
unpow234.2%
associate-*r*34.2%
associate-/l*34.5%
associate-/r*34.5%
Simplified34.5%
if -7.00000000000000062e203 < y Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 58.5%
Final simplification55.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.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in x around inf 53.1%
Final simplification53.1%
herbie shell --seed 2023274
(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)))))