#lang racket/base
(require racket/contract)
(provide/contract
(chebyshev-integral (-> natural-number/c natural-number/c procedure?))
(eval-over-range (-> number? number? procedure? number?))
(x^y (-> number? number? number?)))
(define (chebyshev-integral p q)
(cond
[(= p 0) (let [(q+1 (add1 q))]
(lambda (x)
(- (/ (x^y (- 1 x) q+1)
q+1))))]
[(= q 0) (let [(p+1 (add1 p))]
(lambda (x)
(/ (x^y x p+1) p+1)))]
[else
(let [(p+1 (add1 p))]
(lambda (x)
(/ (+ (* (x^y (- 1 x) q)
(x^y x p+1))
(* q
(apply (chebyshev-integral p+1 (sub1 q))
(list x))))
p+1)))]))
(define (eval-over-range x y f)
(- (f y) (f x)))
(define (x^y x y)
(if (= x 0)
(if (> y 0) 0
(error (format "(x^y ~a ~a)") x y))
(exp (* y (log x)))))