| Alternative 1 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 1737 |
(FPCore (x y z t a) :precision binary64 (/ (- (* x y) (* z t)) a))
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (- (* x y) (* z t))))
(if (or (<= t_1 -2e+288) (not (<= t_1 1e+253)))
(- (/ x (/ a y)) (/ z (/ a t)))
(/ (+ (+ (* x y) (* z t)) (* (* z t) -2.0)) a))))double code(double x, double y, double z, double t, double a) {
return ((x * y) - (z * t)) / a;
}
double code(double x, double y, double z, double t, double a) {
double t_1 = (x * y) - (z * t);
double tmp;
if ((t_1 <= -2e+288) || !(t_1 <= 1e+253)) {
tmp = (x / (a / y)) - (z / (a / t));
} else {
tmp = (((x * y) + (z * t)) + ((z * t) * -2.0)) / a;
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = ((x * y) - (z * t)) / a
end function
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: t_1
real(8) :: tmp
t_1 = (x * y) - (z * t)
if ((t_1 <= (-2d+288)) .or. (.not. (t_1 <= 1d+253))) then
tmp = (x / (a / y)) - (z / (a / t))
else
tmp = (((x * y) + (z * t)) + ((z * t) * (-2.0d0))) / a
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
return ((x * y) - (z * t)) / a;
}
public static double code(double x, double y, double z, double t, double a) {
double t_1 = (x * y) - (z * t);
double tmp;
if ((t_1 <= -2e+288) || !(t_1 <= 1e+253)) {
tmp = (x / (a / y)) - (z / (a / t));
} else {
tmp = (((x * y) + (z * t)) + ((z * t) * -2.0)) / a;
}
return tmp;
}
def code(x, y, z, t, a): return ((x * y) - (z * t)) / a
def code(x, y, z, t, a): t_1 = (x * y) - (z * t) tmp = 0 if (t_1 <= -2e+288) or not (t_1 <= 1e+253): tmp = (x / (a / y)) - (z / (a / t)) else: tmp = (((x * y) + (z * t)) + ((z * t) * -2.0)) / a return tmp
function code(x, y, z, t, a) return Float64(Float64(Float64(x * y) - Float64(z * t)) / a) end
function code(x, y, z, t, a) t_1 = Float64(Float64(x * y) - Float64(z * t)) tmp = 0.0 if ((t_1 <= -2e+288) || !(t_1 <= 1e+253)) tmp = Float64(Float64(x / Float64(a / y)) - Float64(z / Float64(a / t))); else tmp = Float64(Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(Float64(z * t) * -2.0)) / a); end return tmp end
function tmp = code(x, y, z, t, a) tmp = ((x * y) - (z * t)) / a; end
function tmp_2 = code(x, y, z, t, a) t_1 = (x * y) - (z * t); tmp = 0.0; if ((t_1 <= -2e+288) || ~((t_1 <= 1e+253))) tmp = (x / (a / y)) - (z / (a / t)); else tmp = (((x * y) + (z * t)) + ((z * t) * -2.0)) / a; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -2e+288], N[Not[LessEqual[t$95$1, 1e+253]], $MachinePrecision]], N[(N[(x / N[(a / y), $MachinePrecision]), $MachinePrecision] - N[(z / N[(a / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(N[(z * t), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]]]
\frac{x \cdot y - z \cdot t}{a}
\begin{array}{l}
t_1 := x \cdot y - z \cdot t\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+288} \lor \neg \left(t_1 \leq 10^{+253}\right):\\
\;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x \cdot y + z \cdot t\right) + \left(z \cdot t\right) \cdot -2}{a}\\
\end{array}
Results
| Original | 88.5% |
|---|---|
| Target | 91.4% |
| Herbie | 98.8% |
if (-.f64 (*.f64 x y) (*.f64 z t)) < -2e288 or 9.9999999999999994e252 < (-.f64 (*.f64 x y) (*.f64 z t)) Initial program 27.1%
Applied egg-rr99.5%
[Start]27.1 | \[ \frac{x \cdot y - z \cdot t}{a}
\] |
|---|---|
div-sub [=>]27.1 | \[ \color{blue}{\frac{x \cdot y}{a} - \frac{z \cdot t}{a}}
\] |
associate-/l* [=>]61.0 | \[ \color{blue}{\frac{x}{\frac{a}{y}}} - \frac{z \cdot t}{a}
\] |
associate-/l* [=>]99.5 | \[ \frac{x}{\frac{a}{y}} - \color{blue}{\frac{z}{\frac{a}{t}}}
\] |
if -2e288 < (-.f64 (*.f64 x y) (*.f64 z t)) < 9.9999999999999994e252Initial program 98.6%
Applied egg-rr98.5%
[Start]98.6 | \[ \frac{x \cdot y - z \cdot t}{a}
\] |
|---|---|
div-inv [=>]98.5 | \[ \color{blue}{\left(x \cdot y - z \cdot t\right) \cdot \frac{1}{a}}
\] |
*-commutative [=>]98.5 | \[ \color{blue}{\frac{1}{a} \cdot \left(x \cdot y - z \cdot t\right)}
\] |
Applied egg-rr98.5%
[Start]98.5 | \[ \frac{1}{a} \cdot \left(x \cdot y - z \cdot t\right)
\] |
|---|---|
prod-diff [=>]98.5 | \[ \frac{1}{a} \cdot \color{blue}{\left(\mathsf{fma}\left(x, y, -t \cdot z\right) + \mathsf{fma}\left(-t, z, t \cdot z\right)\right)}
\] |
*-commutative [<=]98.5 | \[ \frac{1}{a} \cdot \left(\mathsf{fma}\left(x, y, -\color{blue}{z \cdot t}\right) + \mathsf{fma}\left(-t, z, t \cdot z\right)\right)
\] |
fma-neg [<=]98.5 | \[ \frac{1}{a} \cdot \left(\color{blue}{\left(x \cdot y - z \cdot t\right)} + \mathsf{fma}\left(-t, z, t \cdot z\right)\right)
\] |
*-commutative [<=]98.5 | \[ \frac{1}{a} \cdot \left(\left(x \cdot y - z \cdot t\right) + \mathsf{fma}\left(-t, z, \color{blue}{z \cdot t}\right)\right)
\] |
fma-udef [=>]98.5 | \[ \frac{1}{a} \cdot \left(\left(x \cdot y - z \cdot t\right) + \color{blue}{\left(\left(-t\right) \cdot z + z \cdot t\right)}\right)
\] |
distribute-lft-neg-in [<=]98.5 | \[ \frac{1}{a} \cdot \left(\left(x \cdot y - z \cdot t\right) + \left(\color{blue}{\left(-t \cdot z\right)} + z \cdot t\right)\right)
\] |
*-commutative [<=]98.5 | \[ \frac{1}{a} \cdot \left(\left(x \cdot y - z \cdot t\right) + \left(\left(-\color{blue}{z \cdot t}\right) + z \cdot t\right)\right)
\] |
associate-+r+ [=>]98.5 | \[ \frac{1}{a} \cdot \color{blue}{\left(\left(\left(x \cdot y - z \cdot t\right) + \left(-z \cdot t\right)\right) + z \cdot t\right)}
\] |
distribute-rgt-neg-in [=>]98.5 | \[ \frac{1}{a} \cdot \left(\left(\left(x \cdot y - z \cdot t\right) + \color{blue}{z \cdot \left(-t\right)}\right) + z \cdot t\right)
\] |
Applied egg-rr98.4%
[Start]98.5 | \[ \frac{1}{a} \cdot \left(\left(\left(x \cdot y - z \cdot t\right) + z \cdot \left(-t\right)\right) + z \cdot t\right)
\] |
|---|---|
associate-+l+ [=>]98.5 | \[ \frac{1}{a} \cdot \color{blue}{\left(\left(x \cdot y - z \cdot t\right) + \left(z \cdot \left(-t\right) + z \cdot t\right)\right)}
\] |
+-commutative [=>]98.5 | \[ \frac{1}{a} \cdot \color{blue}{\left(\left(z \cdot \left(-t\right) + z \cdot t\right) + \left(x \cdot y - z \cdot t\right)\right)}
\] |
+-commutative [=>]98.5 | \[ \frac{1}{a} \cdot \left(\color{blue}{\left(z \cdot t + z \cdot \left(-t\right)\right)} + \left(x \cdot y - z \cdot t\right)\right)
\] |
distribute-rgt-neg-out [=>]98.5 | \[ \frac{1}{a} \cdot \left(\left(z \cdot t + \color{blue}{\left(-z \cdot t\right)}\right) + \left(x \cdot y - z \cdot t\right)\right)
\] |
distribute-lft-neg-in [=>]98.5 | \[ \frac{1}{a} \cdot \left(\left(z \cdot t + \color{blue}{\left(-z\right) \cdot t}\right) + \left(x \cdot y - z \cdot t\right)\right)
\] |
add-sqr-sqrt [=>]73.2 | \[ \frac{1}{a} \cdot \left(\left(z \cdot t + \left(-z\right) \cdot \color{blue}{\left(\sqrt{t} \cdot \sqrt{t}\right)}\right) + \left(x \cdot y - z \cdot t\right)\right)
\] |
sqrt-unprod [=>]67.5 | \[ \frac{1}{a} \cdot \left(\left(z \cdot t + \left(-z\right) \cdot \color{blue}{\sqrt{t \cdot t}}\right) + \left(x \cdot y - z \cdot t\right)\right)
\] |
sqr-neg [<=]67.5 | \[ \frac{1}{a} \cdot \left(\left(z \cdot t + \left(-z\right) \cdot \sqrt{\color{blue}{\left(-t\right) \cdot \left(-t\right)}}\right) + \left(x \cdot y - z \cdot t\right)\right)
\] |
sqrt-unprod [<=]13.1 | \[ \frac{1}{a} \cdot \left(\left(z \cdot t + \left(-z\right) \cdot \color{blue}{\left(\sqrt{-t} \cdot \sqrt{-t}\right)}\right) + \left(x \cdot y - z \cdot t\right)\right)
\] |
add-sqr-sqrt [<=]52.3 | \[ \frac{1}{a} \cdot \left(\left(z \cdot t + \left(-z\right) \cdot \color{blue}{\left(-t\right)}\right) + \left(x \cdot y - z \cdot t\right)\right)
\] |
cancel-sign-sub-inv [<=]52.3 | \[ \frac{1}{a} \cdot \left(\color{blue}{\left(z \cdot t - z \cdot \left(-t\right)\right)} + \left(x \cdot y - z \cdot t\right)\right)
\] |
add-sqr-sqrt [=>]32.9 | \[ \frac{1}{a} \cdot \left(\left(\color{blue}{\sqrt{z \cdot t} \cdot \sqrt{z \cdot t}} - z \cdot \left(-t\right)\right) + \left(x \cdot y - z \cdot t\right)\right)
\] |
sqrt-unprod [=>]67.7 | \[ \frac{1}{a} \cdot \left(\left(\color{blue}{\sqrt{\left(z \cdot t\right) \cdot \left(z \cdot t\right)}} - z \cdot \left(-t\right)\right) + \left(x \cdot y - z \cdot t\right)\right)
\] |
sqr-neg [<=]67.7 | \[ \frac{1}{a} \cdot \left(\left(\sqrt{\color{blue}{\left(-z \cdot t\right) \cdot \left(-z \cdot t\right)}} - z \cdot \left(-t\right)\right) + \left(x \cdot y - z \cdot t\right)\right)
\] |
distribute-rgt-neg-out [<=]67.7 | \[ \frac{1}{a} \cdot \left(\left(\sqrt{\color{blue}{\left(z \cdot \left(-t\right)\right)} \cdot \left(-z \cdot t\right)} - z \cdot \left(-t\right)\right) + \left(x \cdot y - z \cdot t\right)\right)
\] |
distribute-rgt-neg-out [<=]67.7 | \[ \frac{1}{a} \cdot \left(\left(\sqrt{\left(z \cdot \left(-t\right)\right) \cdot \color{blue}{\left(z \cdot \left(-t\right)\right)}} - z \cdot \left(-t\right)\right) + \left(x \cdot y - z \cdot t\right)\right)
\] |
sqrt-unprod [<=]55.0 | \[ \frac{1}{a} \cdot \left(\left(\color{blue}{\sqrt{z \cdot \left(-t\right)} \cdot \sqrt{z \cdot \left(-t\right)}} - z \cdot \left(-t\right)\right) + \left(x \cdot y - z \cdot t\right)\right)
\] |
add-sqr-sqrt [<=]98.5 | \[ \frac{1}{a} \cdot \left(\left(\color{blue}{z \cdot \left(-t\right)} - z \cdot \left(-t\right)\right) + \left(x \cdot y - z \cdot t\right)\right)
\] |
Taylor expanded in a around 0 98.6%
Final simplification98.8%
| Alternative 1 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 1737 |
| Alternative 2 | |
|---|---|
| Accuracy | 93.4% |
| Cost | 1608 |
| Alternative 3 | |
|---|---|
| Accuracy | 62.1% |
| Cost | 648 |
| Alternative 4 | |
|---|---|
| Accuracy | 63.8% |
| Cost | 648 |
| Alternative 5 | |
|---|---|
| Accuracy | 50.2% |
| Cost | 585 |
| Alternative 6 | |
|---|---|
| Accuracy | 48.4% |
| Cost | 320 |
herbie shell --seed 2023133
(FPCore (x y z t a)
:name "Data.Colour.Matrix:inverse from colour-2.3.3, B"
:precision binary64
:herbie-target
(if (< z -2.468684968699548e+170) (- (* (/ y a) x) (* (/ t a) z)) (if (< z 6.309831121978371e-71) (/ (- (* x y) (* z t)) a) (- (* (/ y a) x) (* (/ t a) z))))
(/ (- (* x y) (* z t)) a))