
(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 (<= (* (- (* x y) (* y z)) t) 4e+256) (* t (* y (- x z))) (* (- x z) (* y t))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((((x * y) - (y * z)) * t) <= 4e+256) {
tmp = t * (y * (x - z));
} else {
tmp = (x - z) * (y * t);
}
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 * y) - (y * z)) * t) <= 4d+256) then
tmp = t * (y * (x - z))
else
tmp = (x - z) * (y * t)
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 * y) - (y * z)) * t) <= 4e+256) {
tmp = t * (y * (x - z));
} else {
tmp = (x - z) * (y * t);
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if (((x * y) - (y * z)) * t) <= 4e+256: tmp = t * (y * (x - z)) else: tmp = (x - z) * (y * t) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(Float64(x * y) - Float64(y * z)) * t) <= 4e+256) tmp = Float64(t * Float64(y * Float64(x - z))); else tmp = Float64(Float64(x - z) * Float64(y * t)); end return tmp end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((((x * y) - (y * z)) * t) <= 4e+256)
tmp = t * (y * (x - z));
else
tmp = (x - z) * (y * t);
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[N[(N[(N[(x * y), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision], 4e+256], N[(t * N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x - z), $MachinePrecision] * N[(y * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(x \cdot y - y \cdot z\right) \cdot t \leq 4 \cdot 10^{+256}:\\
\;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\
\end{array}
\end{array}
if (*.f64 (-.f64 (*.f64 x y) (*.f64 z y)) t) < 4.0000000000000001e256Initial program 95.6%
distribute-rgt-out--95.6%
Simplified95.6%
if 4.0000000000000001e256 < (*.f64 (-.f64 (*.f64 x y) (*.f64 z y)) t) Initial program 82.7%
*-commutative82.7%
distribute-rgt-out--84.7%
associate-*r*99.9%
*-commutative99.9%
Simplified99.9%
Final simplification96.5%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (or (<= z -4700.0) (not (<= z 1.9e-51))) (* (* y z) (- t)) (* (* x y) t)))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4700.0) || !(z <= 1.9e-51)) {
tmp = (y * z) * -t;
} else {
tmp = (x * y) * t;
}
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 ((z <= (-4700.0d0)) .or. (.not. (z <= 1.9d-51))) then
tmp = (y * z) * -t
else
tmp = (x * y) * t
end if
code = tmp
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4700.0) || !(z <= 1.9e-51)) {
tmp = (y * z) * -t;
} else {
tmp = (x * y) * t;
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if (z <= -4700.0) or not (z <= 1.9e-51): tmp = (y * z) * -t else: tmp = (x * y) * t return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if ((z <= -4700.0) || !(z <= 1.9e-51)) tmp = Float64(Float64(y * z) * Float64(-t)); else tmp = Float64(Float64(x * y) * t); end return tmp end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((z <= -4700.0) || ~((z <= 1.9e-51)))
tmp = (y * z) * -t;
else
tmp = (x * y) * t;
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[z, -4700.0], N[Not[LessEqual[z, 1.9e-51]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-t)), $MachinePrecision], N[(N[(x * y), $MachinePrecision] * t), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4700 \lor \neg \left(z \leq 1.9 \cdot 10^{-51}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-t\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot y\right) \cdot t\\
\end{array}
\end{array}
if z < -4700 or 1.90000000000000001e-51 < z Initial program 90.3%
*-commutative90.3%
distribute-rgt-out--91.1%
associate-*r*90.4%
*-commutative90.4%
Simplified90.4%
Taylor expanded in x around 0 77.0%
mul-1-neg77.0%
distribute-rgt-neg-in77.0%
*-commutative77.0%
distribute-lft-neg-out77.0%
*-commutative77.0%
Simplified77.0%
if -4700 < z < 1.90000000000000001e-51Initial program 95.8%
*-commutative95.8%
distribute-rgt-out--95.8%
associate-*r*89.9%
*-commutative89.9%
Simplified89.9%
Taylor expanded in x around inf 78.5%
*-commutative78.5%
Simplified78.5%
Final simplification77.7%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= z 2.4e+237) (* (- x z) (* y t)) (* (* y z) (- t))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 2.4e+237) {
tmp = (x - z) * (y * t);
} else {
tmp = (y * z) * -t;
}
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 (z <= 2.4d+237) then
tmp = (x - z) * (y * t)
else
tmp = (y * z) * -t
end if
code = tmp
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 2.4e+237) {
tmp = (x - z) * (y * t);
} else {
tmp = (y * z) * -t;
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if z <= 2.4e+237: tmp = (x - z) * (y * t) else: tmp = (y * z) * -t return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if (z <= 2.4e+237) tmp = Float64(Float64(x - z) * Float64(y * t)); else tmp = Float64(Float64(y * z) * Float64(-t)); end return tmp end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (z <= 2.4e+237)
tmp = (x - z) * (y * t);
else
tmp = (y * z) * -t;
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[z, 2.4e+237], N[(N[(x - z), $MachinePrecision] * N[(y * t), $MachinePrecision]), $MachinePrecision], N[(N[(y * z), $MachinePrecision] * (-t)), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.4 \cdot 10^{+237}:\\
\;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-t\right)\\
\end{array}
\end{array}
if z < 2.3999999999999999e237Initial program 93.5%
*-commutative93.5%
distribute-rgt-out--93.5%
associate-*r*91.6%
*-commutative91.6%
Simplified91.6%
if 2.3999999999999999e237 < z Initial program 83.3%
*-commutative83.3%
distribute-rgt-out--89.2%
associate-*r*69.9%
*-commutative69.9%
Simplified69.9%
Taylor expanded in x around 0 89.2%
mul-1-neg89.2%
distribute-rgt-neg-in89.2%
*-commutative89.2%
distribute-lft-neg-out89.2%
*-commutative89.2%
Simplified89.2%
Final simplification91.4%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (* (* x y) t))
assert(y < t);
double code(double x, double y, double z, double t) {
return (x * y) * 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 = (x * y) * t
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
return (x * y) * t;
}
[y, t] = sort([y, t]) def code(x, y, z, t): return (x * y) * t
y, t = sort([y, t]) function code(x, y, z, t) return Float64(Float64(x * y) * t) end
y, t = num2cell(sort([y, t])){:}
function tmp = code(x, y, z, t)
tmp = (x * y) * t;
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(N[(x * y), $MachinePrecision] * t), $MachinePrecision]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\left(x \cdot y\right) \cdot t
\end{array}
Initial program 92.8%
*-commutative92.8%
distribute-rgt-out--93.2%
associate-*r*90.1%
*-commutative90.1%
Simplified90.1%
Taylor expanded in x around inf 48.9%
*-commutative48.9%
Simplified48.9%
Final simplification48.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 92.8%
*-commutative92.8%
distribute-rgt-out--93.2%
associate-*r*90.1%
*-commutative90.1%
Simplified90.1%
Taylor expanded in x around inf 48.9%
associate-*r*50.8%
*-commutative50.8%
Simplified50.8%
Final simplification50.8%
(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 2023290
(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))