Essential (inherent) Ambiguity Examples

"essential ambiguity" = no grammar rule a) is a duplicate of any other, or b) is a composite function -- cannot itself be parsed using grammar rules; and, any "overloads" have been resolved by creating separate grammar rules for all permutation of variable type conversions and eliminating any resulting duplicate rules.



1.  "Self-ambiguous":
is it wi(wi(p, q), r)) or wi(p, wi(q, r))?

Metamath Source
   $c -> wff       $.
   $v p q r        $.
wp $f wff p        $.
wq $f wff q        $.
wr $f wff r        $.
wi $a wff p -> q   $.


Rule
Label
Rule
Type
Code
=========================================================

Grammar Rule Expressions
wi
wff
wff -> wff

Sample
p -> q -> r
Sample Parse RPNs:
1. wp wq wr wi wi
2. wp wq wi wr wi



2.  Overloaded Operator Associativity Ambiguity:
is it plus3(plus2(i, j), k) or plus2(plus3(i, j, k), r)?

Metamath Source
      $c + nbr        $.
      $v i j k r      $.
ni    $f nbr i        $.
nj    $f nbr j        $.
nk    $f nbr k        $.
nr    $f nbr r        $.
plus2 $a nbr + i j    $.
plus3 $a nbr + i j k  $.

Rule
Label
Rule
Type
Code
=========================================================

Grammar Rule Expressions
plus2
nbr
+ nbr nbr
plus3
nbr
+ nbr nbr nbr

Sample + + i j k r Sample Parse RPNs:        
1. ni nj plus2 ni nj plus3
2. ni nj nk plus3 ni plus2



3.  Mixed Prefix, Postfix Ambiguity -- AKA "Overlap"
is it and(p, or(q, r)) or or(and(p, q), r)?

Metamath Source
    $c & | wff      $.
    $v p q r        $.
wp  $f wff p        $.
wq  $f wff q        $.
wr  $f wff r        $.
and $a wff & p q    $.
or  $a wff p q |    $.

Rule
Label
Rule
Type
Code
=========================================================

Grammar Rule Expressions
and
wff
& wff wff
or
wff
wff wff |

Sample & p q r | Sample Parse RPNs:        
1. wp wq wr or and
2. wp wq and wr or





4.  Infix Overlap Ambiguity:
is it
or(and(p, q), r) or and(p, or(q, r)) or ?

Metamath Source
    $c & | wff      $.
    $v p q r        $.
wp  $f wff p        $.
wq  $f wff q        $.
wr  $f wff r        $.
and $a wff p & q    $.
or  $a wff p | q    $.

Rule
Label
Rule
Type
Code
=========================================================

Grammar Rule Expressions
and
wff
wff & wff
or
wff
wff | wff

Sample p & q | r Sample Parse RPNs:        
1. wp wq wr or and
2. wp wq and wr or



5.  Adjacent Term Ambiguity:
is it
part1(c1, "# !", "@ *") or part2(c1, "#", "! @", "*")?

(
NOTE: This example leads me to think that Named Typed Constants should be restricted to Formula length = 2. -- i.e. no more than one Constant per Constant Expression.  Otherwise the GrammaticalParse(E) function becomes much more complicated?)

Metamath Source
         $c ( := ) # ! @ * part component subpart gadget  $.
         $v p1 c1 s1 s2 g1 g2 g3                          $.
p1h      $f part      p1                                  $.
c1h      $f component c1                                  $.
s1h      $f subpart   s1                                  $.
s2h      $f subpart   s2                                  $.
g1h      $f gadget    g1                                  $.
g2h      $f gadget    g2                                  $.
g3h      $f gadget    g3                                  $.
part1    $a part ( c1 := s1 s2 )                          $.
part2    $a part ( c1 := g1 g2 g3 )                       $.
subpart1 $a widget # !                                    $.
subpart2 $a widget @ *                                    $.
gadget1  $a #                                             $.
gadget2  $a ! @                          
gadget3  $a *

Rule
Label
Rule
Type
Code
======================================================

