(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)))
(t_2 (/ t_1 a))
(t_3 (+ (* -1.0 (/ z (/ a t))) (* x (/ y a)))))
(if (<= t_1 -5e+218)
t_3
(if (<= t_1 -1e-132)
t_2
(if (<= t_1 1e-123)
t_3
(if (<= t_1 2e+155) t_2 (+ (* z (- (/ t a))) (* y (/ x a)))))))))
double code(double x, double y, double z, double t, double a) {
return ((x * y) - (z * t)) / a;
}
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) :: t_2
real(8) :: t_3
real(8) :: tmp
t_1 = (x * y) - (z * t)
t_2 = t_1 / a
t_3 = ((-1.0d0) * (z / (a / t))) + (x * (y / a))
if (t_1 <= (-5d+218)) then
tmp = t_3
else if (t_1 <= (-1d-132)) then
tmp = t_2
else if (t_1 <= 1d-123) then
tmp = t_3
else if (t_1 <= 2d+155) then
tmp = t_2
else
tmp = (z * -(t / a)) + (y * (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 * t)) / a;
}
↓
public static double code(double x, double y, double z, double t, double a) {
double t_1 = (x * y) - (z * t);
double t_2 = t_1 / a;
double t_3 = (-1.0 * (z / (a / t))) + (x * (y / a));
double tmp;
if (t_1 <= -5e+218) {
tmp = t_3;
} else if (t_1 <= -1e-132) {
tmp = t_2;
} else if (t_1 <= 1e-123) {
tmp = t_3;
} else if (t_1 <= 2e+155) {
tmp = t_2;
} else {
tmp = (z * -(t / a)) + (y * (x / a));
}
return tmp;
}
def code(x, y, z, t, a):
return ((x * y) - (z * t)) / a
\[\leadsto -1 \cdot \color{blue}{\frac{z}{\frac{a}{t}}} + x \cdot \frac{y}{a}
\]
if -4.99999999999999983e218 < (-.f64 (*.f64 x y) (*.f64 z t)) < -9.9999999999999999e-133 or 1.0000000000000001e-123 < (-.f64 (*.f64 x y) (*.f64 z t)) < 2.00000000000000001e155
Initial program 0.3
\[\frac{x \cdot y - z \cdot t}{a}
\]
if 2.00000000000000001e155 < (-.f64 (*.f64 x y) (*.f64 z t))
\[ z \cdot \color{blue}{\left(-\frac{t}{a}\right)} + \frac{y \cdot x}{a}
\]
rational.json-simplify-2 [=>]12.0
\[ z \cdot \left(-\frac{t}{a}\right) + \frac{\color{blue}{x \cdot y}}{a}
\]
rational.json-simplify-49 [=>]2.6
\[ z \cdot \left(-\frac{t}{a}\right) + \color{blue}{y \cdot \frac{x}{a}}
\]
Recombined 3 regimes into one program.
Final simplification1.1
\[\leadsto \begin{array}{l}
\mathbf{if}\;x \cdot y - z \cdot t \leq -5 \cdot 10^{+218}:\\
\;\;\;\;-1 \cdot \frac{z}{\frac{a}{t}} + x \cdot \frac{y}{a}\\
\mathbf{elif}\;x \cdot y - z \cdot t \leq -1 \cdot 10^{-132}:\\
\;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\
\mathbf{elif}\;x \cdot y - z \cdot t \leq 10^{-123}:\\
\;\;\;\;-1 \cdot \frac{z}{\frac{a}{t}} + x \cdot \frac{y}{a}\\
\mathbf{elif}\;x \cdot y - z \cdot t \leq 2 \cdot 10^{+155}:\\
\;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-\frac{t}{a}\right) + y \cdot \frac{x}{a}\\
\end{array}
\]
Alternatives
Alternative 1
Error
0.7
Cost
2832
\[\begin{array}{l}
t_1 := x \cdot y - z \cdot t\\
t_2 := \frac{t_1}{a}\\
t_3 := z \cdot \left(-\frac{t}{a}\right) + y \cdot \frac{x}{a}\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{+293}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;t_1 \leq -2 \cdot 10^{-159}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_1 \leq 10^{-291}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+155}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;t_3\\
\end{array}
\]
herbie shell --seed 2023064
(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))