
(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 (* 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%
*-lowering-*.f64N/A
metadata-evalN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6499.8%
Simplified99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (* 0.5 y) (pow z -0.5))))
(if (<= y -9.6e+62)
t_0
(if (<= y 3.1e-12)
(* 0.5 x)
(if (<= y 5.4e+73)
t_0
(if (<= y 1.25e+134) (* 0.5 x) (* y (* 0.5 (sqrt z)))))))))
double code(double x, double y, double z) {
double t_0 = (0.5 * y) / pow(z, -0.5);
double tmp;
if (y <= -9.6e+62) {
tmp = t_0;
} else if (y <= 3.1e-12) {
tmp = 0.5 * x;
} else if (y <= 5.4e+73) {
tmp = t_0;
} else if (y <= 1.25e+134) {
tmp = 0.5 * x;
} else {
tmp = y * (0.5 * sqrt(z));
}
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 = (0.5d0 * y) / (z ** (-0.5d0))
if (y <= (-9.6d+62)) then
tmp = t_0
else if (y <= 3.1d-12) then
tmp = 0.5d0 * x
else if (y <= 5.4d+73) then
tmp = t_0
else if (y <= 1.25d+134) then
tmp = 0.5d0 * x
else
tmp = y * (0.5d0 * sqrt(z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (0.5 * y) / Math.pow(z, -0.5);
double tmp;
if (y <= -9.6e+62) {
tmp = t_0;
} else if (y <= 3.1e-12) {
tmp = 0.5 * x;
} else if (y <= 5.4e+73) {
tmp = t_0;
} else if (y <= 1.25e+134) {
tmp = 0.5 * x;
} else {
tmp = y * (0.5 * Math.sqrt(z));
}
return tmp;
}
def code(x, y, z): t_0 = (0.5 * y) / math.pow(z, -0.5) tmp = 0 if y <= -9.6e+62: tmp = t_0 elif y <= 3.1e-12: tmp = 0.5 * x elif y <= 5.4e+73: tmp = t_0 elif y <= 1.25e+134: tmp = 0.5 * x else: tmp = y * (0.5 * math.sqrt(z)) return tmp
function code(x, y, z) t_0 = Float64(Float64(0.5 * y) / (z ^ -0.5)) tmp = 0.0 if (y <= -9.6e+62) tmp = t_0; elseif (y <= 3.1e-12) tmp = Float64(0.5 * x); elseif (y <= 5.4e+73) tmp = t_0; elseif (y <= 1.25e+134) tmp = Float64(0.5 * x); else tmp = Float64(y * Float64(0.5 * sqrt(z))); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (0.5 * y) / (z ^ -0.5); tmp = 0.0; if (y <= -9.6e+62) tmp = t_0; elseif (y <= 3.1e-12) tmp = 0.5 * x; elseif (y <= 5.4e+73) tmp = t_0; elseif (y <= 1.25e+134) tmp = 0.5 * x; else tmp = y * (0.5 * sqrt(z)); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(0.5 * y), $MachinePrecision] / N[Power[z, -0.5], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -9.6e+62], t$95$0, If[LessEqual[y, 3.1e-12], N[(0.5 * x), $MachinePrecision], If[LessEqual[y, 5.4e+73], t$95$0, If[LessEqual[y, 1.25e+134], N[(0.5 * x), $MachinePrecision], N[(y * N[(0.5 * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{0.5 \cdot y}{{z}^{-0.5}}\\
\mathbf{if}\;y \leq -9.6 \cdot 10^{+62}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{-12}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;y \leq 5.4 \cdot 10^{+73}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{+134}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(0.5 \cdot \sqrt{z}\right)\\
\end{array}
\end{array}
if y < -9.6e62 or 3.1000000000000001e-12 < y < 5.3999999999999998e73Initial program 99.6%
*-lowering-*.f64N/A
metadata-evalN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6499.6%
Simplified99.6%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6482.1%
Simplified82.1%
*-commutativeN/A
metadata-evalN/A
associate-/r/N/A
metadata-evalN/A
sqrt-divN/A
associate-*l/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
sqrt-divN/A
metadata-evalN/A
pow1/2N/A
pow-flipN/A
pow-lowering-pow.f64N/A
metadata-eval82.3%
Applied egg-rr82.3%
if -9.6e62 < y < 3.1000000000000001e-12 or 5.3999999999999998e73 < y < 1.24999999999999995e134Initial program 99.9%
*-lowering-*.f64N/A
metadata-evalN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6499.9%
Simplified99.9%
Taylor expanded in x around inf
*-lowering-*.f6482.2%
Simplified82.2%
if 1.24999999999999995e134 < y Initial program 99.9%
*-lowering-*.f64N/A
metadata-evalN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6499.9%
Simplified99.9%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6465.2%
Simplified65.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (* 0.5 (sqrt z)))))
(if (<= y -3.1e+62)
t_0
(if (<= y 3.1e-10)
(* 0.5 x)
(if (<= y 1.4e+73) t_0 (if (<= y 2.1e+134) (* 0.5 x) t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (0.5 * sqrt(z));
double tmp;
if (y <= -3.1e+62) {
tmp = t_0;
} else if (y <= 3.1e-10) {
tmp = 0.5 * x;
} else if (y <= 1.4e+73) {
tmp = t_0;
} else if (y <= 2.1e+134) {
tmp = 0.5 * x;
} else {
tmp = 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 * (0.5d0 * sqrt(z))
if (y <= (-3.1d+62)) then
tmp = t_0
else if (y <= 3.1d-10) then
tmp = 0.5d0 * x
else if (y <= 1.4d+73) then
tmp = t_0
else if (y <= 2.1d+134) then
tmp = 0.5d0 * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (0.5 * Math.sqrt(z));
double tmp;
if (y <= -3.1e+62) {
tmp = t_0;
} else if (y <= 3.1e-10) {
tmp = 0.5 * x;
} else if (y <= 1.4e+73) {
tmp = t_0;
} else if (y <= 2.1e+134) {
tmp = 0.5 * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (0.5 * math.sqrt(z)) tmp = 0 if y <= -3.1e+62: tmp = t_0 elif y <= 3.1e-10: tmp = 0.5 * x elif y <= 1.4e+73: tmp = t_0 elif y <= 2.1e+134: tmp = 0.5 * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(0.5 * sqrt(z))) tmp = 0.0 if (y <= -3.1e+62) tmp = t_0; elseif (y <= 3.1e-10) tmp = Float64(0.5 * x); elseif (y <= 1.4e+73) tmp = t_0; elseif (y <= 2.1e+134) tmp = Float64(0.5 * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (0.5 * sqrt(z)); tmp = 0.0; if (y <= -3.1e+62) tmp = t_0; elseif (y <= 3.1e-10) tmp = 0.5 * x; elseif (y <= 1.4e+73) tmp = t_0; elseif (y <= 2.1e+134) tmp = 0.5 * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(0.5 * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.1e+62], t$95$0, If[LessEqual[y, 3.1e-10], N[(0.5 * x), $MachinePrecision], If[LessEqual[y, 1.4e+73], t$95$0, If[LessEqual[y, 2.1e+134], N[(0.5 * x), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(0.5 \cdot \sqrt{z}\right)\\
\mathbf{if}\;y \leq -3.1 \cdot 10^{+62}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{-10}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{+73}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{+134}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.10000000000000014e62 or 3.10000000000000015e-10 < y < 1.40000000000000004e73 or 2.1000000000000001e134 < y Initial program 99.7%
*-lowering-*.f64N/A
metadata-evalN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6499.7%
Simplified99.7%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6476.1%
Simplified76.1%
if -3.10000000000000014e62 < y < 3.10000000000000015e-10 or 1.40000000000000004e73 < y < 2.1000000000000001e134Initial program 99.9%
*-lowering-*.f64N/A
metadata-evalN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6499.9%
Simplified99.9%
Taylor expanded in x around inf
*-lowering-*.f6482.2%
Simplified82.2%
(FPCore (x y z) :precision binary64 (if (<= z 3.3e+114) (* 0.5 x) (* z (+ (/ (* 0.5 x) z) (* -0.5 (/ (* y y) x))))))
double code(double x, double y, double z) {
double tmp;
if (z <= 3.3e+114) {
tmp = 0.5 * x;
} else {
tmp = z * (((0.5 * x) / z) + (-0.5 * ((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 <= 3.3d+114) then
tmp = 0.5d0 * x
else
tmp = z * (((0.5d0 * x) / z) + ((-0.5d0) * ((y * y) / x)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 3.3e+114) {
tmp = 0.5 * x;
} else {
tmp = z * (((0.5 * x) / z) + (-0.5 * ((y * y) / x)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 3.3e+114: tmp = 0.5 * x else: tmp = z * (((0.5 * x) / z) + (-0.5 * ((y * y) / x))) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 3.3e+114) tmp = Float64(0.5 * x); else tmp = Float64(z * Float64(Float64(Float64(0.5 * x) / z) + Float64(-0.5 * Float64(Float64(y * y) / x)))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 3.3e+114) tmp = 0.5 * x; else tmp = z * (((0.5 * x) / z) + (-0.5 * ((y * y) / x))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 3.3e+114], N[(0.5 * x), $MachinePrecision], N[(z * N[(N[(N[(0.5 * x), $MachinePrecision] / z), $MachinePrecision] + N[(-0.5 * N[(N[(y * y), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 3.3 \cdot 10^{+114}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(\frac{0.5 \cdot x}{z} + -0.5 \cdot \frac{y \cdot y}{x}\right)\\
\end{array}
\end{array}
if z < 3.3000000000000001e114Initial program 99.9%
*-lowering-*.f64N/A
metadata-evalN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6499.9%
Simplified99.9%
Taylor expanded in x around inf
*-lowering-*.f6461.6%
Simplified61.6%
if 3.3000000000000001e114 < z Initial program 99.7%
*-lowering-*.f64N/A
metadata-evalN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6499.7%
Simplified99.7%
*-commutativeN/A
flip-+N/A
associate-*l/N/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
rem-square-sqrtN/A
sqrt-lowering-sqrt.f64N/A
rem-square-sqrtN/A
*-commutativeN/A
*-lowering-*.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
Applied egg-rr42.3%
Taylor expanded in x around inf
Simplified26.5%
Taylor expanded in z around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6452.9%
Simplified52.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.8%
*-lowering-*.f64N/A
metadata-evalN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6499.8%
Simplified99.8%
Taylor expanded in x around inf
*-lowering-*.f6457.0%
Simplified57.0%
herbie shell --seed 2024149
(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)))))