## Overview

I want to apply a specified `Chop`

function to every step in an function call in Mathematica (in my case `LegendreP`

), especially when encountering a machine underflow error. The resulting function should be applicable to a dataframe.

## The Setup

I am trying to calculate a function including an associated Legendre function with complex indices

`function[t_] = 1/Sin[t] * LegendreP[-1/2 + V * I, l+1, Cos[t]]`

where t is between `0`

and `Pi`

, `V`

is of order of magnitude `10`

and `l`

is between `10`

and `100`

. Beside the function I need its logarithmic derivative `function'/function`

.

Ideally I want to do this by applying the function to a dataframe and appending the result in a separate column.

`Append[#, "function" -> function[#timeframe]]`

where timeframe is a column with all the t values.

## The Problem

When I run this code for any `l`

bigger than 12 and very small `t~1e-5`

values, the LegendreP Algorithm throws a machine underflow error `General::munfl`

because it cannot execute a multiplication of extremly small complex numbers.

While for a single call or a plot, it seems to do some chopping or return `Indeterminate`

, when I write it to a dataframe with

`Append[#, "function" -> function[#timeframe]]`

it just returns Failure and does not write anything to the dataframe.

## What I have tried so far

I have tried to use `Chop`

and `Threshold`

, but this does not seem to apply to the single steps of the algorithm but only the final result.

The way I "solve" the problem at the moment is to catch the error and return `0`

instead of my function. This is not ideal since the real or imaginary part of the step in question and the result might not be negligible while the other one is, or it might diverge instead of converge to `0`

.

Since the multiplication that raises the error lists numbers ~1e-300 or so, I doubt that the problem is solvable by increasing the precision.

## My Goal

Ideally I’d like to call Chop, whenever Mathematica encounters a machine underflow. The behavior of Chop on complex numbers is exactly what I need. This way I should be able to preserve the real or imaginary part that does not vanish.

Is the error handling different, when applied to a dataframe as it relates to this question (for plots or even single evaluation points I don’t have the same issue) or can an indeterminate/NaN be written to a dataframe?

Is there a way to set a "global chop rule"?

Grateful for any hint ðŸ˜€