@@ -506,7 +506,7 @@ class FixedPoint(Builtin):
506506 <dt>'FixedPoint[$f$, $expr$]'
507507 <dd>starting with $expr$, iteratively applies $f$ until the result no longer changes.
508508 <dt>'FixedPoint[$f$, $expr$, $n$]'
509- <dd>performs at most $n$ iterations.
509+ <dd>performs at most $n$ iterations. The same that using $MaxIterations->n$
510510 </dl>
511511
512512 >> FixedPoint[Cos, 1.0]
@@ -524,24 +524,46 @@ class FixedPoint(Builtin):
524524 = 0.739085
525525 """
526526
527- def apply (self , f , expr , n , evaluation ):
528- "FixedPoint[f_, expr_, n_:DirectedInfinity[1]]"
527+ options = {
528+ "MaxIterations" : "Infinity" ,
529+ "SameTest" : "Automatic" ,
530+ }
529531
532+ def apply (self , f , expr , n , evaluation , options ):
533+ "FixedPoint[f_, expr_, n_:DirectedInfinity[1], OptionsPattern[FixedPoint]]"
530534 if n == Expression ("DirectedInfinity" , 1 ):
531535 count = None
532536 else :
533537 count = n .get_int_value ()
534538 if count is None or count < 0 :
535539 evaluation .message ("FixedPoint" , "intnn" )
536540 return
541+
542+ if count is None :
543+ count = self .get_option (options , "MaxIterations" , evaluation )
544+ if count .is_numeric ():
545+ count = count .get_int_value ()
546+ else :
547+ count = None
548+
537549 result = expr
538550 index = 0
551+ sametest = self .get_option (options , "SameTest" , evaluation )
552+ if sametest == Symbol ("Automatic" ):
553+ sametest = None
554+
539555 while count is None or index < count :
540556 evaluation .check_stopped ()
541557 new_result = Expression (f , result ).evaluate (evaluation )
542- if new_result == result :
543- result = new_result
544- break
558+ if sametest :
559+ same = Expression (sametest , result , new_result ).evaluate (evaluation )
560+ same = same .is_true ()
561+ if same :
562+ break
563+ else :
564+ if new_result == result :
565+ result = new_result
566+ break
545567 result = new_result
546568 index += 1
547569
0 commit comments