/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * This Maxima script allows the creation of reference data for the Gamma
 * distribution.
 */

/*
 * Set floating-point accuracy to four times the double precision.
 */
fpprec : 64;

/*
 * Probability density function for Gamma distribution with shape parameter a
 * and scale parameter b.
 */
p(x, a, b) := (x / b)**a * exp(-x / b) / x / gamma(a);

/* 
 * Make sure x is a list of exactly representable doubles: use only power-of-two
 * fractions of unity.
 */
out :  openw("gamma-distribution-shape-1.csv");
x : float(makelist(i / 32, i, 1, 3200));
y : p(bfloat(x), 1, 1);
printf(out, "~{~h, ~h~%~}", join(x, y));
close(out);

out :  openw("gamma-distribution-shape-8.csv");
x : float(makelist(i / 32, i, 1, 3200));
y : p(bfloat(x), 8, 1);
printf(out, "~{~h, ~h~%~}", join(x, y));
close(out);

out :  openw("gamma-distribution-shape-10.csv");
x : float(makelist(i / 4, i, 1, 400));
y : p(bfloat(x), 10, 1);
printf(out, "~{~h, ~h~%~}", join(x, y));
close(out);

out :  openw("gamma-distribution-shape-100.csv");
x : float(append(makelist(i / 32, i, 1, 32 * 3), makelist(i + 3, i, 1, 297)));
y : p(bfloat(x), 100, 1);
printf(out, "~{~h, ~h~%~}", join(x, y));
close(out);

out :  openw("gamma-distribution-shape-142.csv");
x : float(append(makelist(i / 32, i, 1, 32 * 10), makelist(i + 10, i, 1, 440)));
y : p(bfloat(x), 142, 1);
printf(out, "~{~h, ~h~%~}", join(x, y));
close(out);

out :  openw("gamma-distribution-shape-1000.csv");
x : float(append(makelist(i / 32, i, 1, 32 * 10), makelist(i + 10, i, 1, 2990)));
y : p(bfloat(x), 1000, 1);
printf(out, "~{~h, ~h~%~}", join(x, y));
close(out);

