@@ -27,13 +27,14 @@ split(d::SegmentDomain, pts) = d
27
27
function splitatroots (f:: Fun )
28
28
d= domain (f)
29
29
pts= union (roots (f)) # union removes multiplicities
30
- splitmap (x -> f (x) ,d,pts)
30
+ splitmap (f ,d,pts)
31
31
end
32
32
33
- function abs (f:: Fun{S,T} ) where {S <: RealUnivariateSpace ,T <: Real }
33
+ function abs (f:: Fun{<:RealUnivariateSpace,<:Real} )
34
34
d= domain (f)
35
+ T = cfstype (f)
35
36
pts = iszero (f) ? T[] : roots (f)
36
- splitmap (x -> abs ( f (x)) ,d,pts)
37
+ splitmap (abs∘ f ,d,pts)
37
38
end
38
39
39
40
function abs (f:: Fun )
@@ -58,9 +59,9 @@ _UnionDomainIfMultiple(d::IntervalOrSegment) = d
58
59
_UnionDomainIfMultiple (d) = UnionDomain (components (d))
59
60
60
61
for 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} )
62
63
d= domain (f)
63
-
64
+ T = cfstype (f)
64
65
pts = iszero (f) ? T[] : roots (f)
65
66
66
67
if isempty (pts)
75
76
76
77
for op in (:(max),:(min))
77
78
@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} )
79
81
h= f- g
80
82
d= domain (h)
81
83
pts= iszero (h) ? cfstype (h)[] : roots (h)
82
84
splitmap (x-> $ op (f (x),g (x)),d,pts)
83
85
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)
86
88
end
87
89
end
88
90
@@ -125,8 +127,8 @@ function ^(f::Fun, β)
125
127
[B;A]\ [first (f)^ β;0 ]
126
128
end
127
129
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 )
130
132
131
133
# # We use \ as the Fun constructor might miss isolated features
132
134
@@ -210,9 +212,10 @@ for (op,ODE,RHS,growth) in ((:(erf),"f'*D^2+(2f*f'^2-f'')*D","0",:(imag)),
210
212
(:(airybiprime)," f'*D^2-f''*D-f*f'^3" ," airybi(f)*f'^3" ,:(imag)))
211
213
L,R = Meta. parse (ODE),Meta. parse (RHS)
212
214
@eval begin
213
- function $op (fin:: Fun{S,T} ) where {S,T}
215
+ function $op (fin:: Fun )
214
216
f= setcanonicaldomain (fin)
215
217
218
+ T = cfstype (fin)
216
219
g= chop ($ growth (f),eps (T))
217
220
xmin = isempty (g. coefficients) ? leftendpoint (domain (g)) : argmin (g)
218
221
xmax = isempty (g. coefficients) ? rightendpoint (domain (g)) : argmax (g)
@@ -291,11 +294,11 @@ end
291
294
292
295
besselh (ν,k:: Integer ,f:: Fun ) = k == 1 ? hankelh1 (ν,f) : k == 2 ? hankelh2 (ν,f) : throw (Base. Math. AmosException (1 ))
293
296
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)
299
302
end
300
303
end
301
304
@@ -305,7 +308,7 @@ for op in (:(expm1),:(log1p),:(lfact),:(sinc),:(cosc),
305
308
:(eta),:(zeta),:(gamma),:(lgamma),
306
309
:(polygamma),:(invdigamma),:(digamma),:(trigamma))
307
310
@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))
309
312
end
310
313
end
311
314
@@ -378,9 +381,9 @@ for op in (:(<=),)
378
381
end
379
382
end
380
383
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)
384
387
385
388
for OP in (:abs ,:sign ,:log ,:angle )
386
389
@eval begin
@@ -431,19 +434,19 @@ end
431
434
432
435
for OP in (:< ,:(Base. isless),:(<= ))
433
436
@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))
437
440
end
438
441
end
439
442
440
443
for OP in (:(Base. max),:(Base. min))
441
444
@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} ) =
443
446
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 ) =
445
448
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} ) =
447
450
Fun ($ OP (a,Number (b)),space (b))
448
451
end
449
452
end
499
502
500
503
for op in (:(findmax),:(findmin))
501
504
@eval begin
502
- function $op (f:: Fun{S,T} ) where {S <: RealSpace ,T <: Real }
505
+ function $op (f:: Fun{<:RealSpace,<:Real} )
503
506
# the following avoids warning when differentiate(f)==0
504
507
pts = extremal_args (f)
505
508
ext,ind = $ op (f .(pts))
@@ -508,7 +511,7 @@ for op in (:(findmax),:(findmin))
508
511
end
509
512
end
510
513
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 )
512
515
513
516
function extremal_args (f:: Fun )
514
517
d = domain (f)
@@ -522,7 +525,7 @@ function extremal_args(f::Fun)
522
525
end
523
526
524
527
for 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} )
526
529
pts = iszero (f' ) ? [leftendpoint (domain (f))] : extremal_args (f)
527
530
v = map (f, pts)
528
531
$ op (v)
532
535
533
536
for op in (:(maximum),:(minimum))
534
537
@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} )
536
539
pts = iszero (f' ) ? [leftendpoint (domain (f))] : extremal_args (f)
537
540
$ op (f .(pts))
538
541
end
@@ -541,20 +544,20 @@ for op in (:(maximum),:(minimum))
541
544
pts = extremal_args (abs (f))
542
545
$ op (f .(pts))
543
546
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} ) =
545
548
$ 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} ) =
547
550
$ op (abs, map (g -> $ op (abs, g),components (f)))
548
551
end
549
552
end
550
553
551
554
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} ) =
553
556
mapreduce (extrema,(x,y)-> extrema ([x... ;y... ]),components (f))
554
557
555
558
function complexroots end
556
559
557
- function roots (f:: Fun{P} ) where P <: PiecewiseSpace
560
+ function roots (f:: Fun{<:PiecewiseSpace} )
558
561
rts= mapreduce (roots,vcat,components (f))
559
562
k= 1
560
563
while k < length (rts)
@@ -568,7 +571,7 @@ function roots(f::Fun{P}) where P<:PiecewiseSpace
568
571
rts
569
572
end
570
573
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 ]
572
575
573
576
574
577
0 commit comments