#ifndef MODELS_HPP
#define MODELS_HPP
#define STAN__SERVICES__COMMAND_HPP
#include <rstan/rstaninc.hpp>
#ifndef USE_STANC3
#define USE_STANC3
#endif
// Code generated by stanc v2.32.2
#include <stan/model/model_header.hpp>
namespace model9a1415b13b8d__namespace {
using stan::model::model_base_crtp;
using namespace stan::math;
stan::math::profile_map profiles__;
static constexpr std::array<const char*, 13> locations_array__ =
  {" (found before start of program)",
  " (in 'string', line 7, column 2 to column 24)",
  " (in 'string', line 8, column 2 to column 24)",
  " (in 'string', line 9, column 2 to column 14)",
  " (in 'string', line 10, column 2 to column 14)",
  " (in 'string', line 14, column 4 to column 111)",
  " (in 'string', line 13, column 17 to line 15, column 3)",
  " (in 'string', line 13, column 2 to line 15, column 3)",
  " (in 'string', line 2, column 2 to column 17)",
  " (in 'string', line 3, column 9 to column 10)",
  " (in 'string', line 3, column 2 to column 12)",
  " (in 'string', line 4, column 9 to column 10)",
  " (in 'string', line 4, column 2 to column 12)"};
class model9a1415b13b8d_ final : public model_base_crtp<model9a1415b13b8d_> {
private:
  int n;
  std::vector<double> x;
  std::vector<double> y;
public:
  ~model9a1415b13b8d_() {}
  model9a1415b13b8d_(stan::io::var_context& context__, unsigned int
                     random_seed__ = 0, std::ostream* pstream__ = nullptr)
      : model_base_crtp(0) {
    int current_statement__ = 0;
    using local_scalar_t__ = double;
    boost::ecuyer1988 base_rng__ =
      stan::services::util::create_rng(random_seed__, 0);
    // suppress unused var warning
    (void) base_rng__;
    static constexpr const char* function__ =
      "model9a1415b13b8d__namespace::model9a1415b13b8d_";
    // suppress unused var warning
    (void) function__;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    try {
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      current_statement__ = 8;
      context__.validate_dims("data initialization", "n", "int",
        std::vector<size_t>{});
      n = std::numeric_limits<int>::min();
      current_statement__ = 8;
      n = context__.vals_i("n")[(1 - 1)];
      current_statement__ = 8;
      stan::math::check_greater_or_equal(function__, "n", n, 0);
      current_statement__ = 9;
      stan::math::validate_non_negative_index("x", "n", n);
      current_statement__ = 10;
      context__.validate_dims("data initialization", "x", "double",
        std::vector<size_t>{static_cast<size_t>(n)});
      x = std::vector<double>(n, std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 10;
      x = context__.vals_r("x");
      current_statement__ = 11;
      stan::math::validate_non_negative_index("y", "n", n);
      current_statement__ = 12;
      context__.validate_dims("data initialization", "y", "double",
        std::vector<size_t>{static_cast<size_t>(n)});
      y = std::vector<double>(n, std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 12;
      y = context__.vals_r("y");
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
    num_params_r__ = 1 + 1 + 1 + 1;
  }
  inline std::string model_name() const final {
    return "model9a1415b13b8d_";
  }
  inline std::vector<std::string> model_compile_info() const noexcept {
    return std::vector<std::string>{"stanc_version = stanc3 v2.32.2",
             "stancflags = --"};
  }
  template <bool propto__, bool jacobian__, typename VecR, typename VecI,
            stan::require_vector_like_t<VecR>* = nullptr,
            stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr>
  inline stan::scalar_type_t<VecR>
  log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream*
                pstream__ = nullptr) const {
    using T__ = stan::scalar_type_t<VecR>;
    using local_scalar_t__ = T__;
    T__ lp__(0.0);
    stan::math::accumulator<T__> lp_accum__;
    stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
    int current_statement__ = 0;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    static constexpr const char* function__ =
      "model9a1415b13b8d__namespace::log_prob";
    // suppress unused var warning
    (void) function__;
    try {
      local_scalar_t__ delta_0 = DUMMY_VAR__;
      current_statement__ = 1;
      delta_0 = in__.template read_constrain_lb<local_scalar_t__,
                  jacobian__>(0, lp__);
      local_scalar_t__ delta_1 = DUMMY_VAR__;
      current_statement__ = 2;
      delta_1 = in__.template read_constrain_lb<local_scalar_t__,
                  jacobian__>(0, lp__);
      local_scalar_t__ beta_0 = DUMMY_VAR__;
      current_statement__ = 3;
      beta_0 = in__.template read<local_scalar_t__>();
      local_scalar_t__ beta_1 = DUMMY_VAR__;
      current_statement__ = 4;
      beta_1 = in__.template read<local_scalar_t__>();
      {
        current_statement__ = 7;
        for (int i = 1; i <= n; ++i) {
          current_statement__ = 5;
          lp_accum__.add((-stan::math::log((delta_0 + (delta_1 *
                             stan::model::rvalue(x, "x",
                               stan::model::index_uni(i))))) - (0.5 *
            stan::math::pow(
              ((stan::model::rvalue(y, "y", stan::model::index_uni(i)) -
              (beta_0 + (beta_1 *
              stan::model::rvalue(x, "x", stan::model::index_uni(i))))) /
              (delta_0 + (delta_1 *
              stan::model::rvalue(x, "x", stan::model::index_uni(i))))), 2))));
        }
      }
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
    lp_accum__.add(lp__);
    return lp_accum__.sum();
  }
  template <typename RNG, typename VecR, typename VecI, typename VecVar,
            stan::require_vector_like_vt<std::is_floating_point,
            VecR>* = nullptr, stan::require_vector_like_vt<std::is_integral,
            VecI>* = nullptr, stan::require_vector_vt<std::is_floating_point,
            VecVar>* = nullptr>
  inline void
  write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__,
                   VecVar& vars__, const bool
                   emit_transformed_parameters__ = true, const bool
                   emit_generated_quantities__ = true, std::ostream*
                   pstream__ = nullptr) const {
    using local_scalar_t__ = double;
    stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
    stan::io::serializer<local_scalar_t__> out__(vars__);
    static constexpr bool propto__ = true;
    // suppress unused var warning
    (void) propto__;
    double lp__ = 0.0;
    // suppress unused var warning
    (void) lp__;
    int current_statement__ = 0;
    stan::math::accumulator<double> lp_accum__;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    constexpr bool jacobian__ = false;
    static constexpr const char* function__ =
      "model9a1415b13b8d__namespace::write_array";
    // suppress unused var warning
    (void) function__;
    try {
      double delta_0 = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 1;
      delta_0 = in__.template read_constrain_lb<local_scalar_t__,
                  jacobian__>(0, lp__);
      double delta_1 = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 2;
      delta_1 = in__.template read_constrain_lb<local_scalar_t__,
                  jacobian__>(0, lp__);
      double beta_0 = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 3;
      beta_0 = in__.template read<local_scalar_t__>();
      double beta_1 = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 4;
      beta_1 = in__.template read<local_scalar_t__>();
      out__.write(delta_0);
      out__.write(delta_1);
      out__.write(beta_0);
      out__.write(beta_1);
      if (stan::math::logical_negation(
            (stan::math::primitive_value(emit_transformed_parameters__) ||
            stan::math::primitive_value(emit_generated_quantities__)))) {
        return ;
      }
      if (stan::math::logical_negation(emit_generated_quantities__)) {
        return ;
      }
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
  }
  template <typename VecVar, typename VecI,
            stan::require_vector_t<VecVar>* = nullptr,
            stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr>
  inline void
  unconstrain_array_impl(const VecVar& params_r__, const VecI& params_i__,
                         VecVar& vars__, std::ostream* pstream__ = nullptr) const {
    using local_scalar_t__ = double;
    stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
    stan::io::serializer<local_scalar_t__> out__(vars__);
    int current_statement__ = 0;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    try {
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      local_scalar_t__ delta_0 = DUMMY_VAR__;
      current_statement__ = 1;
      delta_0 = in__.read<local_scalar_t__>();
      out__.write_free_lb(0, delta_0);
      local_scalar_t__ delta_1 = DUMMY_VAR__;
      current_statement__ = 2;
      delta_1 = in__.read<local_scalar_t__>();
      out__.write_free_lb(0, delta_1);
      local_scalar_t__ beta_0 = DUMMY_VAR__;
      current_statement__ = 3;
      beta_0 = in__.read<local_scalar_t__>();
      out__.write(beta_0);
      local_scalar_t__ beta_1 = DUMMY_VAR__;
      current_statement__ = 4;
      beta_1 = in__.read<local_scalar_t__>();
      out__.write(beta_1);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
  }
  template <typename VecVar, stan::require_vector_t<VecVar>* = nullptr>
  inline void
  transform_inits_impl(const stan::io::var_context& context__, VecVar&
                       vars__, std::ostream* pstream__ = nullptr) const {
    using local_scalar_t__ = double;
    stan::io::serializer<local_scalar_t__> out__(vars__);
    int current_statement__ = 0;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    try {
      current_statement__ = 1;
      context__.validate_dims("parameter initialization", "delta_0",
        "double", std::vector<size_t>{});
      current_statement__ = 2;
      context__.validate_dims("parameter initialization", "delta_1",
        "double", std::vector<size_t>{});
      current_statement__ = 3;
      context__.validate_dims("parameter initialization", "beta_0", "double",
        std::vector<size_t>{});
      current_statement__ = 4;
      context__.validate_dims("parameter initialization", "beta_1", "double",
        std::vector<size_t>{});
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      local_scalar_t__ delta_0 = DUMMY_VAR__;
      current_statement__ = 1;
      delta_0 = context__.vals_r("delta_0")[(1 - 1)];
      out__.write_free_lb(0, delta_0);
      local_scalar_t__ delta_1 = DUMMY_VAR__;
      current_statement__ = 2;
      delta_1 = context__.vals_r("delta_1")[(1 - 1)];
      out__.write_free_lb(0, delta_1);
      local_scalar_t__ beta_0 = DUMMY_VAR__;
      current_statement__ = 3;
      beta_0 = context__.vals_r("beta_0")[(1 - 1)];
      out__.write(beta_0);
      local_scalar_t__ beta_1 = DUMMY_VAR__;
      current_statement__ = 4;
      beta_1 = context__.vals_r("beta_1")[(1 - 1)];
      out__.write(beta_1);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
  }
  inline void
  get_param_names(std::vector<std::string>& names__, const bool
                  emit_transformed_parameters__ = true, const bool
                  emit_generated_quantities__ = true) const {
    names__ = std::vector<std::string>{"delta_0", "delta_1", "beta_0",
                "beta_1"};
    if (emit_transformed_parameters__) {}
    if (emit_generated_quantities__) {}
  }
  inline void
  get_dims(std::vector<std::vector<size_t>>& dimss__, const bool
           emit_transformed_parameters__ = true, const bool
           emit_generated_quantities__ = true) const {
    dimss__ = std::vector<std::vector<size_t>>{std::vector<size_t>{},
                std::vector<size_t>{}, std::vector<size_t>{},
                std::vector<size_t>{}};
    if (emit_transformed_parameters__) {}
    if (emit_generated_quantities__) {}
  }
  inline void
  constrained_param_names(std::vector<std::string>& param_names__, bool
                          emit_transformed_parameters__ = true, bool
                          emit_generated_quantities__ = true) const final {
    param_names__.emplace_back(std::string() + "delta_0");
    param_names__.emplace_back(std::string() + "delta_1");
    param_names__.emplace_back(std::string() + "beta_0");
    param_names__.emplace_back(std::string() + "beta_1");
    if (emit_transformed_parameters__) {}
    if (emit_generated_quantities__) {}
  }
  inline void
  unconstrained_param_names(std::vector<std::string>& param_names__, bool
                            emit_transformed_parameters__ = true, bool
                            emit_generated_quantities__ = true) const final {
    param_names__.emplace_back(std::string() + "delta_0");
    param_names__.emplace_back(std::string() + "delta_1");
    param_names__.emplace_back(std::string() + "beta_0");
    param_names__.emplace_back(std::string() + "beta_1");
    if (emit_transformed_parameters__) {}
    if (emit_generated_quantities__) {}
  }
  inline std::string get_constrained_sizedtypes() const {
    return std::string("[{\"name\":\"delta_0\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"delta_1\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta_0\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta_1\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"}]");
  }
  inline std::string get_unconstrained_sizedtypes() const {
    return std::string("[{\"name\":\"delta_0\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"delta_1\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta_0\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta_1\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"}]");
  }
  // Begin method overload boilerplate
  template <typename RNG> inline void
  write_array(RNG& base_rng, Eigen::Matrix<double,-1,1>& params_r,
              Eigen::Matrix<double,-1,1>& vars, const bool
              emit_transformed_parameters = true, const bool
              emit_generated_quantities = true, std::ostream*
              pstream = nullptr) const {
    const size_t num_params__ = (((1 + 1) + 1) + 1);
    const size_t num_transformed = emit_transformed_parameters * (0);
    const size_t num_gen_quantities = emit_generated_quantities * (0);
    const size_t num_to_write = num_params__ + num_transformed +
      num_gen_quantities;
    std::vector<int> params_i;
    vars = Eigen::Matrix<double,-1,1>::Constant(num_to_write,
             std::numeric_limits<double>::quiet_NaN());
    write_array_impl(base_rng, params_r, params_i, vars,
      emit_transformed_parameters, emit_generated_quantities, pstream);
  }
  template <typename RNG> inline void
  write_array(RNG& base_rng, std::vector<double>& params_r, std::vector<int>&
              params_i, std::vector<double>& vars, bool
              emit_transformed_parameters = true, bool
              emit_generated_quantities = true, std::ostream*
              pstream = nullptr) const {
    const size_t num_params__ = (((1 + 1) + 1) + 1);
    const size_t num_transformed = emit_transformed_parameters * (0);
    const size_t num_gen_quantities = emit_generated_quantities * (0);
    const size_t num_to_write = num_params__ + num_transformed +
      num_gen_quantities;
    vars = std::vector<double>(num_to_write,
             std::numeric_limits<double>::quiet_NaN());
    write_array_impl(base_rng, params_r, params_i, vars,
      emit_transformed_parameters, emit_generated_quantities, pstream);
  }
  template <bool propto__, bool jacobian__, typename T_> inline T_
  log_prob(Eigen::Matrix<T_,-1,1>& params_r, std::ostream* pstream = nullptr) const {
    Eigen::Matrix<int,-1,1> params_i;
    return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
  }
  template <bool propto__, bool jacobian__, typename T_> inline T_
  log_prob(std::vector<T_>& params_r, std::vector<int>& params_i,
           std::ostream* pstream = nullptr) const {
    return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
  }
  inline void
  transform_inits(const stan::io::var_context& context,
                  Eigen::Matrix<double,-1,1>& params_r, std::ostream*
                  pstream = nullptr) const final {
    std::vector<double> params_r_vec(params_r.size());
    std::vector<int> params_i;
    transform_inits(context, params_i, params_r_vec, pstream);
    params_r = Eigen::Map<Eigen::Matrix<double,-1,1>>(params_r_vec.data(),
                 params_r_vec.size());
  }
  inline void
  transform_inits(const stan::io::var_context& context, std::vector<int>&
                  params_i, std::vector<double>& vars, std::ostream*
                  pstream__ = nullptr) const {
    vars.resize(num_params_r__);
    transform_inits_impl(context, vars, pstream__);
  }
  inline void
  unconstrain_array(const std::vector<double>& params_constrained,
                    std::vector<double>& params_unconstrained, std::ostream*
                    pstream = nullptr) const {
    const std::vector<int> params_i;
    params_unconstrained = std::vector<double>(num_params_r__,
                             std::numeric_limits<double>::quiet_NaN());
    unconstrain_array_impl(params_constrained, params_i,
      params_unconstrained, pstream);
  }
  inline void
  unconstrain_array(const Eigen::Matrix<double,-1,1>& params_constrained,
                    Eigen::Matrix<double,-1,1>& params_unconstrained,
                    std::ostream* pstream = nullptr) const {
    const std::vector<int> params_i;
    params_unconstrained = Eigen::Matrix<double,-1,1>::Constant(num_params_r__,
                             std::numeric_limits<double>::quiet_NaN());
    unconstrain_array_impl(params_constrained, params_i,
      params_unconstrained, pstream);
  }
};
}
using stan_model = model9a1415b13b8d__namespace::model9a1415b13b8d_;
#ifndef USING_R
// Boilerplate
stan::model::model_base&
new_model(stan::io::var_context& data_context, unsigned int seed,
          std::ostream* msg_stream) {
  stan_model* m = new stan_model(data_context, seed, msg_stream);
  return *m;
}
stan::math::profile_map& get_stan_profile_data() {
  return model9a1415b13b8d__namespace::profiles__;
}
#endif
#endif