How should a bytecode VM call external C functions?

I am trying to implement a basic bytecode VM, which I plan to target with a compiler. How can I implement the ability to call external C functions using the bytecode, i.e., call arbitrary functions in runtime. For example, my future compiler should be able to produce programs that call printf(), malloc(), etc. My guess is you could somehow ask the OS for the needed functions address and jump to it, probably making use of things like dlopen() and dlsym(), however I don’t know the exact details and the specifics on implementing that in a VM.

dg.differential geometry – A characterization of functions which Riemannian Hessian equal to zero

Consider Euclidean space $mathbb{R}^n$, and measure distances in this space with some Riemannian metric $M(x)$. That is, for two points $x, y$, define $d(x, y)$ to be equal to
$$d(x, y) = inf_{gamma(cdot) in Gamma_{x, y}}sqrt{int_0^1 dot{gamma}(s)^{mathsf{T}}M(gamma(s))dot{gamma}(s)ds},$$ where $Gamma_{x, y}$ denotes the set of all curves over $(0, 1)$ satisfying $gamma(0) = x, gamma(1) = y$.

I’m interested in characterizing the set of “linear” functions with respect to this metric. That is, what are all functions that have Riemannian Hessian equal to zero in this metric? I understand that, on a compact Riemannian manifold, such functions are trivial. But what about a manifold with a single global chart as I’ve constructed here?

c# – How to just pass in primary key values to my CRUD functions?

Here is my code:

albums.cshtml

@page
@model Project.Pages.AlbumsModel            
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<div class="row">
    <h1 class="display-2">Albums</h1>
    <table class="table">
        <thead class="thead-inverse">
            <tr>
                <th>Album ID, artist ID, Album title</th>
            </tr>
        </thead>
        <tbody>
            @foreach (string album in Model.Albums)
            {
                <tr>
                    <td>@album</td>
                    <td><a asp-page="/Albums/Delete" asp-route-id="@album">Delete</a></td>
                    <td><a asp-page="/Albums/Edit" asp-route-id="@album">Edit title</a></td>
                </tr>
            }
        </tbody>
    </table>
</div>
<div class="row">
    <p>Enter a title & ArtistID for a new album:&nbsp;</p>
    <form method="POST">
        <div><input asp-for="Album.Title" /></div>
        <div><input asp-for="Album.ArtistId" /></div>
        <input type="submit" />
    </form>
</div>

albums.cshtml.cs

using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Project.Models;
using System;

namespace Project.Pages
{
    public class AlbumsModel : PageModel
    {
        private Chinook db;

        public AlbumsModel(Chinook injectedContext)
        {
            db = injectedContext;
        }
        public IEnumerable<string> Albums { get; set; }
        public void OnGet()
        {
            ViewData("Title") = "Chinook Web Site - Albums";
            Albums = db.Albums.Select(s => s.AlbumId.ToString() + ". " + s.ArtistId + ". " + s.Title);
        }
        (BindProperty)
        public Album Album { get; set; }

        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                db.Albums.Add(Album);
                db.SaveChanges();
                return RedirectToPage("/albums");
            }
            return Page();
        }

        public IActionResult DeleteAlbum(int AlbumId)
        {
            var album = db.Albums.Find(AlbumId);

            if (album == null) return Page();

            db.Albums.Remove(album); db.SaveChanges(); return RedirectToPage("/albums");
        }
    }
}

delete.cshtml

@page  "{id?}"
@model Project.Pages.Albums.DeleteModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

@{
    ViewData("Title") = "Delete";
}

<h1>Delete</h1>

<p class="text-danger">@Model.ErrorMessage</p>

<h3>Are you sure you want to delete this?</h3>
<div>
    <h4>Album</h4>
    <hr />
    <dl class="row">
        <dt class="col-sm-2">
            @Html.DisplayNameFor(model => model.Album.Title)
        </dt>
        <dd class="col-sm-10">
            @Html.DisplayFor(model => model.Album.Title)
        </dd>
        <dt class="col-sm-2">
            @Html.DisplayNameFor(model => model.Album.ArtistId)
        </dt>
        <dd class="col-sm-10">
            @Html.DisplayFor(model => model.Album.ArtistId)
        </dd>
        <dt class="col-sm-2">
            @Html.DisplayNameFor(model => model.Album.AlbumId)
        </dt>
        <dd class="col-sm-10">
            @Html.DisplayFor(model => model.Album.AlbumId)
        </dd>
    </dl>

        <form method="post">
        <input type="submit" value="Delete" asp-route-id="@Model.Album.AlbumId" class="btn btn-danger" /> |
        <a asp-page="/Albums">Back to List</a>
    </form>
