<commit_before>-- Copyright (c) 2009-2010 Incremental IP Limited
-- see LICENSE for license information

local assert, ipairs = assert, ipairs

local object = require("rima.lib.object")
local lib = require("rima.lib")
local core = require("rima.core")
local linearise = require("rima.mp.linearise")

module(...)


--------------------------------------------------------------------------------

local constraint = object:new(_M, "constraint")

function constraint:new(lhs, rel, rhs)
  assert(rel == "==" or rel == ">=" or rel == "<=")

  o = { type=rel, lhs=lhs, rhs=rhs }

  return object.new(self, o)
end


function constraint:linearise(S)
  local constant, lhs = linearise.linearise(0 + self.lhs - self.rhs, S)
  return lhs, self.type, -constant
end


function constraint:tostring(S)
  local lhs = lib.repr(core.eval(self.lhs, S))
  local rhs = lib.repr(core.eval(self.rhs, S))
  local s = lhs.." "..self.type.." "..rhs
  return s
end

function constraint:__tostring()
  local lhs, rhs = lib.repr(self.lhs), lib.repr(self.rhs)
  local s = lhs.." "..self.type.." "..rhs
  return s
end


-- EOF -------------------------------------------------------------------------<commit_msg>rima: tidied up rima.mp.constraint<commit_after>-- Copyright (c) 2009-2010 Incremental IP Limited
-- see LICENSE for license information

local assert, ipairs = assert, ipairs

local object = require("rima.lib.object")
local lib = require("rima.lib")
local core = require("rima.core")
local linearise = require("rima.mp.linearise")

module(...)


--------------------------------------------------------------------------------

local constraint = object:new(_M, "constraint")

function constraint:new(lhs, rel, rhs)
  assert(rel == "==" or rel == ">=" or rel == "<=")

  o = { type=rel, lhs=lhs, rhs=rhs }

  return object.new(self, o)
end


function constraint:__eval(S)
  return constraint:new(core.eval(self.lhs, S), self.type, core.eval(self.rhs, S))
end


function constraint:linearise(S)
  local constant, lhs = linearise.linearise(0 + self.lhs - self.rhs, S)
  return lhs, self.type, -constant
end


function constraint:tostring(S)
  local lhs = lib.repr(core.eval(self.lhs, S))
  local rhs = lib.repr(core.eval(self.rhs, S))
  local s = lhs.." "..self.type.." "..rhs
  return s
end

function constraint:__repr(format)
  local lhs, rhs = lib.repr(self.lhs, format), lib.repr(self.rhs, format)
  local s = lhs.." "..self.type.." "..rhs
  return s
end
constraint.__tostring = lib.__tostring


-- EOF -------------------------------------------------------------------------
{'fraction_non_alphanumeric': 0.2627879734478719, 'fraction_numerical': 0.007028504490433424, 'mean_word_length': 2.331599479843953, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '893439', 'n_tokens_mistral': 854, 'n_tokens_neox': 827, 'n_words': 214}