
(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 5 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_0 (* 0.375 (/ (sin x) t_0)))))
double code(double x) {
double t_0 = sin((x * -0.5));
return t_0 / (0.375 * (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 = t_0 / (0.375d0 * (sin(x) / t_0))
end function
public static double code(double x) {
double t_0 = Math.sin((x * -0.5));
return t_0 / (0.375 * (Math.sin(x) / t_0));
}
def code(x): t_0 = math.sin((x * -0.5)) return t_0 / (0.375 * (math.sin(x) / t_0))
function code(x) t_0 = sin(Float64(x * -0.5)) return Float64(t_0 / Float64(0.375 * Float64(sin(x) / t_0))) end
function tmp = code(x) t_0 = sin((x * -0.5)); tmp = t_0 / (0.375 * (sin(x) / t_0)); end
code[x_] := Block[{t$95$0 = N[Sin[N[(x * -0.5), $MachinePrecision]], $MachinePrecision]}, N[(t$95$0 / N[(0.375 * N[(N[Sin[x], $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(x \cdot -0.5\right)\\
\frac{t_0}{0.375 \cdot \frac{\sin x}{t_0}}
\end{array}
\end{array}
Initial program 78.7%
associate-/l*99.2%
associate-*r/99.3%
metadata-eval99.3%
remove-double-neg99.3%
sin-neg99.3%
distribute-lft-neg-out99.3%
neg-mul-199.3%
*-commutative99.3%
associate-/l*99.3%
distribute-lft-neg-out99.3%
distribute-rgt-neg-in99.3%
metadata-eval99.3%
associate-/l/99.3%
neg-mul-199.3%
sin-neg99.3%
distribute-rgt-neg-in99.3%
metadata-eval99.3%
Simplified99.3%
associate-*r/99.2%
associate-/l*78.7%
*-commutative78.7%
associate-/l*99.2%
*-un-lft-identity99.2%
times-frac99.5%
metadata-eval99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (x) :precision binary64 (if (or (<= x -8800000000000.0) (not (<= x 1.5e+17))) (* (sin (* x -0.5)) 1.3333333333333333) (* x 0.6666666666666666)))
double code(double x) {
double tmp;
if ((x <= -8800000000000.0) || !(x <= 1.5e+17)) {
tmp = sin((x * -0.5)) * 1.3333333333333333;
} else {
tmp = x * 0.6666666666666666;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-8800000000000.0d0)) .or. (.not. (x <= 1.5d+17))) then
tmp = sin((x * (-0.5d0))) * 1.3333333333333333d0
else
tmp = x * 0.6666666666666666d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -8800000000000.0) || !(x <= 1.5e+17)) {
tmp = Math.sin((x * -0.5)) * 1.3333333333333333;
} else {
tmp = x * 0.6666666666666666;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -8800000000000.0) or not (x <= 1.5e+17): tmp = math.sin((x * -0.5)) * 1.3333333333333333 else: tmp = x * 0.6666666666666666 return tmp
function code(x) tmp = 0.0 if ((x <= -8800000000000.0) || !(x <= 1.5e+17)) tmp = Float64(sin(Float64(x * -0.5)) * 1.3333333333333333); else tmp = Float64(x * 0.6666666666666666); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -8800000000000.0) || ~((x <= 1.5e+17))) tmp = sin((x * -0.5)) * 1.3333333333333333; else tmp = x * 0.6666666666666666; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -8800000000000.0], N[Not[LessEqual[x, 1.5e+17]], $MachinePrecision]], N[(N[Sin[N[(x * -0.5), $MachinePrecision]], $MachinePrecision] * 1.3333333333333333), $MachinePrecision], N[(x * 0.6666666666666666), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8800000000000 \lor \neg \left(x \leq 1.5 \cdot 10^{+17}\right):\\
\;\;\;\;\sin \left(x \cdot -0.5\right) \cdot 1.3333333333333333\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.6666666666666666\\
\end{array}
\end{array}
if x < -8.8e12 or 1.5e17 < x Initial program 99.0%
associate-/l*99.0%
*-lft-identity99.0%
metadata-eval99.0%
times-frac99.0%
neg-mul-199.0%
sin-neg99.0%
associate-/r*99.0%
associate-/r/99.0%
Simplified99.0%
Taylor expanded in x around 0 10.7%
expm1-log1p-u7.4%
expm1-udef7.4%
*-commutative7.4%
add-sqr-sqrt4.9%
sqrt-unprod5.0%
swap-sqr5.0%
metadata-eval5.0%
metadata-eval5.0%
swap-sqr5.0%
sqrt-unprod5.3%
add-sqr-sqrt10.3%
Applied egg-rr10.3%
expm1-def10.3%
expm1-log1p12.1%
*-commutative12.1%
Simplified12.1%
if -8.8e12 < x < 1.5e17Initial program 57.7%
associate-/l*99.5%
associate-*r/99.5%
metadata-eval99.5%
remove-double-neg99.5%
sin-neg99.5%
distribute-lft-neg-out99.5%
neg-mul-199.5%
*-commutative99.5%
associate-/l*99.5%
distribute-lft-neg-out99.5%
distribute-rgt-neg-in99.5%
metadata-eval99.5%
associate-/l/99.5%
neg-mul-199.5%
sin-neg99.5%
distribute-rgt-neg-in99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in x around 0 92.9%
Final simplification51.9%
(FPCore (x) :precision binary64 (* 1.3333333333333333 (sin (* x 0.5))))
double code(double x) {
return 1.3333333333333333 * sin((x * 0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.3333333333333333d0 * sin((x * 0.5d0))
end function
public static double code(double x) {
return 1.3333333333333333 * Math.sin((x * 0.5));
}
def code(x): return 1.3333333333333333 * math.sin((x * 0.5))
function code(x) return Float64(1.3333333333333333 * sin(Float64(x * 0.5))) end
function tmp = code(x) tmp = 1.3333333333333333 * sin((x * 0.5)); end
code[x_] := N[(1.3333333333333333 * N[Sin[N[(x * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1.3333333333333333 \cdot \sin \left(x \cdot 0.5\right)
\end{array}
Initial program 78.7%
associate-/l*99.2%
*-lft-identity99.2%
metadata-eval99.2%
times-frac99.2%
neg-mul-199.2%
sin-neg99.2%
associate-/r*99.2%
associate-/r/99.2%
Simplified99.2%
Taylor expanded in x around 0 51.2%
Final simplification51.2%
(FPCore (x) :precision binary64 (* 1.3333333333333333 (tan (/ x 2.0))))
double code(double x) {
return 1.3333333333333333 * tan((x / 2.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.3333333333333333d0 * tan((x / 2.0d0))
end function
public static double code(double x) {
return 1.3333333333333333 * Math.tan((x / 2.0));
}
def code(x): return 1.3333333333333333 * math.tan((x / 2.0))
function code(x) return Float64(1.3333333333333333 * tan(Float64(x / 2.0))) end
function tmp = code(x) tmp = 1.3333333333333333 * tan((x / 2.0)); end
code[x_] := N[(1.3333333333333333 * N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1.3333333333333333 \cdot \tan \left(\frac{x}{2}\right)
\end{array}
Initial program 78.7%
associate-/l*99.2%
*-lft-identity99.2%
metadata-eval99.2%
times-frac99.2%
neg-mul-199.2%
sin-neg99.2%
associate-/r*99.2%
associate-/r/99.2%
Simplified99.2%
Taylor expanded in x around inf 78.7%
*-commutative78.7%
associate-*l/78.7%
*-commutative78.7%
Simplified78.7%
unpow278.7%
sqr-sin-a56.5%
add-sqr-sqrt16.6%
sqrt-unprod30.7%
swap-sqr30.7%
metadata-eval30.7%
metadata-eval30.7%
swap-sqr30.7%
sqrt-unprod17.2%
add-sqr-sqrt56.5%
sqr-sin-a78.7%
sin-mult56.5%
Applied egg-rr56.5%
+-inverses56.5%
cos-056.5%
distribute-lft-out56.5%
metadata-eval56.5%
*-commutative56.5%
neg-mul-156.5%
Simplified56.5%
Taylor expanded in x around inf 56.5%
neg-mul-156.5%
div-sub56.4%
neg-mul-156.4%
cos-neg56.4%
div-sub56.5%
hang-p0-tan99.5%
Simplified99.5%
Final simplification99.5%
(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 78.7%
associate-/l*99.2%
associate-*r/99.3%
metadata-eval99.3%
remove-double-neg99.3%
sin-neg99.3%
distribute-lft-neg-out99.3%
neg-mul-199.3%
*-commutative99.3%
associate-/l*99.3%
distribute-lft-neg-out99.3%
distribute-rgt-neg-in99.3%
metadata-eval99.3%
associate-/l/99.3%
neg-mul-199.3%
sin-neg99.3%
distribute-rgt-neg-in99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in x around 0 47.2%
Final simplification47.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 2023320
(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)))