Grammar Rule Expressions
part1
part
( component := subpart subpart )
part2
part
( component := gadget gadget gadget )
subpart1
subpart
# !
subpart2
subpart
@ *
gadget1
gadget
#
gadget2
gadget
! @
gadget3
gadget
*

Sample ( c1 := # ! @ * ) Sample Parse RPNs:        
1. c1h subpart1 subpart2 part1
2. c1h gadget1 gadget2 gadget3 part2




6.  Infix Overlap Ambiguity #2:
is it
or(and(p, q), r) or and(p, or(q, r)) or ?

Metamath Source
    $c & | wff .       $.
    $v p q r           $.
wp  $f wff p           $.
wq  $f wff q           $.
wr  $f wff r           $.
and $a wff . p & q     $.
or  $a wff p | q .     $.

Rule
Label
Rule
Type
Code
=========================================================

Grammar Rule Expressions
and
wff
. wff & wff
or
wff
wff | wff .

Sample . p & q | r .Sample Parse RPNs:        
1. wp wq wr or and
2. wp wq and wr or



7.  Adjacent Term Ambiguity #2:
is it
part1(c1, #, !, @, *) or part2(c1, gadget1(!), gadget(*))?

(
Note: this is an example involving use of a Constant as a Named Typed Constant and as a plain old Constant. A similar usage is seen in set.mm's cdiv, wsb, and wsbc where "/" serves as a dual-use Constant -- once as a Class and once as punctuation.. In the example below, Syntax Axioms gadget1 and gadget2 imply that a gadget can be formed with 2 adjacent subparts, and if that "implied grammar rule" were added to the GrammarRuleTree forest then part1 would be immediately seens as being a composite function and hence, ambiguous.)

Metamath Source
         $c ( := ) # ! @ * part component subpart gadget  $.
         $v p1 c1 s1 s2 g1 g2 g3                          $.
p1h      $f part      p1                                  $.
c1h      $f component c1                                  $.
s1h      $f subpart   s1                                  $.
s2h      $f subpart   s2                                  $.
s3h      $f subpart   s3                                  $.
s4h      $f subpart   s4                                  $.
g1h      $f gadget    g1                                  $.
g2h      $f gadget    g2                                  $.
part1    $a part ( c1 := s1 s2 s3 s4 )                    $.
part2    $a part ( c1 := g1 g3 )                          $.
subpart1 $a widget #                                      $.
subpart2 $a widget !                                      $.
subpart3 $a widget @                                      $.
subpart4 $a widget *                                      $.
gadget1  $a # s1                                          $.
gadget2  $a @ s1                                          $.

Rule
Label
Rule
Type
Code
======================================================

Grammar Rule Expressions
part1
part
( component := subpart subpart subpart subpart )
part2
part
( component := gadget gadget )
subpart1
subpart
#
subpart2
subpart
!
subpart3
subpart
@
subpart4
subpart
*
gadget1
gadget
# subpart
gadget2
gadget
@ subpart

Sample ( c1 := # ! @ * ) Sample Parse RPNs:        
1. c1h subpart1 subpart2 subpart3 subpart4 part1
2. c1h subpart2 gadget1  subpart4 gadget2  part2




8.  Dual-use Delimiter/Operator Constant with Expression Embedding Ambiguities (2 samples)
Sample1: is it f(g(a)) or g(f(a))? Sample2: is it f(h(a)) or h(f(a)) or g(g(a))?

The extra ")"s are used as postfix operators, which introduces an ambiguity with the other function of ")" as a delimiter/endpoint. If we had "g $a A ( a ) * $." instead of "g $a A ( a ) ) $." then f(g(a)) would not equal g(f(a)).


Metamath Source
    $c ( ) A        $.
    $v a            $.
wa  $f A a          $.
f   $a A ( a )      $.
g   $a A ( a ) )    $.
h   $a A ( a ) ) )  $.

Rule
Label
Rule
Type
Code
=========================================================

Grammar Rule Expressions
f
A
( A )
g
A
( A ) )
h
A
( A ) ) )

Sample1 ( ( a ) ) ) Sample Parse RPNs:        
1. wa f g
2. wa g f


Sample2 ( ( a ) ) ) ) Sample Parse RPNs:        
1. wa f h
2. wa h f
3. wa g g