</div>

delete.cshtml.cs

#region snippet_All
using Project.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;

namespace Project.Pages.Albums
{
    public class DeleteModel : PageModel
    {
        private readonly Chinook _context;

        public DeleteModel(Chinook context)
        {
            _context = context;
        }

        (BindProperty)
        public Album Album { get; set; }
        public string ErrorMessage { get; set; }

        public async Task<IActionResult> OnGetAsync(string? id, bool? saveChangesError = false) //changed int -> string
        {
            if (id == null)
            {
                return NotFound();
            }
            //using string.split method to split the id parameter, and get the albumid.
            var albumid = System.Convert.ToInt32(id.ToString().Split('.')(0));

            Album = await _context.Albums
                .AsNoTracking()
                .FirstOrDefaultAsync(m => m.AlbumId == albumid);

            if (Album == null)
            {
                return NotFound();
            }

            if (saveChangesError.GetValueOrDefault())
            {
                ErrorMessage = "Delete failed. Try again";
            }

            return Page();
        }

        public async Task<IActionResult> OnPostAsync(int? id)
        {
            if (id == null)
            {
                return NotFound();
            }

            var album = await _context.Albums.FindAsync(id);

            if (album == null)
            {
                return NotFound();
            }

            try
            {
                _context.Albums.Remove(album);
                await _context.SaveChangesAsync();
                return RedirectToPage("/Albums");
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.)
                return RedirectToAction("/Albums/Delete",
                                     new { id, saveChangesError = true });
            }
        }
    }
}
#endregion

edit.cshtml

@page
@model Project.Pages.Albums.EditModel

@{
    ViewData("Title") = "Edit";
}

<h1>Edit</h1>

<h4>Album</h4>
<hr />
<div class="row">
    <div class="col-md-4">
        <form method="post">
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <input type="hidden" asp-for="Album.AlbumId" />
            <div class="form-group">
                <label asp-for="Album.Title" class="control-label"></label>
                <input asp-for="Album.Title" class="form-control" />
                <span asp-validation-for="Album.Title" class="text-danger"></span>
            </div>
            <div class="form-group">
                <input type="submit" value="Save" class="btn btn-primary" />
            </div>
        </form>
    </div>
</div>

<div>
    <a asp-page="/Albums">Back to List</a>
</div>

@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}

edit.cshtml.cs

using Project.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;

namespace Project.Pages.Albums
{
    public class EditModel : PageModel
    {
        private readonly Chinook _context;

        public EditModel(Chinook context)
        {
            _context = context;
        }

        (BindProperty)
        public Album Album { get; set; }
        public string ErrorMessage { get; set; }

        #region snippet_OnGetPost
        // public async Task<IActionResult> OnGetAsync(int? id)
        // {
        //     if (id == null)
        //     {
        //         return NotFound();
        //     }

        //     Album = await _context.Albums.FindAsync(id);

        //     if (Album == null)
        //     {
        //         return NotFound();
        //     }
        //     return Page();
        // }

        public async Task<IActionResult> OnGetAsync(string? id, bool? saveChangesError = false) //changed int -> string
        {
            if (id == null)
            {
                return NotFound();
            }
            //using string.split method to split the id parameter, and get the albumid.
            var albumid = System.Convert.ToInt32(id.ToString().Split('.')(0));

            Album = await _context.Albums
                .AsNoTracking()
                .FirstOrDefaultAsync(m => m.AlbumId == albumid);

            if (Album == null)
            {
                return NotFound();
            }

            if (saveChangesError.GetValueOrDefault())
            {
                ErrorMessage = "Delete failed. Try again";
            }

            return Page();
        }

        public async Task<IActionResult> OnPostAsync(int id)
        {
            var albumToUpdate = await _context.Albums.FindAsync(id);

            if (albumToUpdate == null)
            {
                return NotFound();
            }

            if (await TryUpdateModelAsync<Album>(
                albumToUpdate,
                "album",
                s => s.Title))
            {
                await _context.SaveChangesAsync();
                return RedirectToPage("/Albums");
            }

            return Page();
        }
        #endregion

