
(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 -1.1e+48) (* (* 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.1e+48) {
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.1d+48)) 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.1e+48) {
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.1e+48: 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.1e+48) tmp = Float64(Float64(y * 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.1e+48)
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.1e+48], N[(N[(y * t), $MachinePrecision] * N[(x - z), $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.1 \cdot 10^{+48}:\\
\;\;\;\;\left(y \cdot t\right) \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\
\end{array}
\end{array}
if y < -1.1e48Initial program 81.1%
*-commutative81.1%
distribute-rgt-out--86.1%
associate-*r*96.8%
*-commutative96.8%
Simplified96.8%
if -1.1e48 < y Initial program 94.9%
distribute-rgt-out--94.9%
Simplified94.9%
Final simplification95.4%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= x -2.8e+77) (* t (* y x)) (if (<= x 4.2e+57) (* (* y t) (- z)) (* y (* t x)))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -2.8e+77) {
tmp = t * (y * x);
} else if (x <= 4.2e+57) {
tmp = (y * t) * -z;
} else {
tmp = y * (t * x);
}
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 <= (-2.8d+77)) then
tmp = t * (y * x)
else if (x <= 4.2d+57) then
tmp = (y * t) * -z
else
tmp = y * (t * x)
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 <= -2.8e+77) {
tmp = t * (y * x);
} else if (x <= 4.2e+57) {
tmp = (y * t) * -z;
} else {
tmp = y * (t * x);
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if x <= -2.8e+77: tmp = t * (y * x) elif x <= 4.2e+57: tmp = (y * t) * -z else: tmp = y * (t * x) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if (x <= -2.8e+77) tmp = Float64(t * Float64(y * x)); elseif (x <= 4.2e+57) tmp = Float64(Float64(y * t) * Float64(-z)); else tmp = Float64(y * Float64(t * x)); end return tmp end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (x <= -2.8e+77)
tmp = t * (y * x);
elseif (x <= 4.2e+57)
tmp = (y * t) * -z;
else
tmp = y * (t * x);
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[x, -2.8e+77], N[(t * N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.2e+57], N[(N[(y * t), $MachinePrecision] * (-z)), $MachinePrecision], N[(y * N[(t * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{+77}:\\
\;\;\;\;t \cdot \left(y \cdot x\right)\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{+57}:\\
\;\;\;\;\left(y \cdot t\right) \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(t \cdot x\right)\\
\end{array}
\end{array}
if x < -2.8e77Initial program 80.0%
distribute-rgt-out--83.6%
Simplified83.6%
Taylor expanded in x around inf 67.2%
if -2.8e77 < x < 4.19999999999999982e57Initial program 95.6%
*-commutative95.6%
distribute-rgt-out--95.7%
associate-*r*93.3%
*-commutative93.3%
Simplified93.3%
Taylor expanded in x around 0 76.0%
mul-1-neg76.0%
associate-*r*80.7%
distribute-rgt-neg-out80.7%
*-commutative80.7%
distribute-lft-neg-out80.7%
Simplified80.7%
if 4.19999999999999982e57 < x Initial program 93.0%
*-commutative93.0%
distribute-rgt-out--94.8%
associate-*r*91.0%
*-commutative91.0%
Simplified91.0%
Taylor expanded in x around inf 72.9%
Final simplification76.0%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= y -1.95e+46) (* y (* t x)) (* t (* y x))))
assert(y < t);
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.95e+46) {
tmp = y * (t * x);
} else {
tmp = t * (y * x);
}
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.95d+46)) then
tmp = y * (t * x)
else
tmp = t * (y * x)
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.95e+46) {
tmp = y * (t * x);
} else {
tmp = t * (y * x);
}
return tmp;
}
[y, t] = sort([y, t]) def code(x, y, z, t): tmp = 0 if y <= -1.95e+46: tmp = y * (t * x) else: tmp = t * (y * x) return tmp
y, t = sort([y, t]) function code(x, y, z, t) tmp = 0.0 if (y <= -1.95e+46) tmp = Float64(y * Float64(t * x)); else tmp = Float64(t * Float64(y * x)); end return tmp end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (y <= -1.95e+46)
tmp = y * (t * x);
else
tmp = t * (y * x);
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.95e+46], N[(y * N[(t * x), $MachinePrecision]), $MachinePrecision], N[(t * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{+46}:\\
\;\;\;\;y \cdot \left(t \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if y < -1.94999999999999997e46Initial program 81.1%
*-commutative81.1%
distribute-rgt-out--86.1%
associate-*r*96.8%
*-commutative96.8%
Simplified96.8%
Taylor expanded in x around inf 40.7%
if -1.94999999999999997e46 < y Initial program 94.9%
distribute-rgt-out--94.9%
Simplified94.9%
Taylor expanded in x around inf 53.9%
Final simplification50.7%
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(Float64(y * 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[(N[(y * t), $MachinePrecision] * N[(x - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\left(y \cdot t\right) \cdot \left(x - z\right)
\end{array}
Initial program 91.5%
*-commutative91.5%
distribute-rgt-out--92.8%
associate-*r*91.1%
*-commutative91.1%
Simplified91.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 (* (* y t) x))
assert(y < t);
double code(double x, double y, double z, double t) {
return (y * t) * 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 = (y * t) * x
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
return (y * t) * x;
}
[y, t] = sort([y, t]) def code(x, y, z, t): return (y * t) * x
y, t = sort([y, t]) function code(x, y, z, t) return Float64(Float64(y * t) * x) end
y, t = num2cell(sort([y, t])){:}
function tmp = code(x, y, z, t)
tmp = (y * t) * x;
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(N[(y * t), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\left(y \cdot t\right) \cdot x
\end{array}
Initial program 91.5%
*-commutative91.5%
distribute-rgt-out--92.8%
associate-*r*91.1%
*-commutative91.1%
Simplified91.1%
Taylor expanded in x around inf 48.5%
associate-*r*46.8%
*-commutative46.8%
Simplified46.8%
Final simplification46.8%
NOTE: y and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (* y (* t x)))
assert(y < t);
double code(double x, double y, double z, double t) {
return y * (t * 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 = y * (t * x)
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
return y * (t * x);
}
[y, t] = sort([y, t]) def code(x, y, z, t): return y * (t * x)
y, t = sort([y, t]) function code(x, y, z, t) return Float64(y * Float64(t * x)) end
y, t = num2cell(sort([y, t])){:}
function tmp = code(x, y, z, t)
tmp = y * (t * x);
end
NOTE: y and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(y * N[(t * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
y \cdot \left(t \cdot x\right)
\end{array}
Initial program 91.5%
*-commutative91.5%
distribute-rgt-out--92.8%
associate-*r*91.1%
*-commutative91.1%
Simplified91.1%
Taylor expanded in x around inf 48.5%
Final simplification48.5%
(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 2023268
(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))