
(FPCore (x) :precision binary64 (let* ((t_0 (sin (* x 0.5)))) (/ (* (* (/ 8.0 3.0) t_0) t_0) (sin x))))
double code(double x) {
double t_0 = sin((x * 0.5));
return (((8.0 / 3.0) * t_0) * t_0) / sin(x);
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = sin((x * 0.5d0))
code = (((8.0d0 / 3.0d0) * t_0) * t_0) / sin(x)
end function
public static double code(double x) {
double t_0 = Math.sin((x * 0.5));
return (((8.0 / 3.0) * t_0) * t_0) / Math.sin(x);
}
def code(x): t_0 = math.sin((x * 0.5)) return (((8.0 / 3.0) * t_0) * t_0) / math.sin(x)
function code(x) t_0 = sin(Float64(x * 0.5)) return Float64(Float64(Float64(Float64(8.0 / 3.0) * t_0) * t_0) / sin(x)) end
function tmp = code(x) t_0 = sin((x * 0.5)); tmp = (((8.0 / 3.0) * t_0) * t_0) / sin(x); end
code[x_] := Block[{t$95$0 = N[Sin[N[(x * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(N[(8.0 / 3.0), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(x \cdot 0.5\right)\\
\frac{\left(\frac{8}{3} \cdot t\_0\right) \cdot t\_0}{\sin x}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (let* ((t_0 (sin (* x 0.5)))) (/ (* (* (/ 8.0 3.0) t_0) t_0) (sin x))))
double code(double x) {
double t_0 = sin((x * 0.5));
return (((8.0 / 3.0) * t_0) * t_0) / sin(x);
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = sin((x * 0.5d0))
code = (((8.0d0 / 3.0d0) * t_0) * t_0) / sin(x)
end function
public static double code(double x) {
double t_0 = Math.sin((x * 0.5));
return (((8.0 / 3.0) * t_0) * t_0) / Math.sin(x);
}
def code(x): t_0 = math.sin((x * 0.5)) return (((8.0 / 3.0) * t_0) * t_0) / math.sin(x)
function code(x) t_0 = sin(Float64(x * 0.5)) return Float64(Float64(Float64(Float64(8.0 / 3.0) * t_0) * t_0) / sin(x)) end
function tmp = code(x) t_0 = sin((x * 0.5)); tmp = (((8.0 / 3.0) * t_0) * t_0) / sin(x); end
code[x_] := Block[{t$95$0 = N[Sin[N[(x * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(N[(8.0 / 3.0), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(x \cdot 0.5\right)\\
\frac{\left(\frac{8}{3} \cdot t\_0\right) \cdot t\_0}{\sin x}
\end{array}
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (sin (* x 0.5))))
(*
(* (sqrt 2.6666666666666665) (* (sqrt 2.6666666666666665) t_0))
(/ t_0 (sin x)))))
double code(double x) {
double t_0 = sin((x * 0.5));
return (sqrt(2.6666666666666665) * (sqrt(2.6666666666666665) * t_0)) * (t_0 / sin(x));
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = sin((x * 0.5d0))
code = (sqrt(2.6666666666666665d0) * (sqrt(2.6666666666666665d0) * t_0)) * (t_0 / sin(x))
end function
public static double code(double x) {
double t_0 = Math.sin((x * 0.5));
return (Math.sqrt(2.6666666666666665) * (Math.sqrt(2.6666666666666665) * t_0)) * (t_0 / Math.sin(x));
}
def code(x): t_0 = math.sin((x * 0.5)) return (math.sqrt(2.6666666666666665) * (math.sqrt(2.6666666666666665) * t_0)) * (t_0 / math.sin(x))
function code(x) t_0 = sin(Float64(x * 0.5)) return Float64(Float64(sqrt(2.6666666666666665) * Float64(sqrt(2.6666666666666665) * t_0)) * Float64(t_0 / sin(x))) end
function tmp = code(x) t_0 = sin((x * 0.5)); tmp = (sqrt(2.6666666666666665) * (sqrt(2.6666666666666665) * t_0)) * (t_0 / sin(x)); end
code[x_] := Block[{t$95$0 = N[Sin[N[(x * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[Sqrt[2.6666666666666665], $MachinePrecision] * N[(N[Sqrt[2.6666666666666665], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 / N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(x \cdot 0.5\right)\\
\left(\sqrt{2.6666666666666665} \cdot \left(\sqrt{2.6666666666666665} \cdot t\_0\right)\right) \cdot \frac{t\_0}{\sin x}
\end{array}
\end{array}
Initial program 77.7%
associate-/l*99.3%
*-commutative99.3%
/-rgt-identity99.3%
metadata-eval99.3%
distribute-neg-frac299.3%
distribute-frac-neg99.3%
sin-neg99.3%
distribute-lft-neg-out99.3%
associate-*l/99.3%
*-commutative99.3%
Simplified99.3%
metadata-eval99.3%
add-sqr-sqrt49.5%
pow249.5%
metadata-eval49.5%
Applied egg-rr49.5%
unpow249.5%
sqrt-prod49.6%
associate-*l*49.5%
*-commutative49.5%
sqrt-prod49.5%
associate-*l*49.5%
add-sqr-sqrt99.3%
*-commutative99.3%
Applied egg-rr99.3%
(FPCore (x) :precision binary64 (if (<= x 1e-6) (* 2.6666666666666665 (* x (+ 0.25 (* 0.020833333333333332 (pow x 2.0))))) (/ (pow (sin (* x 0.5)) 2.0) (* (sin x) 0.375))))
double code(double x) {
double tmp;
if (x <= 1e-6) {
tmp = 2.6666666666666665 * (x * (0.25 + (0.020833333333333332 * pow(x, 2.0))));
} else {
tmp = pow(sin((x * 0.5)), 2.0) / (sin(x) * 0.375);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1d-6) then
tmp = 2.6666666666666665d0 * (x * (0.25d0 + (0.020833333333333332d0 * (x ** 2.0d0))))
else
tmp = (sin((x * 0.5d0)) ** 2.0d0) / (sin(x) * 0.375d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1e-6) {
tmp = 2.6666666666666665 * (x * (0.25 + (0.020833333333333332 * Math.pow(x, 2.0))));
} else {
tmp = Math.pow(Math.sin((x * 0.5)), 2.0) / (Math.sin(x) * 0.375);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1e-6: tmp = 2.6666666666666665 * (x * (0.25 + (0.020833333333333332 * math.pow(x, 2.0)))) else: tmp = math.pow(math.sin((x * 0.5)), 2.0) / (math.sin(x) * 0.375) return tmp
function code(x) tmp = 0.0 if (x <= 1e-6) tmp = Float64(2.6666666666666665 * Float64(x * Float64(0.25 + Float64(0.020833333333333332 * (x ^ 2.0))))); else tmp = Float64((sin(Float64(x * 0.5)) ^ 2.0) / Float64(sin(x) * 0.375)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1e-6) tmp = 2.6666666666666665 * (x * (0.25 + (0.020833333333333332 * (x ^ 2.0)))); else tmp = (sin((x * 0.5)) ^ 2.0) / (sin(x) * 0.375); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1e-6], N[(2.6666666666666665 * N[(x * N[(0.25 + N[(0.020833333333333332 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[N[Sin[N[(x * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] / N[(N[Sin[x], $MachinePrecision] * 0.375), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{-6}:\\
\;\;\;\;2.6666666666666665 \cdot \left(x \cdot \left(0.25 + 0.020833333333333332 \cdot {x}^{2}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{\sin \left(x \cdot 0.5\right)}^{2}}{\sin x \cdot 0.375}\\
\end{array}
\end{array}
if x < 9.99999999999999955e-7Initial program 70.4%
add-cbrt-cube45.7%
pow345.6%
add-sqr-sqrt45.5%
pow245.5%
pow-pow45.7%
associate-*l*45.7%
sqrt-prod45.7%
metadata-eval45.7%
sqrt-unprod21.7%
add-sqr-sqrt45.7%
metadata-eval45.7%
Applied egg-rr45.7%
*-un-lft-identity45.7%
associate-*l/45.7%
pow1/344.8%
pow-pow70.3%
pow170.3%
metadata-eval70.3%
sqrt-pow170.3%
sqrt-prod70.1%
metadata-eval70.1%
pow270.1%
add-sqr-sqrt70.3%
*-commutative70.3%
associate-*r*70.2%
Applied egg-rr70.2%
Taylor expanded in x around 0 70.4%
if 9.99999999999999955e-7 < x Initial program 98.7%
add-cbrt-cube98.5%
pow1/349.2%
Applied egg-rr49.4%
unpow1/398.4%
associate-/r*98.5%
Simplified98.5%
pow1/349.5%
pow-pow98.9%
metadata-eval98.9%
inv-pow98.9%
associate-/r*98.9%
associate-/r/98.8%
associate-*l/99.0%
*-un-lft-identity99.0%
div-inv99.0%
metadata-eval99.0%
Applied egg-rr99.0%
Final simplification77.8%
(FPCore (x) :precision binary64 (if (<= x 1e-6) (* 2.6666666666666665 (* x (+ 0.25 (* 0.020833333333333332 (pow x 2.0))))) (* 2.6666666666666665 (/ (pow (sin (* x 0.5)) 2.0) (sin x)))))
double code(double x) {
double tmp;
if (x <= 1e-6) {
tmp = 2.6666666666666665 * (x * (0.25 + (0.020833333333333332 * pow(x, 2.0))));
} else {
tmp = 2.6666666666666665 * (pow(sin((x * 0.5)), 2.0) / sin(x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1d-6) then
tmp = 2.6666666666666665d0 * (x * (0.25d0 + (0.020833333333333332d0 * (x ** 2.0d0))))
else
tmp = 2.6666666666666665d0 * ((sin((x * 0.5d0)) ** 2.0d0) / sin(x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1e-6) {
tmp = 2.6666666666666665 * (x * (0.25 + (0.020833333333333332 * Math.pow(x, 2.0))));
} else {
tmp = 2.6666666666666665 * (Math.pow(Math.sin((x * 0.5)), 2.0) / Math.sin(x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1e-6: tmp = 2.6666666666666665 * (x * (0.25 + (0.020833333333333332 * math.pow(x, 2.0)))) else: tmp = 2.6666666666666665 * (math.pow(math.sin((x * 0.5)), 2.0) / math.sin(x)) return tmp
function code(x) tmp = 0.0 if (x <= 1e-6) tmp = Float64(2.6666666666666665 * Float64(x * Float64(0.25 + Float64(0.020833333333333332 * (x ^ 2.0))))); else tmp = Float64(2.6666666666666665 * Float64((sin(Float64(x * 0.5)) ^ 2.0) / sin(x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1e-6) tmp = 2.6666666666666665 * (x * (0.25 + (0.020833333333333332 * (x ^ 2.0)))); else tmp = 2.6666666666666665 * ((sin((x * 0.5)) ^ 2.0) / sin(x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1e-6], N[(2.6666666666666665 * N[(x * N[(0.25 + N[(0.020833333333333332 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.6666666666666665 * N[(N[Power[N[Sin[N[(x * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{-6}:\\
\;\;\;\;2.6666666666666665 \cdot \left(x \cdot \left(0.25 + 0.020833333333333332 \cdot {x}^{2}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;2.6666666666666665 \cdot \frac{{\sin \left(x \cdot 0.5\right)}^{2}}{\sin x}\\
\end{array}
\end{array}
if x < 9.99999999999999955e-7Initial program 70.4%
add-cbrt-cube45.7%
pow345.6%
add-sqr-sqrt45.5%
pow245.5%
pow-pow45.7%
associate-*l*45.7%
sqrt-prod45.7%
metadata-eval45.7%
sqrt-unprod21.7%
add-sqr-sqrt45.7%
metadata-eval45.7%
Applied egg-rr45.7%
*-un-lft-identity45.7%
associate-*l/45.7%
pow1/344.8%
pow-pow70.3%
pow170.3%
metadata-eval70.3%
sqrt-pow170.3%
sqrt-prod70.1%
metadata-eval70.1%
pow270.1%
add-sqr-sqrt70.3%
*-commutative70.3%
associate-*r*70.2%
Applied egg-rr70.2%
Taylor expanded in x around 0 70.4%
if 9.99999999999999955e-7 < x Initial program 98.7%
associate-/l*98.8%
associate-*r*98.9%
*-commutative98.9%
associate-*r/98.9%
pow298.9%
metadata-eval98.9%
Applied egg-rr98.9%
Final simplification77.8%
(FPCore (x) :precision binary64 (let* ((t_0 (sin (* x 0.5)))) (* t_0 (/ (* 2.6666666666666665 t_0) (sin x)))))
double code(double x) {
double t_0 = sin((x * 0.5));
return t_0 * ((2.6666666666666665 * t_0) / sin(x));
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = sin((x * 0.5d0))
code = t_0 * ((2.6666666666666665d0 * t_0) / sin(x))
end function
public static double code(double x) {
double t_0 = Math.sin((x * 0.5));
return t_0 * ((2.6666666666666665 * t_0) / Math.sin(x));
}
def code(x): t_0 = math.sin((x * 0.5)) return t_0 * ((2.6666666666666665 * t_0) / math.sin(x))
function code(x) t_0 = sin(Float64(x * 0.5)) return Float64(t_0 * Float64(Float64(2.6666666666666665 * t_0) / sin(x))) end
function tmp = code(x) t_0 = sin((x * 0.5)); tmp = t_0 * ((2.6666666666666665 * t_0) / sin(x)); end
code[x_] := Block[{t$95$0 = N[Sin[N[(x * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(t$95$0 * N[(N[(2.6666666666666665 * t$95$0), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(x \cdot 0.5\right)\\
t\_0 \cdot \frac{2.6666666666666665 \cdot t\_0}{\sin x}
\end{array}
\end{array}
Initial program 77.7%
*-commutative77.7%
associate-/l*99.3%
remove-double-neg99.3%
sin-neg99.3%
distribute-lft-neg-out99.3%
distribute-rgt-neg-in99.3%
distribute-frac-neg99.3%
distribute-frac-neg299.3%
neg-mul-199.3%
associate-/r*99.3%
Simplified99.3%
(FPCore (x) :precision binary64 (let* ((t_0 (sin (* x 0.5)))) (* 2.6666666666666665 (* t_0 (/ t_0 (sin x))))))
double code(double x) {
double t_0 = sin((x * 0.5));
return 2.6666666666666665 * (t_0 * (t_0 / sin(x)));
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = sin((x * 0.5d0))
code = 2.6666666666666665d0 * (t_0 * (t_0 / sin(x)))
end function
public static double code(double x) {
double t_0 = Math.sin((x * 0.5));
return 2.6666666666666665 * (t_0 * (t_0 / Math.sin(x)));
}
def code(x): t_0 = math.sin((x * 0.5)) return 2.6666666666666665 * (t_0 * (t_0 / math.sin(x)))
function code(x) t_0 = sin(Float64(x * 0.5)) return Float64(2.6666666666666665 * Float64(t_0 * Float64(t_0 / sin(x)))) end
function tmp = code(x) t_0 = sin((x * 0.5)); tmp = 2.6666666666666665 * (t_0 * (t_0 / sin(x))); end
code[x_] := Block[{t$95$0 = N[Sin[N[(x * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(2.6666666666666665 * N[(t$95$0 * N[(t$95$0 / N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(x \cdot 0.5\right)\\
2.6666666666666665 \cdot \left(t\_0 \cdot \frac{t\_0}{\sin x}\right)
\end{array}
\end{array}
Initial program 77.7%
associate-/l*99.3%
associate-*l*99.2%
metadata-eval99.2%
Simplified99.2%
(FPCore (x) :precision binary64 (* (sin (* x 0.5)) 1.3333333333333333))
double code(double x) {
return sin((x * 0.5)) * 1.3333333333333333;
}
real(8) function code(x)
real(8), intent (in) :: x
code = sin((x * 0.5d0)) * 1.3333333333333333d0
end function
public static double code(double x) {
return Math.sin((x * 0.5)) * 1.3333333333333333;
}
def code(x): return math.sin((x * 0.5)) * 1.3333333333333333
function code(x) return Float64(sin(Float64(x * 0.5)) * 1.3333333333333333) end
function tmp = code(x) tmp = sin((x * 0.5)) * 1.3333333333333333; end
code[x_] := N[(N[Sin[N[(x * 0.5), $MachinePrecision]], $MachinePrecision] * 1.3333333333333333), $MachinePrecision]
\begin{array}{l}
\\
\sin \left(x \cdot 0.5\right) \cdot 1.3333333333333333
\end{array}
Initial program 77.7%
add-cbrt-cube59.3%
pow359.3%
add-sqr-sqrt59.2%
pow259.2%
pow-pow59.3%
associate-*l*59.3%
sqrt-prod59.4%
metadata-eval59.4%
sqrt-unprod27.2%
add-sqr-sqrt59.4%
metadata-eval59.4%
Applied egg-rr59.4%
pow1/358.7%
pow-pow77.7%
metadata-eval77.7%
pow277.7%
swap-sqr77.7%
rem-square-sqrt77.7%
unpow277.7%
*-un-lft-identity77.7%
associate-*l/77.7%
associate-*r*77.6%
unpow277.6%
associate-*r*99.1%
associate-*l/99.2%
metadata-eval99.2%
Applied egg-rr99.2%
Taylor expanded in x around 0 56.9%
Final simplification56.9%
(FPCore (x) :precision binary64 (* x 0.6666666666666666))
double code(double x) {
return x * 0.6666666666666666;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * 0.6666666666666666d0
end function
public static double code(double x) {
return x * 0.6666666666666666;
}
def code(x): return x * 0.6666666666666666
function code(x) return Float64(x * 0.6666666666666666) end
function tmp = code(x) tmp = x * 0.6666666666666666; end
code[x_] := N[(x * 0.6666666666666666), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.6666666666666666
\end{array}
Initial program 77.7%
Taylor expanded in x around 0 53.2%
Final simplification53.2%
(FPCore (x) :precision binary64 (let* ((t_0 (sin (* x 0.5)))) (/ (/ (* 8.0 t_0) 3.0) (/ (sin x) t_0))))
double code(double x) {
double t_0 = sin((x * 0.5));
return ((8.0 * t_0) / 3.0) / (sin(x) / t_0);
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = sin((x * 0.5d0))
code = ((8.0d0 * t_0) / 3.0d0) / (sin(x) / t_0)
end function
public static double code(double x) {
double t_0 = Math.sin((x * 0.5));
return ((8.0 * t_0) / 3.0) / (Math.sin(x) / t_0);
}
def code(x): t_0 = math.sin((x * 0.5)) return ((8.0 * t_0) / 3.0) / (math.sin(x) / t_0)
function code(x) t_0 = sin(Float64(x * 0.5)) return Float64(Float64(Float64(8.0 * t_0) / 3.0) / Float64(sin(x) / t_0)) end
function tmp = code(x) t_0 = sin((x * 0.5)); tmp = ((8.0 * t_0) / 3.0) / (sin(x) / t_0); end
code[x_] := Block[{t$95$0 = N[Sin[N[(x * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(8.0 * t$95$0), $MachinePrecision] / 3.0), $MachinePrecision] / N[(N[Sin[x], $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(x \cdot 0.5\right)\\
\frac{\frac{8 \cdot t\_0}{3}}{\frac{\sin x}{t\_0}}
\end{array}
\end{array}
herbie shell --seed 2024111
(FPCore (x)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, A"
:precision binary64
:alt
(/ (/ (* 8.0 (sin (* x 0.5))) 3.0) (/ (sin x) (sin (* x 0.5))))
(/ (* (* (/ 8.0 3.0) (sin (* x 0.5))) (sin (* x 0.5))) (sin x)))