2929"""
3030
3131
32- from math import exp , log , sqrt
32+ from math import exp , log , sqrt , isinf
3333
3434#####################
3535# SPECIAL FUNCTIONS #
@@ -178,17 +178,37 @@ def bounded_linear(low_bound, high_bound, core_m=1, unsupported_m=0):
178178 1.0
179179 """
180180 assert high_bound > low_bound , 'high must not be less than low.'
181- assert core_m != unsupported_m , "core_m must differ from unsupported_m"
181+ assert core_m > unsupported_m , "core_m must differ from unsupported_m"
182182
183183 gradient = (core_m - unsupported_m ) / (high_bound - low_bound )
184-
184+
185+ # special cases found by hypothesis
186+
187+ def g_0 (x ):
188+ return (core_m + unsupported_m ) / 2
189+
190+ if gradient == 0 :
191+ return g_0
192+
193+ def g_inf (x ):
194+ asympt = (high_bound + low_bound ) / 2
195+ if x < asympt :
196+ return unsupported_m
197+ elif x > asympt :
198+ return core_m
199+ else :
200+ return (core_m + unsupported_m ) / 2
201+
202+ if isinf (gradient ):
203+ return g_inf
204+
185205 def f (x ):
186- m = gradient * (x - low_bound ) + unsupported_m
187- if m < 0 :
206+ y = gradient * (x - low_bound ) + unsupported_m
207+ if y < 0 :
188208 return 0.
189- if m > 1 :
209+ if y > 1 :
190210 return 1.
191- return m
211+ return y
192212 return f
193213
194214
@@ -198,8 +218,7 @@ def R(left, right):
198218 USE THE S() FUNCTION FOR NEGATIVE SLOPE.
199219 """
200220
201- if left >= right :
202- raise ValueError ("left must be less than right." )
221+ assert left < right , "left must be less than right."
203222
204223 def f (x ):
205224 if x < left :
@@ -247,8 +266,7 @@ def rectangular(left, right, core_m=1, unsupported_m=0):
247266 "height" of the rectangle
248267 """
249268
250- if left > right :
251- raise ValueError ('left must not be greater than right.' )
269+ assert left < right , 'left must not be greater than right.'
252270
253271 def f (x ):
254272 if x < left :
0 commit comments