
(FPCore (x y z t) :precision binary64 (* (- (* x y) (* z y)) t))
double code(double x, double y, double z, double t) {
return ((x * y) - (z * y)) * t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x * y) - (z * y)) * t
end function
public static double code(double x, double y, double z, double t) {
return ((x * y) - (z * y)) * t;
}
def code(x, y, z, t): return ((x * y) - (z * y)) * t
function code(x, y, z, t) return Float64(Float64(Float64(x * y) - Float64(z * y)) * t) end
function tmp = code(x, y, z, t) tmp = ((x * y) - (z * y)) * t; end
code[x_, y_, z_, t_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y - z \cdot y\right) \cdot t
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (* (- (* x y) (* z y)) t))
double code(double x, double y, double z, double t) {
return ((x * y) - (z * y)) * t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x * y) - (z * y)) * t
end function
public static double code(double x, double y, double z, double t) {
return ((x * y) - (z * y)) * t;
}
def code(x, y, z, t): return ((x * y) - (z * y)) * t
function code(x, y, z, t) return Float64(Float64(Float64(x * y) - Float64(z * y)) * t) end
function tmp = code(x, y, z, t) tmp = ((x * y) - (z * y)) * t; end
code[x_, y_, z_, t_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y - z \cdot y\right) \cdot t
\end{array}
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= y -8e+128) (* y (* (- x z) t)) (* t (* y (- x z)))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -8e+128) {
tmp = y * ((x - z) * t);
} else {
tmp = t * (y * (x - z));
}
return tmp;
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= (-8d+128)) then
tmp = y * ((x - z) * t)
else
tmp = t * (y * (x - z))
end if
code = tmp
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -8e+128) {
tmp = y * ((x - z) * t);
} else {
tmp = t * (y * (x - z));
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if y <= -8e+128: tmp = y * ((x - z) * t) else: tmp = t * (y * (x - z)) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if (y <= -8e+128) tmp = Float64(y * Float64(Float64(x - z) * t)); else tmp = Float64(t * Float64(y * Float64(x - z))); end return tmp end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (y <= -8e+128)
tmp = y * ((x - z) * t);
else
tmp = t * (y * (x - z));
end
tmp_2 = tmp;
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[y, -8e+128], N[(y * N[(N[(x - z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision], N[(t * N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{+128}:\\
\;\;\;\;y \cdot \left(\left(x - z\right) \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\
\end{array}
\end{array}
if y < -8.0000000000000006e128Initial program 73.7%
distribute-rgt-out--81.3%
associate-*l*97.4%
Simplified97.4%
if -8.0000000000000006e128 < y Initial program 95.2%
distribute-rgt-out--95.7%
Simplified95.7%
Final simplification96.0%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (or (<= x -8.2e+45) (not (<= x 5.2e-52))) (* t (* y x)) (* z (* t (- y)))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -8.2e+45) || !(x <= 5.2e-52)) {
tmp = t * (y * x);
} else {
tmp = z * (t * -y);
}
return tmp;
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((x <= (-8.2d+45)) .or. (.not. (x <= 5.2d-52))) then
tmp = t * (y * x)
else
tmp = z * (t * -y)
end if
code = tmp
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -8.2e+45) || !(x <= 5.2e-52)) {
tmp = t * (y * x);
} else {
tmp = z * (t * -y);
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if (x <= -8.2e+45) or not (x <= 5.2e-52): tmp = t * (y * x) else: tmp = z * (t * -y) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if ((x <= -8.2e+45) || !(x <= 5.2e-52)) tmp = Float64(t * Float64(y * x)); else tmp = Float64(z * Float64(t * Float64(-y))); end return tmp end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((x <= -8.2e+45) || ~((x <= 5.2e-52)))
tmp = t * (y * x);
else
tmp = z * (t * -y);
end
tmp_2 = tmp;
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[Or[LessEqual[x, -8.2e+45], N[Not[LessEqual[x, 5.2e-52]], $MachinePrecision]], N[(t * N[(y * x), $MachinePrecision]), $MachinePrecision], N[(z * N[(t * (-y)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{+45} \lor \neg \left(x \leq 5.2 \cdot 10^{-52}\right):\\
\;\;\;\;t \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(t \cdot \left(-y\right)\right)\\
\end{array}
\end{array}
if x < -8.20000000000000025e45 or 5.1999999999999997e-52 < x Initial program 89.9%
distribute-rgt-out--92.9%
Simplified92.9%
Taylor expanded in x around inf 75.6%
if -8.20000000000000025e45 < x < 5.1999999999999997e-52Initial program 94.0%
distribute-rgt-out--94.0%
Simplified94.0%
Taylor expanded in x around 0 80.7%
neg-mul-180.7%
distribute-lft-neg-in80.7%
Simplified80.7%
distribute-lft-neg-in80.7%
distribute-lft-neg-out80.7%
*-commutative80.7%
associate-*l*82.6%
*-commutative82.6%
Applied egg-rr82.6%
Final simplification78.8%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (* y (* (- x z) t)))
assert(y < t);
double code(double x, double y, double z, double t) {
return y * ((x - z) * t);
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = y * ((x - z) * t)
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
return y * ((x - z) * t);
}
[y, t] = sort([y, t]) def code(x, y, z, t): return y * ((x - z) * t)
y, t = sort([y, t]) function code(x, y, z, t) return Float64(y * Float64(Float64(x - z) * t)) end
y, t = num2cell(sort([y, t])){:}
function tmp = code(x, y, z, t)
tmp = y * ((x - z) * t);
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(y * N[(N[(x - z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
y \cdot \left(\left(x - z\right) \cdot t\right)
\end{array}
Initial program 91.8%
distribute-rgt-out--93.4%
associate-*l*92.9%
Simplified92.9%
Final simplification92.9%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (* y (* x t)))
assert(y < t);
double code(double x, double y, double z, double t) {
return y * (x * t);
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = y * (x * t)
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
return y * (x * t);
}
[y, t] = sort([y, t]) def code(x, y, z, t): return y * (x * t)
y, t = sort([y, t]) function code(x, y, z, t) return Float64(y * Float64(x * t)) end
y, t = num2cell(sort([y, t])){:}
function tmp = code(x, y, z, t)
tmp = y * (x * t);
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(y * N[(x * t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
y \cdot \left(x \cdot t\right)
\end{array}
Initial program 91.8%
distribute-rgt-out--93.4%
associate-*l*92.9%
Simplified92.9%
Taylor expanded in x around inf 52.4%
Final simplification52.4%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (* t (* y x)))
assert(y < t);
double code(double x, double y, double z, double t) {
return t * (y * x);
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = t * (y * x)
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
return t * (y * x);
}
[y, t] = sort([y, t]) def code(x, y, z, t): return t * (y * x)
y, t = sort([y, t]) function code(x, y, z, t) return Float64(t * Float64(y * x)) end
y, t = num2cell(sort([y, t])){:}
function tmp = code(x, y, z, t)
tmp = t * (y * x);
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(t * N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
t \cdot \left(y \cdot x\right)
\end{array}
Initial program 91.8%
distribute-rgt-out--93.4%
Simplified93.4%
Taylor expanded in x around inf 53.1%
Final simplification53.1%
(FPCore (x y z t) :precision binary64 (if (< t -9.231879582886777e-80) (* (* y t) (- x z)) (if (< t 2.543067051564877e+83) (* y (* t (- x z))) (* (* y (- x z)) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (t < -9.231879582886777e-80) {
tmp = (y * t) * (x - z);
} else if (t < 2.543067051564877e+83) {
tmp = y * (t * (x - z));
} else {
tmp = (y * (x - z)) * t;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (t < (-9.231879582886777d-80)) then
tmp = (y * t) * (x - z)
else if (t < 2.543067051564877d+83) then
tmp = y * (t * (x - z))
else
tmp = (y * (x - z)) * t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t < -9.231879582886777e-80) {
tmp = (y * t) * (x - z);
} else if (t < 2.543067051564877e+83) {
tmp = y * (t * (x - z));
} else {
tmp = (y * (x - z)) * t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t < -9.231879582886777e-80: tmp = (y * t) * (x - z) elif t < 2.543067051564877e+83: tmp = y * (t * (x - z)) else: tmp = (y * (x - z)) * t return tmp
function code(x, y, z, t) tmp = 0.0 if (t < -9.231879582886777e-80) tmp = Float64(Float64(y * t) * Float64(x - z)); elseif (t < 2.543067051564877e+83) tmp = Float64(y * Float64(t * Float64(x - z))); else tmp = Float64(Float64(y * Float64(x - z)) * t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t < -9.231879582886777e-80) tmp = (y * t) * (x - z); elseif (t < 2.543067051564877e+83) tmp = y * (t * (x - z)); else tmp = (y * (x - z)) * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Less[t, -9.231879582886777e-80], N[(N[(y * t), $MachinePrecision] * N[(x - z), $MachinePrecision]), $MachinePrecision], If[Less[t, 2.543067051564877e+83], N[(y * N[(t * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t < -9.231879582886777 \cdot 10^{-80}:\\
\;\;\;\;\left(y \cdot t\right) \cdot \left(x - z\right)\\
\mathbf{elif}\;t < 2.543067051564877 \cdot 10^{+83}:\\
\;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot \left(x - z\right)\right) \cdot t\\
\end{array}
\end{array}
herbie shell --seed 2023238
(FPCore (x y z t)
:name "Linear.Projection:inverseInfinitePerspective from linear-1.19.1.3"
:precision binary64
:herbie-target
(if (< t -9.231879582886777e-80) (* (* y t) (- x z)) (if (< t 2.543067051564877e+83) (* y (* t (- x z))) (* (* y (- x z)) t)))
(* (- (* x y) (* z y)) t))