
(FPCore (x y z) :precision binary64 (/ (- x y) (- z y)))
double code(double x, double y, double z) {
return (x - y) / (z - y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x - y) / (z - y)
end function
public static double code(double x, double y, double z) {
return (x - y) / (z - y);
}
def code(x, y, z): return (x - y) / (z - y)
function code(x, y, z) return Float64(Float64(x - y) / Float64(z - y)) end
function tmp = code(x, y, z) tmp = (x - y) / (z - y); end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z - y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (- x y) (- z y)))
double code(double x, double y, double z) {
return (x - y) / (z - y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x - y) / (z - y)
end function
public static double code(double x, double y, double z) {
return (x - y) / (z - y);
}
def code(x, y, z): return (x - y) / (z - y)
function code(x, y, z) return Float64(Float64(x - y) / Float64(z - y)) end
function tmp = code(x, y, z) tmp = (x - y) / (z - y); end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z - y}
\end{array}
(FPCore (x y z) :precision binary64 (- (/ x (- z y)) (/ y (- z y))))
double code(double x, double y, double z) {
return (x / (z - y)) - (y / (z - y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x / (z - y)) - (y / (z - y))
end function
public static double code(double x, double y, double z) {
return (x / (z - y)) - (y / (z - y));
}
def code(x, y, z): return (x / (z - y)) - (y / (z - y))
function code(x, y, z) return Float64(Float64(x / Float64(z - y)) - Float64(y / Float64(z - y))) end
function tmp = code(x, y, z) tmp = (x / (z - y)) - (y / (z - y)); end
code[x_, y_, z_] := N[(N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision] - N[(y / N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{z - y} - \frac{y}{z - y}
\end{array}
Initial program 100.0%
div-sub100.0%
Applied egg-rr100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ x (- z y))) (t_1 (/ y (- y z))))
(if (<= x -9.5e+45)
t_0
(if (<= x 2.8e-127)
t_1
(if (<= x 8.4e-88) (/ x z) (if (<= x 9.2e+34) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = x / (z - y);
double t_1 = y / (y - z);
double tmp;
if (x <= -9.5e+45) {
tmp = t_0;
} else if (x <= 2.8e-127) {
tmp = t_1;
} else if (x <= 8.4e-88) {
tmp = x / z;
} else if (x <= 9.2e+34) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x / (z - y)
t_1 = y / (y - z)
if (x <= (-9.5d+45)) then
tmp = t_0
else if (x <= 2.8d-127) then
tmp = t_1
else if (x <= 8.4d-88) then
tmp = x / z
else if (x <= 9.2d+34) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x / (z - y);
double t_1 = y / (y - z);
double tmp;
if (x <= -9.5e+45) {
tmp = t_0;
} else if (x <= 2.8e-127) {
tmp = t_1;
} else if (x <= 8.4e-88) {
tmp = x / z;
} else if (x <= 9.2e+34) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x / (z - y) t_1 = y / (y - z) tmp = 0 if x <= -9.5e+45: tmp = t_0 elif x <= 2.8e-127: tmp = t_1 elif x <= 8.4e-88: tmp = x / z elif x <= 9.2e+34: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x / Float64(z - y)) t_1 = Float64(y / Float64(y - z)) tmp = 0.0 if (x <= -9.5e+45) tmp = t_0; elseif (x <= 2.8e-127) tmp = t_1; elseif (x <= 8.4e-88) tmp = Float64(x / z); elseif (x <= 9.2e+34) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x / (z - y); t_1 = y / (y - z); tmp = 0.0; if (x <= -9.5e+45) tmp = t_0; elseif (x <= 2.8e-127) tmp = t_1; elseif (x <= 8.4e-88) tmp = x / z; elseif (x <= 9.2e+34) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -9.5e+45], t$95$0, If[LessEqual[x, 2.8e-127], t$95$1, If[LessEqual[x, 8.4e-88], N[(x / z), $MachinePrecision], If[LessEqual[x, 9.2e+34], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{z - y}\\
t_1 := \frac{y}{y - z}\\
\mathbf{if}\;x \leq -9.5 \cdot 10^{+45}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{-127}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 8.4 \cdot 10^{-88}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{elif}\;x \leq 9.2 \cdot 10^{+34}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -9.4999999999999998e45 or 9.1999999999999993e34 < x Initial program 100.0%
Taylor expanded in x around inf 85.4%
if -9.4999999999999998e45 < x < 2.8e-127 or 8.3999999999999998e-88 < x < 9.1999999999999993e34Initial program 99.9%
Taylor expanded in x around 0 81.9%
neg-mul-181.9%
distribute-neg-frac81.9%
Simplified81.9%
frac-2neg81.9%
div-inv81.7%
remove-double-neg81.7%
sub-neg81.7%
distribute-neg-in81.7%
remove-double-neg81.7%
Applied egg-rr81.7%
associate-*r/81.9%
*-rgt-identity81.9%
+-commutative81.9%
sub-neg81.9%
Simplified81.9%
if 2.8e-127 < x < 8.3999999999999998e-88Initial program 100.0%
Taylor expanded in y around 0 100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.4e+36) (not (<= y 8.5e-23))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.4e+36) || !(y <= 8.5e-23)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-2.4d+36)) .or. (.not. (y <= 8.5d-23))) then
tmp = 1.0d0 - (x / y)
else
tmp = x / (z - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.4e+36) || !(y <= 8.5e-23)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.4e+36) or not (y <= 8.5e-23): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.4e+36) || !(y <= 8.5e-23)) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x / Float64(z - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.4e+36) || ~((y <= 8.5e-23))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.4e+36], N[Not[LessEqual[y, 8.5e-23]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{+36} \lor \neg \left(y \leq 8.5 \cdot 10^{-23}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -2.39999999999999992e36 or 8.4999999999999996e-23 < y Initial program 99.9%
Taylor expanded in z around 0 72.1%
div-sub72.1%
sub-neg72.1%
*-inverses72.1%
metadata-eval72.1%
distribute-lft-in72.1%
metadata-eval72.1%
+-commutative72.1%
mul-1-neg72.1%
unsub-neg72.1%
Simplified72.1%
if -2.39999999999999992e36 < y < 8.4999999999999996e-23Initial program 100.0%
Taylor expanded in x around inf 79.1%
Final simplification75.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -5e-56) (not (<= y 4.8e-109))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5e-56) || !(y <= 4.8e-109)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-5d-56)) .or. (.not. (y <= 4.8d-109))) then
tmp = 1.0d0 - (x / y)
else
tmp = x / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5e-56) || !(y <= 4.8e-109)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5e-56) or not (y <= 4.8e-109): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5e-56) || !(y <= 4.8e-109)) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5e-56) || ~((y <= 4.8e-109))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5e-56], N[Not[LessEqual[y, 4.8e-109]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{-56} \lor \neg \left(y \leq 4.8 \cdot 10^{-109}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -4.99999999999999997e-56 or 4.79999999999999977e-109 < y Initial program 99.9%
Taylor expanded in z around 0 66.9%
div-sub67.0%
sub-neg67.0%
*-inverses67.0%
metadata-eval67.0%
distribute-lft-in67.0%
metadata-eval67.0%
+-commutative67.0%
mul-1-neg67.0%
unsub-neg67.0%
Simplified67.0%
if -4.99999999999999997e-56 < y < 4.79999999999999977e-109Initial program 100.0%
Taylor expanded in y around 0 77.0%
Final simplification70.3%
(FPCore (x y z) :precision binary64 (if (<= y -1.6e+39) 1.0 (if (<= y 5.8e-24) (/ x z) (+ 1.0 (/ z y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.6e+39) {
tmp = 1.0;
} else if (y <= 5.8e-24) {
tmp = x / z;
} else {
tmp = 1.0 + (z / y);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-1.6d+39)) then
tmp = 1.0d0
else if (y <= 5.8d-24) then
tmp = x / z
else
tmp = 1.0d0 + (z / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.6e+39) {
tmp = 1.0;
} else if (y <= 5.8e-24) {
tmp = x / z;
} else {
tmp = 1.0 + (z / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.6e+39: tmp = 1.0 elif y <= 5.8e-24: tmp = x / z else: tmp = 1.0 + (z / y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.6e+39) tmp = 1.0; elseif (y <= 5.8e-24) tmp = Float64(x / z); else tmp = Float64(1.0 + Float64(z / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.6e+39) tmp = 1.0; elseif (y <= 5.8e-24) tmp = x / z; else tmp = 1.0 + (z / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.6e+39], 1.0, If[LessEqual[y, 5.8e-24], N[(x / z), $MachinePrecision], N[(1.0 + N[(z / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{+39}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 5.8 \cdot 10^{-24}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{z}{y}\\
\end{array}
\end{array}
if y < -1.59999999999999996e39Initial program 99.9%
Taylor expanded in y around inf 61.3%
if -1.59999999999999996e39 < y < 5.7999999999999997e-24Initial program 100.0%
Taylor expanded in y around 0 64.2%
if 5.7999999999999997e-24 < y Initial program 100.0%
Taylor expanded in y around inf 69.9%
associate-+r-69.9%
distribute-lft-out--69.9%
div-sub69.9%
mul-1-neg69.9%
unsub-neg69.9%
Simplified69.9%
Taylor expanded in x around 0 49.1%
(FPCore (x y z) :precision binary64 (if (<= y -5.2e+37) 1.0 (if (<= y 2.8e-28) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e+37) {
tmp = 1.0;
} else if (y <= 2.8e-28) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-5.2d+37)) then
tmp = 1.0d0
else if (y <= 2.8d-28) then
tmp = x / z
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e+37) {
tmp = 1.0;
} else if (y <= 2.8e-28) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.2e+37: tmp = 1.0 elif y <= 2.8e-28: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.2e+37) tmp = 1.0; elseif (y <= 2.8e-28) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.2e+37) tmp = 1.0; elseif (y <= 2.8e-28) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.2e+37], 1.0, If[LessEqual[y, 2.8e-28], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{+37}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{-28}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -5.1999999999999998e37 or 2.7999999999999998e-28 < y Initial program 99.9%
Taylor expanded in y around inf 54.0%
if -5.1999999999999998e37 < y < 2.7999999999999998e-28Initial program 100.0%
Taylor expanded in y around 0 64.2%
(FPCore (x y z) :precision binary64 (/ (- x y) (- z y)))
double code(double x, double y, double z) {
return (x - y) / (z - y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x - y) / (z - y)
end function
public static double code(double x, double y, double z) {
return (x - y) / (z - y);
}
def code(x, y, z): return (x - y) / (z - y)
function code(x, y, z) return Float64(Float64(x - y) / Float64(z - y)) end
function tmp = code(x, y, z) tmp = (x - y) / (z - y); end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z - y}
\end{array}
Initial program 100.0%
(FPCore (x y z) :precision binary64 1.0)
double code(double x, double y, double z) {
return 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0
end function
public static double code(double x, double y, double z) {
return 1.0;
}
def code(x, y, z): return 1.0
function code(x, y, z) return 1.0 end
function tmp = code(x, y, z) tmp = 1.0; end
code[x_, y_, z_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Taylor expanded in y around inf 33.7%
(FPCore (x y z) :precision binary64 (- (/ x (- z y)) (/ y (- z y))))
double code(double x, double y, double z) {
return (x / (z - y)) - (y / (z - y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x / (z - y)) - (y / (z - y))
end function
public static double code(double x, double y, double z) {
return (x / (z - y)) - (y / (z - y));
}
def code(x, y, z): return (x / (z - y)) - (y / (z - y))
function code(x, y, z) return Float64(Float64(x / Float64(z - y)) - Float64(y / Float64(z - y))) end
function tmp = code(x, y, z) tmp = (x / (z - y)) - (y / (z - y)); end
code[x_, y_, z_] := N[(N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision] - N[(y / N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{z - y} - \frac{y}{z - y}
\end{array}
herbie shell --seed 2024085
(FPCore (x y z)
:name "Graphics.Rasterific.Shading:$sgradientColorAt from Rasterific-0.6.1"
:precision binary64
:alt
(- (/ x (- z y)) (/ y (- z y)))
(/ (- x y) (- z y)))