Did you know ... Search Documentation:
Pack esim_price_per_gb -- README.md

esim_price_per_gb

A small SWI-Prolog library for one question: which data plan is actually cheapest for this trip?

The headline price on a travel eSIM tells you very little. A 10 GB bundle for $18 looks like $1.80 a GB, but if you only use 4.9 GB on a ten day trip you paid $3.67 for every GB you used, and the other 5.1 GB disappears when the plan expires. This library does that sum for you, for bundles, pay as you go, and pay as you go sold in 1 GB blocks.

Install

?- pack_install(esim_price_per_gb).
?- use_module(library(esim_price_per_gb)).

Quick example

Ten days in Japan, normal use (maps, messaging, social apps, some photos):

?- trip_need_gb(10, standard, GB).
GB = 4.9.

?- compare_plans(4.9, [ payg(payg_japan, 2.76),
                        bundle(bundle_5gb, 5, 15),
                        bundle(bundle_10gb, 10, 18) ], Rows).
Rows = [ row(payg_japan, 13.52, 2.76, 0),
         row(bundle_5gb, 15, 3.06, 0.1),
         row(bundle_10gb, 18, 3.67, 5.1) ].

Each row is row(Name, Cost, EffectivePerGB, WastedGB), cheapest first. EffectivePerGB divides the cost by the data you use, so unused data counts against a bundle.

When does the 10 GB bundle start to win?

?- break_even_gb(bundle(bundle_10gb, 10, 18), payg(payg_japan, 2.76), GB).
GB = 6.52.

So above about 6.5 GB the bundle is the better buy. Below that, pay as you go. Against a cheap rate such as $0.76/GB the bundle never wins inside its own 10 GB, and you get GB = never.

Predicates

PredicateWhat it does
per_gb(+Price, +GB, -PerGB)Price of one GB, to the cent
trip_need_gb(+Days, +Usage, -GB)Usage is light (150 MB/day), standard (500), heavy (1500) or mb_per_day(N). Uses 1 GB = 1024 MB and rounds up to 0.1 GB
plan_cost(+Need, +Plan, -Cost, -Wasted)Cost to cover Need, and GB paid for but unused
compare_plans(+Need, +Plans, -Rows)All plans ranked, ties broken by less waste
cheapest_plan(+Need, +Plans, -Row)First row of the above
break_even_gb(+Bundle, +Payg, -GB)Usage where one bundle copy beats pay as you go

Plans are bundle(Name, GB, Price), payg(Name, PerGB) or payg(Name, PerGB, StepGB). Use any currency, just keep it the same across plans.

Picking the usage level

Check last month's mobile data in your phone settings and divide by 30. That is better than any default. Rough guide if you have nothing to go on:

  • light: maps, WhatsApp or Signal, email. Video calls on hotel wifi only.
  • standard: the above plus Instagram or TikTok scrolling and uploading photos.
  • heavy: video calls on mobile data, streaming, or tethering a laptop. Hotspotting a laptop is what blows budgets. A single work day on a laptop can use 1 to 3 GB.

Where to get real rates

Rates change, so the library ships no price table. We maintain Silent eSIM, and our per-country eSIM price per GB table lists our pay-as-you-go rate for 218 countries. When we checked it on 25 November 2026 the cheapest was Ukraine at $0.76/GB, most of the EU and the UK were $1.08/GB, the US $1.74/GB, Japan $2.76/GB and the median $4.73/GB. Compare those with whatever bundles you are looking at, from us or anyone else.

Tests

cd test
swipl -g run_tests -t halt test_esim_price_per_gb.pl

17 plunit tests.

Licence

MIT