
(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 (/ (tan (/ x 2.0)) 0.75))
double code(double x) {
return tan((x / 2.0)) / 0.75;
}
real(8) function code(x)
real(8), intent (in) :: x
code = tan((x / 2.0d0)) / 0.75d0
end function
public static double code(double x) {
return Math.tan((x / 2.0)) / 0.75;
}
def code(x): return math.tan((x / 2.0)) / 0.75
function code(x) return Float64(tan(Float64(x / 2.0)) / 0.75) end
function tmp = code(x) tmp = tan((x / 2.0)) / 0.75; end
code[x_] := N[(N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision] / 0.75), $MachinePrecision]
\begin{array}{l}
\\
\frac{\tan \left(\frac{x}{2}\right)}{0.75}
\end{array}
Initial program 80.4%
*-commutative80.4%
*-lft-identity80.4%
metadata-eval80.4%
times-frac99.2%
associate-/l*99.2%
*-commutative99.2%
neg-mul-199.2%
sin-neg99.2%
distribute-lft-neg-out99.2%
associate-/l*99.2%
associate-*r/99.3%
Simplified99.3%
associate-/l*80.4%
associate-*l*80.4%
*-commutative80.4%
associate-/l*80.4%
sin-mult58.4%
associate-/l/58.4%
div-inv58.4%
Applied egg-rr58.5%
un-div-inv58.5%
associate-*l*58.5%
associate-/r*58.4%
hang-p0-tan99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (or (<= x -3.2) (not (<= x 3.1))) (* (sin x) 2.6666666666666665) (/ 1.0 (+ (* x -0.125) (* 1.5 (/ 1.0 x))))))
double code(double x) {
double tmp;
if ((x <= -3.2) || !(x <= 3.1)) {
tmp = sin(x) * 2.6666666666666665;
} else {
tmp = 1.0 / ((x * -0.125) + (1.5 * (1.0 / x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-3.2d0)) .or. (.not. (x <= 3.1d0))) then
tmp = sin(x) * 2.6666666666666665d0
else
tmp = 1.0d0 / ((x * (-0.125d0)) + (1.5d0 * (1.0d0 / x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -3.2) || !(x <= 3.1)) {
tmp = Math.sin(x) * 2.6666666666666665;
} else {
tmp = 1.0 / ((x * -0.125) + (1.5 * (1.0 / x)));
}
return tmp;
}
def code(x): tmp = 0 if (x <= -3.2) or not (x <= 3.1): tmp = math.sin(x) * 2.6666666666666665 else: tmp = 1.0 / ((x * -0.125) + (1.5 * (1.0 / x))) return tmp
function code(x) tmp = 0.0 if ((x <= -3.2) || !(x <= 3.1)) tmp = Float64(sin(x) * 2.6666666666666665); else tmp = Float64(1.0 / Float64(Float64(x * -0.125) + Float64(1.5 * Float64(1.0 / x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -3.2) || ~((x <= 3.1))) tmp = sin(x) * 2.6666666666666665; else tmp = 1.0 / ((x * -0.125) + (1.5 * (1.0 / x))); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -3.2], N[Not[LessEqual[x, 3.1]], $MachinePrecision]], N[(N[Sin[x], $MachinePrecision] * 2.6666666666666665), $MachinePrecision], N[(1.0 / N[(N[(x * -0.125), $MachinePrecision] + N[(1.5 * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \lor \neg \left(x \leq 3.1\right):\\
\;\;\;\;\sin x \cdot 2.6666666666666665\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot -0.125 + 1.5 \cdot \frac{1}{x}}\\
\end{array}
\end{array}
if x < -3.2000000000000002 or 3.10000000000000009 < x Initial program 99.1%
*-commutative99.1%
*-lft-identity99.1%
metadata-eval99.1%
times-frac99.0%
associate-/l*99.0%
*-commutative99.0%
neg-mul-199.0%
sin-neg99.0%
distribute-lft-neg-out99.0%
associate-/l*99.0%
associate-*r/99.1%
Simplified99.1%
associate-/l*99.0%
clear-num99.0%
associate-/r/99.0%
Applied egg-rr18.4%
if -3.2000000000000002 < x < 3.10000000000000009Initial program 56.3%
*-commutative56.3%
*-lft-identity56.3%
metadata-eval56.3%
times-frac99.6%
associate-/l*99.6%
*-commutative99.6%
neg-mul-199.6%
sin-neg99.6%
distribute-lft-neg-out99.6%
associate-/l*99.6%
associate-*r/99.5%
Simplified99.5%
associate-/l*56.3%
associate-*l*56.2%
*-commutative56.2%
associate-/l*56.2%
sin-mult6.9%
associate-/l/6.9%
div-inv6.9%
Applied egg-rr6.9%
un-div-inv6.9%
associate-*l*6.9%
associate-/r*6.9%
clear-num6.9%
metadata-eval6.9%
hang-p0-tan99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 99.5%
Final simplification53.9%
(FPCore (x) :precision binary64 (* (tan (/ x 2.0)) 1.3333333333333333))
double code(double x) {
return tan((x / 2.0)) * 1.3333333333333333;
}
real(8) function code(x)
real(8), intent (in) :: x
code = tan((x / 2.0d0)) * 1.3333333333333333d0
end function
public static double code(double x) {
return Math.tan((x / 2.0)) * 1.3333333333333333;
}
def code(x): return math.tan((x / 2.0)) * 1.3333333333333333
function code(x) return Float64(tan(Float64(x / 2.0)) * 1.3333333333333333) end
function tmp = code(x) tmp = tan((x / 2.0)) * 1.3333333333333333; end
code[x_] := N[(N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision] * 1.3333333333333333), $MachinePrecision]
\begin{array}{l}
\\
\tan \left(\frac{x}{2}\right) \cdot 1.3333333333333333
\end{array}
Initial program 80.4%
*-commutative80.4%
*-lft-identity80.4%
metadata-eval80.4%
times-frac99.2%
associate-/l*99.2%
*-commutative99.2%
neg-mul-199.2%
sin-neg99.2%
distribute-lft-neg-out99.2%
associate-/l*99.2%
associate-*r/99.3%
Simplified99.3%
associate-/l*80.4%
associate-*l*80.4%
*-commutative80.4%
associate-/l*80.4%
sin-mult58.4%
associate-/l/58.4%
div-inv58.4%
Applied egg-rr58.5%
Taylor expanded in x around inf 58.5%
hang-p0-tan99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x) :precision binary64 (/ 1.0 (+ (* x -0.125) (* 1.5 (/ 1.0 x)))))
double code(double x) {
return 1.0 / ((x * -0.125) + (1.5 * (1.0 / x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / ((x * (-0.125d0)) + (1.5d0 * (1.0d0 / x)))
end function
public static double code(double x) {
return 1.0 / ((x * -0.125) + (1.5 * (1.0 / x)));
}
def code(x): return 1.0 / ((x * -0.125) + (1.5 * (1.0 / x)))
function code(x) return Float64(1.0 / Float64(Float64(x * -0.125) + Float64(1.5 * Float64(1.0 / x)))) end
function tmp = code(x) tmp = 1.0 / ((x * -0.125) + (1.5 * (1.0 / x))); end
code[x_] := N[(1.0 / N[(N[(x * -0.125), $MachinePrecision] + N[(1.5 * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x \cdot -0.125 + 1.5 \cdot \frac{1}{x}}
\end{array}
Initial program 80.4%
*-commutative80.4%
*-lft-identity80.4%
metadata-eval80.4%
times-frac99.2%
associate-/l*99.2%
*-commutative99.2%
neg-mul-199.2%
sin-neg99.2%
distribute-lft-neg-out99.2%
associate-/l*99.2%
associate-*r/99.3%
Simplified99.3%
associate-/l*80.4%
associate-*l*80.4%
*-commutative80.4%
associate-/l*80.4%
sin-mult58.4%
associate-/l/58.4%
div-inv58.4%
Applied egg-rr58.5%
un-div-inv58.5%
associate-*l*58.5%
associate-/r*58.4%
clear-num58.4%
metadata-eval58.4%
hang-p0-tan99.5%
Applied egg-rr99.5%
Taylor expanded in x around 0 45.7%
Final simplification45.7%
(FPCore (x) :precision binary64 (/ 1.0 (/ 1.5 x)))
double code(double x) {
return 1.0 / (1.5 / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (1.5d0 / x)
end function
public static double code(double x) {
return 1.0 / (1.5 / x);
}
def code(x): return 1.0 / (1.5 / x)
function code(x) return Float64(1.0 / Float64(1.5 / x)) end
function tmp = code(x) tmp = 1.0 / (1.5 / x); end
code[x_] := N[(1.0 / N[(1.5 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{1.5}{x}}
\end{array}
Initial program 80.4%
*-commutative80.4%
*-lft-identity80.4%
metadata-eval80.4%
times-frac99.2%
associate-/l*99.2%
*-commutative99.2%
neg-mul-199.2%
sin-neg99.2%
distribute-lft-neg-out99.2%
associate-/l*99.2%
associate-*r/99.3%
Simplified99.3%
associate-/l*80.4%
associate-*l*80.4%
*-commutative80.4%
associate-/l*80.4%
sin-mult58.4%
associate-/l/58.4%
div-inv58.4%
Applied egg-rr58.5%
un-div-inv58.5%
associate-*l*58.5%
associate-/r*58.4%
clear-num58.4%
metadata-eval58.4%
hang-p0-tan99.5%
Applied egg-rr99.5%
Taylor expanded in x around 0 45.3%
Final simplification45.3%
(FPCore (x) :precision binary64 (/ (* x 0.5) 0.75))
double code(double x) {
return (x * 0.5) / 0.75;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * 0.5d0) / 0.75d0
end function
public static double code(double x) {
return (x * 0.5) / 0.75;
}
def code(x): return (x * 0.5) / 0.75
function code(x) return Float64(Float64(x * 0.5) / 0.75) end
function tmp = code(x) tmp = (x * 0.5) / 0.75; end
code[x_] := N[(N[(x * 0.5), $MachinePrecision] / 0.75), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot 0.5}{0.75}
\end{array}
Initial program 80.4%
*-commutative80.4%
*-lft-identity80.4%
metadata-eval80.4%
times-frac99.2%
associate-/l*99.2%
*-commutative99.2%
neg-mul-199.2%
sin-neg99.2%
distribute-lft-neg-out99.2%
associate-/l*99.2%
associate-*r/99.3%
Simplified99.3%
associate-/l*80.4%
associate-*l*80.4%
*-commutative80.4%
associate-/l*80.4%
sin-mult58.4%
associate-/l/58.4%
div-inv58.4%
Applied egg-rr58.5%
un-div-inv58.5%
associate-*l*58.5%
associate-/r*58.4%
hang-p0-tan99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 45.4%
*-commutative45.4%
Simplified45.4%
Final simplification45.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 80.4%
*-commutative80.4%
*-lft-identity80.4%
metadata-eval80.4%
times-frac99.2%
associate-/l*99.2%
*-commutative99.2%
neg-mul-199.2%
sin-neg99.2%
distribute-lft-neg-out99.2%
associate-/l*99.2%
associate-*r/99.3%
Simplified99.3%
Taylor expanded in x around 0 45.2%
*-commutative45.2%
Simplified45.2%
Final simplification45.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 2023297
(FPCore (x)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, A"
:precision binary64
:herbie-target
(/ (/ (* 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)))