        private bool AlbumExists(int id)
        {
            return _context.Albums.Any(e => e.AlbumId == id);
        }
    }
}

My code build and runs OK, but when I go to edit, I get, for instance

This localhost page can’t be found
No web page was found for the web address: https://localhost:5001/Albums/Edit/353.%20123.%20Test

I’m sure it should just be passing in the AlbumId, as in

https://localhost:5001/Albums/Edit/353

…and when I manually change the URL to that, it works.

The delete function works from, for instance…

https://localhost:5001/Albums/Delete/353.%20123.%20Test2

…where ‘353’ is the AlbumId, ‘123’ is the ArtistId, and ‘Test2’ is the Title.

…but that actually does work. So how can I just get both Delete and Edit to work from the AlbumId? That is all that’s needed, right? TIA for any help.

time complexity – Existence of a function between two functions $f$ and $g$ where $f in o(g)$

Yes.

For example, let $h=sqrt{fg}$, assuming $f$ and $g$ are positive.

If not, we can let $h(x)=max(sqrt{|f(x)g(x)|}, g(x)/(|x|+1))$. The term, $g(x)/(|x|+1)$ makes sure that $h(x)$ will stay positive eventually.


Exercise. For each two functions $f$ and $g$, where $f in omega(g)$, there exists a function $h$ where $f in omega(h)$ and $h in omega(g)$.

parametric functions – How to initiate a matrix with indexed parameters

I couldn’t find it in the documentation, so I’m posting it here.
I want to create two by two matrices as follows:
$$
`W = begin{bmatrix}w_{11} & w_{12} \ w_{21} & w_{22} end{bmatrix},
V = begin{bmatrix}v_{11} & v_{21} \ v_{12} & v_{22} end{bmatrix}`
$$

so I could calculate $V^{-1}$ and see the result with the parameters $v_{ij}$‘s.

Tnx.

functions – WordPress wp_dequeue_script remove all other scripts

I want to override function in child theme to remove specific scripts, which is defined inside a class in parent theme.

Parent theme functions.php

class Theme_Assets extends Theme_Base {

    /**
     * Hold data for wa_theme for frontend
     * @var array
     */
    private static $theme_json = array();

    /**
     * (__construct description)
     * @method __construct
     */
    public function __construct() {

        // Frontend
        $this->add_action( 'wp_enqueue_scripts', 'dequeue', 2 );
        $this->add_action( 'wp_enqueue_scripts', 'register' );
        $this->add_action( 'wp_enqueue_scripts', 'enqueue' );

        self::add_config( 'uris', array(
            'ajax'    => admin_url('admin-ajax.php', 'relative')
        ));
    }

    /**
     * Unregister Scripts and Styles
     * @method dequeue
     * @return (type)  (description)
     */
    public function dequeue() {

    }

    /**
     * Register Scripts and Styles
     * @method register
     * @return (type)   (description)
     */
    public function register() {

        $this->script( 'bootstrap', $this->get_vendor_uri( 'bootstrap/js/bootstrap.min.js' ), array( 'jquery' ) );
        $this->script( 'intersection-observer', $this->get_vendor_uri( 'intersection-observer.js' ), array( 'jquery' ) );
        $this->script( 'jquery-lazyload', $this->get_vendor_uri( 'lazyload.min.js' ), array( 'jquery' ) );
        $this->script( 'imagesloaded', $this->get_vendor_uri( 'imagesloaded.pkgd.min.js' ), array( 'jquery' ) );
        $this->script( 'jquery-vivus', $this->get_vendor_uri( 'vivus.min.js' ), array( 'jquery' ) );
        $this->script( 'splittext', $this->get_vendor_uri( 'greensock/utils/SplitText.min.js' ), array( 'jquery' ) );
        $this->script( 'scrollmagic', $this->get_vendor_uri( 'scrollmagic/ScrollMagic.min.js' ), array( 'jquery' ) );
        $this->script( 'jquery-tinycolor', $this->get_vendor_uri( 'tinycolor-min.js' ), array( 'jquery' ) );
        
        $deps = array(
            'bootstrap',
            'intersection-observer',
            'imagesloaded',
            'scrollmagic',
        );
        
        // LazyLoad
        $enable_lazyload = theme_helper()->get_option( 'enable-lazy-load' );
        if( 'on' === $enable_lazyload ) {
            array_push( $deps,
                'jquery-lazyload'
            );
        }
        // Header Js
        $enable_header = theme_helper()->get_option( 'header-enable-switch' );
        if( 'on' === $enable_header ) {
            array_push( $deps,
                'jquery-tinycolor'
            );
        }

        if( is_page() ) {
            array_push( $deps,
                'splittext',
                'jquery-tinycolor'
            );
        }
    }

