
(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 6 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 -4e+79) (* y (* t (- x z))) (* t (- (* y x) (* y z)))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -4e+79) {
tmp = y * (t * (x - z));
} else {
tmp = t * ((y * x) - (y * 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 <= (-4d+79)) then
tmp = y * (t * (x - z))
else
tmp = t * ((y * x) - (y * 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 <= -4e+79) {
tmp = y * (t * (x - z));
} else {
tmp = t * ((y * x) - (y * z));
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if y <= -4e+79: tmp = y * (t * (x - z)) else: tmp = t * ((y * x) - (y * z)) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if (y <= -4e+79) tmp = Float64(y * Float64(t * Float64(x - z))); else tmp = Float64(t * Float64(Float64(y * x) - Float64(y * z))); end return tmp end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (y <= -4e+79)
tmp = y * (t * (x - z));
else
tmp = t * ((y * x) - (y * 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, -4e+79], N[(y * N[(t * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t * N[(N[(y * x), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+79}:\\
\;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(y \cdot x - y \cdot z\right)\\
\end{array}
\end{array}
if y < -3.99999999999999987e79Initial program 79.6%
*-commutative79.6%
distribute-rgt-out--81.7%
associate-*r*93.7%
*-commutative93.7%
Simplified93.7%
Taylor expanded in y around 0 97.7%
if -3.99999999999999987e79 < y Initial program 96.1%
Final simplification96.4%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (or (<= z -7.2e-28) (not (<= z 1.55e+99))) (* y (* t (- z))) (* x (* y t))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -7.2e-28) || !(z <= 1.55e+99)) {
tmp = y * (t * -z);
} 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 <= (-7.2d-28)) .or. (.not. (z <= 1.55d+99))) then
tmp = y * (t * -z)
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 <= -7.2e-28) || !(z <= 1.55e+99)) {
tmp = y * (t * -z);
} else {
tmp = x * (y * t);
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if (z <= -7.2e-28) or not (z <= 1.55e+99): tmp = y * (t * -z) else: tmp = x * (y * t) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if ((z <= -7.2e-28) || !(z <= 1.55e+99)) tmp = Float64(y * Float64(t * Float64(-z))); else tmp = Float64(x * 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 ((z <= -7.2e-28) || ~((z <= 1.55e+99)))
tmp = y * (t * -z);
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, -7.2e-28], N[Not[LessEqual[z, 1.55e+99]], $MachinePrecision]], N[(y * N[(t * (-z)), $MachinePrecision]), $MachinePrecision], N[(x * N[(y * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.2 \cdot 10^{-28} \lor \neg \left(z \leq 1.55 \cdot 10^{+99}\right):\\
\;\;\;\;y \cdot \left(t \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot t\right)\\
\end{array}
\end{array}
if z < -7.1999999999999997e-28 or 1.55e99 < z Initial program 93.0%
*-commutative93.0%
distribute-rgt-out--93.9%
associate-*r*94.5%
*-commutative94.5%
Simplified94.5%
Taylor expanded in x around 0 74.8%
mul-1-neg74.8%
distribute-rgt-neg-in74.8%
distribute-rgt-neg-out74.8%
Simplified74.8%
if -7.1999999999999997e-28 < z < 1.55e99Initial program 93.2%
*-commutative93.2%
distribute-rgt-out--93.2%
associate-*r*94.0%
*-commutative94.0%
Simplified94.0%
flip--73.1%
associate-*r/66.4%
Applied egg-rr66.4%
associate-/l*73.0%
associate-/l*74.6%
difference-of-squares74.6%
associate-/r*92.3%
*-inverses92.3%
Simplified92.3%
Taylor expanded in x around inf 79.3%
*-un-lft-identity79.3%
div-inv79.3%
times-frac81.6%
clear-num81.7%
/-rgt-identity81.7%
add-sqr-sqrt36.3%
sqrt-unprod38.2%
frac-times38.2%
metadata-eval38.2%
metadata-eval38.2%
frac-times38.2%
sqrt-unprod10.8%
add-sqr-sqrt14.8%
div-inv14.8%
add-sqr-sqrt10.8%
sqrt-unprod38.2%
frac-times38.2%
metadata-eval38.2%
metadata-eval38.2%
frac-times38.2%
sqrt-unprod36.2%
add-sqr-sqrt81.8%
remove-double-div81.8%
Applied egg-rr81.8%
Final simplification78.7%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= t 1e-5) (* y (* t (- x z))) (* (- x z) (* y t))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if (t <= 1e-5) {
tmp = y * (t * (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 (t <= 1d-5) then
tmp = y * (t * (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 (t <= 1e-5) {
tmp = y * (t * (x - z));
} else {
tmp = (x - z) * (y * t);
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if t <= 1e-5: tmp = y * (t * (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 (t <= 1e-5) tmp = Float64(y * Float64(t * 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 (t <= 1e-5)
tmp = y * (t * (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[t, 1e-5], N[(y * N[(t * 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}\;t \leq 10^{-5}:\\
\;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\
\end{array}
\end{array}
if t < 1.00000000000000008e-5Initial program 92.1%
*-commutative92.1%
distribute-rgt-out--92.1%
associate-*r*93.9%
*-commutative93.9%
Simplified93.9%
Taylor expanded in y around 0 90.7%
if 1.00000000000000008e-5 < t Initial program 96.4%
*-commutative96.4%
distribute-rgt-out--97.9%
associate-*r*95.4%
*-commutative95.4%
Simplified95.4%
Final simplification91.9%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= y -1.5e+78) (* y (* t (- x z))) (* t (* y (- x z)))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.5e+78) {
tmp = y * (t * (x - z));
} 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 <= (-1.5d+78)) then
tmp = y * (t * (x - z))
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 <= -1.5e+78) {
tmp = y * (t * (x - z));
} else {
tmp = t * (y * (x - z));
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if y <= -1.5e+78: tmp = y * (t * (x - z)) else: tmp = t * (y * (x - z)) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if (y <= -1.5e+78) tmp = Float64(y * Float64(t * Float64(x - z))); 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 <= -1.5e+78)
tmp = y * (t * (x - z));
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, -1.5e+78], N[(y * N[(t * N[(x - z), $MachinePrecision]), $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 -1.5 \cdot 10^{+78}:\\
\;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\
\end{array}
\end{array}
if y < -1.49999999999999991e78Initial program 80.0%
*-commutative80.0%
distribute-rgt-out--82.1%
associate-*r*93.8%
*-commutative93.8%
Simplified93.8%
Taylor expanded in y around 0 97.8%
if -1.49999999999999991e78 < y Initial program 96.1%
distribute-rgt-out--96.0%
Simplified96.0%
Final simplification96.4%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (* y (* t (- x z))))
assert(y < t);
double code(double x, double y, double z, double t) {
return y * (t * (x - z));
}
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 * (t * (x - z))
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
return y * (t * (x - z));
}
[y, t] = sort([y, t]) def code(x, y, z, t): return y * (t * (x - z))
y, t = sort([y, t]) function code(x, y, z, t) return Float64(y * Float64(t * Float64(x - z))) end
y, t = num2cell(sort([y, t])){:}
function tmp = code(x, y, z, t)
tmp = y * (t * (x - z));
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(y * N[(t * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
y \cdot \left(t \cdot \left(x - z\right)\right)
\end{array}
Initial program 93.1%
*-commutative93.1%
distribute-rgt-out--93.5%
associate-*r*94.2%
*-commutative94.2%
Simplified94.2%
Taylor expanded in y around 0 91.1%
Final simplification91.1%
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(x * Float64(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[(x * N[(y * t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
x \cdot \left(y \cdot t\right)
\end{array}
Initial program 93.1%
*-commutative93.1%
distribute-rgt-out--93.5%
associate-*r*94.2%
*-commutative94.2%
Simplified94.2%
flip--67.7%
associate-*r/62.0%
Applied egg-rr62.0%
associate-/l*67.7%
associate-/l*67.5%
difference-of-squares70.4%
associate-/r*91.1%
*-inverses91.1%
Simplified91.1%
Taylor expanded in x around inf 56.2%
*-un-lft-identity56.2%
div-inv56.1%
times-frac59.3%
clear-num59.4%
/-rgt-identity59.4%
add-sqr-sqrt27.1%
sqrt-unprod31.6%
frac-times31.5%
metadata-eval31.5%
metadata-eval31.5%
frac-times31.6%
sqrt-unprod9.8%
add-sqr-sqrt13.5%
div-inv13.5%
add-sqr-sqrt9.8%
sqrt-unprod31.5%
frac-times31.5%
metadata-eval31.5%
metadata-eval31.5%
frac-times31.5%
sqrt-unprod27.1%
add-sqr-sqrt59.4%
remove-double-div59.4%
Applied egg-rr59.4%
Final simplification59.4%
(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 2023274
(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))