
(FPCore (x y) :precision binary64 (+ x (* (- 1.0 x) (- 1.0 y))))
double code(double x, double y) {
return x + ((1.0 - x) * (1.0 - y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + ((1.0d0 - x) * (1.0d0 - y))
end function
public static double code(double x, double y) {
return x + ((1.0 - x) * (1.0 - y));
}
def code(x, y): return x + ((1.0 - x) * (1.0 - y))
function code(x, y) return Float64(x + Float64(Float64(1.0 - x) * Float64(1.0 - y))) end
function tmp = code(x, y) tmp = x + ((1.0 - x) * (1.0 - y)); end
code[x_, y_] := N[(x + N[(N[(1.0 - x), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(1 - x\right) \cdot \left(1 - y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ x (* (- 1.0 x) (- 1.0 y))))
double code(double x, double y) {
return x + ((1.0 - x) * (1.0 - y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + ((1.0d0 - x) * (1.0d0 - y))
end function
public static double code(double x, double y) {
return x + ((1.0 - x) * (1.0 - y));
}
def code(x, y): return x + ((1.0 - x) * (1.0 - y))
function code(x, y) return Float64(x + Float64(Float64(1.0 - x) * Float64(1.0 - y))) end
function tmp = code(x, y) tmp = x + ((1.0 - x) * (1.0 - y)); end
code[x_, y_] := N[(x + N[(N[(1.0 - x), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(1 - x\right) \cdot \left(1 - y\right)
\end{array}
(FPCore (x y) :precision binary64 (fma x y (- 1.0 y)))
double code(double x, double y) {
return fma(x, y, (1.0 - y));
}
function code(x, y) return fma(x, y, Float64(1.0 - y)) end
code[x_, y_] := N[(x * y + N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, 1 - y\right)
\end{array}
Initial program 76.9%
sub-neg76.9%
distribute-rgt-in76.9%
*-lft-identity76.9%
associate-+r+87.0%
+-commutative87.0%
sub-neg87.0%
associate-+l+100.0%
neg-mul-1100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-*r*100.0%
neg-mul-1100.0%
mul0-lft100.0%
metadata-eval100.0%
sub-neg100.0%
distribute-rgt-in100.0%
*-lft-identity100.0%
associate-+r+100.0%
sub-neg100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -1.02e+23)
(- y)
(if (<= y -1.7e-28)
(* x y)
(if (<= y 2.2e-38) 1.0 (if (<= y 6.2e+200) (* x y) (- y))))))
double code(double x, double y) {
double tmp;
if (y <= -1.02e+23) {
tmp = -y;
} else if (y <= -1.7e-28) {
tmp = x * y;
} else if (y <= 2.2e-38) {
tmp = 1.0;
} else if (y <= 6.2e+200) {
tmp = x * y;
} else {
tmp = -y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.02d+23)) then
tmp = -y
else if (y <= (-1.7d-28)) then
tmp = x * y
else if (y <= 2.2d-38) then
tmp = 1.0d0
else if (y <= 6.2d+200) then
tmp = x * y
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.02e+23) {
tmp = -y;
} else if (y <= -1.7e-28) {
tmp = x * y;
} else if (y <= 2.2e-38) {
tmp = 1.0;
} else if (y <= 6.2e+200) {
tmp = x * y;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.02e+23: tmp = -y elif y <= -1.7e-28: tmp = x * y elif y <= 2.2e-38: tmp = 1.0 elif y <= 6.2e+200: tmp = x * y else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.02e+23) tmp = Float64(-y); elseif (y <= -1.7e-28) tmp = Float64(x * y); elseif (y <= 2.2e-38) tmp = 1.0; elseif (y <= 6.2e+200) tmp = Float64(x * y); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.02e+23) tmp = -y; elseif (y <= -1.7e-28) tmp = x * y; elseif (y <= 2.2e-38) tmp = 1.0; elseif (y <= 6.2e+200) tmp = x * y; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.02e+23], (-y), If[LessEqual[y, -1.7e-28], N[(x * y), $MachinePrecision], If[LessEqual[y, 2.2e-38], 1.0, If[LessEqual[y, 6.2e+200], N[(x * y), $MachinePrecision], (-y)]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.02 \cdot 10^{+23}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq -1.7 \cdot 10^{-28}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{-38}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{+200}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -1.02e23 or 6.19999999999999988e200 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
distribute-rgt-neg-in100.0%
sub-neg100.0%
distribute-neg-in100.0%
metadata-eval100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 66.7%
neg-mul-166.7%
Simplified66.7%
if -1.02e23 < y < -1.7e-28 or 2.20000000000000007e-38 < y < 6.19999999999999988e200Initial program 85.1%
Taylor expanded in x around inf 51.5%
mul-1-neg51.5%
unsub-neg51.5%
sub-neg51.5%
associate--r+64.9%
metadata-eval64.9%
neg-sub064.9%
remove-double-neg64.9%
Simplified64.9%
if -1.7e-28 < y < 2.20000000000000007e-38Initial program 53.3%
Taylor expanded in y around 0 82.1%
Final simplification72.8%
(FPCore (x y) :precision binary64 (if (or (<= y -1.8e-28) (not (<= y 8.6e-38))) (* y (+ x -1.0)) 1.0))
double code(double x, double y) {
double tmp;
if ((y <= -1.8e-28) || !(y <= 8.6e-38)) {
tmp = y * (x + -1.0);
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-1.8d-28)) .or. (.not. (y <= 8.6d-38))) then
tmp = y * (x + (-1.0d0))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.8e-28) || !(y <= 8.6e-38)) {
tmp = y * (x + -1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.8e-28) or not (y <= 8.6e-38): tmp = y * (x + -1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.8e-28) || !(y <= 8.6e-38)) tmp = Float64(y * Float64(x + -1.0)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.8e-28) || ~((y <= 8.6e-38))) tmp = y * (x + -1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.8e-28], N[Not[LessEqual[y, 8.6e-38]], $MachinePrecision]], N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{-28} \lor \neg \left(y \leq 8.6 \cdot 10^{-38}\right):\\
\;\;\;\;y \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.7999999999999999e-28 or 8.6000000000000004e-38 < y Initial program 94.0%
Taylor expanded in y around inf 96.6%
mul-1-neg96.6%
distribute-rgt-neg-in96.6%
sub-neg96.6%
distribute-neg-in96.6%
metadata-eval96.6%
remove-double-neg96.6%
Simplified96.6%
if -1.7999999999999999e-28 < y < 8.6000000000000004e-38Initial program 53.3%
Taylor expanded in y around 0 82.1%
Final simplification90.5%
(FPCore (x y) :precision binary64 (if (<= x -4.5e+51) (* x y) (if (<= x 2.05e+17) (- 1.0 y) (* x y))))
double code(double x, double y) {
double tmp;
if (x <= -4.5e+51) {
tmp = x * y;
} else if (x <= 2.05e+17) {
tmp = 1.0 - y;
} else {
tmp = x * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-4.5d+51)) then
tmp = x * y
else if (x <= 2.05d+17) then
tmp = 1.0d0 - y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4.5e+51) {
tmp = x * y;
} else if (x <= 2.05e+17) {
tmp = 1.0 - y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4.5e+51: tmp = x * y elif x <= 2.05e+17: tmp = 1.0 - y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -4.5e+51) tmp = Float64(x * y); elseif (x <= 2.05e+17) tmp = Float64(1.0 - y); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4.5e+51) tmp = x * y; elseif (x <= 2.05e+17) tmp = 1.0 - y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4.5e+51], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.05e+17], N[(1.0 - y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{+51}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.05 \cdot 10^{+17}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -4.5e51 or 2.05e17 < x Initial program 52.3%
Taylor expanded in x around inf 52.3%
mul-1-neg52.3%
unsub-neg52.3%
sub-neg52.3%
associate--r+75.7%
metadata-eval75.7%
neg-sub075.7%
remove-double-neg75.7%
Simplified75.7%
if -4.5e51 < x < 2.05e17Initial program 95.3%
Taylor expanded in x around 0 96.2%
Final simplification87.4%
(FPCore (x y) :precision binary64 (- (+ 1.0 (* x y)) y))
double code(double x, double y) {
return (1.0 + (x * y)) - y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 + (x * y)) - y
end function
public static double code(double x, double y) {
return (1.0 + (x * y)) - y;
}
def code(x, y): return (1.0 + (x * y)) - y
function code(x, y) return Float64(Float64(1.0 + Float64(x * y)) - y) end
function tmp = code(x, y) tmp = (1.0 + (x * y)) - y; end
code[x_, y_] := N[(N[(1.0 + N[(x * y), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\left(1 + x \cdot y\right) - y
\end{array}
Initial program 76.9%
Taylor expanded in x around -inf 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (- y) (if (<= y 1.0) 1.0 (- y))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = -y;
} else if (y <= 1.0) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.0d0)) then
tmp = -y
else if (y <= 1.0d0) then
tmp = 1.0d0
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = -y;
} else if (y <= 1.0) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = -y elif y <= 1.0: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(-y); elseif (y <= 1.0) tmp = 1.0; else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = -y; elseif (y <= 1.0) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], (-y), If[LessEqual[y, 1.0], 1.0, (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 99.6%
mul-1-neg99.6%
distribute-rgt-neg-in99.6%
sub-neg99.6%
distribute-neg-in99.6%
metadata-eval99.6%
remove-double-neg99.6%
Simplified99.6%
Taylor expanded in x around 0 56.2%
neg-mul-156.2%
Simplified56.2%
if -1 < y < 1Initial program 51.5%
Taylor expanded in y around 0 75.3%
Final simplification65.3%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 76.9%
Taylor expanded in y around 0 37.4%
Final simplification37.4%
(FPCore (x y) :precision binary64 (- (* y x) (- y 1.0)))
double code(double x, double y) {
return (y * x) - (y - 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * x) - (y - 1.0d0)
end function
public static double code(double x, double y) {
return (y * x) - (y - 1.0);
}
def code(x, y): return (y * x) - (y - 1.0)
function code(x, y) return Float64(Float64(y * x) - Float64(y - 1.0)) end
function tmp = code(x, y) tmp = (y * x) - (y - 1.0); end
code[x_, y_] := N[(N[(y * x), $MachinePrecision] - N[(y - 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x - \left(y - 1\right)
\end{array}
herbie shell --seed 2023240
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.Vectors:renderPlotVectors from Chart-1.5.3"
:precision binary64
:herbie-target
(- (* y x) (- y 1.0))
(+ x (* (- 1.0 x) (- 1.0 y))))