    /**
     * Enqueue Scripts and Styles
     * @method enqueue
     * @return (type)  (description)
     */
    public function enqueue() {

        if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
            wp_enqueue_script( 'comment-reply' );
        }
    }
    
    // Register Helpers ----------------------------------------------------------
    public function script( $handle, $src, $deps = null, $in_footer = true, $ver = null ) {
        wp_register_script( $handle, $src, $deps, $ver, $in_footer);
    }

    public function style( $handle, $src, $deps = null, $ver = null, $media = 'all' ) {
        wp_register_style( $handle, $src, $deps, $ver, $media );
    }

    // Uri Helpers ---------------------------------------------------------------

    public function get_theme_uri($file = '') {
        return get_template_directory_uri() . '/' . $file;
    }

    public function get_child_uri($file = '') {
        return get_stylesheet_directory_uri() . '/' . $file;
    }

    public function get_css_uri($file = '') {
        return $this->get_theme_uri('assets/css/'.$file.'.css');
    }

    public function get_elements_uri( $file = '' ) {
        return $this->get_theme_uri( 'assets/css/elements/' . $file . '.css' );
    }

    public function get_js_uri($file = '') {
        return $this->get_theme_uri('assets/js/'.$file.'.js');
    }

    public function get_vendor_uri($file = '') {
        return $this->get_theme_uri('assets/vendors/'.$file);
    }
}

new Theme_Assets;

I want to remove ‘splittext‘ and ‘jquery-tinycolor‘ scripts by inheriting dequeue function in parent theme but it remove all other scripts

Here is Child theme’s code in functions.php

add_action( 'after_setup_theme', function() {

   class D extends Theme_Assets{

   function __construct(){
      $this->add_action( 'wp_enqueue_scripts', 'dequeue', 20 );
   }
       
      public function dequeue(){
         wp_dequeue_script('jquery-tinycolor');
         wp_deregister_script('jquery-tinycolor');
         wp_dequeue_script('splittext');
         wp_deregister_script('splittext');
      }
   }

   new D();
});

Any helps are appreciate.

programming languages – Dfferences in c++ about how variables are used in functions and when to use int

I would want to know why code::blocks do not print the same thing if I write the next sequence of code:

int n,m,a(11)(11),x(11),y,z,v(11),i;
int va(int k)
{
    return a(x(k-1))(i) && !v(i);
}
int s(int k)
{
    return i==y;
}
void t(int k)
{
    for(int j=1; j<=k; j++)
              cout<<x(j)<<' ';
    cout<<endl;
}
void ck(int k)
{
    for(int i=1; i<=n; i++)
        if(va(k))
        {
            v(i)=1;
            x(k)=i;
            if(s(k))
            {
                t(k);
            }
            else ck(k-1);
            v(i)=0;
        }
}

as when I write the following one:

int n,m,a(11)(11),x(11),y,z,v(11),i;
int va(int k)
{
    return a(x(k-1))(i) && !v(i);
}
int s(int k)
{
    return x(k)==y;
}
void t(int k)
{
    for(int j=1; j<=k; j++)
              cout<<x(j)<<' ';
    cout<<endl;
}
void ck(int k)
{
    for(int i=1; i<=n; i++)
        if(a(x(k-1))(i) && !v(i))
        {
            v(i)=1;
            x(k)=i;
            if(s(k))
            {
                t(k);
            }
            else ck(k+1);
            v(i)=0;
        }
}

or the following one:

int n,m,a(11)(11),x(11),y,z,v(11),i;
int valid(int k)
{
    return a(x(k-1))(i) && !v(i);
}
int solutie(int k)
{
    return i==y;
}
void tipar(int k)
{
    for(int j=1; j<=k; j++)
              cout<<x(j)<<' ';
    cout<<endl;
}
void ck(int k)
{
    for(i=1; i<=n; i++)
        if(a(x(k-1))(i) && !v(i))
        {
            v(i)=1;
            x(k)=i;
            if(s(k))
            {
                t(k);
            }
            else ck(k+1);
            v(i)=0;
        }
}