PHP code example of gosuperscript / schema-interval

1. Go to this page and download the library: Download gosuperscript/schema-interval library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gosuperscript / schema-interval example snippets


use Superscript\Axiom\Interval\Types\IntervalType;
use Superscript\Interval\Interval;
use Superscript\Interval\IntervalNotation;
use Brick\Math\BigNumber;

$type = new IntervalType();

// Transform from string
$result = $type->transform('[1,2]');
$interval = $result->unwrap()->unwrap();

// Transform from Interval object
$interval = new Interval(
    BigNumber::of(1),
    BigNumber::of(2),
    IntervalNotation::Closed
);
$result = $type->transform($interval);

// Compare two intervals
$a = $type->transform('[1,2]')->unwrap()->unwrap();
$b = $type->transform('[1,2]')->unwrap()->unwrap();
$isEqual = $type->compare($a, $b); // true

// Format interval back to string
$formatted = $type->format($interval); // "[1,2]"

use Superscript\Axiom\Interval\Operators\IntervalOverloader;
use Superscript\Interval\Interval;

$overloader = new IntervalOverloader();
$interval = Interval::fromString('[2,3]');

// Check if operator is supported
$supports = $overloader->supportsOverloading($interval, 1, '>'); // true

// Evaluate comparisons
$overloader->evaluate($interval, 1, '>');   // true (interval is greater than 1)
$overloader->evaluate($interval, 2, '>=');  // true (interval is >= 2)
$overloader->evaluate($interval, 3, '<=');  // true (interval is <= 3)
$overloader->evaluate($interval, 4, '<');   // true (interval is less than 4)