
(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 9 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 (* 0.5 x)))) (* (/ t_0 (sin x)) (/ t_0 0.375))))
double code(double x) {
double t_0 = sin((0.5 * x));
return (t_0 / sin(x)) * (t_0 / 0.375);
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = sin((0.5d0 * x))
code = (t_0 / sin(x)) * (t_0 / 0.375d0)
end function
public static double code(double x) {
double t_0 = Math.sin((0.5 * x));
return (t_0 / Math.sin(x)) * (t_0 / 0.375);
}
def code(x): t_0 = math.sin((0.5 * x)) return (t_0 / math.sin(x)) * (t_0 / 0.375)
function code(x) t_0 = sin(Float64(0.5 * x)) return Float64(Float64(t_0 / sin(x)) * Float64(t_0 / 0.375)) end
function tmp = code(x) t_0 = sin((0.5 * x)); tmp = (t_0 / sin(x)) * (t_0 / 0.375); end
code[x_] := Block[{t$95$0 = N[Sin[N[(0.5 * x), $MachinePrecision]], $MachinePrecision]}, N[(N[(t$95$0 / N[Sin[x], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 / 0.375), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot x\right)\\
\frac{t\_0}{\sin x} \cdot \frac{t\_0}{0.375}
\end{array}
\end{array}
Initial program 75.9%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-/r*N/A
clear-numN/A
frac-2negN/A
neg-mul-1N/A
*-commutativeN/A
associate-/l*N/A
times-fracN/A
lower-*.f64N/A
Applied rewrites99.6%
(FPCore (x) :precision binary64 (* 1.3333333333333333 (tan (* 0.5 x))))
double code(double x) {
return 1.3333333333333333 * tan((0.5 * x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.3333333333333333d0 * tan((0.5d0 * x))
end function
public static double code(double x) {
return 1.3333333333333333 * Math.tan((0.5 * x));
}
def code(x): return 1.3333333333333333 * math.tan((0.5 * x))
function code(x) return Float64(1.3333333333333333 * tan(Float64(0.5 * x))) end
function tmp = code(x) tmp = 1.3333333333333333 * tan((0.5 * x)); end
code[x_] := N[(1.3333333333333333 * N[Tan[N[(0.5 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1.3333333333333333 \cdot \tan \left(0.5 \cdot x\right)
\end{array}
Initial program 75.9%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-/r*N/A
div-invN/A
associate-/r*N/A
clear-numN/A
lower-/.f64N/A
lower-/.f64N/A
lift-/.f64N/A
metadata-evalN/A
lift-sin.f64N/A
lift-sin.f64N/A
Applied rewrites49.1%
Taylor expanded in x around inf
lower-*.f64N/A
hang-p0-tanN/A
*-rgt-identityN/A
associate-/l*N/A
metadata-evalN/A
*-commutativeN/A
lower-tan.f64N/A
*-commutativeN/A
lower-*.f6499.4
Applied rewrites99.4%
Final simplification99.4%
(FPCore (x)
:precision binary64
(/
2.6666666666666665
(/
(fma
(* x x)
(fma
(* x x)
(fma (* x x) -0.00013227513227513228 -0.005555555555555556)
-0.3333333333333333)
4.0)
x)))
double code(double x) {
return 2.6666666666666665 / (fma((x * x), fma((x * x), fma((x * x), -0.00013227513227513228, -0.005555555555555556), -0.3333333333333333), 4.0) / x);
}
function code(x) return Float64(2.6666666666666665 / Float64(fma(Float64(x * x), fma(Float64(x * x), fma(Float64(x * x), -0.00013227513227513228, -0.005555555555555556), -0.3333333333333333), 4.0) / x)) end
code[x_] := N[(2.6666666666666665 / N[(N[(N[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * -0.00013227513227513228 + -0.005555555555555556), $MachinePrecision] + -0.3333333333333333), $MachinePrecision] + 4.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2.6666666666666665}{\frac{\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, -0.00013227513227513228, -0.005555555555555556\right), -0.3333333333333333\right), 4\right)}{x}}
\end{array}
Initial program 75.9%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-/l*N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lift-/.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
sqr-sin-aN/A
sub-negN/A
+-commutativeN/A
Applied rewrites49.1%
Taylor expanded in x around 0
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6456.2
Applied rewrites56.2%
(FPCore (x) :precision binary64 (/ 2.6666666666666665 (/ (fma (* x x) -0.3333333333333333 4.0) x)))
double code(double x) {
return 2.6666666666666665 / (fma((x * x), -0.3333333333333333, 4.0) / x);
}
function code(x) return Float64(2.6666666666666665 / Float64(fma(Float64(x * x), -0.3333333333333333, 4.0) / x)) end
code[x_] := N[(2.6666666666666665 / N[(N[(N[(x * x), $MachinePrecision] * -0.3333333333333333 + 4.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2.6666666666666665}{\frac{\mathsf{fma}\left(x \cdot x, -0.3333333333333333, 4\right)}{x}}
\end{array}
Initial program 75.9%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-/l*N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lift-/.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
sqr-sin-aN/A
sub-negN/A
+-commutativeN/A
Applied rewrites49.1%
Taylor expanded in x around 0
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6456.1
Applied rewrites56.1%
(FPCore (x) :precision binary64 (* 1.3333333333333333 (* x (fma (* x x) (fma x (* x 0.004166666666666667) 0.041666666666666664) 0.5))))
double code(double x) {
return 1.3333333333333333 * (x * fma((x * x), fma(x, (x * 0.004166666666666667), 0.041666666666666664), 0.5));
}
function code(x) return Float64(1.3333333333333333 * Float64(x * fma(Float64(x * x), fma(x, Float64(x * 0.004166666666666667), 0.041666666666666664), 0.5))) end
code[x_] := N[(1.3333333333333333 * N[(x * N[(N[(x * x), $MachinePrecision] * N[(x * N[(x * 0.004166666666666667), $MachinePrecision] + 0.041666666666666664), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1.3333333333333333 \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, x \cdot 0.004166666666666667, 0.041666666666666664\right), 0.5\right)\right)
\end{array}
Initial program 75.9%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-/r*N/A
div-invN/A
associate-/r*N/A
clear-numN/A
lower-/.f64N/A
lower-/.f64N/A
lift-/.f64N/A
metadata-evalN/A
lift-sin.f64N/A
lift-sin.f64N/A
Applied rewrites49.1%
Taylor expanded in x around inf
lower-*.f64N/A
hang-p0-tanN/A
*-rgt-identityN/A
associate-/l*N/A
metadata-evalN/A
*-commutativeN/A
lower-tan.f64N/A
*-commutativeN/A
lower-*.f6499.4
Applied rewrites99.4%
Taylor expanded in x around 0
Applied rewrites55.3%
(FPCore (x) :precision binary64 (* x (fma (* x x) (fma x (* x 0.005555555555555556) 0.05555555555555555) 0.6666666666666666)))
double code(double x) {
return x * fma((x * x), fma(x, (x * 0.005555555555555556), 0.05555555555555555), 0.6666666666666666);
}
function code(x) return Float64(x * fma(Float64(x * x), fma(x, Float64(x * 0.005555555555555556), 0.05555555555555555), 0.6666666666666666)) end
code[x_] := N[(x * N[(N[(x * x), $MachinePrecision] * N[(x * N[(x * 0.005555555555555556), $MachinePrecision] + 0.05555555555555555), $MachinePrecision] + 0.6666666666666666), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, x \cdot 0.005555555555555556, 0.05555555555555555\right), 0.6666666666666666\right)
\end{array}
Initial program 75.9%
Taylor expanded in x around 0
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f6455.3
Applied rewrites55.3%
(FPCore (x) :precision binary64 (fma (* x (* x x)) 0.05555555555555555 (* x 0.6666666666666666)))
double code(double x) {
return fma((x * (x * x)), 0.05555555555555555, (x * 0.6666666666666666));
}
function code(x) return fma(Float64(x * Float64(x * x)), 0.05555555555555555, Float64(x * 0.6666666666666666)) end
code[x_] := N[(N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] * 0.05555555555555555 + N[(x * 0.6666666666666666), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot \left(x \cdot x\right), 0.05555555555555555, x \cdot 0.6666666666666666\right)
\end{array}
Initial program 75.9%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-sin.f64N/A
lift-sin.f64N/A
sqr-sin-aN/A
sub-negN/A
distribute-rgt-inN/A
lift-/.f64N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lift-/.f64N/A
lower-+.f64N/A
Applied rewrites49.0%
Taylor expanded in x around 0
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6455.1
Applied rewrites55.1%
Applied rewrites55.1%
(FPCore (x) :precision binary64 (* x (fma 0.05555555555555555 (* x x) 0.6666666666666666)))
double code(double x) {
return x * fma(0.05555555555555555, (x * x), 0.6666666666666666);
}
function code(x) return Float64(x * fma(0.05555555555555555, Float64(x * x), 0.6666666666666666)) end
code[x_] := N[(x * N[(0.05555555555555555 * N[(x * x), $MachinePrecision] + 0.6666666666666666), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(0.05555555555555555, x \cdot x, 0.6666666666666666\right)
\end{array}
Initial program 75.9%
Taylor expanded in x around 0
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6455.1
Applied rewrites55.1%
(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 75.9%
Taylor expanded in x around 0
lower-*.f6455.0
Applied rewrites55.0%
Final simplification55.0%
(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 2024222
(FPCore (x)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, A"
:precision binary64
: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)))