@@ -27,13 +27,14 @@ split(d::SegmentDomain, pts) = d
2727function splitatroots (f:: Fun )
2828 d= domain (f)
2929 pts= union (roots (f)) # union removes multiplicities
30- splitmap (x -> f (x) ,d,pts)
30+ splitmap (f ,d,pts)
3131end
3232
33- function abs (f:: Fun{S,T} ) where {S <: RealUnivariateSpace ,T <: Real }
33+ function abs (f:: Fun{<:RealUnivariateSpace,<:Real} )
3434 d= domain (f)
35+ T = cfstype (f)
3536 pts = iszero (f) ? T[] : roots (f)
36- splitmap (x -> abs ( f (x)) ,d,pts)
37+ splitmap (abs∘ f ,d,pts)
3738end
3839
3940function abs (f:: Fun )
@@ -58,9 +59,9 @@ _UnionDomainIfMultiple(d::IntervalOrSegment) = d
5859_UnionDomainIfMultiple (d) = UnionDomain (components (d))
5960
6061for OP in (:sign ,:angle )
61- @eval function $OP (f:: Fun{S,T} ) where {S <: RealUnivariateSpace ,T <: Real }
62+ @eval function $OP (f:: Fun{<:RealUnivariateSpace,<:Real} )
6263 d= domain (f)
63-
64+ T = cfstype (f)
6465 pts = iszero (f) ? T[] : roots (f)
6566
6667 if isempty (pts)
7576
7677for op in (:(max),:(min))
7778 @eval begin
78- function $op (f:: Fun{S,T1} ,g:: Fun{V,T2} ) where {S<: RealUnivariateSpace ,V<: RealUnivariateSpace ,T1<: Real ,T2<: Real }
79+ function $op (f:: Fun{<:RealUnivariateSpace,<:Real} ,
80+ g:: Fun{<:RealUnivariateSpace,<:Real} )
7981 h= f- g
8082 d= domain (h)
8183 pts= iszero (h) ? cfstype (h)[] : roots (h)
8284 splitmap (x-> $ op (f (x),g (x)),d,pts)
8385 end
84- $ op (f:: Fun{S,T} ,g :: Real ) where {S <: RealUnivariateSpace ,T <: Real } = $ op (f,Fun (g,domain (f)))
85- $ op (f:: Real ,g:: Fun{S,T} ) where {S <: RealUnivariateSpace ,T <: Real } = $ op (Fun (f,domain (g)),g)
86+ $ op (f:: Fun{<:RealUnivariateSpace,<:Real} ,g :: Real ) = $ op (f,Fun (g,domain (f)))
87+ $ op (f:: Real ,g:: Fun{<:RealUnivariateSpace,<:Real} ) = $ op (Fun (f,domain (g)),g)
8688 end
8789end
8890
@@ -125,8 +127,8 @@ function ^(f::Fun, β)
125127 [B;A]\ [first (f)^ β;0 ]
126128end
127129
128- sqrt (f:: Fun{S,T} ) where {S,T} = f^ 0.5
129- cbrt (f:: Fun{S,T} ) where {S,T} = f^ (1 / 3 )
130+ sqrt (f:: Fun ) = f^ 0.5
131+ cbrt (f:: Fun ) = f^ (1 / 3 )
130132
131133# # We use \ as the Fun constructor might miss isolated features
132134
@@ -210,9 +212,10 @@ for (op,ODE,RHS,growth) in ((:(erf),"f'*D^2+(2f*f'^2-f'')*D","0",:(imag)),
210212 (:(airybiprime)," f'*D^2-f''*D-f*f'^3" ," airybi(f)*f'^3" ,:(imag)))
211213 L,R = Meta. parse (ODE),Meta. parse (RHS)
212214 @eval begin
213- function $op (fin:: Fun{S,T} ) where {S,T}
215+ function $op (fin:: Fun )
214216 f= setcanonicaldomain (fin)
215217
218+ T = cfstype (fin)
216219 g= chop ($ growth (f),eps (T))
217220 xmin = isempty (g. coefficients) ? leftendpoint (domain (g)) : argmin (g)
218221 xmax = isempty (g. coefficients) ? rightendpoint (domain (g)) : argmax (g)
@@ -291,11 +294,11 @@ end
291294
292295besselh (ν,k:: Integer ,f:: Fun ) = k == 1 ? hankelh1 (ν,f) : k == 2 ? hankelh2 (ν,f) : throw (Base. Math. AmosException (1 ))
293296
294- for jy in (" j " , " y " ), ν in ( 0 , 1 )
295- bjy = Symbol (string ( " bessel" ,jy) )
296- bjynu = Meta . parse ( string ( " SpecialFunctions.bessel " ,jy,ν) )
297- @eval begin
298- $ bjynu (f:: Fun ) = $ bjy ($ ν,f)
297+ for jy in (:j , :y )
298+ bjy = Symbol (: bessel, jy )
299+ for ν in ( 0 , 1 )
300+ bjynu = Symbol (bjy, ν)
301+ @eval SpecialFunctions. $ bjynu (f:: Fun ) = $ bjy ($ ν,f)
299302 end
300303end
301304
@@ -305,7 +308,7 @@ for op in (:(expm1),:(log1p),:(lfact),:(sinc),:(cosc),
305308 :(eta),:(zeta),:(gamma),:(lgamma),
306309 :(polygamma),:(invdigamma),:(digamma),:(trigamma))
307310 @eval begin
308- $ op (f:: Fun{S,T} ) where {S,T} = Fun ($ op ∘ f,domain (f))
311+ $ op (f:: Fun ) = Fun ($ op ∘ f,domain (f))
309312 end
310313end
311314
@@ -378,9 +381,9 @@ for op in (:(<=),)
378381 end
379382end
380383
381- / (c:: Number ,f:: Fun{S} ) where {S <: PiecewiseSpace } = Fun (map (f-> c/ f,components (f)),PiecewiseSpace)
382- ^ (f:: Fun{S } ,c:: Integer ) where {S <: PiecewiseSpace } = Fun (map (f-> f^ c,components (f)),PiecewiseSpace)
383- ^ (f:: Fun{S } ,c:: Number ) where {S <: PiecewiseSpace } = Fun (map (f-> f^ c,components (f)),PiecewiseSpace)
384+ / (c:: Number ,f:: Fun{<:PiecewiseSpace} ) = Fun (map (f-> c/ f,components (f)),PiecewiseSpace)
385+ ^ (f:: Fun{<:PiecewiseSpace } ,c:: Integer ) = Fun (map (f-> f^ c,components (f)),PiecewiseSpace)
386+ ^ (f:: Fun{<:PiecewiseSpace } ,c:: Number ) = Fun (map (f-> f^ c,components (f)),PiecewiseSpace)
384387
385388for OP in (:abs ,:sign ,:log ,:angle )
386389 @eval begin
@@ -431,19 +434,19 @@ end
431434
432435for OP in (:< ,:(Base. isless),:(<= ))
433436 @eval begin
434- $ OP (a:: Fun{CS } ,b:: Fun{CS} ) where {CS <: ConstantSpace } = $ OP (convert (Number,a),Number (b))
435- $ OP (a:: Fun{CS } ,b:: Number ) where {CS <: ConstantSpace } = $ OP (convert (Number,a),b)
436- $ OP (a:: Number ,b:: Fun{CS} ) where {CS <: ConstantSpace } = $ OP (a,convert (Number,b))
437+ $ OP (a:: Fun{<:ConstantSpace } ,b:: Fun{<:ConstantSpace} ) = $ OP (convert (Number,a),Number (b))
438+ $ OP (a:: Fun{<:ConstantSpace } ,b:: Number ) = $ OP (convert (Number,a),b)
439+ $ OP (a:: Number ,b:: Fun{<:ConstantSpace} ) = $ OP (a,convert (Number,b))
437440 end
438441end
439442
440443for OP in (:(Base. max),:(Base. min))
441444 @eval begin
442- $ OP (a:: Fun{CS1,T } ,b:: Fun{CS2,V} ) where {CS1 <: ConstantSpace ,CS2 <: ConstantSpace ,T <: Real ,V <: Real } =
445+ $ OP (a:: Fun{<:ConstantSpace,<:Real } ,b:: Fun{<:ConstantSpace,<: Real} ) =
443446 Fun ($ OP (Number (a),Number (b)),space (a) ∪ space (b))
444- $ OP (a:: Fun{CS,T} ,b :: Real ) where {CS <: ConstantSpace ,T <: Real } =
447+ $ OP (a:: Fun{<:ConstantSpace,<:Real} ,b :: Real ) =
445448 Fun ($ OP (Number (a),b),space (a))
446- $ OP (a:: Real ,b:: Fun{CS,T} ) where {CS <: ConstantSpace ,T <: Real } =
449+ $ OP (a:: Real ,b:: Fun{<:ConstantSpace,<:Real} ) =
447450 Fun ($ OP (a,Number (b)),space (b))
448451 end
449452end
499502
500503for op in (:(findmax),:(findmin))
501504 @eval begin
502- function $op (f:: Fun{S,T} ) where {S <: RealSpace ,T <: Real }
505+ function $op (f:: Fun{<:RealSpace,<:Real} )
503506 # the following avoids warning when differentiate(f)==0
504507 pts = extremal_args (f)
505508 ext,ind = $ op (f .(pts))
@@ -508,7 +511,7 @@ for op in (:(findmax),:(findmin))
508511 end
509512end
510513
511- extremal_args (f:: Fun{S} ) where {S <: PiecewiseSpace } = cat (1 ,[extremal_args (fp) for fp in components (f)]. .. , dims= 1 )
514+ extremal_args (f:: Fun{<:PiecewiseSpace} ) = cat (1 ,[extremal_args (fp) for fp in components (f)]. .. , dims= 1 )
512515
513516function extremal_args (f:: Fun )
514517 d = domain (f)
@@ -522,7 +525,7 @@ function extremal_args(f::Fun)
522525end
523526
524527for op in (:(maximum),:(minimum),:(extrema))
525- @eval function $op (f:: Fun{S,T} ) where {S <: RealSpace ,T <: Real }
528+ @eval function $op (f:: Fun{<:RealSpace,<:Real} )
526529 pts = iszero (f' ) ? [leftendpoint (domain (f))] : extremal_args (f)
527530 v = map (f, pts)
528531 $ op (v)
532535
533536for op in (:(maximum),:(minimum))
534537 @eval begin
535- function $op (:: typeof (abs), f:: Fun{S,T} ) where {S <: RealSpace ,T <: Real }
538+ function $op (:: typeof (abs), f:: Fun{<:RealSpace,<:Real} )
536539 pts = iszero (f' ) ? [leftendpoint (domain (f))] : extremal_args (f)
537540 $ op (f .(pts))
538541 end
@@ -541,20 +544,20 @@ for op in (:(maximum),:(minimum))
541544 pts = extremal_args (abs (f))
542545 $ op (f .(pts))
543546 end
544- $ op (f:: Fun{PiecewiseSpace{SV,DD,RR},T} ) where {SV,DD <: UnionDomain ,RR <: Real ,T <: Real } =
547+ $ op (f:: Fun{PiecewiseSpace{<:Any, <:UnionDomain,<:Real}, <:Real} ) =
545548 $ op (map ($ op,components (f)))
546- $ op (:: typeof (abs), f:: Fun{PiecewiseSpace{SV,DD,RR},T} ) where {SV,DD <: UnionDomain ,RR <: Real ,T <: Real } =
549+ $ op (:: typeof (abs), f:: Fun{PiecewiseSpace{<:Any, <:UnionDomain,<:Real}, <:Real} ) =
547550 $ op (abs, map (g -> $ op (abs, g),components (f)))
548551 end
549552end
550553
551554
552- extrema (f:: Fun{PiecewiseSpace{SV,DD,RR},T} ) where {SV,DD <: UnionDomain ,RR <: Real ,T <: Real } =
555+ extrema (f:: Fun{PiecewiseSpace{<:Any, <:UnionDomain,<:Real}, <:Real} ) =
553556 mapreduce (extrema,(x,y)-> extrema ([x... ;y... ]),components (f))
554557
555558function complexroots end
556559
557- function roots (f:: Fun{P} ) where P <: PiecewiseSpace
560+ function roots (f:: Fun{<:PiecewiseSpace} )
558561 rts= mapreduce (roots,vcat,components (f))
559562 k= 1
560563 while k < length (rts)
@@ -568,7 +571,7 @@ function roots(f::Fun{P}) where P<:PiecewiseSpace
568571 rts
569572end
570573
571- roots (f:: Fun{S,T} ) where {S <: PointSpace ,T} = space (f). points[values (f) .== 0 ]
574+ roots (f:: Fun{<:PointSpace} ) = space (f). points[values (f) .== 0 ]
572575
573576
574577
0 commit comments