You can use exp(x) function of math library, which is same as e^x. Hence you may write your code as:

import math
x.append(1 - math.exp( -0.5 * (value1*value2)**2))

I have modified the equation by replacing 1/2 as 0.5. Else for Python <2.7, we'll have to explicitly type cast the division value to float because Python round of the result of division of two int as integer. For example: 1/2 gives 0 in python 2.7 and below.

Answer from Moinuddin Quadri on Stack Overflow
🌐
Python
docs.python.org › 3 › library › math.html
math — Mathematical functions
1 week ago - If x is zero, returns (0.0, 0), otherwise 0.5 <= abs(m) < 1. This is used to “pick apart” the internal representation of a float in a portable way. Note that frexp() has a different call/return pattern than its C equivalents: it takes a single argument and return a pair of values, rather than returning its second return value through an ‘output parameter’ (there is no such thing in Python).
🌐
W3Schools
w3schools.com › python › ref_math_exp.asp
Python math.exp() Method
'E' is the base of the natural system of logarithms (approximately 2.718282) and x is the number passed to it. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ...
🌐
Tutorialspoint
tutorialspoint.com › home › python › python number exponential function
Python Number Exponential Function
February 21, 2009 - Following is the syntax for the Python math.exp() method − ... This method returns exponential of x: ex.
Top answer
1 of 1
1

I don't know if the exponential curve math is accurate in this code, but it certainly isn't the slow point.

First, you read the input data in one read call. It does have to be read, but that loads the entire file. The next step takes the first line only, so it would seem more appropriate to use readline. That split itself is O(n) where n is the file size, at least, which might include data you were ignoring since you only process one line.

Second, you convert that line into an int. This probably requires Python's long integer support, but the operation could be O(n) or O(n^2). A single pass algorithm would multiply the accumulated number by 10 for each digit, allocating one or two new (longer) longs each time.

Third, sum_digits breaks that long int down into digits again. It does so using division, which is expensive, and two operations as well, rather than using divmod. That's O(n^2), because each division has to process every higher digit for each digit. And it's only needed because of the conversion you just did.

Summing the digits found in a string is likely easier done with something like sum(int(c) for c in l if c.isdigit()) where l is the input line. It's not particularly fast, as there's quite a bit of overhead in the digit conversions and the sum might grow large, but it does make a single pass with a fairly tight loop; it's somewhere between O(n) and O(n log n), depending on the length of the data, because the sum might grow large itself.

As for the unknown exponential curve, the existence of an exception for a low number is concerning. There's likely some other option that's both faster and more accurate if the answer's an integer anyway.

Lastly, you have at least four distinct output data formats: error, 2, 3.0, 3e+20. Do you know which of these is expected? Perhaps you should be using formatted output rather than str to convert your numbers.

One extra note: If the data is really large, processing it in chunks will definitely speed things up (instead of running out of memory, needing to swap, etc). As you're looking for a digit sum your size complexity can be reduced from O(n) to O(log n).

🌐
GeeksforGeeks
geeksforgeeks.org › python › python-math-library-exp-method
Python math library | exp() method - GeeksforGeeks
February 7, 2023 - Python has math library and has many functions regarding it. One such function is exp(). This method is used to calculate the power of e i.e. e^y or we can say exponential of y.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.exp.html
numpy.exp — NumPy v2.1 Manual
The irrational number e is also known as Euler’s number. It is approximately 2.718281, and is the base of the natural logarithm, ln (this means that, if \(x = \ln y = \log_e y\), then \(e^x = y\).
Find elsewhere
🌐
Codecademy
codecademy.com › docs › python:numpy › math methods › .exp()
Python:NumPy | Math Methods | .exp() | Codecademy
April 17, 2025 - The exponential function, np.exp(x), returns e^x, where e is Euler’s number with an approximate value of 2.71828. As a part of NumPy, a widely used library for numerical computing in Python, this function is particularly useful in scientific computations where exponential functions are common.
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.exp.html
numpy.exp — NumPy v2.2 Manual
The irrational number e is also known as Euler’s number. It is approximately 2.718281, and is the base of the natural logarithm, ln (this means that, if \(x = \ln y = \log_e y\), then \(e^x = y\).
🌐
Reddit
reddit.com › r/learnpython › exponential functions
r/learnpython on Reddit: Exponential Functions
April 13, 2024 -

I am trying to get my code to work with 2**x, where x is an array filled with Float Values. It seems Python does not like this one bit.
Is there something I need to Import or do I need to rephrase the expression?

🌐
Educative
educative.io › answers › calculating-the-exponential-value-in-python
Calculating the exponential value in Python
The exp() function in Python allows users to calculate the exponential value with the base set to e.
🌐
DataCamp
datacamp.com › tutorial › exponents-in-python
Exponents in Python: A Comprehensive Guide for Beginners | DataCamp
November 25, 2024 - The math.exp(x) function computes the exponential value of x, which is equivalent to raising Euler's number e to the power of x.
🌐
W3Schools
w3schools.com › python › ref_cmath_exp.asp
Python cmath.exp() Method
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.exp.html
numpy.exp — NumPy v2.3 Manual
The irrational number e is also known as Euler’s number. It is approximately 2.718281, and is the base of the natural logarithm, ln (this means that, if \(x = \ln y = \log_e y\), then \(e^x = y\).
🌐
GeeksforGeeks
geeksforgeeks.org › python › computing-ex-element-wise-in-a-numpy-array
Computing e^x element-wise in a NumPy array - GeeksforGeeks
July 15, 2025 - Python3 1== # importing the module ... 148.4131591 1096.63315843] Example 2 : We can also find the exponential using the math.exp() method....
🌐
Vultr Docs
docs.vultr.com › python › third-party › numpy › exp
Python Numpy exp() - Calculate Exponential | Vultr Docs
November 18, 2024 - This code computes e raised to the power of 2 (e²). The result is approximately 7.389056, showcasing how exp() calculates exponential values. Recognize that Python's floating point numbers have limitations in precision.
🌐
YouTube
youtube.com › watch
exp() function in Python | methods in python | function in python | python for beginners | python - YouTube
In this comprehensive tutorial, we'll cover the following key points:1.exp() function in python for beginners in english2.Function in Python for beginners in...
Published   December 29, 2023
🌐
Profound Academy
profound.academy › python-introduction › calculate-expx-WKmSTWsKSEpJrC0bh6QO
Calculate exp(x) - Introduction to Python
November 2, 2024 - Introduction to Python · Description · Implement a function exp(x) that would compute and return the result of with the following formula: The input contains a single integer x. The function exp should compute and return the expression up until n = 10 (inclusive).