
(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 6 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 (/ (tan (* x 0.5)) 0.75))
double code(double x) {
return tan((x * 0.5)) / 0.75;
}
real(8) function code(x)
real(8), intent (in) :: x
code = tan((x * 0.5d0)) / 0.75d0
end function
public static double code(double x) {
return Math.tan((x * 0.5)) / 0.75;
}
def code(x): return math.tan((x * 0.5)) / 0.75
function code(x) return Float64(tan(Float64(x * 0.5)) / 0.75) end
function tmp = code(x) tmp = tan((x * 0.5)) / 0.75; end
code[x_] := N[(N[Tan[N[(x * 0.5), $MachinePrecision]], $MachinePrecision] / 0.75), $MachinePrecision]
\begin{array}{l}
\\
\frac{\tan \left(x \cdot 0.5\right)}{0.75}
\end{array}
Initial program 76.5%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-/r*N/A
clear-numN/A
lift-sin.f64N/A
lift-sin.f64N/A
sin-multN/A
div-invN/A
metadata-evalN/A
frac-2negN/A
neg-mul-1N/A
*-commutativeN/A
Applied rewrites51.7%
lift-/.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lift-sin.f64N/A
hang-p0-tanN/A
div-invN/A
metadata-evalN/A
lift-*.f64N/A
lower-tan.f6499.6
lift-*.f64N/A
*-commutativeN/A
lift-*.f6499.6
Applied rewrites99.6%
lift-tan.f64N/A
tan-quotN/A
lift-*.f64N/A
*-commutativeN/A
lower-/.f64N/A
*-commutativeN/A
lift-*.f64N/A
lower-sin.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6499.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.4
Applied rewrites99.4%
lift-*.f64N/A
lift-/.f64N/A
lift-sin.f64N/A
lift-cos.f64N/A
tan-quotN/A
lift-tan.f64N/A
metadata-evalN/A
div-invN/A
lower-/.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (* 1.3333333333333333 (tan (* x 0.5))))
double code(double x) {
return 1.3333333333333333 * tan((x * 0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.3333333333333333d0 * tan((x * 0.5d0))
end function
public static double code(double x) {
return 1.3333333333333333 * Math.tan((x * 0.5));
}
def code(x): return 1.3333333333333333 * math.tan((x * 0.5))
function code(x) return Float64(1.3333333333333333 * tan(Float64(x * 0.5))) end
function tmp = code(x) tmp = 1.3333333333333333 * tan((x * 0.5)); end
code[x_] := N[(1.3333333333333333 * N[Tan[N[(x * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1.3333333333333333 \cdot \tan \left(x \cdot 0.5\right)
\end{array}
Initial program 76.5%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-/r*N/A
clear-numN/A
lift-sin.f64N/A
lift-sin.f64N/A
sin-multN/A
div-invN/A
metadata-evalN/A
frac-2negN/A
neg-mul-1N/A
*-commutativeN/A
Applied rewrites51.7%
lift-/.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lift-sin.f64N/A
hang-p0-tanN/A
div-invN/A
metadata-evalN/A
lift-*.f64N/A
lower-tan.f6499.6
lift-*.f64N/A
*-commutativeN/A
lift-*.f6499.6
Applied rewrites99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (/ 1.0 (/ 1.0 (/ x (fma (* x x) -0.125 1.5)))))
double code(double x) {
return 1.0 / (1.0 / (x / fma((x * x), -0.125, 1.5)));
}
function code(x) return Float64(1.0 / Float64(1.0 / Float64(x / fma(Float64(x * x), -0.125, 1.5)))) end
code[x_] := N[(1.0 / N[(1.0 / N[(x / N[(N[(x * x), $MachinePrecision] * -0.125 + 1.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{1}{\frac{x}{\mathsf{fma}\left(x \cdot x, -0.125, 1.5\right)}}}
\end{array}
Initial program 76.5%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-/r*N/A
clear-numN/A
lift-sin.f64N/A
lift-sin.f64N/A
sin-multN/A
div-invN/A
metadata-evalN/A
frac-2negN/A
neg-mul-1N/A
*-commutativeN/A
Applied rewrites51.7%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
associate-*l/N/A
lift-/.f64N/A
lift-*.f64N/A
inv-powN/A
lower-pow.f6451.7
Applied rewrites99.1%
Taylor expanded in x around 0
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6452.3
Applied rewrites52.3%
Applied rewrites52.4%
(FPCore (x) :precision binary64 (/ 1.0 (fma -0.125 x (/ 1.5 x))))
double code(double x) {
return 1.0 / fma(-0.125, x, (1.5 / x));
}
function code(x) return Float64(1.0 / fma(-0.125, x, Float64(1.5 / x))) end
code[x_] := N[(1.0 / N[(-0.125 * x + N[(1.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\mathsf{fma}\left(-0.125, x, \frac{1.5}{x}\right)}
\end{array}
Initial program 76.5%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-/r*N/A
clear-numN/A
lift-sin.f64N/A
lift-sin.f64N/A
sin-multN/A
div-invN/A
metadata-evalN/A
frac-2negN/A
neg-mul-1N/A
*-commutativeN/A
Applied rewrites51.7%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
associate-*l/N/A
lift-/.f64N/A
lift-*.f64N/A
inv-powN/A
lower-pow.f6451.7
Applied rewrites99.1%
Taylor expanded in x around 0
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6452.3
Applied rewrites52.3%
Taylor expanded in x around 0
metadata-evalN/A
lft-mult-inverseN/A
associate-*l*N/A
distribute-rgt-inN/A
metadata-evalN/A
sub-negN/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
distribute-rgt-out--N/A
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
cancel-sign-subN/A
Applied rewrites52.4%
(FPCore (x) :precision binary64 (/ (* 0.25 x) 0.375))
double code(double x) {
return (0.25 * x) / 0.375;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (0.25d0 * x) / 0.375d0
end function
public static double code(double x) {
return (0.25 * x) / 0.375;
}
def code(x): return (0.25 * x) / 0.375
function code(x) return Float64(Float64(0.25 * x) / 0.375) end
function tmp = code(x) tmp = (0.25 * x) / 0.375; end
code[x_] := N[(N[(0.25 * x), $MachinePrecision] / 0.375), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.25 \cdot x}{0.375}
\end{array}
Initial program 76.5%
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
associate-/r*N/A
lower-/.f64N/A
Applied rewrites51.7%
Taylor expanded in x around 0
lower-*.f6452.4
Applied rewrites52.4%
(FPCore (x) :precision binary64 (* 0.6666666666666666 x))
double code(double x) {
return 0.6666666666666666 * x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.6666666666666666d0 * x
end function
public static double code(double x) {
return 0.6666666666666666 * x;
}
def code(x): return 0.6666666666666666 * x
function code(x) return Float64(0.6666666666666666 * x) end
function tmp = code(x) tmp = 0.6666666666666666 * x; end
code[x_] := N[(0.6666666666666666 * x), $MachinePrecision]
\begin{array}{l}
\\
0.6666666666666666 \cdot x
\end{array}
Initial program 76.5%
Taylor expanded in x around 0
lower-*.f6452.1
Applied rewrites52.1%
(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 2024332
(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)))