Home /Modules/advantage/SLJointProfitMax.sleela

SLJointProfitMax.sleela

lib/advantage/math/SLJointProfitMax.sleela · 119 line(s) · sleela

<< lib/advantage/math/SLJointProfitMax.sleela
   SLeeLa Standard Library Definition.
   Definition: Joint Profit Maximization -- the integrated surplus formula for
   a coordinated buyer+seller system. >>
#sleela 3.0
material;
artifact;
pure;
gasoline;
< Model 1 of the advantage trade subject. Treat buyer and seller as one >
< coordinated system and maximize the total economic surplus BEFORE dividing >
< it: Pi_total(Q) = R_B(Q) - C_S(Q). >
<  >
< Curve convention (quadratic, so Q* and the marginals are exact): >
<   R_B(Q) = rbA*Q - rbB*Q^2     buyer revenue / utility (concave) >
<   C_S(Q) = csA*Q + csB*Q^2     seller cost (convex) >
< Marginal revenue  dR_B/dQ = rbA - 2*rbB*Q. >
< Marginal cost     dC_S/dQ = csA + 2*csB*Q. >
< Decision rule MR = MC gives Q* = (rbA - csA) / (2*(rbB + csB)). >
class SLJointProfitMax {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 10522;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-11-08";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-11-08";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 8;
  << metaNationalSchedule: the profit-maximizing rule MR = MC is classical
     marginalism (Cournot, 1838); an academic result, not a statute. >>
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }

  < ---- Curve coefficients ---- >
  < linear term of buyer revenue R_B(Q) >
  double rbA;
  < quadratic (diminishing) term of buyer revenue >
  double rbB;
  < linear term of seller cost C_S(Q) >
  double csA;
  < quadratic (convex) term of seller cost >
  double csB;

  void configureCurves(double rbA0, double rbB0, double csA0, double csB0) {
    rbA = rbA0;
    rbB = rbB0;
    csA = csA0;
    csB = csB0;
  }

  double getRbA() { return rbA; }
  double getRbB() { return rbB; }
  double getCsA() { return csA; }
  double getCsB() { return csB; }

  < Buyer revenue / utility from Q units. >
  double buyerRevenue(double q) { return rbA * q - rbB * q * q; }

  < Seller total cost for Q units. >
  double sellerCost(double q) { return csA * q + csB * q * q; }

  < Total available pool of profit: Pi_total(Q) = R_B(Q) - C_S(Q). >
  double jointProfit(double q) { return buyerRevenue(q) - sellerCost(q); }

  < Marginal revenue dR_B/dQ. >
  double marginalRevenue(double q) { return rbA - 2.0 * rbB * q; }

  < Marginal supply cost dC_S/dQ. >
  double marginalCost(double q) { return csA + 2.0 * csB * q; }

  < Optimal quantity Q* where MR = MC. 0 if no interior optimum exists. >
  double optimalQuantity() {
    double denom = 2.0 * (rbB + csB);
    if (denom <= 0.0) { return 0.0; }
    double q = (rbA - csA) / denom;
    if (q < 0.0) { return 0.0; }
    return q;
  }

  < The maximum joint surplus, evaluated at Q*. >
  double maxJointProfit() { return jointProfit(optimalQuantity()); }

  String describe() {
    double q = optimalQuantity();
    return "JointProfitMax: Q*=" + q + " Pi_total(Q*)=" + jointProfit(q)
         + " (MR=" + marginalRevenue(q) + " MC=" + marginalCost(q) + ")";
  }
}