# -------------------------------------------------------------------
# braking-safety-worlds.n3
#
# Toy case study: braking safety in four "worlds".
#
# We model road scenarios with:
#   - speed v (m/s),
#   - friction coefficient mu (0 < mu ≤ 1),
#   - available distance d_avail (m) to brake safely before impact.
#
# Worlds:
#   W0  = "physics-based" world
#         d_stop = v * 1.0s + v^2 / (2 mu g), with g ≈ 9.8 m/s²
#
#   W1  = simplified rule (no reaction time, g ≈ 10):
#         d_stop ≈ v^2 / (2 mu 10)
#
#   W2  = naive world that ignores actual mu and assumes dry road:
#         d_stop ≈ v^2 / (2 * 0.7 * 10)
#
#   W3  = cautious world that multiplies W0 distance by 1.5:
#         d_stop ≈ 1.5 * d_stop_W0
#
# A scenario is "safe" in world W if:
#   d_stop_W ≤ d_avail
# and "risky" if:
#   d_stop_W > d_avail.
#
# ARC layer:
#   :answer  – summary of how the worlds classify four example
#              scenarios.
#   :reason  – short explanation of why the worlds disagree.
#   :check1..5 – small derived checks witnessing relationships
#                between the worlds on these examples.
#
# Formulas are simplified; this is NOT a real safety calculator.
# -------------------------------------------------------------------

@prefix :        <http://example.org/braking#> .
@prefix brake:   <http://example.org/braking#> .
@prefix thm:     <http://example.org/theorem#> .
@prefix rel:     <http://example.org/rel#> .

@prefix math:  <http://www.w3.org/2000/10/swap/math#> .
@prefix list:  <http://www.w3.org/2000/10/swap/list#> .
@prefix log:   <http://www.w3.org/2000/10/swap/log#> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

# -------------------------------------------------------------------
# Worlds and scenarios
# -------------------------------------------------------------------

:World    a rdfs:Class .
:Scenario a rdfs:Class .

:worldId     a rdf:Property .
:description a rdf:Property .

# Four worlds, in increasing "cautiousness"

:W0 a :World ;
    :worldId 0 ;
    :description "physics-based stopping distance with reaction time" .

:W1 a :World ;
    :worldId 1 ;
    :description "simplified braking-only rule (no reaction time, g≈10)" .

:W2 a :World ;
    :worldId 2 ;
    :description "naive rule: assumes dry friction (mu=0.7) for everyone" .

:W3 a :World ;
    :worldId 3 ;
    :description "cautious rule: 1.5 times the physics-based stopping distance" .

# Scenario parameters

:speed         a rdf:Property .  # m/s
:mu            a rdf:Property .  # dimensionless friction coefficient
:availDistance a rdf:Property .  # meters

# World-specific stopping distances

:stopDistance_W0 a rdf:Property .  # meters
:stopDistance_W1 a rdf:Property .
:stopDistance_W2 a rdf:Property .
:stopDistance_W3 a rdf:Property .

# Safety classifications per world

brake:safeInWorld  a rdf:Property .  # Scenario × World
brake:riskyInWorld a rdf:Property .

# -------------------------------------------------------------------
# Core stopping-distance rules
# -------------------------------------------------------------------

# World 0: physics-based distance with 1.0s reaction
#
#   d_react = v * 1.0
#   d_brake = v^2 / (2 mu g) with g ≈ 9.8
#   d_stop  = d_react + d_brake

{
  ?S :stopDistance_W0 ?d0 .
}
<=
{
  ?S a :Scenario ;
     :speed ?v ;
     :mu ?mu .

  (?v 1.0) math:product ?d_react .

  (?v 2) math:exponentiation ?v2 .
  (?mu 2.0) math:product ?tmp1 .
  (?tmp1 9.8) math:product ?denom .
  (?v2 ?denom) math:quotient ?d_brake .

  (?d_react ?d_brake) math:sum ?d0 .
} .

# World 1: simplified braking-only rule, g≈10, no reaction time
#
#   d_stop ≈ v^2 / (2 mu 10)

{
  ?S :stopDistance_W1 ?d1 .
}
<=
{
  ?S a :Scenario ;
     :speed ?v ;
     :mu ?mu .

  (?v 2) math:exponentiation ?v2 .
  (?mu 2.0) math:product ?tmp1 .
  (?tmp1 10.0) math:product ?denom1 .
  (?v2 ?denom1) math:quotient ?d1 .
} .

# World 2: naive rule assuming mu = 0.7 (dry)
#
#   d_stop ≈ v^2 / (2 * 0.7 * 10) = v^2 / 14

{
  ?S :stopDistance_W2 ?d2 .
}
<=
{
  ?S a :Scenario ;
     :speed ?v .

  (?v 2) math:exponentiation ?v2 .
  (?v2 14.0) math:quotient ?d2 .
} .

# World 3: cautious rule: 1.5 × World-0 distance

{
  ?S :stopDistance_W3 ?d3 .
}
<=
{
  ?S :stopDistance_W0 ?d0 .
  (?d0 1.5) math:product ?d3 .
} .

