
(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 74.4%
clear-numN/A
associate-*l*N/A
associate-/r*N/A
clear-numN/A
sin-multN/A
div-invN/A
metadata-evalN/A
frac-2negN/A
neg-mul-1N/A
*-commutativeN/A
associate-/l*N/A
times-fracN/A
Applied egg-rr51.5%
Taylor expanded in x around inf
hang-p0-tanN/A
*-rgt-identityN/A
associate-/l*N/A
metadata-evalN/A
*-commutativeN/A
tan-lowering-tan.f64N/A
*-commutativeN/A
*-lowering-*.f6499.4
Simplified99.4%
tan-quotN/A
associate-*l/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f64N/A
*-lowering-*.f64N/A
cos-lowering-cos.f64N/A
*-lowering-*.f6499.4
Applied egg-rr99.4%
associate-*l/N/A
div-invN/A
div-invN/A
tan-quotN/A
metadata-evalN/A
div-invN/A
hang-p0-tanN/A
metadata-evalN/A
div-invN/A
hang-p0-tanN/A
div-invN/A
metadata-evalN/A
/-lowering-/.f64N/A
tan-lowering-tan.f64N/A
*-lowering-*.f6499.8
Applied egg-rr99.8%
(FPCore (x) :precision binary64 (* (tan (* x 0.5)) 1.3333333333333333))
double code(double x) {
return tan((x * 0.5)) * 1.3333333333333333;
}
real(8) function code(x)
real(8), intent (in) :: x
code = tan((x * 0.5d0)) * 1.3333333333333333d0
end function
public static double code(double x) {
return Math.tan((x * 0.5)) * 1.3333333333333333;
}
def code(x): return math.tan((x * 0.5)) * 1.3333333333333333
function code(x) return Float64(tan(Float64(x * 0.5)) * 1.3333333333333333) end
function tmp = code(x) tmp = tan((x * 0.5)) * 1.3333333333333333; end
code[x_] := N[(N[Tan[N[(x * 0.5), $MachinePrecision]], $MachinePrecision] * 1.3333333333333333), $MachinePrecision]
\begin{array}{l}
\\
\tan \left(x \cdot 0.5\right) \cdot 1.3333333333333333
\end{array}
Initial program 74.4%
clear-numN/A
associate-*l*N/A
associate-/r*N/A
clear-numN/A
sin-multN/A
div-invN/A
metadata-evalN/A
frac-2negN/A
neg-mul-1N/A
*-commutativeN/A
associate-/l*N/A
times-fracN/A
Applied egg-rr51.5%
Taylor expanded in x around inf
hang-p0-tanN/A
*-rgt-identityN/A
associate-/l*N/A
metadata-evalN/A
*-commutativeN/A
tan-lowering-tan.f64N/A
*-commutativeN/A
*-lowering-*.f6499.4
Simplified99.4%
(FPCore (x)
:precision binary64
(*
1.3333333333333333
(/
1.0
(/
(fma
(* x x)
(fma
(* x x)
(fma x (* x -6.613756613756614e-5) -0.002777777777777778)
-0.16666666666666666)
2.0)
x))))
double code(double x) {
return 1.3333333333333333 * (1.0 / (fma((x * x), fma((x * x), fma(x, (x * -6.613756613756614e-5), -0.002777777777777778), -0.16666666666666666), 2.0) / x));
}
function code(x) return Float64(1.3333333333333333 * Float64(1.0 / Float64(fma(Float64(x * x), fma(Float64(x * x), fma(x, Float64(x * -6.613756613756614e-5), -0.002777777777777778), -0.16666666666666666), 2.0) / x))) end
code[x_] := N[(1.3333333333333333 * N[(1.0 / N[(N[(N[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * N[(x * N[(x * -6.613756613756614e-5), $MachinePrecision] + -0.002777777777777778), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] + 2.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1.3333333333333333 \cdot \frac{1}{\frac{\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, x \cdot -6.613756613756614 \cdot 10^{-5}, -0.002777777777777778\right), -0.16666666666666666\right), 2\right)}{x}}
\end{array}
Initial program 74.4%
clear-numN/A
associate-*l*N/A
associate-/r*N/A
clear-numN/A
sin-multN/A
div-invN/A
metadata-evalN/A
frac-2negN/A
neg-mul-1N/A
*-commutativeN/A
associate-/l*N/A
times-fracN/A
Applied egg-rr51.5%
Taylor expanded in x around inf
hang-p0-tanN/A
*-rgt-identityN/A
associate-/l*N/A
metadata-evalN/A
*-commutativeN/A
tan-lowering-tan.f64N/A
*-commutativeN/A
*-lowering-*.f6499.4
Simplified99.4%
tan-quotN/A
clear-numN/A
/-lowering-/.f64N/A
clear-numN/A
tan-quotN/A
/-lowering-/.f64N/A
tan-lowering-tan.f64N/A
*-lowering-*.f6499.4
Applied egg-rr99.4%
Taylor expanded in x around 0
/-lowering-/.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f64N/A
sub-negN/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6452.7
Simplified52.7%
Final simplification52.7%
(FPCore (x) :precision binary64 (* 1.3333333333333333 (/ 1.0 (/ (fma x (* x -0.16666666666666666) 2.0) x))))
double code(double x) {
return 1.3333333333333333 * (1.0 / (fma(x, (x * -0.16666666666666666), 2.0) / x));
}
function code(x) return Float64(1.3333333333333333 * Float64(1.0 / Float64(fma(x, Float64(x * -0.16666666666666666), 2.0) / x))) end
code[x_] := N[(1.3333333333333333 * N[(1.0 / N[(N[(x * N[(x * -0.16666666666666666), $MachinePrecision] + 2.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1.3333333333333333 \cdot \frac{1}{\frac{\mathsf{fma}\left(x, x \cdot -0.16666666666666666, 2\right)}{x}}
\end{array}
Initial program 74.4%
clear-numN/A
associate-*l*N/A
associate-/r*N/A
clear-numN/A
sin-multN/A
div-invN/A
metadata-evalN/A
frac-2negN/A
neg-mul-1N/A
*-commutativeN/A
associate-/l*N/A
times-fracN/A
Applied egg-rr51.5%
Taylor expanded in x around inf
hang-p0-tanN/A
*-rgt-identityN/A
associate-/l*N/A
metadata-evalN/A
*-commutativeN/A
tan-lowering-tan.f64N/A
*-commutativeN/A
*-lowering-*.f6499.4
Simplified99.4%
tan-quotN/A
clear-numN/A
/-lowering-/.f64N/A
clear-numN/A
tan-quotN/A
/-lowering-/.f64N/A
tan-lowering-tan.f64N/A
*-lowering-*.f6499.4
Applied egg-rr99.4%
Taylor expanded in x around 0
/-lowering-/.f64N/A
+-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6452.7
Simplified52.7%
Final simplification52.7%
(FPCore (x) :precision binary64 (/ (* x 0.25) 0.375))
double code(double x) {
return (x * 0.25) / 0.375;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * 0.25d0) / 0.375d0
end function
public static double code(double x) {
return (x * 0.25) / 0.375;
}
def code(x): return (x * 0.25) / 0.375
function code(x) return Float64(Float64(x * 0.25) / 0.375) end
function tmp = code(x) tmp = (x * 0.25) / 0.375; end
code[x_] := N[(N[(x * 0.25), $MachinePrecision] / 0.375), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot 0.25}{0.375}
\end{array}
Initial program 74.4%
clear-numN/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
/-lowering-/.f64N/A
Applied egg-rr51.5%
Taylor expanded in x around 0
*-commutativeN/A
*-lowering-*.f6452.4
Simplified52.4%
(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 74.4%
Taylor expanded in x around 0
*-lowering-*.f6452.1
Simplified52.1%
Final simplification52.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 2024205
(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)))