
module thermostat
{
  var temp : real; // Input temperature
  var heatOn : bool; // Pure output for turning heater on
  var heatOff : bool; // Pure output for turning heater off
  var heating : bool; // State of the heater (true for on, false for off)
  var cooling : bool; // State of cooling (true for on, false for off)

  init {
    // Initialize heating and cooling based on initial temperature
    if (temp < 20) {
      heating := true;
      cooling := false;
    } else {
      heating := false;
      cooling := true;
    }
  }

  next {
    // Check if heater needs to be turned on
    if (temp < 18 && !heating) {
      heatOn := true;
    } else {
      heatOn := false;
    }

    // Check if heater needs to be turned off
    if (temp > 22 && heating) {
      heatOff := true;
    } else {
      heatOff := false;
    }
  }
}