# -------------------------------------------------------------------
# Safety classification rules
#
# A scenario is "safe" in world W if:
#   d_stop_W ≤ availDistance
#
# and "risky" if:
#   d_stop_W >  availDistance
# -------------------------------------------------------------------

# World 0

{
  ?S brake:safeInWorld :W0 .
}
<=
{
  ?S :stopDistance_W0 ?d0 ;
     :availDistance ?da .
  ?d0 math:notGreaterThan ?da .
} .

{
  ?S brake:riskyInWorld :W0 .
}
<=
{
  ?S :stopDistance_W0 ?d0 ;
     :availDistance ?da .
  ?d0 math:greaterThan ?da .
} .

# World 1

{
  ?S brake:safeInWorld :W1 .
}
<=
{
  ?S :stopDistance_W1 ?d1 ;
     :availDistance ?da .
  ?d1 math:notGreaterThan ?da .
} .

{
  ?S brake:riskyInWorld :W1 .
}
<=
{
  ?S :stopDistance_W1 ?d1 ;
     :availDistance ?da .
  ?d1 math:greaterThan ?da .
} .

# World 2

{
  ?S brake:safeInWorld :W2 .
}
<=
{
  ?S :stopDistance_W2 ?d2 ;
     :availDistance ?da .
  ?d2 math:notGreaterThan ?da .
} .

{
  ?S brake:riskyInWorld :W2 .
}
<=
{
  ?S :stopDistance_W2 ?d2 ;
     :availDistance ?da .
  ?d2 math:greaterThan ?da .
} .

# World 3

{
  ?S brake:safeInWorld :W3 .
}
<=
{
  ?S :stopDistance_W3 ?d3 ;
     :availDistance ?da .
  ?d3 math:notGreaterThan ?da .
} .

{
  ?S brake:riskyInWorld :W3 .
}
<=
{
  ?S :stopDistance_W3 ?d3 ;
     :availDistance ?da .
  ?d3 math:greaterThan ?da .
} .

# -------------------------------------------------------------------
# Example scenarios
#
# All speeds in m/s, distances in meters.
# These values are illustrative, not calibrated.
# -------------------------------------------------------------------

# City driving, dry road
#   ~50 km/h (13.9 m/s), good friction, generous distance
:CityDry a :Scenario ;
  :description "city driving ~50 km/h, dry asphalt, generous gap" ;
  :speed 13.9 ;
  :mu 0.8 ;
  :availDistance 40.0 .

# Highway speed, dry road, short-ish gap
#   ~100 km/h (27.8 m/s), good friction, limited distance
:HighwayDryShortGap a :Scenario ;
  :description "highway ~100 km/h, dry asphalt, short gap to obstacle" ;
  :speed 27.8 ;
  :mu 0.8 ;
  :availDistance 60.0 .

# City speed, wet road
#   ~50 km/h, lower friction, moderate distance
:CityWet a :Scenario ;
  :description "city ~50 km/h, wet surface, moderate gap" ;
  :speed 13.9 ;
  :mu 0.4 ;
  :availDistance 40.0 .

# City speed, icy road, short distance
#   ~50 km/h, very low friction, short distance
:CityIce a :Scenario ;
  :description "city ~50 km/h, icy surface, short gap" ;
  :speed 13.9 ;
  :mu 0.2 ;
  :availDistance 30.0 .

# -------------------------------------------------------------------
# ARC-style Answer / Reason / Checks
#
# Like the EV case, these nodes are *derived* from the classifications
# over the four scenarios. If you change the scenarios or rules, the
# Answer/Reason/Checks will adapt or disappear.
# -------------------------------------------------------------------

:text         a rdf:Property .
:usesWorld    a rdf:Property .
:usesScenario a rdf:Property .
:ok           a rdf:Property .
:msg          a rdf:Property .
:says         a rdf:Property .

# A: Answer
#
# We assert :answer when the following pattern holds:
#
#   CityDry:
#     safe  in W0, W1, W2, W3.
#
#   HighwayDryShortGap:
#     risky in W0 and W3, safe in W1 and W2.
#
#   CityWet:
#     safe  in W0, W1, W2, risky in W3.
#
#   CityIce:
#     risky in W0, W1, W3, safe in W2.
#
# This pattern reflects W0 as physics reference, W1/W2 as optimistic,
# and W3 as cautious.

