Skip to content

Commit

Permalink
Correctly parse division terms as Real literals
Browse files Browse the repository at this point in the history
  • Loading branch information
bpandreotti committed Feb 23, 2024
1 parent 60fb1e1 commit 02ea63f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion carcara/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
};
use error::assert_num_args;
use indexmap::{IndexMap, IndexSet};
use rug::Integer;
use rug::{Integer, Rational};
use std::{io::BufRead, str::FromStr};

use self::error::assert_indexed_op_args_value;
Expand Down Expand Up @@ -257,6 +257,17 @@ impl<'a, R: BufRead> Parser<'a, R> {
SortError::assert_eq(&Sort::Real, sorts[0])?;
SortError::assert_all_eq(&sorts)?;
}

// If the term is a division between two positive integer constants, and their GCD
// is 1, then it should be interpreted as a rational literal. The only exception to
// this is the term '(/ 1 1)', which is still interpreted as a divison term.
if let Some(a) = args[0].as_integer() {
if let Some(b) = args[1].as_integer() {
if a > 0 && b > 0 && !(a == 1 && b == 1) && a.clone().gcd(&b) == 1 {
return Ok(self.pool.add(Term::new_real(Rational::from((a, b)))));
}
}
}
}
Operator::Mod => {
assert_num_args(&args, 2)?;
Expand Down

0 comments on commit 02ea63f

Please sign in to comment.