
(FPCore (x y z t) :precision binary64 (/ (* x 2.0) (- (* y z) (* t z))))
double code(double x, double y, double z, double t) {
return (x * 2.0) / ((y * z) - (t * z));
}
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 * 2.0d0) / ((y * z) - (t * z))
end function
public static double code(double x, double y, double z, double t) {
return (x * 2.0) / ((y * z) - (t * z));
}
def code(x, y, z, t): return (x * 2.0) / ((y * z) - (t * z))
function code(x, y, z, t) return Float64(Float64(x * 2.0) / Float64(Float64(y * z) - Float64(t * z))) end
function tmp = code(x, y, z, t) tmp = (x * 2.0) / ((y * z) - (t * z)); end
code[x_, y_, z_, t_] := N[(N[(x * 2.0), $MachinePrecision] / N[(N[(y * z), $MachinePrecision] - N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (/ (* x 2.0) (- (* y z) (* t z))))
double code(double x, double y, double z, double t) {
return (x * 2.0) / ((y * z) - (t * z));
}
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 * 2.0d0) / ((y * z) - (t * z))
end function
public static double code(double x, double y, double z, double t) {
return (x * 2.0) / ((y * z) - (t * z));
}
def code(x, y, z, t): return (x * 2.0) / ((y * z) - (t * z))
function code(x, y, z, t) return Float64(Float64(x * 2.0) / Float64(Float64(y * z) - Float64(t * z))) end
function tmp = code(x, y, z, t) tmp = (x * 2.0) / ((y * z) - (t * z)); end
code[x_, y_, z_, t_] := N[(N[(x * 2.0), $MachinePrecision] / N[(N[(y * z), $MachinePrecision] - N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\end{array}
(FPCore (x y z t) :precision binary64 (* 2.0 (/ (/ x z) (- y t))))
double code(double x, double y, double z, double t) {
return 2.0 * ((x / 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 = 2.0d0 * ((x / z) / (y - t))
end function
public static double code(double x, double y, double z, double t) {
return 2.0 * ((x / z) / (y - t));
}
def code(x, y, z, t): return 2.0 * ((x / z) / (y - t))
function code(x, y, z, t) return Float64(2.0 * Float64(Float64(x / z) / Float64(y - t))) end
function tmp = code(x, y, z, t) tmp = 2.0 * ((x / z) / (y - t)); end
code[x_, y_, z_, t_] := N[(2.0 * N[(N[(x / z), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \frac{\frac{x}{z}}{y - t}
\end{array}
Initial program 90.6%
distribute-rgt-out--93.4%
Simplified93.4%
Taylor expanded in x around 0 93.3%
associate-/r*95.7%
Simplified95.7%
Final simplification95.7%
(FPCore (x y z t) :precision binary64 (if (or (<= t -1.3e-30) (not (<= t 5.8e-13))) (* -2.0 (/ x (* z t))) (* (/ 2.0 z) (/ x y))))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -1.3e-30) || !(t <= 5.8e-13)) {
tmp = -2.0 * (x / (z * t));
} else {
tmp = (2.0 / z) * (x / y);
}
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 <= (-1.3d-30)) .or. (.not. (t <= 5.8d-13))) then
tmp = (-2.0d0) * (x / (z * t))
else
tmp = (2.0d0 / z) * (x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -1.3e-30) || !(t <= 5.8e-13)) {
tmp = -2.0 * (x / (z * t));
} else {
tmp = (2.0 / z) * (x / y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t <= -1.3e-30) or not (t <= 5.8e-13): tmp = -2.0 * (x / (z * t)) else: tmp = (2.0 / z) * (x / y) return tmp
function code(x, y, z, t) tmp = 0.0 if ((t <= -1.3e-30) || !(t <= 5.8e-13)) tmp = Float64(-2.0 * Float64(x / Float64(z * t))); else tmp = Float64(Float64(2.0 / z) * Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((t <= -1.3e-30) || ~((t <= 5.8e-13))) tmp = -2.0 * (x / (z * t)); else tmp = (2.0 / z) * (x / y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -1.3e-30], N[Not[LessEqual[t, 5.8e-13]], $MachinePrecision]], N[(-2.0 * N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 / z), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.3 \cdot 10^{-30} \lor \neg \left(t \leq 5.8 \cdot 10^{-13}\right):\\
\;\;\;\;-2 \cdot \frac{x}{z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{z} \cdot \frac{x}{y}\\
\end{array}
\end{array}
if t < -1.29999999999999993e-30 or 5.7999999999999995e-13 < t Initial program 91.2%
distribute-rgt-out--95.7%
Simplified95.7%
Taylor expanded in y around 0 79.5%
*-commutative79.5%
Simplified79.5%
if -1.29999999999999993e-30 < t < 5.7999999999999995e-13Initial program 89.9%
distribute-rgt-out--90.7%
Simplified90.7%
*-commutative90.7%
times-frac92.0%
Applied egg-rr92.0%
Taylor expanded in y around inf 78.3%
Final simplification78.9%
(FPCore (x y z t) :precision binary64 (if (or (<= t -1.75e+34) (not (<= t 2.35e-14))) (* -2.0 (/ x (* z t))) (* (/ x z) (/ 2.0 y))))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -1.75e+34) || !(t <= 2.35e-14)) {
tmp = -2.0 * (x / (z * t));
} else {
tmp = (x / z) * (2.0 / y);
}
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 <= (-1.75d+34)) .or. (.not. (t <= 2.35d-14))) then
tmp = (-2.0d0) * (x / (z * t))
else
tmp = (x / z) * (2.0d0 / y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -1.75e+34) || !(t <= 2.35e-14)) {
tmp = -2.0 * (x / (z * t));
} else {
tmp = (x / z) * (2.0 / y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t <= -1.75e+34) or not (t <= 2.35e-14): tmp = -2.0 * (x / (z * t)) else: tmp = (x / z) * (2.0 / y) return tmp
function code(x, y, z, t) tmp = 0.0 if ((t <= -1.75e+34) || !(t <= 2.35e-14)) tmp = Float64(-2.0 * Float64(x / Float64(z * t))); else tmp = Float64(Float64(x / z) * Float64(2.0 / y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((t <= -1.75e+34) || ~((t <= 2.35e-14))) tmp = -2.0 * (x / (z * t)); else tmp = (x / z) * (2.0 / y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -1.75e+34], N[Not[LessEqual[t, 2.35e-14]], $MachinePrecision]], N[(-2.0 * N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] * N[(2.0 / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.75 \cdot 10^{+34} \lor \neg \left(t \leq 2.35 \cdot 10^{-14}\right):\\
\;\;\;\;-2 \cdot \frac{x}{z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} \cdot \frac{2}{y}\\
\end{array}
\end{array}
if t < -1.74999999999999999e34 or 2.3500000000000001e-14 < t Initial program 90.9%
distribute-rgt-out--95.9%
Simplified95.9%
Taylor expanded in y around 0 81.3%
*-commutative81.3%
Simplified81.3%
if -1.74999999999999999e34 < t < 2.3500000000000001e-14Initial program 90.4%
distribute-rgt-out--91.1%
Simplified91.1%
Taylor expanded in x around 0 91.1%
associate-/r*97.7%
Simplified97.7%
Taylor expanded in y around inf 73.9%
associate-*r/73.9%
times-frac79.7%
*-commutative79.7%
Simplified79.7%
Final simplification80.5%
(FPCore (x y z t) :precision binary64 (if (or (<= t -2.7e+33) (not (<= t 2.5e-16))) (* -2.0 (/ x (* z t))) (/ (* x (/ 2.0 z)) y)))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -2.7e+33) || !(t <= 2.5e-16)) {
tmp = -2.0 * (x / (z * t));
} else {
tmp = (x * (2.0 / z)) / y;
}
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 <= (-2.7d+33)) .or. (.not. (t <= 2.5d-16))) then
tmp = (-2.0d0) * (x / (z * t))
else
tmp = (x * (2.0d0 / z)) / y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -2.7e+33) || !(t <= 2.5e-16)) {
tmp = -2.0 * (x / (z * t));
} else {
tmp = (x * (2.0 / z)) / y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t <= -2.7e+33) or not (t <= 2.5e-16): tmp = -2.0 * (x / (z * t)) else: tmp = (x * (2.0 / z)) / y return tmp
function code(x, y, z, t) tmp = 0.0 if ((t <= -2.7e+33) || !(t <= 2.5e-16)) tmp = Float64(-2.0 * Float64(x / Float64(z * t))); else tmp = Float64(Float64(x * Float64(2.0 / z)) / y); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((t <= -2.7e+33) || ~((t <= 2.5e-16))) tmp = -2.0 * (x / (z * t)); else tmp = (x * (2.0 / z)) / y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -2.7e+33], N[Not[LessEqual[t, 2.5e-16]], $MachinePrecision]], N[(-2.0 * N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[(2.0 / z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.7 \cdot 10^{+33} \lor \neg \left(t \leq 2.5 \cdot 10^{-16}\right):\\
\;\;\;\;-2 \cdot \frac{x}{z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \frac{2}{z}}{y}\\
\end{array}
\end{array}
if t < -2.69999999999999991e33 or 2.5000000000000002e-16 < t Initial program 90.9%
distribute-rgt-out--95.9%
Simplified95.9%
Taylor expanded in y around 0 81.3%
*-commutative81.3%
Simplified81.3%
if -2.69999999999999991e33 < t < 2.5000000000000002e-16Initial program 90.4%
distribute-rgt-out--91.1%
Simplified91.1%
Taylor expanded in x around 0 91.1%
associate-/r*97.7%
Simplified97.7%
Taylor expanded in y around inf 73.9%
associate-*r/73.9%
times-frac79.7%
*-commutative79.7%
Simplified79.7%
associate-*r/79.8%
associate-*l/79.8%
associate-*r/79.8%
Applied egg-rr79.8%
Final simplification80.5%
(FPCore (x y z t) :precision binary64 (if (or (<= t -6.8e+33) (not (<= t 5e-12))) (* -2.0 (/ x (* z t))) (/ (/ x (* z 0.5)) y)))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -6.8e+33) || !(t <= 5e-12)) {
tmp = -2.0 * (x / (z * t));
} else {
tmp = (x / (z * 0.5)) / y;
}
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 <= (-6.8d+33)) .or. (.not. (t <= 5d-12))) then
tmp = (-2.0d0) * (x / (z * t))
else
tmp = (x / (z * 0.5d0)) / y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -6.8e+33) || !(t <= 5e-12)) {
tmp = -2.0 * (x / (z * t));
} else {
tmp = (x / (z * 0.5)) / y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t <= -6.8e+33) or not (t <= 5e-12): tmp = -2.0 * (x / (z * t)) else: tmp = (x / (z * 0.5)) / y return tmp
function code(x, y, z, t) tmp = 0.0 if ((t <= -6.8e+33) || !(t <= 5e-12)) tmp = Float64(-2.0 * Float64(x / Float64(z * t))); else tmp = Float64(Float64(x / Float64(z * 0.5)) / y); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((t <= -6.8e+33) || ~((t <= 5e-12))) tmp = -2.0 * (x / (z * t)); else tmp = (x / (z * 0.5)) / y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -6.8e+33], N[Not[LessEqual[t, 5e-12]], $MachinePrecision]], N[(-2.0 * N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / N[(z * 0.5), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -6.8 \cdot 10^{+33} \lor \neg \left(t \leq 5 \cdot 10^{-12}\right):\\
\;\;\;\;-2 \cdot \frac{x}{z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{z \cdot 0.5}}{y}\\
\end{array}
\end{array}
if t < -6.7999999999999999e33 or 4.9999999999999997e-12 < t Initial program 90.9%
distribute-rgt-out--95.9%
Simplified95.9%
Taylor expanded in y around 0 81.3%
*-commutative81.3%
Simplified81.3%
if -6.7999999999999999e33 < t < 4.9999999999999997e-12Initial program 90.4%
distribute-rgt-out--91.1%
Simplified91.1%
Taylor expanded in y around inf 73.9%
*-commutative73.9%
Simplified73.9%
associate-/r*79.8%
div-inv79.7%
associate-*r/79.7%
clear-num79.7%
un-div-inv79.7%
div-inv79.7%
metadata-eval79.7%
Applied egg-rr79.7%
associate-*r/79.8%
*-rgt-identity79.8%
Simplified79.8%
Final simplification80.6%
(FPCore (x y z t) :precision binary64 (* -2.0 (/ x (* z t))))
double code(double x, double y, double z, double t) {
return -2.0 * (x / (z * 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 = (-2.0d0) * (x / (z * t))
end function
public static double code(double x, double y, double z, double t) {
return -2.0 * (x / (z * t));
}
def code(x, y, z, t): return -2.0 * (x / (z * t))
function code(x, y, z, t) return Float64(-2.0 * Float64(x / Float64(z * t))) end
function tmp = code(x, y, z, t) tmp = -2.0 * (x / (z * t)); end
code[x_, y_, z_, t_] := N[(-2.0 * N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \frac{x}{z \cdot t}
\end{array}
Initial program 90.6%
distribute-rgt-out--93.4%
Simplified93.4%
Taylor expanded in y around 0 52.2%
*-commutative52.2%
Simplified52.2%
Final simplification52.2%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (/ x (* (- y t) z)) 2.0))
(t_2 (/ (* x 2.0) (- (* y z) (* t z)))))
(if (< t_2 -2.559141628295061e-13)
t_1
(if (< t_2 1.045027827330126e-269) (/ (* (/ x z) 2.0) (- y t)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = (x / ((y - t) * z)) * 2.0;
double t_2 = (x * 2.0) / ((y * z) - (t * z));
double tmp;
if (t_2 < -2.559141628295061e-13) {
tmp = t_1;
} else if (t_2 < 1.045027827330126e-269) {
tmp = ((x / z) * 2.0) / (y - t);
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = (x / ((y - t) * z)) * 2.0d0
t_2 = (x * 2.0d0) / ((y * z) - (t * z))
if (t_2 < (-2.559141628295061d-13)) then
tmp = t_1
else if (t_2 < 1.045027827330126d-269) then
tmp = ((x / z) * 2.0d0) / (y - t)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = (x / ((y - t) * z)) * 2.0;
double t_2 = (x * 2.0) / ((y * z) - (t * z));
double tmp;
if (t_2 < -2.559141628295061e-13) {
tmp = t_1;
} else if (t_2 < 1.045027827330126e-269) {
tmp = ((x / z) * 2.0) / (y - t);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = (x / ((y - t) * z)) * 2.0 t_2 = (x * 2.0) / ((y * z) - (t * z)) tmp = 0 if t_2 < -2.559141628295061e-13: tmp = t_1 elif t_2 < 1.045027827330126e-269: tmp = ((x / z) * 2.0) / (y - t) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(Float64(x / Float64(Float64(y - t) * z)) * 2.0) t_2 = Float64(Float64(x * 2.0) / Float64(Float64(y * z) - Float64(t * z))) tmp = 0.0 if (t_2 < -2.559141628295061e-13) tmp = t_1; elseif (t_2 < 1.045027827330126e-269) tmp = Float64(Float64(Float64(x / z) * 2.0) / Float64(y - t)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (x / ((y - t) * z)) * 2.0; t_2 = (x * 2.0) / ((y * z) - (t * z)); tmp = 0.0; if (t_2 < -2.559141628295061e-13) tmp = t_1; elseif (t_2 < 1.045027827330126e-269) tmp = ((x / z) * 2.0) / (y - t); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x / N[(N[(y - t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * 2.0), $MachinePrecision] / N[(N[(y * z), $MachinePrecision] - N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Less[t$95$2, -2.559141628295061e-13], t$95$1, If[Less[t$95$2, 1.045027827330126e-269], N[(N[(N[(x / z), $MachinePrecision] * 2.0), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{x}{\left(y - t\right) \cdot z} \cdot 2\\
t_2 := \frac{x \cdot 2}{y \cdot z - t \cdot z}\\
\mathbf{if}\;t\_2 < -2.559141628295061 \cdot 10^{-13}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 < 1.045027827330126 \cdot 10^{-269}:\\
\;\;\;\;\frac{\frac{x}{z} \cdot 2}{y - t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
herbie shell --seed 2024071
(FPCore (x y z t)
:name "Linear.Projection:infinitePerspective from linear-1.19.1.3, A"
:precision binary64
:alt
(if (< (/ (* x 2.0) (- (* y z) (* t z))) -2.559141628295061e-13) (* (/ x (* (- y t) z)) 2.0) (if (< (/ (* x 2.0) (- (* y z) (* t z))) 1.045027827330126e-269) (/ (* (/ x z) 2.0) (- y t)) (* (/ x (* (- y t) z)) 2.0)))
(/ (* x 2.0) (- (* y z) (* t z))))