lhs * (1/rhs)

Percentage Accurate: 99.6% → 100.0%
Time: 1.7s
Alternatives: 1
Speedup: 1.4×

Specification

?
\[\left(-10 \leq lhs \land lhs \leq 10\right) \land \left(-10 \leq rhs \land rhs \leq 10\right)\]
\[\begin{array}{l} \\ lhs \cdot \frac{1}{rhs} \end{array} \]
(FPCore (lhs rhs) :precision binary64 (* lhs (/ 1.0 rhs)))
double code(double lhs, double rhs) {
	return lhs * (1.0 / rhs);
}
real(8) function code(lhs, rhs)
    real(8), intent (in) :: lhs
    real(8), intent (in) :: rhs
    code = lhs * (1.0d0 / rhs)
end function
public static double code(double lhs, double rhs) {
	return lhs * (1.0 / rhs);
}
def code(lhs, rhs):
	return lhs * (1.0 / rhs)
function code(lhs, rhs)
	return Float64(lhs * Float64(1.0 / rhs))
end
function tmp = code(lhs, rhs)
	tmp = lhs * (1.0 / rhs);
end
code[lhs_, rhs_] := N[(lhs * N[(1.0 / rhs), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
lhs \cdot \frac{1}{rhs}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 1 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ lhs \cdot \frac{1}{rhs} \end{array} \]
(FPCore (lhs rhs) :precision binary64 (* lhs (/ 1.0 rhs)))
double code(double lhs, double rhs) {
	return lhs * (1.0 / rhs);
}
real(8) function code(lhs, rhs)
    real(8), intent (in) :: lhs
    real(8), intent (in) :: rhs
    code = lhs * (1.0d0 / rhs)
end function
public static double code(double lhs, double rhs) {
	return lhs * (1.0 / rhs);
}
def code(lhs, rhs):
	return lhs * (1.0 / rhs)
function code(lhs, rhs)
	return Float64(lhs * Float64(1.0 / rhs))
end
function tmp = code(lhs, rhs)
	tmp = lhs * (1.0 / rhs);
end
code[lhs_, rhs_] := N[(lhs * N[(1.0 / rhs), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
lhs \cdot \frac{1}{rhs}
\end{array}

Alternative 1: 100.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \frac{lhs}{rhs} \end{array} \]
(FPCore (lhs rhs) :precision binary64 (/ lhs rhs))
double code(double lhs, double rhs) {
	return lhs / rhs;
}
real(8) function code(lhs, rhs)
    real(8), intent (in) :: lhs
    real(8), intent (in) :: rhs
    code = lhs / rhs
end function
public static double code(double lhs, double rhs) {
	return lhs / rhs;
}
def code(lhs, rhs):
	return lhs / rhs
function code(lhs, rhs)
	return Float64(lhs / rhs)
end
function tmp = code(lhs, rhs)
	tmp = lhs / rhs;
end
code[lhs_, rhs_] := N[(lhs / rhs), $MachinePrecision]
\begin{array}{l}

\\
\frac{lhs}{rhs}
\end{array}
Derivation
  1. Initial program 99.6%

    \[lhs \cdot \frac{1}{rhs} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \color{blue}{lhs \cdot \frac{1}{rhs}} \]
    2. lift-/.f64N/A

      \[\leadsto lhs \cdot \color{blue}{\frac{1}{rhs}} \]
    3. un-div-invN/A

      \[\leadsto \color{blue}{\frac{lhs}{rhs}} \]
    4. lower-/.f64100.0

      \[\leadsto \color{blue}{\frac{lhs}{rhs}} \]
  4. Applied rewrites100.0%

    \[\leadsto \color{blue}{\frac{lhs}{rhs}} \]
  5. Add Preprocessing

Reproduce

?
herbie shell --seed 1 
(FPCore (lhs rhs)
  :name "lhs * (1/rhs)"
  :precision binary64
  :pre (and (and (<= -10.0 lhs) (<= lhs 10.0)) (and (<= -10.0 rhs) (<= rhs 10.0)))
  (* lhs (/ 1.0 rhs)))