
(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 4 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))) (t_1 (/ (* (* (/ 8.0 3.0) t_0) t_0) (sin x)))) (if (<= t_1 -4e-159) t_1 (if (<= t_1 0.0) (* x 0.5) t_1))))
double code(double x) {
double t_0 = sin((x * 0.5));
double t_1 = (((8.0 / 3.0) * t_0) * t_0) / sin(x);
double tmp;
if (t_1 <= -4e-159) {
tmp = t_1;
} else if (t_1 <= 0.0) {
tmp = x * 0.5;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = sin((x * 0.5d0))
t_1 = (((8.0d0 / 3.0d0) * t_0) * t_0) / sin(x)
if (t_1 <= (-4d-159)) then
tmp = t_1
else if (t_1 <= 0.0d0) then
tmp = x * 0.5d0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sin((x * 0.5));
double t_1 = (((8.0 / 3.0) * t_0) * t_0) / Math.sin(x);
double tmp;
if (t_1 <= -4e-159) {
tmp = t_1;
} else if (t_1 <= 0.0) {
tmp = x * 0.5;
} else {
tmp = t_1;
}
return tmp;
}
def code(x): t_0 = math.sin((x * 0.5)) t_1 = (((8.0 / 3.0) * t_0) * t_0) / math.sin(x) tmp = 0 if t_1 <= -4e-159: tmp = t_1 elif t_1 <= 0.0: tmp = x * 0.5 else: tmp = t_1 return tmp
function code(x) t_0 = sin(Float64(x * 0.5)) t_1 = Float64(Float64(Float64(Float64(8.0 / 3.0) * t_0) * t_0) / sin(x)) tmp = 0.0 if (t_1 <= -4e-159) tmp = t_1; elseif (t_1 <= 0.0) tmp = Float64(x * 0.5); else tmp = t_1; end return tmp end
function tmp_2 = code(x) t_0 = sin((x * 0.5)); t_1 = (((8.0 / 3.0) * t_0) * t_0) / sin(x); tmp = 0.0; if (t_1 <= -4e-159) tmp = t_1; elseif (t_1 <= 0.0) tmp = x * 0.5; else tmp = t_1; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sin[N[(x * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(N[(8.0 / 3.0), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -4e-159], t$95$1, If[LessEqual[t$95$1, 0.0], N[(x * 0.5), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(x \cdot 0.5\right)\\
t_1 := \frac{\left(\frac{8}{3} \cdot t\_0\right) \cdot t\_0}{\sin x}\\
\mathbf{if}\;t\_1 \leq -4 \cdot 10^{-159}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_1 \leq 0:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 (*.f64 (/.f64 #s(literal 8 binary64) #s(literal 3 binary64)) (sin.f64 (*.f64 x #s(literal 1/2 binary64)))) (sin.f64 (*.f64 x #s(literal 1/2 binary64)))) (sin.f64 x)) < -3.99999999999999995e-159 or -0.0 < (/.f64 (*.f64 (*.f64 (/.f64 #s(literal 8 binary64) #s(literal 3 binary64)) (sin.f64 (*.f64 x #s(literal 1/2 binary64)))) (sin.f64 (*.f64 x #s(literal 1/2 binary64)))) (sin.f64 x)) Initial program 98.7%
if -3.99999999999999995e-159 < (/.f64 (*.f64 (*.f64 (/.f64 #s(literal 8 binary64) #s(literal 3 binary64)) (sin.f64 (*.f64 x #s(literal 1/2 binary64)))) (sin.f64 (*.f64 x #s(literal 1/2 binary64)))) (sin.f64 x)) < -0.0Initial program 7.1%
Taylor expanded in x around 0
Applied rewrites18.8%
Taylor expanded in x around 0
Applied rewrites20.7%
(FPCore (x)
:precision binary64
(let* ((t_0 (sin (* x 0.5))))
(if (<= (/ (* (* (/ 8.0 3.0) t_0) t_0) (sin x)) 5e-8)
(* x 0.5)
(/ 8.0 3.0))))
double code(double x) {
double t_0 = sin((x * 0.5));
double tmp;
if (((((8.0 / 3.0) * t_0) * t_0) / sin(x)) <= 5e-8) {
tmp = x * 0.5;
} else {
tmp = 8.0 / 3.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = sin((x * 0.5d0))
if (((((8.0d0 / 3.0d0) * t_0) * t_0) / sin(x)) <= 5d-8) then
tmp = x * 0.5d0
else
tmp = 8.0d0 / 3.0d0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sin((x * 0.5));
double tmp;
if (((((8.0 / 3.0) * t_0) * t_0) / Math.sin(x)) <= 5e-8) {
tmp = x * 0.5;
} else {
tmp = 8.0 / 3.0;
}
return tmp;
}
def code(x): t_0 = math.sin((x * 0.5)) tmp = 0 if ((((8.0 / 3.0) * t_0) * t_0) / math.sin(x)) <= 5e-8: tmp = x * 0.5 else: tmp = 8.0 / 3.0 return tmp
function code(x) t_0 = sin(Float64(x * 0.5)) tmp = 0.0 if (Float64(Float64(Float64(Float64(8.0 / 3.0) * t_0) * t_0) / sin(x)) <= 5e-8) tmp = Float64(x * 0.5); else tmp = Float64(8.0 / 3.0); end return tmp end
function tmp_2 = code(x) t_0 = sin((x * 0.5)); tmp = 0.0; if (((((8.0 / 3.0) * t_0) * t_0) / sin(x)) <= 5e-8) tmp = x * 0.5; else tmp = 8.0 / 3.0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sin[N[(x * 0.5), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(N[(N[(8.0 / 3.0), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision], 5e-8], N[(x * 0.5), $MachinePrecision], N[(8.0 / 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(x \cdot 0.5\right)\\
\mathbf{if}\;\frac{\left(\frac{8}{3} \cdot t\_0\right) \cdot t\_0}{\sin x} \leq 5 \cdot 10^{-8}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{8}{3}\\
\end{array}
\end{array}
if (/.f64 (*.f64 (*.f64 (/.f64 #s(literal 8 binary64) #s(literal 3 binary64)) (sin.f64 (*.f64 x #s(literal 1/2 binary64)))) (sin.f64 (*.f64 x #s(literal 1/2 binary64)))) (sin.f64 x)) < 4.9999999999999998e-8Initial program 70.8%
Taylor expanded in x around 0
Applied rewrites16.0%
Taylor expanded in x around 0
Applied rewrites14.4%
if 4.9999999999999998e-8 < (/.f64 (*.f64 (*.f64 (/.f64 #s(literal 8 binary64) #s(literal 3 binary64)) (sin.f64 (*.f64 x #s(literal 1/2 binary64)))) (sin.f64 (*.f64 x #s(literal 1/2 binary64)))) (sin.f64 x)) Initial program 98.9%
Taylor expanded in x around 0
Applied rewrites18.2%
(FPCore (x) :precision binary64 (sin x))
double code(double x) {
return sin(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = sin(x)
end function
public static double code(double x) {
return Math.sin(x);
}
def code(x): return math.sin(x)
function code(x) return sin(x) end
function tmp = code(x) tmp = sin(x); end
code[x_] := N[Sin[x], $MachinePrecision]
\begin{array}{l}
\\
\sin x
\end{array}
Initial program 77.3%
Taylor expanded in x around 0
Applied rewrites15.1%
Taylor expanded in x around 0
Applied rewrites19.8%
(FPCore (x) :precision binary64 (* x 0.5))
double code(double x) {
return x * 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * 0.5d0
end function
public static double code(double x) {
return x * 0.5;
}
def code(x): return x * 0.5
function code(x) return Float64(x * 0.5) end
function tmp = code(x) tmp = x * 0.5; end
code[x_] := N[(x * 0.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5
\end{array}
Initial program 77.3%
Taylor expanded in x around 0
Applied rewrites15.1%
Taylor expanded in x around 0
Applied rewrites12.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 2024321
(FPCore (x)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, A"
:precision binary64
:pre (TRUE)
:alt
(! :herbie-platform default (/ (/ (* 8 (sin (* x 1/2))) 3) (/ (sin x) (sin (* x 1/2)))))
(/ (* (* (/ 8.0 3.0) (sin (* x 0.5))) (sin (* x 0.5))) (sin x)))