
(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%
metadata-eval99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* 0.5 (* y (sqrt z))))
(t_1 (* 0.5 (- x (* z (* y (/ y (- x)))))))
(t_2 (* 0.5 (- x (* z (* y (/ y x)))))))
(if (<= x -1.4e-150)
t_1
(if (<= x 3.5e-124)
t_0
(if (<= x 7.8e-92)
t_2
(if (<= x 3500000000000.0)
t_0
(if (<= x 8.5e+28) t_1 (if (<= x 2.05e+90) t_0 t_2))))))))
double code(double x, double y, double z) {
double t_0 = 0.5 * (y * sqrt(z));
double t_1 = 0.5 * (x - (z * (y * (y / -x))));
double t_2 = 0.5 * (x - (z * (y * (y / x))));
double tmp;
if (x <= -1.4e-150) {
tmp = t_1;
} else if (x <= 3.5e-124) {
tmp = t_0;
} else if (x <= 7.8e-92) {
tmp = t_2;
} else if (x <= 3500000000000.0) {
tmp = t_0;
} else if (x <= 8.5e+28) {
tmp = t_1;
} else if (x <= 2.05e+90) {
tmp = t_0;
} else {
tmp = t_2;
}
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) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = 0.5d0 * (y * sqrt(z))
t_1 = 0.5d0 * (x - (z * (y * (y / -x))))
t_2 = 0.5d0 * (x - (z * (y * (y / x))))
if (x <= (-1.4d-150)) then
tmp = t_1
else if (x <= 3.5d-124) then
tmp = t_0
else if (x <= 7.8d-92) then
tmp = t_2
else if (x <= 3500000000000.0d0) then
tmp = t_0
else if (x <= 8.5d+28) then
tmp = t_1
else if (x <= 2.05d+90) then
tmp = t_0
else
tmp = t_2
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 0.5 * (y * Math.sqrt(z));
double t_1 = 0.5 * (x - (z * (y * (y / -x))));
double t_2 = 0.5 * (x - (z * (y * (y / x))));
double tmp;
if (x <= -1.4e-150) {
tmp = t_1;
} else if (x <= 3.5e-124) {
tmp = t_0;
} else if (x <= 7.8e-92) {
tmp = t_2;
} else if (x <= 3500000000000.0) {
tmp = t_0;
} else if (x <= 8.5e+28) {
tmp = t_1;
} else if (x <= 2.05e+90) {
tmp = t_0;
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y, z): t_0 = 0.5 * (y * math.sqrt(z)) t_1 = 0.5 * (x - (z * (y * (y / -x)))) t_2 = 0.5 * (x - (z * (y * (y / x)))) tmp = 0 if x <= -1.4e-150: tmp = t_1 elif x <= 3.5e-124: tmp = t_0 elif x <= 7.8e-92: tmp = t_2 elif x <= 3500000000000.0: tmp = t_0 elif x <= 8.5e+28: tmp = t_1 elif x <= 2.05e+90: tmp = t_0 else: tmp = t_2 return tmp
function code(x, y, z) t_0 = Float64(0.5 * Float64(y * sqrt(z))) t_1 = Float64(0.5 * Float64(x - Float64(z * Float64(y * Float64(y / Float64(-x)))))) t_2 = Float64(0.5 * Float64(x - Float64(z * Float64(y * Float64(y / x))))) tmp = 0.0 if (x <= -1.4e-150) tmp = t_1; elseif (x <= 3.5e-124) tmp = t_0; elseif (x <= 7.8e-92) tmp = t_2; elseif (x <= 3500000000000.0) tmp = t_0; elseif (x <= 8.5e+28) tmp = t_1; elseif (x <= 2.05e+90) tmp = t_0; else tmp = t_2; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 0.5 * (y * sqrt(z)); t_1 = 0.5 * (x - (z * (y * (y / -x)))); t_2 = 0.5 * (x - (z * (y * (y / x)))); tmp = 0.0; if (x <= -1.4e-150) tmp = t_1; elseif (x <= 3.5e-124) tmp = t_0; elseif (x <= 7.8e-92) tmp = t_2; elseif (x <= 3500000000000.0) tmp = t_0; elseif (x <= 8.5e+28) tmp = t_1; elseif (x <= 2.05e+90) tmp = t_0; else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(0.5 * N[(y * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[(x - N[(z * N[(y * N[(y / (-x)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(0.5 * N[(x - N[(z * N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.4e-150], t$95$1, If[LessEqual[x, 3.5e-124], t$95$0, If[LessEqual[x, 7.8e-92], t$95$2, If[LessEqual[x, 3500000000000.0], t$95$0, If[LessEqual[x, 8.5e+28], t$95$1, If[LessEqual[x, 2.05e+90], t$95$0, t$95$2]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(y \cdot \sqrt{z}\right)\\
t_1 := 0.5 \cdot \left(x - z \cdot \left(y \cdot \frac{y}{-x}\right)\right)\\
t_2 := 0.5 \cdot \left(x - z \cdot \left(y \cdot \frac{y}{x}\right)\right)\\
\mathbf{if}\;x \leq -1.4 \cdot 10^{-150}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{-124}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 7.8 \cdot 10^{-92}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \leq 3500000000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 8.5 \cdot 10^{+28}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 2.05 \cdot 10^{+90}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\end{array}
if x < -1.39999999999999998e-150 or 3.5e12 < x < 8.49999999999999954e28Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
flip-+51.1%
div-inv51.0%
*-commutative51.0%
*-commutative51.0%
swap-sqr48.6%
add-sqr-sqrt48.6%
Applied egg-rr48.6%
Taylor expanded in x around inf 42.8%
Taylor expanded in x around 0 69.0%
+-commutative69.0%
mul-1-neg69.0%
unsub-neg69.0%
unpow269.0%
associate-/l*69.6%
associate-/r/70.2%
Simplified70.2%
frac-2neg70.2%
neg-sub070.2%
metadata-eval70.2%
div-sub70.2%
metadata-eval70.2%
add-sqr-sqrt70.2%
sqrt-unprod64.5%
sqr-neg64.5%
sqrt-unprod21.7%
add-sqr-sqrt78.3%
frac-2neg78.3%
associate-/l*85.4%
Applied egg-rr85.4%
div085.4%
neg-sub085.4%
associate-/l*78.3%
distribute-neg-frac78.3%
neg-mul-178.3%
associate-*l/78.3%
metadata-eval78.3%
associate-/r*78.3%
neg-mul-178.3%
*-commutative78.3%
associate-*l*85.4%
associate-*r/85.4%
*-rgt-identity85.4%
Simplified85.4%
if -1.39999999999999998e-150 < x < 3.4999999999999999e-124 or 7.7999999999999993e-92 < x < 3.5e12 or 8.49999999999999954e28 < x < 2.05000000000000021e90Initial program 99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in x around 0 87.3%
if 3.4999999999999999e-124 < x < 7.7999999999999993e-92 or 2.05000000000000021e90 < x Initial program 100.0%
metadata-eval100.0%
Simplified100.0%
flip-+31.1%
div-inv31.1%
*-commutative31.1%
*-commutative31.1%
swap-sqr27.6%
add-sqr-sqrt27.6%
Applied egg-rr27.6%
Taylor expanded in x around inf 30.3%
Taylor expanded in x around 0 71.8%
+-commutative71.8%
mul-1-neg71.8%
unsub-neg71.8%
unpow271.8%
associate-/l*75.7%
associate-/r/76.5%
Simplified76.5%
Taylor expanded in y around 0 76.5%
unpow276.5%
associate-*r/83.3%
Simplified83.3%
Final simplification85.6%
(FPCore (x y z) :precision binary64 (if (<= x -6.2e-202) (* 0.5 (- x (* z (* y (/ y (- x)))))) (* 0.5 (- x (* z (* y (/ y x)))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.2e-202) {
tmp = 0.5 * (x - (z * (y * (y / -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 (x <= (-6.2d-202)) then
tmp = 0.5d0 * (x - (z * (y * (y / -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 (x <= -6.2e-202) {
tmp = 0.5 * (x - (z * (y * (y / -x))));
} else {
tmp = 0.5 * (x - (z * (y * (y / x))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6.2e-202: tmp = 0.5 * (x - (z * (y * (y / -x)))) else: tmp = 0.5 * (x - (z * (y * (y / x)))) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6.2e-202) tmp = Float64(0.5 * Float64(x - Float64(z * Float64(y * Float64(y / Float64(-x)))))); else tmp = Float64(0.5 * Float64(x - Float64(z * Float64(y * Float64(y / x))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -6.2e-202) tmp = 0.5 * (x - (z * (y * (y / -x)))); else tmp = 0.5 * (x - (z * (y * (y / x)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6.2e-202], N[(0.5 * N[(x - N[(z * N[(y * N[(y / (-x)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(x - N[(z * N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{-202}:\\
\;\;\;\;0.5 \cdot \left(x - z \cdot \left(y \cdot \frac{y}{-x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x - z \cdot \left(y \cdot \frac{y}{x}\right)\right)\\
\end{array}
\end{array}
if x < -6.2e-202Initial program 99.9%
metadata-eval99.9%
Simplified99.9%
flip-+50.7%
div-inv50.6%
*-commutative50.6%
*-commutative50.6%
swap-sqr47.2%
add-sqr-sqrt47.2%
Applied egg-rr47.2%
Taylor expanded in x around inf 37.1%
Taylor expanded in x around 0 64.0%
+-commutative64.0%
mul-1-neg64.0%
unsub-neg64.0%
unpow264.0%
associate-/l*64.6%
associate-/r/65.2%
Simplified65.2%
frac-2neg65.2%
neg-sub065.2%
metadata-eval65.2%
div-sub65.2%
metadata-eval65.2%
add-sqr-sqrt65.2%
sqrt-unprod59.6%
sqr-neg59.6%
sqrt-unprod21.5%
add-sqr-sqrt72.2%
frac-2neg72.2%
associate-/l*79.3%
Applied egg-rr79.3%
div079.3%
neg-sub079.3%
associate-/l*72.2%
distribute-neg-frac72.2%
neg-mul-172.2%
associate-*l/72.2%
metadata-eval72.2%
associate-/r*72.2%
neg-mul-172.2%
*-commutative72.2%
associate-*l*79.3%
associate-*r/79.3%
*-rgt-identity79.3%
Simplified79.3%
if -6.2e-202 < x Initial program 99.7%
metadata-eval99.7%
Simplified99.7%
flip-+47.9%
div-inv47.8%
*-commutative47.8%
*-commutative47.8%
swap-sqr38.7%
add-sqr-sqrt38.7%
Applied egg-rr38.7%
Taylor expanded in x around inf 22.8%
Taylor expanded in x around 0 41.0%
+-commutative41.0%
mul-1-neg41.0%
unsub-neg41.0%
unpow241.0%
associate-/l*42.3%
associate-/r/42.9%
Simplified42.9%
Taylor expanded in y around 0 42.9%
unpow242.9%
associate-*r/45.5%
Simplified45.5%
Final simplification57.5%
(FPCore (x y z) :precision binary64 (* 0.5 (- x (* z (* y (/ y x))))))
double code(double x, double y, double z) {
return 0.5 * (x - (z * (y * (y / 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 - (z * (y * (y / x))))
end function
public static double code(double x, double y, double z) {
return 0.5 * (x - (z * (y * (y / x))));
}
def code(x, y, z): return 0.5 * (x - (z * (y * (y / x))))
function code(x, y, z) return Float64(0.5 * Float64(x - Float64(z * Float64(y * Float64(y / x))))) end
function tmp = code(x, y, z) tmp = 0.5 * (x - (z * (y * (y / x)))); end
code[x_, y_, z_] := N[(0.5 * N[(x - N[(z * N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(x - z \cdot \left(y \cdot \frac{y}{x}\right)\right)
\end{array}
Initial program 99.8%
metadata-eval99.8%
Simplified99.8%
flip-+48.9%
div-inv48.8%
*-commutative48.8%
*-commutative48.8%
swap-sqr41.7%
add-sqr-sqrt41.7%
Applied egg-rr41.7%
Taylor expanded in x around inf 27.9%
Taylor expanded in x around 0 49.2%
+-commutative49.2%
mul-1-neg49.2%
unsub-neg49.2%
unpow249.2%
associate-/l*50.2%
associate-/r/50.8%
Simplified50.8%
Taylor expanded in y around 0 50.8%
unpow250.8%
associate-*r/55.2%
Simplified55.2%
Final simplification55.2%
(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 52.6%
Final simplification52.6%
herbie shell --seed 2023182
(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)))))