| Alternative 1 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 2249 |
(FPCore (x y z t a) :precision binary64 (/ (- (* x y) (* (* z 9.0) t)) (* a 2.0)))
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (* z (* t (/ -4.5 a)))) (t_2 (+ (* x y) (* t (* z -9.0)))))
(if (<= t_2 -1e+223)
(+ t_1 (/ (* y 0.5) (/ a x)))
(if (<= t_2 4e+289) (/ t_2 (* a 2.0)) (+ t_1 (* (* y 0.5) (/ x a)))))))double code(double x, double y, double z, double t, double a) {
return ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
}
double code(double x, double y, double z, double t, double a) {
double t_1 = z * (t * (-4.5 / a));
double t_2 = (x * y) + (t * (z * -9.0));
double tmp;
if (t_2 <= -1e+223) {
tmp = t_1 + ((y * 0.5) / (a / x));
} else if (t_2 <= 4e+289) {
tmp = t_2 / (a * 2.0);
} else {
tmp = t_1 + ((y * 0.5) * (x / 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 * 9.0d0) * t)) / (a * 2.0d0)
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) :: t_2
real(8) :: tmp
t_1 = z * (t * ((-4.5d0) / a))
t_2 = (x * y) + (t * (z * (-9.0d0)))
if (t_2 <= (-1d+223)) then
tmp = t_1 + ((y * 0.5d0) / (a / x))
else if (t_2 <= 4d+289) then
tmp = t_2 / (a * 2.0d0)
else
tmp = t_1 + ((y * 0.5d0) * (x / 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 * 9.0) * t)) / (a * 2.0);
}
public static double code(double x, double y, double z, double t, double a) {
double t_1 = z * (t * (-4.5 / a));
double t_2 = (x * y) + (t * (z * -9.0));
double tmp;
if (t_2 <= -1e+223) {
tmp = t_1 + ((y * 0.5) / (a / x));
} else if (t_2 <= 4e+289) {
tmp = t_2 / (a * 2.0);
} else {
tmp = t_1 + ((y * 0.5) * (x / a));
}
return tmp;
}
def code(x, y, z, t, a): return ((x * y) - ((z * 9.0) * t)) / (a * 2.0)
def code(x, y, z, t, a): t_1 = z * (t * (-4.5 / a)) t_2 = (x * y) + (t * (z * -9.0)) tmp = 0 if t_2 <= -1e+223: tmp = t_1 + ((y * 0.5) / (a / x)) elif t_2 <= 4e+289: tmp = t_2 / (a * 2.0) else: tmp = t_1 + ((y * 0.5) * (x / a)) return tmp
function code(x, y, z, t, a) return Float64(Float64(Float64(x * y) - Float64(Float64(z * 9.0) * t)) / Float64(a * 2.0)) end
function code(x, y, z, t, a) t_1 = Float64(z * Float64(t * Float64(-4.5 / a))) t_2 = Float64(Float64(x * y) + Float64(t * Float64(z * -9.0))) tmp = 0.0 if (t_2 <= -1e+223) tmp = Float64(t_1 + Float64(Float64(y * 0.5) / Float64(a / x))); elseif (t_2 <= 4e+289) tmp = Float64(t_2 / Float64(a * 2.0)); else tmp = Float64(t_1 + Float64(Float64(y * 0.5) * Float64(x / a))); end return tmp end
function tmp = code(x, y, z, t, a) tmp = ((x * y) - ((z * 9.0) * t)) / (a * 2.0); end
function tmp_2 = code(x, y, z, t, a) t_1 = z * (t * (-4.5 / a)); t_2 = (x * y) + (t * (z * -9.0)); tmp = 0.0; if (t_2 <= -1e+223) tmp = t_1 + ((y * 0.5) / (a / x)); elseif (t_2 <= 4e+289) tmp = t_2 / (a * 2.0); else tmp = t_1 + ((y * 0.5) * (x / a)); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(z * N[(t * N[(-4.5 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y), $MachinePrecision] + N[(t * N[(z * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1e+223], N[(t$95$1 + N[(N[(y * 0.5), $MachinePrecision] / N[(a / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 4e+289], N[(t$95$2 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[(N[(y * 0.5), $MachinePrecision] * N[(x / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\begin{array}{l}
t_1 := z \cdot \left(t \cdot \frac{-4.5}{a}\right)\\
t_2 := x \cdot y + t \cdot \left(z \cdot -9\right)\\
\mathbf{if}\;t_2 \leq -1 \cdot 10^{+223}:\\
\;\;\;\;t_1 + \frac{y \cdot 0.5}{\frac{a}{x}}\\
\mathbf{elif}\;t_2 \leq 4 \cdot 10^{+289}:\\
\;\;\;\;\frac{t_2}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;t_1 + \left(y \cdot 0.5\right) \cdot \frac{x}{a}\\
\end{array}
Results
| Original | 88.5% |
|---|---|
| Target | 91.4% |
| Herbie | 98.8% |
if (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < -1.00000000000000005e223Initial program 48.6%
Simplified49.3%
[Start]48.6 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
sub-neg [=>]48.6 | \[ \frac{\color{blue}{x \cdot y + \left(-\left(z \cdot 9\right) \cdot t\right)}}{a \cdot 2}
\] |
remove-double-neg [<=]48.6 | \[ \frac{\color{blue}{\left(-\left(-x \cdot y\right)\right)} + \left(-\left(z \cdot 9\right) \cdot t\right)}{a \cdot 2}
\] |
distribute-neg-in [<=]48.6 | \[ \frac{\color{blue}{-\left(\left(-x \cdot y\right) + \left(z \cdot 9\right) \cdot t\right)}}{a \cdot 2}
\] |
+-commutative [<=]48.6 | \[ \frac{-\color{blue}{\left(\left(z \cdot 9\right) \cdot t + \left(-x \cdot y\right)\right)}}{a \cdot 2}
\] |
sub-neg [<=]48.6 | \[ \frac{-\color{blue}{\left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
neg-mul-1 [=>]48.6 | \[ \frac{\color{blue}{-1 \cdot \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
associate-/l* [=>]48.6 | \[ \color{blue}{\frac{-1}{\frac{a \cdot 2}{\left(z \cdot 9\right) \cdot t - x \cdot y}}}
\] |
associate-/r/ [=>]48.6 | \[ \color{blue}{\frac{-1}{a \cdot 2} \cdot \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}
\] |
sub-neg [=>]48.6 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(\left(z \cdot 9\right) \cdot t + \left(-x \cdot y\right)\right)}
\] |
+-commutative [=>]48.6 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(\left(-x \cdot y\right) + \left(z \cdot 9\right) \cdot t\right)}
\] |
neg-sub0 [=>]48.6 | \[ \frac{-1}{a \cdot 2} \cdot \left(\color{blue}{\left(0 - x \cdot y\right)} + \left(z \cdot 9\right) \cdot t\right)
\] |
associate-+l- [=>]48.6 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(0 - \left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)\right)}
\] |
sub0-neg [=>]48.6 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(-\left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)\right)}
\] |
distribute-rgt-neg-out [=>]48.6 | \[ \color{blue}{-\frac{-1}{a \cdot 2} \cdot \left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)}
\] |
distribute-lft-neg-in [=>]48.6 | \[ \color{blue}{\left(-\frac{-1}{a \cdot 2}\right) \cdot \left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)}
\] |
Taylor expanded in x around 0 49.4%
Applied egg-rr32.1%
[Start]49.4 | \[ -4.5 \cdot \frac{t \cdot z}{a} + 0.5 \cdot \frac{y \cdot x}{a}
\] |
|---|---|
expm1-log1p-u [=>]35.4 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(-4.5 \cdot \frac{t \cdot z}{a}\right)\right)} + 0.5 \cdot \frac{y \cdot x}{a}
\] |
expm1-udef [=>]32.1 | \[ \color{blue}{\left(e^{\mathsf{log1p}\left(-4.5 \cdot \frac{t \cdot z}{a}\right)} - 1\right)} + 0.5 \cdot \frac{y \cdot x}{a}
\] |
clear-num [=>]32.1 | \[ \left(e^{\mathsf{log1p}\left(-4.5 \cdot \color{blue}{\frac{1}{\frac{a}{t \cdot z}}}\right)} - 1\right) + 0.5 \cdot \frac{y \cdot x}{a}
\] |
un-div-inv [=>]32.1 | \[ \left(e^{\mathsf{log1p}\left(\color{blue}{\frac{-4.5}{\frac{a}{t \cdot z}}}\right)} - 1\right) + 0.5 \cdot \frac{y \cdot x}{a}
\] |
associate-/r/ [=>]32.1 | \[ \left(e^{\mathsf{log1p}\left(\color{blue}{\frac{-4.5}{a} \cdot \left(t \cdot z\right)}\right)} - 1\right) + 0.5 \cdot \frac{y \cdot x}{a}
\] |
Simplified72.8%
[Start]32.1 | \[ \left(e^{\mathsf{log1p}\left(\frac{-4.5}{a} \cdot \left(t \cdot z\right)\right)} - 1\right) + 0.5 \cdot \frac{y \cdot x}{a}
\] |
|---|---|
expm1-def [=>]35.4 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-4.5}{a} \cdot \left(t \cdot z\right)\right)\right)} + 0.5 \cdot \frac{y \cdot x}{a}
\] |
expm1-log1p [=>]49.4 | \[ \color{blue}{\frac{-4.5}{a} \cdot \left(t \cdot z\right)} + 0.5 \cdot \frac{y \cdot x}{a}
\] |
associate-*r* [=>]72.8 | \[ \color{blue}{\left(\frac{-4.5}{a} \cdot t\right) \cdot z} + 0.5 \cdot \frac{y \cdot x}{a}
\] |
Applied egg-rr98.3%
[Start]72.8 | \[ \left(\frac{-4.5}{a} \cdot t\right) \cdot z + 0.5 \cdot \frac{y \cdot x}{a}
\] |
|---|---|
*-commutative [=>]72.8 | \[ \left(\frac{-4.5}{a} \cdot t\right) \cdot z + \color{blue}{\frac{y \cdot x}{a} \cdot 0.5}
\] |
associate-/l* [=>]98.3 | \[ \left(\frac{-4.5}{a} \cdot t\right) \cdot z + \color{blue}{\frac{y}{\frac{a}{x}}} \cdot 0.5
\] |
associate-*l/ [=>]98.3 | \[ \left(\frac{-4.5}{a} \cdot t\right) \cdot z + \color{blue}{\frac{y \cdot 0.5}{\frac{a}{x}}}
\] |
if -1.00000000000000005e223 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < 4.0000000000000002e289Initial program 98.8%
if 4.0000000000000002e289 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) Initial program 14.2%
Simplified14.6%
[Start]14.2 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
sub-neg [=>]14.2 | \[ \frac{\color{blue}{x \cdot y + \left(-\left(z \cdot 9\right) \cdot t\right)}}{a \cdot 2}
\] |
remove-double-neg [<=]14.2 | \[ \frac{\color{blue}{\left(-\left(-x \cdot y\right)\right)} + \left(-\left(z \cdot 9\right) \cdot t\right)}{a \cdot 2}
\] |
distribute-neg-in [<=]14.2 | \[ \frac{\color{blue}{-\left(\left(-x \cdot y\right) + \left(z \cdot 9\right) \cdot t\right)}}{a \cdot 2}
\] |
+-commutative [<=]14.2 | \[ \frac{-\color{blue}{\left(\left(z \cdot 9\right) \cdot t + \left(-x \cdot y\right)\right)}}{a \cdot 2}
\] |
sub-neg [<=]14.2 | \[ \frac{-\color{blue}{\left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
neg-mul-1 [=>]14.2 | \[ \frac{\color{blue}{-1 \cdot \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
associate-/l* [=>]14.2 | \[ \color{blue}{\frac{-1}{\frac{a \cdot 2}{\left(z \cdot 9\right) \cdot t - x \cdot y}}}
\] |
associate-/r/ [=>]14.2 | \[ \color{blue}{\frac{-1}{a \cdot 2} \cdot \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}
\] |
sub-neg [=>]14.2 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(\left(z \cdot 9\right) \cdot t + \left(-x \cdot y\right)\right)}
\] |
+-commutative [=>]14.2 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(\left(-x \cdot y\right) + \left(z \cdot 9\right) \cdot t\right)}
\] |
neg-sub0 [=>]14.2 | \[ \frac{-1}{a \cdot 2} \cdot \left(\color{blue}{\left(0 - x \cdot y\right)} + \left(z \cdot 9\right) \cdot t\right)
\] |
associate-+l- [=>]14.2 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(0 - \left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)\right)}
\] |
sub0-neg [=>]14.2 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(-\left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)\right)}
\] |
distribute-rgt-neg-out [=>]14.2 | \[ \color{blue}{-\frac{-1}{a \cdot 2} \cdot \left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)}
\] |
distribute-lft-neg-in [=>]14.2 | \[ \color{blue}{\left(-\frac{-1}{a \cdot 2}\right) \cdot \left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)}
\] |
Taylor expanded in x around 0 14.8%
Applied egg-rr9.3%
[Start]14.8 | \[ -4.5 \cdot \frac{t \cdot z}{a} + 0.5 \cdot \frac{y \cdot x}{a}
\] |
|---|---|
expm1-log1p-u [=>]9.6 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(-4.5 \cdot \frac{t \cdot z}{a}\right)\right)} + 0.5 \cdot \frac{y \cdot x}{a}
\] |
expm1-udef [=>]9.3 | \[ \color{blue}{\left(e^{\mathsf{log1p}\left(-4.5 \cdot \frac{t \cdot z}{a}\right)} - 1\right)} + 0.5 \cdot \frac{y \cdot x}{a}
\] |
clear-num [=>]9.3 | \[ \left(e^{\mathsf{log1p}\left(-4.5 \cdot \color{blue}{\frac{1}{\frac{a}{t \cdot z}}}\right)} - 1\right) + 0.5 \cdot \frac{y \cdot x}{a}
\] |
un-div-inv [=>]9.3 | \[ \left(e^{\mathsf{log1p}\left(\color{blue}{\frac{-4.5}{\frac{a}{t \cdot z}}}\right)} - 1\right) + 0.5 \cdot \frac{y \cdot x}{a}
\] |
associate-/r/ [=>]9.3 | \[ \left(e^{\mathsf{log1p}\left(\color{blue}{\frac{-4.5}{a} \cdot \left(t \cdot z\right)}\right)} - 1\right) + 0.5 \cdot \frac{y \cdot x}{a}
\] |
Simplified50.6%
[Start]9.3 | \[ \left(e^{\mathsf{log1p}\left(\frac{-4.5}{a} \cdot \left(t \cdot z\right)\right)} - 1\right) + 0.5 \cdot \frac{y \cdot x}{a}
\] |
|---|---|
expm1-def [=>]9.6 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-4.5}{a} \cdot \left(t \cdot z\right)\right)\right)} + 0.5 \cdot \frac{y \cdot x}{a}
\] |
expm1-log1p [=>]14.8 | \[ \color{blue}{\frac{-4.5}{a} \cdot \left(t \cdot z\right)} + 0.5 \cdot \frac{y \cdot x}{a}
\] |
associate-*r* [=>]50.6 | \[ \color{blue}{\left(\frac{-4.5}{a} \cdot t\right) \cdot z} + 0.5 \cdot \frac{y \cdot x}{a}
\] |
Applied egg-rr68.8%
[Start]50.6 | \[ \left(\frac{-4.5}{a} \cdot t\right) \cdot z + 0.5 \cdot \frac{y \cdot x}{a}
\] |
|---|---|
expm1-log1p-u [=>]45.1 | \[ \left(\frac{-4.5}{a} \cdot t\right) \cdot z + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(0.5 \cdot \frac{y \cdot x}{a}\right)\right)}
\] |
expm1-udef [=>]45.1 | \[ \left(\frac{-4.5}{a} \cdot t\right) \cdot z + \color{blue}{\left(e^{\mathsf{log1p}\left(0.5 \cdot \frac{y \cdot x}{a}\right)} - 1\right)}
\] |
*-commutative [=>]45.1 | \[ \left(\frac{-4.5}{a} \cdot t\right) \cdot z + \left(e^{\mathsf{log1p}\left(\color{blue}{\frac{y \cdot x}{a} \cdot 0.5}\right)} - 1\right)
\] |
*-commutative [=>]45.1 | \[ \left(\frac{-4.5}{a} \cdot t\right) \cdot z + \left(e^{\mathsf{log1p}\left(\frac{\color{blue}{x \cdot y}}{a} \cdot 0.5\right)} - 1\right)
\] |
associate-/l* [=>]68.8 | \[ \left(\frac{-4.5}{a} \cdot t\right) \cdot z + \left(e^{\mathsf{log1p}\left(\color{blue}{\frac{x}{\frac{a}{y}}} \cdot 0.5\right)} - 1\right)
\] |
associate-/r/ [=>]68.8 | \[ \left(\frac{-4.5}{a} \cdot t\right) \cdot z + \left(e^{\mathsf{log1p}\left(\color{blue}{\left(\frac{x}{a} \cdot y\right)} \cdot 0.5\right)} - 1\right)
\] |
Simplified99.3%
[Start]68.8 | \[ \left(\frac{-4.5}{a} \cdot t\right) \cdot z + \left(e^{\mathsf{log1p}\left(\left(\frac{x}{a} \cdot y\right) \cdot 0.5\right)} - 1\right)
\] |
|---|---|
expm1-def [=>]68.8 | \[ \left(\frac{-4.5}{a} \cdot t\right) \cdot z + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(\frac{x}{a} \cdot y\right) \cdot 0.5\right)\right)}
\] |
expm1-log1p [=>]99.3 | \[ \left(\frac{-4.5}{a} \cdot t\right) \cdot z + \color{blue}{\left(\frac{x}{a} \cdot y\right) \cdot 0.5}
\] |
associate-*l* [=>]99.3 | \[ \left(\frac{-4.5}{a} \cdot t\right) \cdot z + \color{blue}{\frac{x}{a} \cdot \left(y \cdot 0.5\right)}
\] |
Final simplification98.8%
| Alternative 1 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 2249 |
| Alternative 2 | |
|---|---|
| Accuracy | 92.6% |
| Cost | 2120 |
| Alternative 3 | |
|---|---|
| Accuracy | 61.5% |
| Cost | 1240 |
| Alternative 4 | |
|---|---|
| Accuracy | 61.4% |
| Cost | 1240 |
| Alternative 5 | |
|---|---|
| Accuracy | 61.4% |
| Cost | 1240 |
| Alternative 6 | |
|---|---|
| Accuracy | 61.4% |
| Cost | 1240 |
| Alternative 7 | |
|---|---|
| Accuracy | 84.7% |
| Cost | 1096 |
| Alternative 8 | |
|---|---|
| Accuracy | 84.8% |
| Cost | 1096 |
| Alternative 9 | |
|---|---|
| Accuracy | 60.4% |
| Cost | 976 |
| Alternative 10 | |
|---|---|
| Accuracy | 60.3% |
| Cost | 976 |
| Alternative 11 | |
|---|---|
| Accuracy | 60.4% |
| Cost | 976 |
| Alternative 12 | |
|---|---|
| Accuracy | 60.4% |
| Cost | 976 |
| Alternative 13 | |
|---|---|
| Accuracy | 50.2% |
| Cost | 712 |
| Alternative 14 | |
|---|---|
| Accuracy | 48.4% |
| Cost | 580 |
| Alternative 15 | |
|---|---|
| Accuracy | 48.5% |
| Cost | 580 |
| Alternative 16 | |
|---|---|
| Accuracy | 48.7% |
| Cost | 448 |
herbie shell --seed 2023131
(FPCore (x y z t a)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, I"
:precision binary64
:herbie-target
(if (< a -2.090464557976709e+86) (- (* 0.5 (/ (* y x) a)) (* 4.5 (/ t (/ a z)))) (if (< a 2.144030707833976e+99) (/ (- (* x y) (* z (* 9.0 t))) (* a 2.0)) (- (* (/ y a) (* x 0.5)) (* (/ t a) (* z 4.5)))))
(/ (- (* x y) (* (* z 9.0) t)) (* a 2.0)))