Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://gitlab.inria.fr/line/aide-group/macrovsa
04 May 2026, 13:41:51 UTC
  • Code
  • Branches (1)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/master
    No releases to show
  • d85ce8c
  • /
  • src
  • /
  • algo.cpp
Raw File Download Save again
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:92efb86e6277754e7337b24dbb29ea4a0cb60573
origin badgedirectory badge
swh:1:dir:b8157120e03f8858febdc76e496e300e843c5750
origin badgerevision badge
swh:1:rev:31a87d848f8ab28a06ccf77d0b359fc966974138
origin badgesnapshot badge
swh:1:snp:ffb1e6ef77e78b82672462770a7171c80c299b3b

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
Tip revision: 31a87d848f8ab28a06ccf77d0b359fc966974138 authored by vthierry on 15 December 2025, 21:31:50 UTC
sync from makefile
Tip revision: 31a87d8
algo.cpp
#include "algo.hpp"
#include "Binding.hpp"
#include "Bundling.hpp"
#include "AssociativeMap.hpp"
#include <map>

namespace macrovsa {
  const Symbol& algo::reduce(const Symbol& symbol)
  {
    static Symbol::Symbols symbols;
    return reduce(symbol, symbols);
  }
  const Symbol& algo::reduce(const Symbol& symbol, Symbol::Symbols& symbols)
  {
    switch(symbol.getType()) {
    case Symbol::bundling:
    {
      const Bundling& s_ = dynamic_cast < const Bundling& > (symbol);
      // Expands the reduction through a bundling arguments
      Bundling *result = new Bundling();
      for(auto it = s_.get().cbegin(); it != s_.get().cend(); it++) {
        result->add(reduce(*(it->second), symbols));
      }
      return reduce(result, symbols);
    }
    case Symbol::binding:
    {
      const Binding& s_ = dynamic_cast < const Binding& > (symbol);
      if(s_.y().getType() == Symbol::bundling) {
        // Expands binding on the y bundling argument
        const Bundling& y_ = dynamic_cast < const Bundling& > (s_.y());
        Bundling *result = new Bundling();
        for(auto it = y_.get().cbegin(); it != y_.get().cend(); it++) {
          Binding b_it(*(it->second), s_.x(), s_.b(), s_.normalized());
          result->add(reduce(b_it, symbols));
        }
        return reduce(result, symbols);
      } else {
        const Symbol& x_ = reduce(s_.x(), symbols);
        switch(x_.getType()) {
        case Symbol::bundling:
        {
          // Expands binding on the x bundling argument
          const Bundling& x__ = dynamic_cast < const Bundling& > (x_);
          Bundling *result = new Bundling();
          for(auto it = x__.get().cbegin(); it != x__.get().cend(); it++) {
            Binding b_it(s_.y(), *(it->second), s_.b(), s_.normalized());
            result->add(reduce(b_it, symbols));
          }
          return reduce(result, symbols);
        }
        case Symbol::binding:
        {
          // Reduces dual binding unbinding operation
          const Binding& x__ = dynamic_cast < const Binding& > (x_);
          if(s_.y().equals(x__.y()) && s_.b() != x__.b()) {
            Symbol& result = *Symbol::clone(reduce(x__.x(), symbols), symbols);
            result.setBelief(s_.getBelief().tau * x__.getBelief().tau, s_.getBelief().sigma + x__.getBelief().sigma + algo::sigma_0);
            return result;
          }
        }
        default: // Symbol::atomic:
          return symbol;
        }
      }
    }
    case Symbol::associativemap:
      return reduce(dynamic_cast < const AssociativeMap& > (symbol).getBundling());
    default:
      return symbol;
    }
  }
  const Symbol& algo::reduce(Bundling *bundling, Symbol::Symbols& symbols)
  {
    // Empty bundling, returns the ``empty´´ symbol
    if(bundling->get().size() == 0) {
      Symbol *result = new Symbol("", bundling->getBelief().tau, bundling->getBelief().sigma);
      symbols.add(result);
      return *result;
    }
    // Bundling singleton, returns the unique symbol
    if(bundling->get().size() == 1) {
      Symbol *result = Symbol::clone(*(bundling->get().cbegin()->second), symbols);
      return *result;
    }
    symbols.add(bundling);
    return *bundling;
  }
  Belief algo::sim(const Symbol& s1, const Symbol& s2, bool reduce)
  {
    if(reduce) {
      return sim(algo::reduce(s1), algo::reduce(s2), false);
    }
    if(s1.getType() == Symbol::bundling) {
      const Bundling& s1_ = dynamic_cast < const Bundling& > (s1);
      Belief result(0, 0);
      for(auto it = s1_.get().cbegin(); it != s1_.get().cend(); it++) {
        Belief result_it = sim(*(it->second), s2, false);
        result.tau += result_it.tau;
        result.sigma += result_it.sigma;
      }
      return result;
    } else if(s1.getType() == Symbol::associativemap) {
      const AssociativeMap& s1_ = dynamic_cast < const AssociativeMap& > (s1);
      Belief result(0, 0);
      for(auto it = s1_.get().cbegin(); it != s1_.get().cend(); it++) {
        for(auto jt = it->second.second.cbegin(); jt != it->second.second.cend(); jt++) {
          Binding binding(*(it->second.first), *(jt->second));
          Belief result_it = sim(binding, s2, false);
          result.tau += result_it.tau;
          result.sigma += result_it.sigma;
        }
      }
      return result;
    } else if(s2.getType() == Symbol::bundling) {
      return sim(s2, s1, false);
    } else if(s2.getType() == Symbol::associativemap) {
      return sim(s2, s1, false);
    }
    Belief result(s1.getID() == s2.getID() ? s1.getBelief().tau *s2.getBelief().tau : 0, fabs (s1.getBelief().tau *s2.getBelief().tau) *sigma_0 + fabs (s2.getBelief().tau) *s1.getBelief().sigma + fabs (s1.getBelief().tau) *s2.getBelief().sigma);
    return result;
  }
  double algo::msim(const Symbol& s1, const Symbol& s2)
  {
    const double *v1 = s1.getVector(), *v2 = s2.getVector();
    double r = 0;
    for(unsigned int i = 0; i < Symbol::getDimension(); i++) {
      r += v1[i] * v2[i];
    }
    return r;
  }
  Belief algo::conj(const Belief& a1, const Belief& a2)
  {
    Belief belief(fmax (0, fmin(a1.tau, a2.tau)), a1.sigma + a2.sigma);
    return belief;
  }
  Belief algo::conj(const Belief& a1, const Belief& a2, const Belief& a3)
  {
    Belief belief(fmax (0, fmin(a1.tau, fmin(a2.tau, a3.tau))), a1.sigma + a2.sigma + a3.sigma);
    return belief;
  }
  Belief algo::conj(const Belief& a1, const Belief& a2, const Belief& a3, const Belief& a4)
  {
    Belief belief(fmax (0, fmin(a1.tau, fmin(a2.tau, fmin(a3.tau, a4.tau)))), a1.sigma + a2.sigma + a3.sigma + a4.sigma);
    return belief;
  }
  Belief algo::conj(const Belief& a1, const Belief& a2, const Belief& a3, const Belief& a4, const Belief& a5)
  {
    Belief belief(fmax (0, fmin(a1.tau, fmin(a2.tau, fmin(a3.tau, fmin(a4.tau, a5.tau))))), a1.sigma + a2.sigma + a3.sigma + a4.sigma + a5.sigma);
    return belief;
  }
  Belief algo::conj(const Belief& a1, const Belief& a2, const Belief& a3, const Belief& a4, const Belief& a5, const Belief& a6)
  {
    Belief belief(fmax (0, fmin(a1.tau, fmin(a2.tau, fmin(a3.tau, fmin(a4.tau, fmin(a5.tau, a6.tau)))))), a1.sigma + a2.sigma + a3.sigma + a4.sigma + a5.sigma + a6.sigma);
    return belief;
  }
  Belief algo::conj(const Belief& a1, const Belief& a2, const Belief& a3, const Belief& a4, const Belief& a5, const Belief& a6, const Belief& a7)
  {
    Belief belief(fmax (0, fmin(a1.tau, fmin(a2.tau, fmin(a3.tau, fmin(a4.tau, fmin(a5.tau, fmin(a6.tau, a7.tau))))))), a1.sigma + a2.sigma + a3.sigma + a4.sigma + a5.sigma + a6.sigma + a7.sigma);
    return belief;
  }
  Belief algo::conj(const Belief& a1, const Belief& a2, const Belief& a3, const Belief& a4, const Belief& a5, const Belief& a6, const Belief& a7, const Belief& a8)
  {
    Belief belief(fmax (0, fmin(a1.tau, fmin(a2.tau, fmin(a3.tau, fmin(a4.tau, fmin(a5.tau, fmin(a6.tau, fmin(a7.tau, a8.tau)))))))), a1.sigma + a2.sigma + a3.sigma + a4.sigma + a5.sigma + a6.sigma + a7.sigma + a8.sigma);
    return belief;
  }
  double algo::sigma_0 = 0, algo::sigma_04 = 0;
}

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API