{
  :CityDry brake:safeInWorld :W0, :W1, :W2, :W3 .

  :HighwayDryShortGap brake:riskyInWorld :W0, :W3 ;
                      brake:safeInWorld  :W1, :W2 .

  :CityWet brake:safeInWorld  :W0, :W1, :W2 ;
           brake:riskyInWorld :W3 .

  :CityIce brake:riskyInWorld :W0, :W1, :W3 ;
           brake:safeInWorld  :W2 .
}
=>
{
  :answer
    :text "On these four road scenarios, the physics-based world W0 judges CityDry and CityWet as safe and HighwayDryShortGap and CityIce as risky. The simplified worlds W1 and W2 are more optimistic: they treat the high-speed HighwayDryShortGap case as safe, and W2 even calls the icy CityIce scenario safe by assuming a dry-road friction. The cautious world W3 multiplies the physics-based stopping distance by a safety factor and therefore flags both HighwayDryShortGap and CityWet as risky, agreeing with W0 that CityIce is clearly unsafe. Together, the four worlds show how different stopping-distance rules can disagree about whether the available distance is enough to brake safely." ;
    :usesWorld :W0, :W1, :W2, :W3 ;
    :usesScenario :CityDry, :HighwayDryShortGap, :CityWet, :CityIce .
} .

# R: Reason
#
# We derive :reason from the same pattern. It explains how each world
# simplifies or strengthens the reference model.

{
  :CityDry brake:safeInWorld :W0, :W1, :W2, :W3 .

  :HighwayDryShortGap brake:riskyInWorld :W0, :W3 ;
                      brake:safeInWorld  :W1, :W2 .

  :CityWet brake:safeInWorld  :W0, :W1, :W2 ;
           brake:riskyInWorld :W3 .

  :CityIce brake:riskyInWorld :W0, :W1, :W3 ;
           brake:safeInWorld  :W2 .
}
=>
{
  :reason
    :says "World W0 treats braking as a combination of reaction distance and friction-limited deceleration. On the four examples, it cleanly separates easy situations (CityDry, CityWet) from clearly risky ones (HighwayDryShortGap, CityIce). World W1 drops the reaction time and behaves like a bare braking-distance rule; W2 goes further by assuming good dry friction for everyone, so they both tend to be more optimistic and call some borderline scenarios safe. World W3 goes in the opposite direction: it amplifies W0’s stopping distance with a safety factor, which can turn marginally safe cases like CityWet into risky ones. In this way, the worlds illustrate how different simplifications and safety margins change the answer to the real-world question: 'Is there enough distance to brake in time?'" .
} .

# -------------------------------------------------------------------
# C: Checks – harness rules
#
# Five small checks that each confirm one relationship between worlds.
# They only depend on brake:safeInWorld / brake:riskyInWorld facts.
# -------------------------------------------------------------------

# Check 1: W2 is the most optimistic on ice.
#          On CityIce, it is the only world that calls the situation
#          safe, while W0, W1 and W3 all agree it is risky.

{
  :CityIce brake:safeInWorld  :W2 ;
           brake:riskyInWorld :W0, :W1, :W3 .
}
=>
{
  :check1
    :ok true ;
    :msg "Check 1: on the icy CityIce scenario, world W2 is strictly more optimistic than W0, W1 and W3 because it assumes dry-road friction and still calls the situation safe while all others see risk." .
} .

# Check 2: W3 is at least as cautious as W0 on these scenarios.
#          Wherever W3 says safe, W0 also says safe; and W3 rejects
#          at least all scenarios that W0 rejects.

{
  :CityDry brake:safeInWorld  :W0, :W3 .
  :HighwayDryShortGap brake:riskyInWorld :W0, :W3 .
  :CityWet brake:safeInWorld  :W0 ;
           brake:riskyInWorld :W3 .
  :CityIce brake:riskyInWorld :W0, :W3 .
}
=>
{
  :check2
    :ok true ;
    :msg "Check 2: on these examples, the cautious world W3 is at least as conservative as the physics-based world W0: whenever W3 says safe, W0 also says safe, and W3 rejects all cases that W0 rejects, plus one more." .
} .

# Check 3: All four worlds agree on the easy city case.
#          CityDry is universally classified as safe.

{
  :CityDry brake:safeInWorld :W0, :W1, :W2, :W3 .
}
=>
{
  :check3
    :ok true ;
    :msg "Check 3: all worlds agree that the CityDry scenario — moderate speed, dry asphalt, generous distance — is safe, so the models converge on an uncontroversial case." .
} .

# Check 4: W1 and W2 are more optimistic than W0 on the high-speed,
#          short-gap highway case: they treat it as safe while W0
#          (and W3) see risk.

{
  :HighwayDryShortGap brake:riskyInWorld :W0, :W3 ;
                      brake:safeInWorld  :W1, :W2 .
}
=>
{
  :check4
    :ok true ;
    :msg "Check 4: on the HighwayDryShortGap scenario, worlds W1 and W2 are more optimistic than the reference world W0 and the cautious world W3, since they classify the situation as safe despite W0 and W3 judging the available distance as insufficient." .
} .

# Check 5: Every scenario that W0 considers risky is also risky in at
#          least one other world; there are no W0-only risks.

{
  :HighwayDryShortGap brake:riskyInWorld :W0, :W3 .
  :CityIce brake:riskyInWorld :W0, :W1, :W3 .
}
=>
{
  :check5
    :ok true ;
    :msg "Check 5: for all scenarios that the physics-based world W0 marks as risky, at least one other world also flags risk; in this example set there is no case where only W0 detects a problem." .
} .

