
(FPCore (x y z t a) :precision binary64 (/ (- (* x y) (* z t)) 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
public static double code(double x, double y, double z, double t, double a) {
return ((x * y) - (z * t)) / a;
}
def code(x, y, z, t, a): return ((x * y) - (z * t)) / a
function code(x, y, z, t, a) return Float64(Float64(Float64(x * y) - Float64(z * t)) / a) end
function tmp = code(x, y, z, t, a) tmp = ((x * y) - (z * t)) / a; end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y - z \cdot t}{a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (/ (- (* x y) (* z t)) 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
public static double code(double x, double y, double z, double t, double a) {
return ((x * y) - (z * t)) / a;
}
def code(x, y, z, t, a): return ((x * y) - (z * t)) / a
function code(x, y, z, t, a) return Float64(Float64(Float64(x * y) - Float64(z * t)) / a) end
function tmp = code(x, y, z, t, a) tmp = ((x * y) - (z * t)) / a; end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y - z \cdot t}{a}
\end{array}
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (- (* y x) (* t z))))
(if (or (<= t_1 -1e+272) (not (<= t_1 1e+280)))
(- (/ x (/ a y)) (/ z (/ a t)))
(/ t_1 a))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (y * x) - (t * z);
double tmp;
if ((t_1 <= -1e+272) || !(t_1 <= 1e+280)) {
tmp = (x / (a / y)) - (z / (a / t));
} else {
tmp = t_1 / 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
real(8) :: t_1
real(8) :: tmp
t_1 = (y * x) - (t * z)
if ((t_1 <= (-1d+272)) .or. (.not. (t_1 <= 1d+280))) then
tmp = (x / (a / y)) - (z / (a / t))
else
tmp = t_1 / a
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double t_1 = (y * x) - (t * z);
double tmp;
if ((t_1 <= -1e+272) || !(t_1 <= 1e+280)) {
tmp = (x / (a / y)) - (z / (a / t));
} else {
tmp = t_1 / a;
}
return tmp;
}
def code(x, y, z, t, a): t_1 = (y * x) - (t * z) tmp = 0 if (t_1 <= -1e+272) or not (t_1 <= 1e+280): tmp = (x / (a / y)) - (z / (a / t)) else: tmp = t_1 / a return tmp
function code(x, y, z, t, a) t_1 = Float64(Float64(y * x) - Float64(t * z)) tmp = 0.0 if ((t_1 <= -1e+272) || !(t_1 <= 1e+280)) tmp = Float64(Float64(x / Float64(a / y)) - Float64(z / Float64(a / t))); else tmp = Float64(t_1 / a); end return tmp end
function tmp_2 = code(x, y, z, t, a) t_1 = (y * x) - (t * z); tmp = 0.0; if ((t_1 <= -1e+272) || ~((t_1 <= 1e+280))) tmp = (x / (a / y)) - (z / (a / t)); else tmp = t_1 / a; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(y * x), $MachinePrecision] - N[(t * z), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -1e+272], N[Not[LessEqual[t$95$1, 1e+280]], $MachinePrecision]], N[(N[(x / N[(a / y), $MachinePrecision]), $MachinePrecision] - N[(z / N[(a / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot x - t \cdot z\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{+272} \lor \neg \left(t_1 \leq 10^{+280}\right):\\
\;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1}{a}\\
\end{array}
\end{array}
if (-.f64 (*.f64 x y) (*.f64 z t)) < -1.0000000000000001e272 or 1e280 < (-.f64 (*.f64 x y) (*.f64 z t)) Initial program 73.0%
div-sub68.1%
associate-/l*78.5%
associate-/l*92.6%
Applied egg-rr92.6%
if -1.0000000000000001e272 < (-.f64 (*.f64 x y) (*.f64 z t)) < 1e280Initial program 97.5%
Final simplification96.0%
(FPCore (x y z t a) :precision binary64 (if (<= (* y x) 2e+307) (/ (- (* y x) (* t z)) a) (* y (/ x a))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((y * x) <= 2e+307) {
tmp = ((y * x) - (t * z)) / a;
} else {
tmp = y * (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
real(8) :: tmp
if ((y * x) <= 2d+307) then
tmp = ((y * x) - (t * z)) / a
else
tmp = y * (x / a)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if ((y * x) <= 2e+307) {
tmp = ((y * x) - (t * z)) / a;
} else {
tmp = y * (x / a);
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if (y * x) <= 2e+307: tmp = ((y * x) - (t * z)) / a else: tmp = y * (x / a) return tmp
function code(x, y, z, t, a) tmp = 0.0 if (Float64(y * x) <= 2e+307) tmp = Float64(Float64(Float64(y * x) - Float64(t * z)) / a); else tmp = Float64(y * Float64(x / a)); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if ((y * x) <= 2e+307) tmp = ((y * x) - (t * z)) / a; else tmp = y * (x / a); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[N[(y * x), $MachinePrecision], 2e+307], N[(N[(N[(y * x), $MachinePrecision] - N[(t * z), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(y * N[(x / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot x \leq 2 \cdot 10^{+307}:\\
\;\;\;\;\frac{y \cdot x - t \cdot z}{a}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{a}\\
\end{array}
\end{array}
if (*.f64 x y) < 1.99999999999999997e307Initial program 93.0%
if 1.99999999999999997e307 < (*.f64 x y) Initial program 52.1%
Taylor expanded in x around inf 57.5%
associate-*r/91.2%
Simplified91.2%
Final simplification92.8%
(FPCore (x y z t a) :precision binary64 (if (<= y 1.24e-85) (- (/ y (/ a x)) (* (/ t a) z)) (/ (- (* y x) (* t z)) a)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (y <= 1.24e-85) {
tmp = (y / (a / x)) - ((t / a) * z);
} else {
tmp = ((y * x) - (t * z)) / 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
real(8) :: tmp
if (y <= 1.24d-85) then
tmp = (y / (a / x)) - ((t / a) * z)
else
tmp = ((y * x) - (t * z)) / a
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (y <= 1.24e-85) {
tmp = (y / (a / x)) - ((t / a) * z);
} else {
tmp = ((y * x) - (t * z)) / a;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if y <= 1.24e-85: tmp = (y / (a / x)) - ((t / a) * z) else: tmp = ((y * x) - (t * z)) / a return tmp
function code(x, y, z, t, a) tmp = 0.0 if (y <= 1.24e-85) tmp = Float64(Float64(y / Float64(a / x)) - Float64(Float64(t / a) * z)); else tmp = Float64(Float64(Float64(y * x) - Float64(t * z)) / a); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (y <= 1.24e-85) tmp = (y / (a / x)) - ((t / a) * z); else tmp = ((y * x) - (t * z)) / a; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[y, 1.24e-85], N[(N[(y / N[(a / x), $MachinePrecision]), $MachinePrecision] - N[(N[(t / a), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y * x), $MachinePrecision] - N[(t * z), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.24 \cdot 10^{-85}:\\
\;\;\;\;\frac{y}{\frac{a}{x}} - \frac{t}{a} \cdot z\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot x - t \cdot z}{a}\\
\end{array}
\end{array}
if y < 1.23999999999999995e-85Initial program 87.7%
div-sub85.4%
*-commutative85.4%
add-cube-cbrt85.0%
times-frac89.4%
fma-neg90.0%
pow290.0%
associate-/l*91.1%
Applied egg-rr91.1%
fma-neg90.5%
associate-/l*89.4%
*-commutative89.4%
associate-/l*91.4%
associate-/r/91.0%
Simplified91.0%
frac-times86.1%
unpow286.1%
add-cube-cbrt86.5%
associate-/l*89.3%
Applied egg-rr89.3%
if 1.23999999999999995e-85 < y Initial program 94.1%
Final simplification90.9%
(FPCore (x y z t a) :precision binary64 (if (or (<= t -2.7e-101) (not (<= t 3.8e+67))) (* (- t) (/ z a)) (* y (/ x a))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((t <= -2.7e-101) || !(t <= 3.8e+67)) {
tmp = -t * (z / a);
} else {
tmp = y * (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
real(8) :: tmp
if ((t <= (-2.7d-101)) .or. (.not. (t <= 3.8d+67))) then
tmp = -t * (z / a)
else
tmp = y * (x / a)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if ((t <= -2.7e-101) || !(t <= 3.8e+67)) {
tmp = -t * (z / a);
} else {
tmp = y * (x / a);
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if (t <= -2.7e-101) or not (t <= 3.8e+67): tmp = -t * (z / a) else: tmp = y * (x / a) return tmp
function code(x, y, z, t, a) tmp = 0.0 if ((t <= -2.7e-101) || !(t <= 3.8e+67)) tmp = Float64(Float64(-t) * Float64(z / a)); else tmp = Float64(y * Float64(x / a)); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if ((t <= -2.7e-101) || ~((t <= 3.8e+67))) tmp = -t * (z / a); else tmp = y * (x / a); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[t, -2.7e-101], N[Not[LessEqual[t, 3.8e+67]], $MachinePrecision]], N[((-t) * N[(z / a), $MachinePrecision]), $MachinePrecision], N[(y * N[(x / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.7 \cdot 10^{-101} \lor \neg \left(t \leq 3.8 \cdot 10^{+67}\right):\\
\;\;\;\;\left(-t\right) \cdot \frac{z}{a}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{a}\\
\end{array}
\end{array}
if t < -2.7000000000000002e-101 or 3.8000000000000002e67 < t Initial program 87.0%
Taylor expanded in x around 0 64.7%
mul-1-neg64.7%
*-commutative64.7%
associate-*l/69.0%
*-commutative69.0%
distribute-lft-neg-in69.0%
Simplified69.0%
if -2.7000000000000002e-101 < t < 3.8000000000000002e67Initial program 93.6%
Taylor expanded in x around inf 72.4%
associate-*r/71.8%
Simplified71.8%
Final simplification70.2%
(FPCore (x y z t a) :precision binary64 (if (<= t -2.6e-97) (* (- t) (/ z a)) (if (<= t 2.75e+23) (* y (/ x a)) (* (/ t a) (- z)))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= -2.6e-97) {
tmp = -t * (z / a);
} else if (t <= 2.75e+23) {
tmp = y * (x / a);
} else {
tmp = (t / a) * -z;
}
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
real(8) :: tmp
if (t <= (-2.6d-97)) then
tmp = -t * (z / a)
else if (t <= 2.75d+23) then
tmp = y * (x / a)
else
tmp = (t / a) * -z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= -2.6e-97) {
tmp = -t * (z / a);
} else if (t <= 2.75e+23) {
tmp = y * (x / a);
} else {
tmp = (t / a) * -z;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if t <= -2.6e-97: tmp = -t * (z / a) elif t <= 2.75e+23: tmp = y * (x / a) else: tmp = (t / a) * -z return tmp
function code(x, y, z, t, a) tmp = 0.0 if (t <= -2.6e-97) tmp = Float64(Float64(-t) * Float64(z / a)); elseif (t <= 2.75e+23) tmp = Float64(y * Float64(x / a)); else tmp = Float64(Float64(t / a) * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (t <= -2.6e-97) tmp = -t * (z / a); elseif (t <= 2.75e+23) tmp = y * (x / a); else tmp = (t / a) * -z; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[t, -2.6e-97], N[((-t) * N[(z / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 2.75e+23], N[(y * N[(x / a), $MachinePrecision]), $MachinePrecision], N[(N[(t / a), $MachinePrecision] * (-z)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.6 \cdot 10^{-97}:\\
\;\;\;\;\left(-t\right) \cdot \frac{z}{a}\\
\mathbf{elif}\;t \leq 2.75 \cdot 10^{+23}:\\
\;\;\;\;y \cdot \frac{x}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{t}{a} \cdot \left(-z\right)\\
\end{array}
\end{array}
if t < -2.60000000000000007e-97Initial program 92.2%
Taylor expanded in x around 0 63.8%
mul-1-neg63.8%
*-commutative63.8%
associate-*l/66.7%
*-commutative66.7%
distribute-lft-neg-in66.7%
Simplified66.7%
if -2.60000000000000007e-97 < t < 2.75000000000000002e23Initial program 93.3%
Taylor expanded in x around inf 73.2%
associate-*r/71.6%
Simplified71.6%
if 2.75000000000000002e23 < t Initial program 81.0%
Taylor expanded in x around 0 65.1%
associate-*r/65.1%
associate-*r*65.1%
neg-mul-165.1%
Simplified65.1%
distribute-lft-neg-out65.1%
distribute-frac-neg65.1%
associate-*l/69.4%
distribute-rgt-neg-in69.4%
Applied egg-rr69.4%
Final simplification69.4%
(FPCore (x y z t a) :precision binary64 (* y (/ x a)))
double code(double x, double y, double z, double t, double a) {
return y * (x / 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 = y * (x / a)
end function
public static double code(double x, double y, double z, double t, double a) {
return y * (x / a);
}
def code(x, y, z, t, a): return y * (x / a)
function code(x, y, z, t, a) return Float64(y * Float64(x / a)) end
function tmp = code(x, y, z, t, a) tmp = y * (x / a); end
code[x_, y_, z_, t_, a_] := N[(y * N[(x / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \frac{x}{a}
\end{array}
Initial program 89.8%
Taylor expanded in x around inf 51.0%
associate-*r/53.7%
Simplified53.7%
Final simplification53.7%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (- (* (/ y a) x) (* (/ t a) z))))
(if (< z -2.468684968699548e+170)
t_1
(if (< z 6.309831121978371e-71) (/ (- (* x y) (* z t)) a) t_1))))
double code(double x, double y, double z, double t, double a) {
double t_1 = ((y / a) * x) - ((t / a) * z);
double tmp;
if (z < -2.468684968699548e+170) {
tmp = t_1;
} else if (z < 6.309831121978371e-71) {
tmp = ((x * y) - (z * t)) / a;
} else {
tmp = t_1;
}
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
real(8) :: t_1
real(8) :: tmp
t_1 = ((y / a) * x) - ((t / a) * z)
if (z < (-2.468684968699548d+170)) then
tmp = t_1
else if (z < 6.309831121978371d-71) then
tmp = ((x * y) - (z * t)) / a
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double t_1 = ((y / a) * x) - ((t / a) * z);
double tmp;
if (z < -2.468684968699548e+170) {
tmp = t_1;
} else if (z < 6.309831121978371e-71) {
tmp = ((x * y) - (z * t)) / a;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t, a): t_1 = ((y / a) * x) - ((t / a) * z) tmp = 0 if z < -2.468684968699548e+170: tmp = t_1 elif z < 6.309831121978371e-71: tmp = ((x * y) - (z * t)) / a else: tmp = t_1 return tmp
function code(x, y, z, t, a) t_1 = Float64(Float64(Float64(y / a) * x) - Float64(Float64(t / a) * z)) tmp = 0.0 if (z < -2.468684968699548e+170) tmp = t_1; elseif (z < 6.309831121978371e-71) tmp = Float64(Float64(Float64(x * y) - Float64(z * t)) / a); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t, a) t_1 = ((y / a) * x) - ((t / a) * z); tmp = 0.0; if (z < -2.468684968699548e+170) tmp = t_1; elseif (z < 6.309831121978371e-71) tmp = ((x * y) - (z * t)) / a; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(N[(y / a), $MachinePrecision] * x), $MachinePrecision] - N[(N[(t / a), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[Less[z, -2.468684968699548e+170], t$95$1, If[Less[z, 6.309831121978371e-71], N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{y}{a} \cdot x - \frac{t}{a} \cdot z\\
\mathbf{if}\;z < -2.468684968699548 \cdot 10^{+170}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z < 6.309831121978371 \cdot 10^{-71}:\\
\;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
herbie shell --seed 2023268
(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))