<jupyter_start><jupyter_text><jupyter_code>import numpy as np

n = 100

def riemann_integral(f, a, b):
    w = (b - a)/n
    r_left = sum([f(a + i*w) * w for i in range(1, n)])
    r_right = sum([f(a + (i+1)*w) * w for i in range(1, n)])
    return np.array([r_left , r_right]).mean()


def run(r, f, a,b):
  print(r + ": ", riemann_integral(f, a, b))

print ("Using Reimann Integral")
run("Value of Pi",lambda x: 4.0/(1 + x**2), 0,1)
run ("Area of circle quadrant", lambda x: np.square(1)*((np.cos(2*x)+1)/2),0, np.pi/2)

run ("fun eval", lambda x:2*x*x ,0, 2)<jupyter_output>Using Reimann Integral
Value of Pi:  3.1015779867231466
Area of circle quadrant:  0.7696921378624116
fun eval:  5.333592000000003
{'fraction_non_alphanumeric': 0.18838526912181303, 'fraction_numerical': 0.10056657223796034, 'mean_word_length': 4.1231884057971016, 'pattern_counts': {'":': 1, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '152914', 'license': 'MIT', 'n_tokens_mistral': 355, 'n_tokens_neox': 312, 'n_words': 83, 'path': 'RiemannIntegral.ipynb', 'repo_name': 'bkgsur/FinanceModelingComputation', 'size': '706'}