
(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 (/ (sin (* x 0.5)) (* (cos (* x 0.5)) 0.75)))
double code(double x) {
return sin((x * 0.5)) / (cos((x * 0.5)) * 0.75);
}
real(8) function code(x)
real(8), intent (in) :: x
code = sin((x * 0.5d0)) / (cos((x * 0.5d0)) * 0.75d0)
end function
public static double code(double x) {
return Math.sin((x * 0.5)) / (Math.cos((x * 0.5)) * 0.75);
}
def code(x): return math.sin((x * 0.5)) / (math.cos((x * 0.5)) * 0.75)
function code(x) return Float64(sin(Float64(x * 0.5)) / Float64(cos(Float64(x * 0.5)) * 0.75)) end
function tmp = code(x) tmp = sin((x * 0.5)) / (cos((x * 0.5)) * 0.75); end
code[x_] := N[(N[Sin[N[(x * 0.5), $MachinePrecision]], $MachinePrecision] / N[(N[Cos[N[(x * 0.5), $MachinePrecision]], $MachinePrecision] * 0.75), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin \left(x \cdot 0.5\right)}{\cos \left(x \cdot 0.5\right) \cdot 0.75}
\end{array}
Initial program 78.6%
associate-*r/99.2%
associate-*l*99.2%
metadata-eval99.2%
Simplified99.2%
associate-*r/78.6%
associate-*r/78.6%
expm1-log1p-u66.1%
associate-*l/66.0%
expm1-udef43.8%
Applied egg-rr43.0%
expm1-def43.0%
expm1-log1p55.5%
associate-*r/55.5%
associate-*l/55.5%
metadata-eval55.5%
metadata-eval55.5%
distribute-lft-neg-in55.5%
distribute-rgt-neg-in55.5%
distribute-lft-in55.5%
sub-neg55.5%
cos-055.5%
metadata-eval55.5%
associate-/r/55.4%
associate-/l*55.5%
*-lft-identity55.5%
times-frac55.5%
*-commutative55.5%
times-frac55.5%
metadata-eval55.5%
Simplified99.5%
Taylor expanded in x around inf 99.3%
associate-*r/99.4%
*-commutative99.4%
*-commutative99.4%
associate-/l*99.3%
associate-/r/99.4%
Simplified99.4%
*-commutative99.4%
clear-num99.4%
un-div-inv99.6%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x) :precision binary64 (/ 1.0 (/ 0.75 (tan (* x 0.5)))))
double code(double x) {
return 1.0 / (0.75 / tan((x * 0.5)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (0.75d0 / tan((x * 0.5d0)))
end function
public static double code(double x) {
return 1.0 / (0.75 / Math.tan((x * 0.5)));
}
def code(x): return 1.0 / (0.75 / math.tan((x * 0.5)))
function code(x) return Float64(1.0 / Float64(0.75 / tan(Float64(x * 0.5)))) end
function tmp = code(x) tmp = 1.0 / (0.75 / tan((x * 0.5))); end
code[x_] := N[(1.0 / N[(0.75 / N[Tan[N[(x * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{0.75}{\tan \left(x \cdot 0.5\right)}}
\end{array}
Initial program 78.6%
associate-*r/99.2%
associate-*l*99.2%
metadata-eval99.2%
Simplified99.2%
associate-*r/78.6%
associate-*r/78.6%
expm1-log1p-u66.1%
associate-*l/66.0%
expm1-udef43.8%
Applied egg-rr43.0%
expm1-def43.0%
expm1-log1p55.5%
associate-*r/55.5%
associate-*l/55.5%
metadata-eval55.5%
metadata-eval55.5%
distribute-lft-neg-in55.5%
distribute-rgt-neg-in55.5%
distribute-lft-in55.5%
sub-neg55.5%
cos-055.5%
metadata-eval55.5%
associate-/r/55.4%
associate-/l*55.5%
*-lft-identity55.5%
times-frac55.5%
*-commutative55.5%
times-frac55.5%
metadata-eval55.5%
Simplified99.5%
Taylor expanded in x around inf 99.3%
associate-*r/99.4%
*-commutative99.4%
*-commutative99.4%
associate-/l*99.3%
associate-/r/99.4%
Simplified99.4%
associate-*l/99.4%
clear-num99.2%
*-commutative99.2%
Applied egg-rr99.2%
expm1-log1p-u62.0%
expm1-udef61.6%
*-un-lft-identity61.6%
*-commutative61.6%
times-frac61.7%
metadata-eval61.7%
metadata-eval61.7%
times-frac61.6%
*-un-lft-identity61.6%
associate-/l*61.7%
tan-quot61.6%
Applied egg-rr61.6%
expm1-def62.1%
expm1-log1p99.5%
Simplified99.5%
Final simplification99.5%
(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.6%
associate-*r/99.2%
associate-*l*99.2%
metadata-eval99.2%
Simplified99.2%
associate-*r/78.6%
associate-*r/78.6%
expm1-log1p-u66.1%
associate-*l/66.0%
expm1-udef43.8%
Applied egg-rr43.0%
expm1-def43.0%
expm1-log1p55.5%
associate-*r/55.5%
associate-*l/55.5%
metadata-eval55.5%
metadata-eval55.5%
distribute-lft-neg-in55.5%
distribute-rgt-neg-in55.5%
distribute-lft-in55.5%
sub-neg55.5%
cos-055.5%
metadata-eval55.5%
associate-/r/55.4%
associate-/l*55.5%
*-lft-identity55.5%
times-frac55.5%
*-commutative55.5%
times-frac55.5%
metadata-eval55.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x) :precision binary64 (* 1.3333333333333333 (/ 1.0 (+ (* x -0.16666666666666666) (* 2.0 (/ 1.0 x))))))
double code(double x) {
return 1.3333333333333333 * (1.0 / ((x * -0.16666666666666666) + (2.0 * (1.0 / x))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.3333333333333333d0 * (1.0d0 / ((x * (-0.16666666666666666d0)) + (2.0d0 * (1.0d0 / x))))
end function
public static double code(double x) {
return 1.3333333333333333 * (1.0 / ((x * -0.16666666666666666) + (2.0 * (1.0 / x))));
}
def code(x): return 1.3333333333333333 * (1.0 / ((x * -0.16666666666666666) + (2.0 * (1.0 / x))))
function code(x) return Float64(1.3333333333333333 * Float64(1.0 / Float64(Float64(x * -0.16666666666666666) + Float64(2.0 * Float64(1.0 / x))))) end
function tmp = code(x) tmp = 1.3333333333333333 * (1.0 / ((x * -0.16666666666666666) + (2.0 * (1.0 / x)))); end
code[x_] := N[(1.3333333333333333 * N[(1.0 / N[(N[(x * -0.16666666666666666), $MachinePrecision] + N[(2.0 * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1.3333333333333333 \cdot \frac{1}{x \cdot -0.16666666666666666 + 2 \cdot \frac{1}{x}}
\end{array}
Initial program 78.6%
associate-*r/99.2%
associate-*l*99.2%
metadata-eval99.2%
Simplified99.2%
associate-*r/78.6%
associate-*r/78.6%
expm1-log1p-u66.1%
associate-*l/66.0%
expm1-udef43.8%
Applied egg-rr43.0%
expm1-def43.0%
expm1-log1p55.5%
associate-*r/55.5%
associate-*l/55.5%
metadata-eval55.5%
metadata-eval55.5%
distribute-lft-neg-in55.5%
distribute-rgt-neg-in55.5%
distribute-lft-in55.5%
sub-neg55.5%
cos-055.5%
metadata-eval55.5%
associate-/r/55.4%
associate-/l*55.5%
*-lft-identity55.5%
times-frac55.5%
*-commutative55.5%
times-frac55.5%
metadata-eval55.5%
Simplified99.5%
tan-quot99.3%
div-inv99.3%
metadata-eval99.3%
clear-num99.3%
div-inv99.3%
metadata-eval99.3%
Applied egg-rr99.3%
Taylor expanded in x around 0 49.0%
Final simplification49.0%
(FPCore (x) :precision binary64 (/ 1.0 (+ (* x -0.125) (* (/ 1.0 x) 1.5))))
double code(double x) {
return 1.0 / ((x * -0.125) + ((1.0 / x) * 1.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / ((x * (-0.125d0)) + ((1.0d0 / x) * 1.5d0))
end function
public static double code(double x) {
return 1.0 / ((x * -0.125) + ((1.0 / x) * 1.5));
}
def code(x): return 1.0 / ((x * -0.125) + ((1.0 / x) * 1.5))
function code(x) return Float64(1.0 / Float64(Float64(x * -0.125) + Float64(Float64(1.0 / x) * 1.5))) end
function tmp = code(x) tmp = 1.0 / ((x * -0.125) + ((1.0 / x) * 1.5)); end
code[x_] := N[(1.0 / N[(N[(x * -0.125), $MachinePrecision] + N[(N[(1.0 / x), $MachinePrecision] * 1.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x \cdot -0.125 + \frac{1}{x} \cdot 1.5}
\end{array}
Initial program 78.6%
associate-*r/99.2%
associate-*l*99.2%
metadata-eval99.2%
Simplified99.2%
associate-*r/78.6%
associate-*r/78.6%
expm1-log1p-u66.1%
associate-*l/66.0%
expm1-udef43.8%
Applied egg-rr43.0%
expm1-def43.0%
expm1-log1p55.5%
associate-*r/55.5%
associate-*l/55.5%
metadata-eval55.5%
metadata-eval55.5%
distribute-lft-neg-in55.5%
distribute-rgt-neg-in55.5%
distribute-lft-in55.5%
sub-neg55.5%
cos-055.5%
metadata-eval55.5%
associate-/r/55.4%
associate-/l*55.5%
*-lft-identity55.5%
times-frac55.5%
*-commutative55.5%
times-frac55.5%
metadata-eval55.5%
Simplified99.5%
Taylor expanded in x around inf 99.3%
associate-*r/99.4%
*-commutative99.4%
*-commutative99.4%
associate-/l*99.3%
associate-/r/99.4%
Simplified99.4%
associate-*l/99.4%
clear-num99.2%
*-commutative99.2%
Applied egg-rr99.2%
Taylor expanded in x around 0 49.0%
Final simplification49.0%
(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 78.6%
associate-*r/99.2%
associate-*l*99.2%
metadata-eval99.2%
Simplified99.2%
associate-*r/78.6%
associate-*r/78.6%
expm1-log1p-u66.1%
associate-*l/66.0%
expm1-udef43.8%
Applied egg-rr43.0%
expm1-def43.0%
expm1-log1p55.5%
associate-*r/55.5%
associate-*l/55.5%
metadata-eval55.5%
metadata-eval55.5%
distribute-lft-neg-in55.5%
distribute-rgt-neg-in55.5%
distribute-lft-in55.5%
sub-neg55.5%
cos-055.5%
metadata-eval55.5%
associate-/r/55.4%
associate-/l*55.5%
*-lft-identity55.5%
times-frac55.5%
*-commutative55.5%
times-frac55.5%
metadata-eval55.5%
Simplified99.5%
Taylor expanded in x around inf 99.3%
associate-*r/99.4%
*-commutative99.4%
*-commutative99.4%
associate-/l*99.3%
associate-/r/99.4%
Simplified99.4%
associate-*l/99.4%
clear-num99.2%
*-commutative99.2%
Applied egg-rr99.2%
Taylor expanded in x around 0 48.1%
Final simplification48.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 78.6%
associate-*r/99.2%
associate-*l*99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in x around 0 48.1%
Final simplification48.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 2023230
(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)))