
(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 (+ (* (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.8%
*-commutative99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sqrt z) y)))
(if (or (<= t_0 -3.8e+34)
(not
(or (<= t_0 1.1e-49)
(and (not (<= t_0 11200.0)) (<= t_0 6.2e+70)))))
(* 0.5 t_0)
(* 0.5 x))))
double code(double x, double y, double z) {
double t_0 = sqrt(z) * y;
double tmp;
if ((t_0 <= -3.8e+34) || !((t_0 <= 1.1e-49) || (!(t_0 <= 11200.0) && (t_0 <= 6.2e+70)))) {
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 = sqrt(z) * y
if ((t_0 <= (-3.8d+34)) .or. (.not. (t_0 <= 1.1d-49) .or. (.not. (t_0 <= 11200.0d0)) .and. (t_0 <= 6.2d+70))) 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 = Math.sqrt(z) * y;
double tmp;
if ((t_0 <= -3.8e+34) || !((t_0 <= 1.1e-49) || (!(t_0 <= 11200.0) && (t_0 <= 6.2e+70)))) {
tmp = 0.5 * t_0;
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): t_0 = math.sqrt(z) * y tmp = 0 if (t_0 <= -3.8e+34) or not ((t_0 <= 1.1e-49) or (not (t_0 <= 11200.0) and (t_0 <= 6.2e+70))): tmp = 0.5 * t_0 else: tmp = 0.5 * x return tmp
function code(x, y, z) t_0 = Float64(sqrt(z) * y) tmp = 0.0 if ((t_0 <= -3.8e+34) || !((t_0 <= 1.1e-49) || (!(t_0 <= 11200.0) && (t_0 <= 6.2e+70)))) 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 = sqrt(z) * y; tmp = 0.0; if ((t_0 <= -3.8e+34) || ~(((t_0 <= 1.1e-49) || (~((t_0 <= 11200.0)) && (t_0 <= 6.2e+70))))) tmp = 0.5 * t_0; else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sqrt[z], $MachinePrecision] * y), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -3.8e+34], N[Not[Or[LessEqual[t$95$0, 1.1e-49], And[N[Not[LessEqual[t$95$0, 11200.0]], $MachinePrecision], LessEqual[t$95$0, 6.2e+70]]]], $MachinePrecision]], N[(0.5 * t$95$0), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{z} \cdot y\\
\mathbf{if}\;t_0 \leq -3.8 \cdot 10^{+34} \lor \neg \left(t_0 \leq 1.1 \cdot 10^{-49} \lor \neg \left(t_0 \leq 11200\right) \land t_0 \leq 6.2 \cdot 10^{+70}\right):\\
\;\;\;\;0.5 \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if (*.f64 y (sqrt.f64 z)) < -3.8000000000000001e34 or 1.09999999999999995e-49 < (*.f64 y (sqrt.f64 z)) < 11200 or 6.2000000000000006e70 < (*.f64 y (sqrt.f64 z)) Initial program 99.0%
metadata-eval99.0%
Simplified99.0%
Taylor expanded in x around 0 85.9%
if -3.8000000000000001e34 < (*.f64 y (sqrt.f64 z)) < 1.09999999999999995e-49 or 11200 < (*.f64 y (sqrt.f64 z)) < 6.2000000000000006e70Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 81.7%
Final simplification83.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sqrt z) y)))
(if (<= t_0 -2e+41)
(* (sqrt z) (* y 0.5))
(if (or (<= t_0 4e-57) (and (not (<= t_0 5000.0)) (<= t_0 5e+70)))
(* 0.5 x)
(* 0.5 t_0)))))
double code(double x, double y, double z) {
double t_0 = sqrt(z) * y;
double tmp;
if (t_0 <= -2e+41) {
tmp = sqrt(z) * (y * 0.5);
} else if ((t_0 <= 4e-57) || (!(t_0 <= 5000.0) && (t_0 <= 5e+70))) {
tmp = 0.5 * x;
} else {
tmp = 0.5 * 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 = sqrt(z) * y
if (t_0 <= (-2d+41)) then
tmp = sqrt(z) * (y * 0.5d0)
else if ((t_0 <= 4d-57) .or. (.not. (t_0 <= 5000.0d0)) .and. (t_0 <= 5d+70)) then
tmp = 0.5d0 * x
else
tmp = 0.5d0 * t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.sqrt(z) * y;
double tmp;
if (t_0 <= -2e+41) {
tmp = Math.sqrt(z) * (y * 0.5);
} else if ((t_0 <= 4e-57) || (!(t_0 <= 5000.0) && (t_0 <= 5e+70))) {
tmp = 0.5 * x;
} else {
tmp = 0.5 * t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.sqrt(z) * y tmp = 0 if t_0 <= -2e+41: tmp = math.sqrt(z) * (y * 0.5) elif (t_0 <= 4e-57) or (not (t_0 <= 5000.0) and (t_0 <= 5e+70)): tmp = 0.5 * x else: tmp = 0.5 * t_0 return tmp
function code(x, y, z) t_0 = Float64(sqrt(z) * y) tmp = 0.0 if (t_0 <= -2e+41) tmp = Float64(sqrt(z) * Float64(y * 0.5)); elseif ((t_0 <= 4e-57) || (!(t_0 <= 5000.0) && (t_0 <= 5e+70))) tmp = Float64(0.5 * x); else tmp = Float64(0.5 * t_0); end return tmp end
function tmp_2 = code(x, y, z) t_0 = sqrt(z) * y; tmp = 0.0; if (t_0 <= -2e+41) tmp = sqrt(z) * (y * 0.5); elseif ((t_0 <= 4e-57) || (~((t_0 <= 5000.0)) && (t_0 <= 5e+70))) tmp = 0.5 * x; else tmp = 0.5 * t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sqrt[z], $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+41], N[(N[Sqrt[z], $MachinePrecision] * N[(y * 0.5), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[t$95$0, 4e-57], And[N[Not[LessEqual[t$95$0, 5000.0]], $MachinePrecision], LessEqual[t$95$0, 5e+70]]], N[(0.5 * x), $MachinePrecision], N[(0.5 * t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{z} \cdot y\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{+41}:\\
\;\;\;\;\sqrt{z} \cdot \left(y \cdot 0.5\right)\\
\mathbf{elif}\;t_0 \leq 4 \cdot 10^{-57} \lor \neg \left(t_0 \leq 5000\right) \land t_0 \leq 5 \cdot 10^{+70}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot t_0\\
\end{array}
\end{array}
if (*.f64 y (sqrt.f64 z)) < -2.00000000000000001e41Initial program 97.8%
metadata-eval97.8%
Simplified97.8%
Taylor expanded in x around 0 85.5%
add-sqr-sqrt0.0%
sqrt-unprod1.0%
*-commutative1.0%
*-commutative1.0%
swap-sqr0.9%
add-sqr-sqrt0.9%
Applied egg-rr0.9%
*-commutative0.9%
associate-*l*1.0%
Simplified1.0%
Taylor expanded in y around 0 85.5%
associate-*r*87.3%
*-commutative87.3%
*-commutative87.3%
Simplified87.3%
if -2.00000000000000001e41 < (*.f64 y (sqrt.f64 z)) < 3.99999999999999982e-57 or 5e3 < (*.f64 y (sqrt.f64 z)) < 5.0000000000000002e70Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 81.7%
if 3.99999999999999982e-57 < (*.f64 y (sqrt.f64 z)) < 5e3 or 5.0000000000000002e70 < (*.f64 y (sqrt.f64 z)) Initial program 99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in x around 0 86.2%
Final simplification83.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sqrt z) y)))
(if (<= t_0 -2e+41)
(* (sqrt z) (* y 0.5))
(if (<= t_0 4e-57)
(* 0.5 x)
(if (<= t_0 5000.0)
(* 0.5 (sqrt (* y (* z y))))
(if (<= t_0 5e+70) (* 0.5 x) (* 0.5 t_0)))))))
double code(double x, double y, double z) {
double t_0 = sqrt(z) * y;
double tmp;
if (t_0 <= -2e+41) {
tmp = sqrt(z) * (y * 0.5);
} else if (t_0 <= 4e-57) {
tmp = 0.5 * x;
} else if (t_0 <= 5000.0) {
tmp = 0.5 * sqrt((y * (z * y)));
} else if (t_0 <= 5e+70) {
tmp = 0.5 * x;
} else {
tmp = 0.5 * 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 = sqrt(z) * y
if (t_0 <= (-2d+41)) then
tmp = sqrt(z) * (y * 0.5d0)
else if (t_0 <= 4d-57) then
tmp = 0.5d0 * x
else if (t_0 <= 5000.0d0) then
tmp = 0.5d0 * sqrt((y * (z * y)))
else if (t_0 <= 5d+70) then
tmp = 0.5d0 * x
else
tmp = 0.5d0 * t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.sqrt(z) * y;
double tmp;
if (t_0 <= -2e+41) {
tmp = Math.sqrt(z) * (y * 0.5);
} else if (t_0 <= 4e-57) {
tmp = 0.5 * x;
} else if (t_0 <= 5000.0) {
tmp = 0.5 * Math.sqrt((y * (z * y)));
} else if (t_0 <= 5e+70) {
tmp = 0.5 * x;
} else {
tmp = 0.5 * t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.sqrt(z) * y tmp = 0 if t_0 <= -2e+41: tmp = math.sqrt(z) * (y * 0.5) elif t_0 <= 4e-57: tmp = 0.5 * x elif t_0 <= 5000.0: tmp = 0.5 * math.sqrt((y * (z * y))) elif t_0 <= 5e+70: tmp = 0.5 * x else: tmp = 0.5 * t_0 return tmp
function code(x, y, z) t_0 = Float64(sqrt(z) * y) tmp = 0.0 if (t_0 <= -2e+41) tmp = Float64(sqrt(z) * Float64(y * 0.5)); elseif (t_0 <= 4e-57) tmp = Float64(0.5 * x); elseif (t_0 <= 5000.0) tmp = Float64(0.5 * sqrt(Float64(y * Float64(z * y)))); elseif (t_0 <= 5e+70) tmp = Float64(0.5 * x); else tmp = Float64(0.5 * t_0); end return tmp end
function tmp_2 = code(x, y, z) t_0 = sqrt(z) * y; tmp = 0.0; if (t_0 <= -2e+41) tmp = sqrt(z) * (y * 0.5); elseif (t_0 <= 4e-57) tmp = 0.5 * x; elseif (t_0 <= 5000.0) tmp = 0.5 * sqrt((y * (z * y))); elseif (t_0 <= 5e+70) tmp = 0.5 * x; else tmp = 0.5 * t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sqrt[z], $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+41], N[(N[Sqrt[z], $MachinePrecision] * N[(y * 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 4e-57], N[(0.5 * x), $MachinePrecision], If[LessEqual[t$95$0, 5000.0], N[(0.5 * N[Sqrt[N[(y * N[(z * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e+70], N[(0.5 * x), $MachinePrecision], N[(0.5 * t$95$0), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{z} \cdot y\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{+41}:\\
\;\;\;\;\sqrt{z} \cdot \left(y \cdot 0.5\right)\\
\mathbf{elif}\;t_0 \leq 4 \cdot 10^{-57}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;t_0 \leq 5000:\\
\;\;\;\;0.5 \cdot \sqrt{y \cdot \left(z \cdot y\right)}\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+70}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot t_0\\
\end{array}
\end{array}
if (*.f64 y (sqrt.f64 z)) < -2.00000000000000001e41Initial program 97.8%
metadata-eval97.8%
Simplified97.8%
Taylor expanded in x around 0 85.5%
add-sqr-sqrt0.0%
sqrt-unprod1.0%
*-commutative1.0%
*-commutative1.0%
swap-sqr0.9%
add-sqr-sqrt0.9%
Applied egg-rr0.9%
*-commutative0.9%
associate-*l*1.0%
Simplified1.0%
Taylor expanded in y around 0 85.5%
associate-*r*87.3%
*-commutative87.3%
*-commutative87.3%
Simplified87.3%
if -2.00000000000000001e41 < (*.f64 y (sqrt.f64 z)) < 3.99999999999999982e-57 or 5e3 < (*.f64 y (sqrt.f64 z)) < 5.0000000000000002e70Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf 81.7%
if 3.99999999999999982e-57 < (*.f64 y (sqrt.f64 z)) < 5e3Initial program 99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in x around 0 97.7%
add-sqr-sqrt97.1%
sqrt-unprod97.7%
*-commutative97.7%
*-commutative97.7%
swap-sqr98.2%
add-sqr-sqrt98.2%
Applied egg-rr98.2%
*-commutative98.2%
associate-*l*98.2%
Simplified98.2%
if 5.0000000000000002e70 < (*.f64 y (sqrt.f64 z)) Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around 0 84.5%
Final simplification83.8%
(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 (* 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.2%
Final simplification53.2%
herbie shell --seed 2023213
(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)))))